-
Notifications
You must be signed in to change notification settings - Fork 2
/
TASS_mask.ino
158 lines (151 loc) · 3.8 KB
/
TASS_mask.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
155
156
157
158
/* TASS - Mask
*
* Bytemask Manipulation Functions
*
* Author: Matthew J. Wolf <[email protected]>
* Date: 12-NOV-2018
*
* - Version 0.7-n4mtt
* = Added function get_bit_mask_state()
*
* - 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.
*/
byte set_mask(int x, byte mask) {
switch (x) {
case 1: mask |= 0x01; break;
case 2: mask |= 0x02; break;
case 3: mask |= 0x04; break;
case 4: mask |= 0x08; break;
case 5: mask |= 0x10; break;
case 6: mask |= 0x20; break;
case 7: mask |= 0x40; break;
case 8: mask |= 0x80; break;
}
return mask;
} // of set_mask
byte clear_mask_top(byte mask) {
mask = mask & 0xF0;
return mask;
}
byte clear_mask_bottom(byte mask) {
mask = mask & 0x0F;
return mask;
}
byte clear_mask(byte mask) {
mask = mask & 0x00;
return mask;
}
byte clear_S_mask(int relay,byte mask) {
#ifdef SPLIT
if (relay >=1 && relay <=4) {
mask = clear_mask_top(mask);
} else {
mask = clear_mask_bottom(mask);
} // if
#else
mask = clear_mask(mask);
#endif
return mask;
}
int get_bit_mask_state(int relay, byte mask) {
int temp = -1;
switch(relay){
case 0:
temp = mask & 0x01;
if (temp == 0x01) {
return (1);
}
else {
return(0);
}
break;
case 1:
temp = mask & 0x02;
if (temp == 0x02) {
return (1);
}
else {
return(0);
}
break;
case 2:
temp = mask & 0x04;
if (temp == 0x04) {
return (1);
}
else {
return(0);
}
break;
case 3:
temp = mask & 0x08;
if (temp == 0x08) {
return (1);
}
else {
return(0);
}
break;
case 4:
temp = mask & 0x10;
if (temp == 0x10) {
return (1);
}
else {
return(0);
}
break;
case 5:
temp = mask & 0x20;
if (temp == 0x20) {
return (1);
}
else {
return(0);
}
break;
case 6:
temp = mask & 0x40;
if (temp == 0x40) {
return (1);
}
else {
return(0);
}
break;
case 7:
temp = mask & 0x80;
if (temp == 0x80) {
return (1);
}
else {
return(0);
}
break;
default:
return (0);
break;
}
}