Skip to content

Commit cb83bfb

Browse files
committed
Inverse the default rx/tx/err led behaviour and introduce
WITH_LEDS_BLINKING_INVERSE option in MyConfig. This allows easy inversing of led blink behavior depending on how the leds were connected. Introduce hw-macro for digitalWrite used by the LED blinking.
1 parent 4775371 commit cb83bfb

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

libraries/MySensors/MyConfig.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@
5353
// but now can be used in any sensor node. Also the LEDs can now be
5454
// disabled in the gateway.
5555

56-
// #define WITH_LEDS_BLINKING
56+
//#define WITH_LEDS_BLINKING
57+
58+
// The following setting allows you to inverse the blinking feature WITH_LEDS_BLINKING
59+
// When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
60+
// off when blinking
61+
62+
//#define WITH_LEDS_BLINKING_INVERSE
63+
5764

5865
// default LEDs blinking period in milliseconds
5966
#define DEFAULT_LED_BLINK_PERIOD 300

libraries/MySensors/MyHwATMega328.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ do { \
5757

5858

5959
// Define these as macros to save valuable space
60+
61+
#define hw_digitalWrite(__pin, __value) (digitalWrite(__pin, __value))
6062
#define hw_init() Serial.begin(BAUD_RATE)
6163
#define hw_watchdogReset() wdt_reset()
6264
#define hw_reboot() wdt_enable(WDTO_15MS); while (1)

libraries/MySensors/MySensor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,33 +107,33 @@ void MySensor::handleLedsBlinking() {
107107
// do the actual blinking
108108
if(countRx && countRx != 255) {
109109
// switch led on
110-
digitalWrite(pinRx, HIGH);
110+
hw_digitalWrite(pinRx, LED_ON);
111111
}
112112
else if(!countRx) {
113113
// switching off
114-
digitalWrite(pinRx, LOW);
114+
hw_digitalWrite(pinRx, LED_OFF);
115115
}
116116
if(countRx != 255)
117117
--countRx;
118118

119119
if(countTx && countTx != 255) {
120120
// switch led on
121-
digitalWrite(pinTx, HIGH);
121+
hw_digitalWrite(pinTx, LED_ON);
122122
}
123123
else if(!countTx) {
124124
// switching off
125-
digitalWrite(pinTx, LOW);
125+
hw_digitalWrite(pinTx, LED_OFF);
126126
}
127127
if(countTx != 255)
128128
--countTx;
129129

130130
if(countErr && countErr != 255) {
131131
// switch led on
132-
digitalWrite(pinEr, HIGH);
132+
hw_digitalWrite(pinEr, LED_ON);
133133
}
134134
else if(!countErr) {
135135
// switching off
136-
digitalWrite(pinEr, LOW);
136+
hw_digitalWrite(pinEr, LED_OFF);
137137
}
138138
if(countErr != 255)
139139
--countErr;
@@ -179,9 +179,9 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
179179
pinMode(pinEr, OUTPUT);
180180

181181
// Set initial state of leds
182-
digitalWrite(pinRx, LOW);
183-
digitalWrite(pinTx, LOW);
184-
digitalWrite(pinEr, LOW);
182+
hw_digitalWrite(pinRx, LED_OFF);
183+
hw_digitalWrite(pinTx, LED_OFF);
184+
hw_digitalWrite(pinEr, LED_OFF);
185185

186186
// initialize counters
187187
countRx = 0;

libraries/MySensors/MySensor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ typedef MyHwATMega328 MyHwDriver;
5252
#define debug(x,...)
5353
#endif
5454

55+
#ifdef WITH_LEDS_BLINKING_INVERSE
56+
#define LED_ON 0x1
57+
#define LED_OFF 0x0
58+
#else
59+
#define LED_ON 0x0
60+
#define LED_OFF 0x1
61+
#endif
62+
5563

5664
// EEPROM start address for mysensors library data
5765
#define EEPROM_START 0

0 commit comments

Comments
 (0)