Merge pull request #566 from tbowmo/led

Fixes LED issues discussed in #562
This commit is contained in:
Henrik Ekblad
2016-08-20 12:52:42 +02:00
committed by GitHub
15 changed files with 216 additions and 276 deletions
+10 -13
View File
@@ -223,25 +223,22 @@
/**********************************
* Information LEDs blinking
***********************************/
// This feature enables LEDs blinking on message receive, transmit
// or if some error occurred. This was commonly used only in gateways,
// but now can be used in any sensor node. Also the LEDs can now be
// disabled in the gateway.
// If one of the following is defined here, or in the sketch, the pin will be used for the
// corresponding led function.
// They have to be enabled here (or in your sketch). Replace x with the pin number you have the LED on.
//
// NOTE!! that on some platforms (for example sensebender GW) the hardware variant can enable LEDs by default,
// These defaults can be overridden by defining one of these.
//#define MY_DEFAULT_ERR_LED_PIN x
//#define MY_DEFAULT_TX_LED_PIN x
//#define MY_DEFAULT_RX_LED_PIN x
//#define MY_LEDS_BLINKING_FEATURE
// The following setting allows you to inverse the blinking feature MY_LEDS_BLINKING_FEATURE
// The following setting allows you to inverse the LED blinking
// When MY_WITH_LEDS_BLINKING_INVERSE is enabled LEDSs are normally turned on and switches
// off when blinking
//#define MY_WITH_LEDS_BLINKING_INVERSE
// The following defines can be used to set the port pin, that the LED is connected to
// If one of the following is defined here, or in the sketch, MY_LEDS_BLINKING_FEATURE will be
// enabled by default. (Replace x with the pin number you have the LED on)
//#define MY_DEFAULT_ERR_LED_PIN x
//#define MY_DEFAULT_TX_LED_PIN x
//#define MY_DEFAULT_RX_LED_PIN x
/**********************************************
* Gateway inclusion button/mode configuration
+3 -43
View File
@@ -84,17 +84,10 @@
#define MY_DEFAULT_RX_LED_PIN MY_HW_TX_LED_PIN
#endif
// Not necessary to include blinking feature if no LED's are defined!
#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MY_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN)
#undef MY_LEDS_BLINKING_FEATURE
#if defined(MY_LEDS_BLINKING_FEATURE)
#warning MY_LEDS_BLINKING_FEATURE is not working, define MY_DEFAULT_ERR_LED_PIN, MY_DEFAULT_TX_LED_PIN or MY_DEFAULT_RX_LED_PIN in your sketch
#endif
// Enable LED BLINKING FEATURE, if there are any LEDs defined.
#if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED) || defined(MY_DEFAULT_TX_LED_PIN)
#define MY_LEDS_BLINKING_FEATURE
#endif
/**
* @def MY_DEFAULT_LED_BLINK_PERIOD
* @brief Default LEDs blinking period in milliseconds.
@@ -102,41 +95,8 @@
#ifndef MY_DEFAULT_LED_BLINK_PERIOD
#define MY_DEFAULT_LED_BLINK_PERIOD 300
#endif
/**
* @def MY_DEFAULT_RX_LED_PIN
* @brief The RX LED default pin.
*/
#ifndef MY_DEFAULT_RX_LED_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_DEFAULT_RX_LED_PIN 8
#else
#define MY_DEFAULT_RX_LED_PIN 6
#endif
#endif
/**
* @def MY_DEFAULT_TX_LED_PIN
* @brief The TX LED default pin.
*/
#ifndef MY_DEFAULT_TX_LED_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_DEFAULT_TX_LED_PIN 9
#else
#define MY_DEFAULT_TX_LED_PIN 5
#endif
#endif
/**
* @def MY_DEFAULT_ERR_LED_PIN
* @brief The Error LED default pin.
*/
#ifndef MY_DEFAULT_ERR_LED_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define MY_DEFAULT_ERR_LED_PIN 7
#else
#define MY_DEFAULT_ERR_LED_PIN 4
#endif
#endif
#if defined(MY_LEDS_BLINKING_FEATURE)
#if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
#include "core/MyLeds.cpp"
#else
#include "core/MyLeds.h"
+10 -4
View File
@@ -18,20 +18,26 @@
*/
#include "MyIndication.h"
#ifdef MY_LEDS_BLINKING_FEATURE
#if defined(MY_DEFAULT_TX_LED_PIN)|| defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
#include "MyLeds.h"
#endif
void setIndication( const indication_t ind )
{
#ifdef MY_LEDS_BLINKING_FEATURE
#if defined(MY_DEFAULT_TX_LED_PIN)
if ((INDICATION_TX == ind) || (INDICATION_GW_TX == ind))
{
ledsBlinkTx(1);
} else if ((INDICATION_RX == ind) || (INDICATION_GW_RX == ind))
} else
#endif
#if defined(MY_DEFAULT_RX_LED_PIN)
if ((INDICATION_RX == ind) || (INDICATION_GW_RX == ind))
{
ledsBlinkRx(1);
} else if (ind > INDICATION_ERR_START)
} else
#endif
#if defined(MY_DEFAULT_ERR_LED_PIN)
if (ind > INDICATION_ERR_START)
{
// Number of blinks indicates which error occurred.
ledsBlinkErr(ind-INDICATION_ERR_START);
+12 -2
View File
@@ -37,10 +37,15 @@ inline void ledsInit()
countErr = 0;
// Setup led pins
#if defined(MY_DEFAULT_RX_LED_PIN)
pinMode(MY_DEFAULT_RX_LED_PIN, OUTPUT);
#endif
#if defined(MY_DEFAULT_TX_LED_PIN)
pinMode(MY_DEFAULT_TX_LED_PIN, OUTPUT);
#endif
#if defined(MY_DEFAULT_ERR_LED_PIN)
pinMode(MY_DEFAULT_ERR_LED_PIN, OUTPUT);
#endif
ledsProcess();
}
@@ -55,17 +60,23 @@ void ledsProcess() {
// For an On/Off ratio of 4, the pattern repeated will be [on, on, on, off]
// until the counter becomes 0.
#if defined(MY_DEFAULT_RX_LED_PIN)
state = (countRx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
hwDigitalWrite(MY_DEFAULT_RX_LED_PIN, state);
if (countRx) --countRx;
#endif
#if defined(MY_DEFAULT_TX_LED_PIN)
state = (countTx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
hwDigitalWrite(MY_DEFAULT_TX_LED_PIN, state);
if (countTx) --countTx;
#endif
#if defined(MY_DEFAULT_ERR_LED_PIN)
state = (countErr & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
hwDigitalWrite(MY_DEFAULT_ERR_LED_PIN, state);
if (countErr) --countErr;
#endif
}
void ledsBlinkRx(uint8_t cnt) {
@@ -79,4 +90,3 @@ void ledsBlinkTx(uint8_t cnt) {
void ledsBlinkErr(uint8_t cnt) {
if(!countErr) { countErr = cnt*LED_ON_OFF_RATIO; }
}
+1 -1
View File
@@ -29,7 +29,7 @@
#define LED_OFF 0x1
#endif
#ifdef MY_LEDS_BLINKING_FEATURE
#if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
#define ledBlinkTx(x,...) ledsBlinkTx(x)
#define ledBlinkRx(x,...) ledsBlinkRx(x)
#define ledBlinkErr(x,...) ledsBlinkErr(x)
+3 -3
View File
@@ -35,7 +35,7 @@ void (*_timeCallback)(unsigned long); // Callback for requested time messages
void _process() {
hwWatchdogReset();
#if defined (MY_LEDS_BLINKING_FEATURE)
#if defined (MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
ledsProcess();
#endif
@@ -58,7 +58,7 @@ void _infiniteLoop() {
#if defined(ARDUINO_ARCH_ESP8266)
yield();
#endif
#if defined (MY_LEDS_BLINKING_FEATURE)
#if defined (MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
ledsProcess();
#endif
}
@@ -81,7 +81,7 @@ void _begin() {
before();
}
#if defined(MY_LEDS_BLINKING_FEATURE)
#if defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
ledsInit();
#endif
+2 -6
View File
@@ -33,7 +33,7 @@
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
*
* LED purposes:
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch, only the LEDs that is defined is used.
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
@@ -116,11 +116,10 @@
#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Flash leds on rx/tx/err
// #define MY_LEDS_BLINKING_FEATURE
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
@@ -145,6 +144,3 @@ void presentation() {
void loop() {
// Send locally attached sensors data here
}
@@ -26,7 +26,7 @@
* The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
*
* LED purposes:
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
@@ -105,11 +105,6 @@
#define MY_PORT 1883
/*
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
@@ -119,6 +114,10 @@
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
@@ -138,6 +137,3 @@ void presentation() {
void loop() {
// Send locally attech sensors data here
}
@@ -118,11 +118,10 @@
#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Flash leds on rx/tx/err
// #define MY_LEDS_BLINKING_FEATURE
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
@@ -171,7 +170,3 @@ void loop() {
// Send locally attech sensors data here
ArduinoOTA.handle();
}
+8 -14
View File
@@ -29,7 +29,7 @@
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
*
* LEDs (OPTIONAL):
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
@@ -56,14 +56,6 @@
#define MY_BAUD_RATE 38400
#endif
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Inverses the behavior of leds
//#define MY_WITH_LEDS_BLINKING_INVERSE
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
@@ -77,6 +69,13 @@
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Inverses the behavior of leds
//#define MY_WITH_LEDS_BLINKING_INVERSE
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
@@ -95,8 +94,3 @@ void presentation() {
void loop() {
// Send locally attached sensor data here
}
@@ -28,7 +28,6 @@
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
*
* LEDs (OPTIONAL):
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
@@ -64,10 +63,6 @@
// Enable serial gateway
#define MY_GATEWAY_SERIAL
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
@@ -78,6 +73,10 @@
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
@@ -95,8 +94,3 @@ void presentation() {
void loop() {
// Send locally attached sensor data here
}
+4 -6
View File
@@ -90,11 +90,6 @@
// Note that most of the Ardunio examples use "DEAD BEEF FEED" for the MAC address.
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
@@ -104,6 +99,10 @@
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
@@ -123,4 +122,3 @@ void setup()
void loop() {
}
@@ -114,11 +114,6 @@
#define MY_PORT 1883
/*
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
@@ -128,6 +123,10 @@
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
@@ -148,6 +147,3 @@ void presentation() {
void loop() {
// Send locally attached sensors data here
}
@@ -29,7 +29,7 @@
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
*
* LEDs (OPTIONAL):
* - To use the feature, uncomment MY_LEDS_BLINKING_FEATURE in MyConfig.h
* - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
@@ -56,14 +56,6 @@
#define MY_BAUD_RATE 38400
#endif
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Inverses the behavior of leds
//#define MY_WITH_LEDS_BLINKING_INVERSE
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
@@ -77,6 +69,13 @@
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Inverses the behavior of leds
//#define MY_WITH_LEDS_BLINKING_INVERSE
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
-1
View File
@@ -52,7 +52,6 @@ MY_PARENT_NODE_IS_STATIC LITERAL1
MY_OTA_FIRMWARE_FEATURE LITERAL1
MY_OTA_FLASH_SS LITERAL1
MY_OTA_FLASH_JDECID LITERAL1
MY_LEDS_BLINKING_FEATURE LITERAL1
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1
MY_DEFAULT_LED_BLINK_PERIOD LITERAL1
MY_WITH_LEDS_BLINKING_INVERSE LITERAL1