Skip to content

Commit 945c7f4

Browse files
committed
Merge pull request #136 from Yveaux/master
Allow disabling of LED/Inclusion pins
2 parents a1fcad5 + 99917b4 commit 945c7f4

File tree

2 files changed

+71
-58
lines changed

2 files changed

+71
-58
lines changed

libraries/MySensors/MyGateway.cpp

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
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;
2020
boolean buttonTriggeredInclusion;
2121
volatile uint8_t countRx;
2222
volatile uint8_t countTx;
2323
volatile uint8_t countErr;
2424
boolean 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

259265
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--; }
288302
}
289303

290304
void MyGateway::rxBlink(uint8_t cnt) {
@@ -296,4 +310,3 @@ void MyGateway::txBlink(uint8_t cnt) {
296310
void MyGateway::errBlink(uint8_t cnt) {
297311
if(countErr == 255) { countErr = cnt; }
298312
}
299-

libraries/MySensors/MyGateway.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class MyGateway : public MySensor
3030
* @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9)
3131
* @param _cspin The pin attached to RF24 Chip Select (defualt 10)
3232
* @param _inclusion_time Time of inclusion mode (in minutes, default 1)
33-
* @param _inclusion_pin Digital pin that triggers inclusion mode
34-
* @param _rx Digital pin for receive led
35-
* @param _tx Digital pin for transfer led
36-
* @param _er Digital pin for error led
33+
* @param _inclusion_pin Digital pin that triggers inclusion mode, negative value disables functionality.
34+
* @param _rx Digital pin for receive led, negative value disables functionality.
35+
* @param _tx Digital pin for transfer led, negative value disables functionality.
36+
* @param _er Digital pin for error led, negative value disables functionality.
3737
*
3838
*/
39-
MyGateway(uint8_t _cepin=DEFAULT_CE_PIN, uint8_t _cspin=DEFAULT_CS_PIN, uint8_t _inclusion_time = 1, uint8_t _inclusion_pin = 3, uint8_t _rx=6, uint8_t _tx=5, uint8_t _er=4);
39+
MyGateway(uint8_t _cepin=DEFAULT_CE_PIN, uint8_t _cspin=DEFAULT_CS_PIN, uint8_t _inclusion_time = 1, int8_t _inclusion_pin=-1, int8_t _rx=-1, int8_t _tx=-1, int8_t _er=-1);
4040

4141
/* Use this and pass a function that should be called when you want to process commands that arrive from radio network */
4242
void begin(rf24_pa_dbm_e paLevel=RF24_PA_LEVEL_GW, uint8_t channel=RF24_CHANNEL, rf24_datarate_e dataRate=RF24_DATARATE, void (*dataCallback)(char *)=NULL);
@@ -50,7 +50,7 @@ class MyGateway : public MySensor
5050
unsigned long inclusionStartTime;
5151
boolean useWriteCallback;
5252
void (*dataCallback)(char *);
53-
uint8_t pinInclusion;
53+
int8_t pinInclusion;
5454
uint8_t inclusionTime;
5555

5656
uint8_t h2i(char c);

0 commit comments

Comments
 (0)