-
Notifications
You must be signed in to change notification settings - Fork 2
/
TASS_board.ino
154 lines (132 loc) · 4.3 KB
/
TASS_board.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* TASS - Board
*
* Hardware write functions
*
* Author: Matthew J. Wolf <matthew.wolf.hpsdr@speciosus.net>
* Date: 18-NOV-2018
*
* - Version 0.7-n4mtt
* = Added logic to restore the relays after a reset or power on.
* = Added function
* -= restore_relays()
*
* - Original author is John Ackermann, N8UR
*
* Copyright (c) 2016 John Ackermann
* Copyright (c) 2018 Matthew J. Wolf
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
void setup_board() {
// set configuration pins to input pullup
pinMode(14,INPUT_PULLUP);
pinMode(15,INPUT_PULLUP);
pinMode(16,INPUT_PULLUP);
pinMode(17,INPUT_PULLUP);
pinMode(18,INPUT_PULLUP);
pinMode(19,INPUT_PULLUP);
pinMode(22,INPUT_PULLUP);
// set up digital pins for each board
for (int relay_num=A_1;relay_num<=A_1+8;relay_num++){
pinMode(relay_num, OUTPUT);}
for (int relay_num=B_1;relay_num<=B_1+8;relay_num++){
pinMode(relay_num, OUTPUT);}
for (int relay_num=C_1;relay_num<=C_1+8;relay_num++){
pinMode(relay_num, OUTPUT);}
for (int relay_num=D_1;relay_num<=D_1+8;relay_num++){
pinMode(relay_num, OUTPUT);}
// Restore the relays from masks stored in EEPROM
#ifdef USE_EEPROM
// Board A
restore_relays(1,0,4);
// Board B
restore_relays(2,1,5);
// Board C
restore_relays(3,2,6);
// Board D
restore_relays(4,3,7);
#endif
} // setup_board()
void write_board(int first_io, byte cmd_mask,bool K9) {
int counter = first_io; // first relay
for (byte mask = 00000001; mask>0; mask <<= 1) { //iterate through bit mask
if (cmd_mask & mask) { // if bitwise AND resolves to true
digitalWrite(counter,HIGH);
} else {
digitalWrite(counter,LOW);
} // of if
counter++;
} // of for
#ifndef SPLIT
// set K9
if (K9) {
digitalWrite(first_io+8,HIGH);
} else {
digitalWrite(first_io+8,LOW);
} // if
#endif
} // of write_board
#ifdef USE_EEPROM
void restore_relays(int board, int s_mask_loc, int h_mask_loc) {
/* Test EEPROM values for the correct range.
*
* The EEPROM is empty (NAN) when the sketch is run
* on a microprocessor that had it's EEPROM
* erased. When a microprocessor is recycled there
* is no way of knowing what values are stored in
* the EEPROM. The tests are need because I am not
* aware of any way Arduino can directly initialize
* EEPROM values.
*/
int s_mask = -1;
int h_mask = -1;
int cmd_mask = -1;
int i = -1;
s_mask = EEPROM.read(s_mask_loc);
h_mask = EEPROM.read(h_mask_loc);
// Only if bits in the masks are nether all low or all high.
if ( ((s_mask != 0) || (s_mask != 255))
|| ((h_mask != 0) || (h_mask != 255)) ) {
cmd_mask = h_mask | s_mask;
switch (board) {
case 1:
H_mask_A = h_mask;
S_mask_A = s_mask;
write_board(A_1,cmd_mask,K9);
break;
case 2:
H_mask_B = h_mask;
S_mask_B = s_mask;
write_board(B_1,cmd_mask,K9);
break;
case 3:
H_mask_C = h_mask;
S_mask_C = s_mask;
write_board(C_1,cmd_mask,K9);
break;
case 4:
H_mask_D = h_mask;
S_mask_D = s_mask;
write_board(D_1,cmd_mask,K9);
break;
}
}
}
#endif