1414#include " utility/PinChangeInt.h"
1515
1616
17- uint8_t pinRx;
18- uint8_t pinTx;
19- uint8_t pinEr;
17+ int8_t pinRx;
18+ int8_t pinTx;
19+ int8_t pinEr;
2020boolean buttonTriggeredInclusion;
2121volatile uint8_t countRx;
2222volatile uint8_t countTx;
2323volatile uint8_t countErr;
2424boolean inclusionMode; // Keeps track on inclusion mode
2525
26+ #define LED_ON (LOW)
27+ #define LED_OFF (HIGH)
2628
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) {
2831 pinInclusion = _inclusion_pin;
2932 inclusionTime = _inclusion_time;
3033 pinRx = _rx;
@@ -56,23 +59,29 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
5659 countTx = 0 ;
5760 countErr = 0 ;
5861
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+ }
6778 // 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+ }
7685
7786 // Start up the radio library
7887 setupRadio (paLevel, channel, dataRate);
@@ -84,9 +93,6 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
8493 MsTimer2::set (300 , ledTimersInterrupt);
8594 MsTimer2::start ();
8695
87- // Add interrupt for inclusion button to pin
88- PCintPort::attachInterrupt (pinInclusion, startInclusionInterrupt, RISING);
89-
9096 // Send startup log message on serial
9197 serial (PSTR (" 0;0;%d;0;%d;Gateway startup complete.\n " ), C_INTERNAL, I_GATEWAY_READY);
9298}
@@ -257,34 +263,42 @@ void MyGateway::serial(MyMessage &msg) {
257263
258264
259265void 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--; }
288302}
289303
290304void MyGateway::rxBlink (uint8_t cnt) {
@@ -296,4 +310,3 @@ void MyGateway::txBlink(uint8_t cnt) {
296310void MyGateway::errBlink (uint8_t cnt) {
297311 if (countErr == 255 ) { countErr = cnt; }
298312}
299-
0 commit comments