14
14
#include " utility/PinChangeInt.h"
15
15
16
16
17
- uint8_t pinRx;
18
- uint8_t pinTx;
19
- uint8_t pinEr;
17
+ int8_t pinRx;
18
+ int8_t pinTx;
19
+ int8_t pinEr;
20
20
boolean buttonTriggeredInclusion;
21
21
volatile uint8_t countRx;
22
22
volatile uint8_t countTx;
23
23
volatile uint8_t countErr;
24
24
boolean inclusionMode; // Keeps track on inclusion mode
25
25
26
+ #define LED_ON (LOW)
27
+ #define LED_OFF (HIGH)
26
28
27
- MyGateway::MyGateway (uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time, uint8_t _inclusion_pin, uint8_t _rx, uint8_t _tx, uint8_t _er) : MySensor(_cepin, _cspin) {
29
+
30
+ MyGateway::MyGateway (uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time, int8_t _inclusion_pin, int8_t _rx, int8_t _tx, int8_t _er) : MySensor(_cepin, _cspin) {
28
31
pinInclusion = _inclusion_pin;
29
32
inclusionTime = _inclusion_time;
30
33
pinRx = _rx;
@@ -56,23 +59,29 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
56
59
countTx = 0 ;
57
60
countErr = 0 ;
58
61
59
- // Setup led pins
60
- pinMode (pinRx, OUTPUT);
61
- pinMode (pinTx, OUTPUT);
62
- pinMode (pinEr, OUTPUT);
63
- digitalWrite (pinRx, LOW);
64
- digitalWrite (pinTx, LOW);
65
- digitalWrite (pinEr, LOW);
66
-
62
+ // Setup led pins & set initial state of leds
63
+ if (pinRx >= 0 )
64
+ {
65
+ digitalWrite (pinRx, LED_OFF);
66
+ pinMode (pinRx, OUTPUT);
67
+ }
68
+ if (pinTx >= 0 )
69
+ {
70
+ digitalWrite (pinTx, LED_OFF);
71
+ pinMode (pinTx, OUTPUT);
72
+ }
73
+ if (pinEr >= 0 )
74
+ {
75
+ digitalWrite (pinEr, LED_OFF);
76
+ pinMode (pinEr, OUTPUT);
77
+ }
67
78
// Setup digital in that triggers inclusion mode
68
- pinMode (pinInclusion, INPUT);
69
- digitalWrite (pinInclusion, HIGH);
70
-
71
- // Set initial state of leds
72
- digitalWrite (pinRx, HIGH);
73
- digitalWrite (pinTx, HIGH);
74
- digitalWrite (pinEr, HIGH);
75
-
79
+ if (pinInclusion >= 0 )
80
+ {
81
+ pinMode (pinInclusion, INPUT);
82
+ // Add interrupt for inclusion button to pin
83
+ PCintPort::attachInterrupt (pinInclusion, startInclusionInterrupt, RISING);
84
+ }
76
85
77
86
// Start up the radio library
78
87
setupRadio (paLevel, channel, dataRate);
@@ -84,9 +93,6 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
84
93
MsTimer2::set (300 , ledTimersInterrupt);
85
94
MsTimer2::start ();
86
95
87
- // Add interrupt for inclusion button to pin
88
- PCintPort::attachInterrupt (pinInclusion, startInclusionInterrupt, RISING);
89
-
90
96
// Send startup log message on serial
91
97
serial (PSTR (" 0;0;%d;0;%d;Gateway startup complete.\n " ), C_INTERNAL, I_GATEWAY_READY);
92
98
}
@@ -257,34 +263,42 @@ void MyGateway::serial(MyMessage &msg) {
257
263
258
264
259
265
void ledTimersInterrupt () {
260
- if (countRx && countRx != 255 ) {
261
- // switch led on
262
- digitalWrite (pinRx, LOW);
263
- } else if (!countRx) {
264
- // switching off
265
- digitalWrite (pinRx, HIGH);
266
- }
267
- if (countRx != 255 ) { countRx--; }
268
-
269
- if (countTx && countTx != 255 ) {
270
- // switch led on
271
- digitalWrite (pinTx, LOW);
272
- } else if (!countTx) {
273
- // switching off
274
- digitalWrite (pinTx, HIGH);
275
- }
276
- if (countTx != 255 ) { countTx--; }
277
- else if (inclusionMode) { countTx = 8 ; }
278
-
279
- if (countErr && countErr != 255 ) {
280
- // switch led on
281
- digitalWrite (pinEr, LOW);
282
- } else if (!countErr) {
283
- // switching off
284
- digitalWrite (pinEr, HIGH);
285
- }
286
- if (countErr != 255 ) { countErr--; }
287
-
266
+ if (pinRx >= 0 )
267
+ {
268
+ if (countRx && countRx != 255 ) {
269
+ // switch led on
270
+ digitalWrite (pinRx, LED_ON);
271
+ } else if (!countRx) {
272
+ // switching off
273
+ digitalWrite (pinRx, LED_OFF);
274
+ }
275
+ }
276
+ if (countRx != 255 ) { countRx--; }
277
+
278
+ if (pinTx >= 0 )
279
+ {
280
+ if (countTx && countTx != 255 ) {
281
+ // switch led on
282
+ digitalWrite (pinTx, LED_ON);
283
+ } else if (!countTx) {
284
+ // switching off
285
+ digitalWrite (pinTx, LED_OFF);
286
+ }
287
+ }
288
+ if (countTx != 255 ) { countTx--; }
289
+ else if (inclusionMode) { countTx = 8 ; }
290
+
291
+ if (pinEr >= 0 )
292
+ {
293
+ if (countErr && countErr != 255 ) {
294
+ // switch led on
295
+ digitalWrite (pinEr, LED_ON);
296
+ } else if (!countErr) {
297
+ // switching off
298
+ digitalWrite (pinEr, LED_OFF);
299
+ }
300
+ }
301
+ if (countErr != 255 ) { countErr--; }
288
302
}
289
303
290
304
void MyGateway::rxBlink (uint8_t cnt) {
@@ -296,4 +310,3 @@ void MyGateway::txBlink(uint8_t cnt) {
296
310
void MyGateway::errBlink (uint8_t cnt) {
297
311
if (countErr == 255 ) { countErr = cnt; }
298
312
}
299
-
0 commit comments