AGirs
GirsUtils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "LedLcdManager.h" // for led_t
4 #include <MultiDecoder.h> // for MultiDecoder::Type
5 #include <IPAddress.h>
6 #include "defineMissingStuff.h"
7 
8 class GirsUtils {
9 private:
10  GirsUtils();
11 
12 public:
13  static unsigned long freeRam();
14  static void reset();
15 
16  // TODO: where should this go?
17  static led_t decode2logicalLed(MultiDecoder::Type type) {
18  return (led_t) ((int) type - 1);
19  }
20 
21  static void printVariable(Stream& stream, const char *variableName, unsigned long value) {
22  stream.print(variableName);
23  stream.print("=");
24  stream.println(value);
25  }
26 
27  static pin_t receiverPin(uint8_t receiverNo UNUSED) {
28 
29 #ifdef IRRECEIVER_1_PIN
30  if (receiverNo == 1)
31  return IRRECEIVER_1_PIN;
32 #endif
33 
34 #ifdef IRRECEIVER_2_PIN
35  if (receiverNo == 2)
36  return IRRECEIVER_2_PIN;
37 #endif
38 
39 #ifdef IRRECEIVER_3_PIN
40  if (receiverNo == 3)
41  return IRRECEIVER_3_PIN;
42 #endif
43 
44 #ifdef IRRECEIVER_4_PIN
45  if (receiverNo == 4)
46  return IRRECEIVER_4_PIN;
47 #endif
48 
49 #ifdef IRRECEIVER_5_PIN
50  if (receiverNo == 5)
51  return IRRECEIVER_5_PIN;
52 #endif
53 
54 #ifdef IRRECEIVER_6_PIN
55  if (receiverNo == 6)
56  return IRRECEIVER_6_PIN;
57 #endif
58 
59 #ifdef IRRECEIVER_7_PIN
60  if (receiverNo == 7)
61  return IRRECEIVER_7_PIN;
62 #endif
63 
64 #ifdef IRRECEIVER_8_PIN
65  if (receiverNo == 8)
66  return IRRECEIVER_8_PIN;
67 #endif
68  return invalidPin;
69  }
70 
71  static bool receiverPullup(uint8_t receiverNo UNUSED) {
72 
73 #ifdef IRRECEIVER_1_PIN
74  if (receiverNo == 1)
76 #endif
77 
78 #ifdef IRRECEIVER_2_PIN
79  if (receiverNo == 2)
81 #endif
82 
83 #ifdef IRRECEIVER_3_PIN
84  if (receiverNo == 3)
86 #endif
87 
88 #ifdef IRRECEIVER_4_PIN
89  if (receiverNo == 4)
91 #endif
92 
93 #ifdef IRRECEIVER_5_PIN
94  if (receiverNo == 5)
96 #endif
97 
98 #ifdef IRRECEIVER_6_PIN
99  if (receiverNo == 6)
101 #endif
102 
103 #ifdef IRRECEIVER_7_PIN
104  if (receiverNo == 7)
106 #endif
107 
108 #ifdef IRRECEIVER_8_PIN
109  if (receiverNo == 8)
111 #endif
112  return false;
113  }
114 
115  static void setupLeds() {
116 #ifdef SIGNAL_LED_1_GND
117  pinMode(SIGNAL_LED_1_GND, OUTPUT);
118  digitalWrite(SIGNAL_LED_1_GND, LOW);
119 #endif
120 
121 #ifdef SIGNAL_LED_2_GND
122  pinMode(SIGNAL_LED_2_GND, OUTPUT);
123  digitalWrite(SIGNAL_LED_2_GND, LOW);
124 #endif
125 
126 #ifdef SIGNAL_LED_3_GND
127  pinMode(SIGNAL_LED_3_GND, OUTPUT);
128  digitalWrite(SIGNAL_LED_3_GND, LOW);
129 #endif
130 
131 #ifdef SIGNAL_LED_4_GND
132  pinMode(SIGNAL_LED_4_GND, OUTPUT);
133  digitalWrite(SIGNAL_LED_4_GND, LOW);
134 #endif
135 
136 #ifdef SIGNAL_LED_5_GND
137  pinMode(SIGNAL_LED_5_GND, OUTPUT);
138  digitalWrite(SIGNAL_LED_5_GND, LOW);
139 #endif
140 
141 #ifdef SIGNAL_LED_6_GND
142  pinMode(SIGNAL_LED_6_GND, OUTPUT);
143  digitalWrite(SIGNAL_LED_6_GND, LOW);
144 #endif
145 
146 #ifdef SIGNAL_LED_7_GND
147  pinMode(SIGNAL_LED_7_GND, OUTPUT);
148  digitalWrite(SIGNAL_LED_7_GND, LOW);
149 #endif
150 
151 #ifdef SIGNAL_LED_8_GND
152  pinMode(SIGNAL_LED_8_GND, OUTPUT);
153  digitalWrite(SIGNAL_LED_8_GND, LOW);
154 #endif
155  }
156 
157  static void setupReceivers() {
158 #ifdef IRRECEIVER_1_GND
159  pinMode(IRRECEIVER_1_GND, OUTPUT);
160  digitalWrite(IRRECEIVER_1_GND, LOW);
161 #endif
162 
163 #ifdef IRRECEIVER_2_GND
164  pinMode(IRRECEIVER_2_GND, OUTPUT);
165  digitalWrite(IRRECEIVER_2_GND, LOW);
166 #endif
167 
168 #ifdef IRRECEIVER_3_GND
169  pinMode(IRRECEIVER_3_GND, OUTPUT);
170  digitalWrite(IRRECEIVER_3_GND, LOW);
171 #endif
172 
173 #ifdef IRRECEIVER_4_GND
174  pinMode(IRRECEIVER_4_GND, OUTPUT);
175  digitalWrite(IRRECEIVER_4_GND, LOW);
176 #endif
177 
178 #ifdef IRRECEIVER_5_GND
179  pinMode(IRRECEIVER_5_GND, OUTPUT);
180  digitalWrite(IRRECEIVER_5_GND, LOW);
181 #endif
182 
183 #ifdef IRRECEIVER_6_GND
184  pinMode(IRRECEIVER_6_GND, OUTPUT);
185  digitalWrite(IRRECEIVER_6_GND, LOW);
186 #endif
187 
188 #ifdef IRRECEIVER_7_GND
189  pinMode(IRRECEIVER_7_GND, OUTPUT);
190  digitalWrite(IRRECEIVER_7_GND, LOW);
191 #endif
192 
193 #ifdef IRRECEIVER_8_GND
194  pinMode(IRRECEIVER_8_GND, OUTPUT);
195  digitalWrite(IRRECEIVER_8_GND, LOW);
196 #endif
197 
198 #ifdef IRRECEIVER_1_VCC
199  pinMode(IRRECEIVER_1_VCC, OUTPUT);
200  digitalWrite(IRRECEIVER_1_VCC, HIGH);
201 #endif
202 
203 #ifdef IRRECEIVER_2_VCC
204  pinMode(IRRECEIVER_2_VCC, OUTPUT);
205  digitalWrite(IRRECEIVER_2_VCC, HIGH);
206 #endif
207 
208 #ifdef IRRECEIVER_3_VCC
209  pinMode(IRRECEIVER_3_VCC, OUTPUT);
210  digitalWrite(IRRECEIVER_3_VCC, HIGH);
211 #endif
212 
213 #ifdef IRRECEIVER_4_VCC
214  pinMode(IRRECEIVER_4_VCC, OUTPUT);
215  digitalWrite(IRRECEIVER_4_VCC, HIGH);
216 #endif
217 
218 #ifdef IRRECEIVER_5_VCC
219  pinMode(IRRECEIVER_5_VCC, OUTPUT);
220  digitalWrite(IRRECEIVER_5_VCC, HIGH);
221 #endif
222 
223 #ifdef IRRECEIVER_6_VCC
224  pinMode(IRRECEIVER_6_VCC, OUTPUT);
225  digitalWrite(IRRECEIVER_6_VCC, HIGH);
226 #endif
227 
228 #ifdef IRRECEIVER_7_VCC
229  pinMode(IRRECEIVER_7_VCC, OUTPUT);
230  digitalWrite(IRRECEIVER_7_VCC, HIGH);
231 #endif
232 
233 #ifdef IRRECEIVER_8_VCC
234  pinMode(IRRECEIVER_8_VCC, OUTPUT);
235  digitalWrite(IRRECEIVER_8_VCC, HIGH);
236 #endif
237  }
238 
239  static void setupSensors() {
240 #ifdef IRSENSOR_1_GND
241  pinMode(IRSENSOR_1_GND, OUTPUT);
242  digitalWrite(IRSENSOR_1_GND, LOW);
243 #endif
244 
245 #ifdef IRSENSOR_2_GND
246  pinMode(IRSENSOR_2_GND, OUTPUT);
247  digitalWrite(IRSENSOR_2_GND, LOW);
248 #endif
249 
250 #ifdef IRSENSOR_3_GND
251  pinMode(IRSENSOR_3_GND, OUTPUT);
252  digitalWrite(IRSENSOR_3_GND, LOW);
253 #endif
254 
255 #ifdef IRSENSOR_4_GND
256  pinMode(IRSENSOR_4_GND, OUTPUT);
257  digitalWrite(IRSENSOR_4_GND, LOW);
258 #endif
259 
260 #ifdef IRSENSOR_5_GND
261  pinMode(IRSENSOR_5_GND, OUTPUT);
262  digitalWrite(IRSENSOR_5_GND, LOW);
263 #endif
264 
265 #ifdef IRSENSOR_6_GND
266  pinMode(IRSENSOR_6_GND, OUTPUT);
267  digitalWrite(IRSENSOR_6_GND, LOW);
268 #endif
269 
270 #ifdef IRSENSOR_7_GND
271  pinMode(IRSENSOR_7_GND, OUTPUT);
272  digitalWrite(IRSENSOR_7_GND, LOW);
273 #endif
274 
275 #ifdef IRSENSOR_8_GND
276  pinMode(IRSENSOR_8_GND, OUTPUT);
277  digitalWrite(IRSENSOR_8_GND, LOW);
278 #endif
279 
280 #ifdef IRSENSOR_1_VCC
281  pinMode(IRSENSOR_1_VCC, OUTPUT);
282  digitalWrite(IRSENSOR_1_VCC, HIGH);
283 #endif
284 
285 #ifdef IRSENSOR_2_VCC
286  pinMode(IRSENSOR_2_VCC, OUTPUT);
287  digitalWrite(IRSENSOR_2_VCC, HIGH);
288 #endif
289 
290 #ifdef IRSENSOR_3_VCC
291  pinMode(IRSENSOR_3_VCC, OUTPUT);
292  digitalWrite(IRSENSOR_3_VCC, HIGH);
293 #endif
294 
295 #ifdef IRSENSOR_4_VCC
296  pinMode(IRSENSOR_4_VCC, OUTPUT);
297  digitalWrite(IRSENSOR_4_VCC, HIGH);
298 #endif
299 
300 #ifdef IRSENSOR_5_VCC
301  pinMode(IRSENSOR_5_VCC, OUTPUT);
302  digitalWrite(IRSENSOR_5_VCC, HIGH);
303 #endif
304 
305 #ifdef IRSENSOR_6_VCC
306  pinMode(IRSENSOR_6_VCC, OUTPUT);
307  digitalWrite(IRSENSOR_6_VCC, HIGH);
308 #endif
309 
310 #ifdef IRSENSOR_7_VCC
311  pinMode(IRSENSOR_7_VCC, OUTPUT);
312  digitalWrite(IRSENSOR_7_VCC, HIGH);
313 #endif
314 
315 #ifdef IRSENSOR_8_VCC
316  pinMode(IRSENSOR_8_VCC, OUTPUT);
317  digitalWrite(IRSENSOR_8_VCC, HIGH);
318 #endif
319  }
320 
321  static bool sensorPullup(uint8_t sensorNo UNUSED) {
322 
323 #ifdef IRSENSOR_1_PIN
324  if (sensorNo == 1)
326 #endif
327 
328 #ifdef IRSENSOR_2_PIN
329  if (sensorNo == 2)
331 #endif
332 
333 #ifdef IRSENSOR_3_PIN
334  if (sensorNo == 3)
336 #endif
337 
338 #ifdef IRSENSOR_4_PIN
339  if (sensorNo == 4)
341 #endif
342 
343 #ifdef IRSENSOR_5_PIN
344  if (sensorNo == 5)
346 #endif
347 
348 #ifdef IRSENSOR_6_PIN
349  if (sensorNo == 6)
351 #endif
352 
353 #ifdef IRSENSOR_7_PIN
354  if (sensorNo == 7)
356 #endif
357 
358 #ifdef IRSENSOR_8_PIN
359  if (sensorNo == 8)
361 #endif
362  return false;
363  }
364 
365 #ifndef NON_MOD_PIN
366 #define NON_MOD_PIN invalidPin
367 #endif
368 };
static const uint8_t receiverNo
Definition: Girs.cpp:131
static const unsigned sensorNo
Definition: Girs.cpp:117
uint8_t led_t
Definition: LedLcdManager.h:9
static void printVariable(Stream &stream, const char *variableName, unsigned long value)
Definition: GirsUtils.h:21
static bool sensorPullup(uint8_t sensorNo UNUSED)
Definition: GirsUtils.h:321
static void setupLeds()
Definition: GirsUtils.h:115
static unsigned long freeRam()
Definition: GirsUtils.cpp:5
static void setupSensors()
Definition: GirsUtils.h:239
static pin_t receiverPin(uint8_t receiverNo UNUSED)
Definition: GirsUtils.h:27
static bool receiverPullup(uint8_t receiverNo UNUSED)
Definition: GirsUtils.h:71
static void setupReceivers()
Definition: GirsUtils.h:157
static void reset()
Definition: GirsUtils.cpp:17
static led_t decode2logicalLed(MultiDecoder::Type type)
Definition: GirsUtils.h:17
#define IRSENSOR_4_PULLUP_VALUE
#define IRSENSOR_1_PULLUP_VALUE
#define IRRECEIVER_3_PULLUP_VALUE
#define IRRECEIVER_5_PULLUP_VALUE
#define IRSENSOR_5_PULLUP_VALUE
#define IRSENSOR_3_PULLUP_VALUE
#define IRSENSOR_6_PULLUP_VALUE
#define IRSENSOR_2_PULLUP_VALUE
#define IRSENSOR_8_PULLUP_VALUE
#define IRRECEIVER_8_PULLUP_VALUE
#define IRSENSOR_7_PULLUP_VALUE
#define IRRECEIVER_6_PULLUP_VALUE
#define IRRECEIVER_7_PULLUP_VALUE
#define IRRECEIVER_2_PULLUP_VALUE
#define UNUSED
#define IRRECEIVER_4_PULLUP_VALUE
#define IRRECEIVER_1_PULLUP_VALUE
#define IRRECEIVER_2_PIN
#define IRRECEIVER_1_PIN
#define IRRECEIVER_3_PIN
#define IRRECEIVER_4_PIN
#define SIGNAL_LED_7_GND
#define SIGNAL_LED_8_GND
#define SIGNAL_LED_5_GND
#define IRRECEIVER_5_PIN
#define SIGNAL_LED_6_GND
#define IRRECEIVER_1_GND
#define IRRECEIVER_1_VCC
#define SIGNAL_LED_3_GND
#define IRSENSOR_1_GND
#define IRSENSOR_1_VCC
#define SIGNAL_LED_4_GND
#define SIGNAL_LED_2_GND