From cb83bfbdb3ed32ef57040cff9954b390ec9a2528 Mon Sep 17 00:00:00 2001 From: Henrik Ekblad Date: Tue, 4 Aug 2015 21:00:32 +0200 Subject: [PATCH] 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. --- libraries/MySensors/MyConfig.h | 9 ++++++++- libraries/MySensors/MyHwATMega328.h | 2 ++ libraries/MySensors/MySensor.cpp | 18 +++++++++--------- libraries/MySensors/MySensor.h | 8 ++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index 098a1f9..88db782 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -53,7 +53,14 @@ // but now can be used in any sensor node. Also the LEDs can now be // disabled in the gateway. -// #define WITH_LEDS_BLINKING +//#define WITH_LEDS_BLINKING + +// The following setting allows you to inverse the blinking feature WITH_LEDS_BLINKING +// When WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches +// off when blinking + +//#define WITH_LEDS_BLINKING_INVERSE + // default LEDs blinking period in milliseconds #define DEFAULT_LED_BLINK_PERIOD 300 diff --git a/libraries/MySensors/MyHwATMega328.h b/libraries/MySensors/MyHwATMega328.h index 12698d4..9e42b55 100644 --- a/libraries/MySensors/MyHwATMega328.h +++ b/libraries/MySensors/MyHwATMega328.h @@ -57,6 +57,8 @@ do { \ // Define these as macros to save valuable space + +#define hw_digitalWrite(__pin, __value) (digitalWrite(__pin, __value)) #define hw_init() Serial.begin(BAUD_RATE) #define hw_watchdogReset() wdt_reset() #define hw_reboot() wdt_enable(WDTO_15MS); while (1) diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index bdab9c2..9d6ecb8 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -107,33 +107,33 @@ void MySensor::handleLedsBlinking() { // do the actual blinking if(countRx && countRx != 255) { // switch led on - digitalWrite(pinRx, HIGH); + hw_digitalWrite(pinRx, LED_ON); } else if(!countRx) { // switching off - digitalWrite(pinRx, LOW); + hw_digitalWrite(pinRx, LED_OFF); } if(countRx != 255) --countRx; if(countTx && countTx != 255) { // switch led on - digitalWrite(pinTx, HIGH); + hw_digitalWrite(pinTx, LED_ON); } else if(!countTx) { // switching off - digitalWrite(pinTx, LOW); + hw_digitalWrite(pinTx, LED_OFF); } if(countTx != 255) --countTx; if(countErr && countErr != 255) { // switch led on - digitalWrite(pinEr, HIGH); + hw_digitalWrite(pinEr, LED_ON); } else if(!countErr) { // switching off - digitalWrite(pinEr, LOW); + hw_digitalWrite(pinEr, LED_OFF); } if(countErr != 255) --countErr; @@ -179,9 +179,9 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b pinMode(pinEr, OUTPUT); // Set initial state of leds - digitalWrite(pinRx, LOW); - digitalWrite(pinTx, LOW); - digitalWrite(pinEr, LOW); + hw_digitalWrite(pinRx, LED_OFF); + hw_digitalWrite(pinTx, LED_OFF); + hw_digitalWrite(pinEr, LED_OFF); // initialize counters countRx = 0; diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index abf7283..0a54987 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -52,6 +52,14 @@ typedef MyHwATMega328 MyHwDriver; #define debug(x,...) #endif +#ifdef WITH_LEDS_BLINKING_INVERSE +#define LED_ON 0x1 +#define LED_OFF 0x0 +#else +#define LED_ON 0x0 +#define LED_OFF 0x1 +#endif + // EEPROM start address for mysensors library data #define EEPROM_START 0