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.
This commit is contained in:
Henrik Ekblad
2015-08-04 21:00:32 +02:00
parent 477537147c
commit cb83bfbdb3
4 changed files with 27 additions and 10 deletions
+8 -1
View File
@@ -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
+2
View File
@@ -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)
+9 -9
View File
@@ -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;
+8
View File
@@ -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