Allow disabling of LED/Inclusion pins

LED/inclusion pins will always be controlled, even when not configured
to use them.
This fix will ignore pins when a negative pin number is passed.
This commit is contained in:
Yveaux
2015-07-16 20:16:10 +02:00
parent 6cc5eb63ce
commit 99917b43ac
2 changed files with 69 additions and 56 deletions
+63 -50
View File
@@ -14,17 +14,20 @@
#include "utility/PinChangeInt.h" #include "utility/PinChangeInt.h"
uint8_t pinRx; int8_t pinRx;
uint8_t pinTx; int8_t pinTx;
uint8_t pinEr; int8_t pinEr;
boolean buttonTriggeredInclusion; boolean buttonTriggeredInclusion;
volatile uint8_t countRx; volatile uint8_t countRx;
volatile uint8_t countTx; volatile uint8_t countTx;
volatile uint8_t countErr; volatile uint8_t countErr;
boolean inclusionMode; // Keeps track on inclusion mode boolean inclusionMode; // Keeps track on inclusion mode
#define LED_ON (LOW)
#define LED_OFF (HIGH)
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) {
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) {
pinInclusion = _inclusion_pin; pinInclusion = _inclusion_pin;
inclusionTime = _inclusion_time; inclusionTime = _inclusion_time;
pinRx = _rx; pinRx = _rx;
@@ -56,23 +59,29 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
countTx = 0; countTx = 0;
countErr = 0; countErr = 0;
// Setup led pins // Setup led pins & set initial state of leds
pinMode(pinRx, OUTPUT); if (pinRx >= 0)
pinMode(pinTx, OUTPUT); {
pinMode(pinEr, OUTPUT); digitalWrite(pinRx, LED_OFF);
digitalWrite(pinRx, LOW); pinMode(pinRx, OUTPUT);
digitalWrite(pinTx, LOW); }
digitalWrite(pinEr, LOW); if (pinTx >= 0)
{
digitalWrite(pinTx, LED_OFF);
pinMode(pinTx, OUTPUT);
}
if (pinEr >= 0)
{
digitalWrite(pinEr, LED_OFF);
pinMode(pinEr, OUTPUT);
}
// Setup digital in that triggers inclusion mode // Setup digital in that triggers inclusion mode
pinMode(pinInclusion, INPUT); if (pinInclusion >= 0)
digitalWrite(pinInclusion, HIGH); {
pinMode(pinInclusion, INPUT);
// Set initial state of leds // Add interrupt for inclusion button to pin
digitalWrite(pinRx, HIGH); PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
digitalWrite(pinTx, HIGH); }
digitalWrite(pinEr, HIGH);
// Start up the radio library // Start up the radio library
setupRadio(paLevel, channel, dataRate); setupRadio(paLevel, channel, dataRate);
@@ -84,9 +93,6 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
MsTimer2::set(300, ledTimersInterrupt); MsTimer2::set(300, ledTimersInterrupt);
MsTimer2::start(); MsTimer2::start();
// Add interrupt for inclusion button to pin
PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
// Send startup log message on serial // Send startup log message on serial
serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY); serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
} }
@@ -257,34 +263,42 @@ void MyGateway::serial(MyMessage &msg) {
void ledTimersInterrupt() { void ledTimersInterrupt() {
if(countRx && countRx != 255) { if (pinRx >= 0)
// switch led on {
digitalWrite(pinRx, LOW); if(countRx && countRx != 255) {
} else if(!countRx) { // switch led on
// switching off digitalWrite(pinRx, LED_ON);
digitalWrite(pinRx, HIGH); } else if(!countRx) {
} // switching off
if(countRx != 255) { countRx--; } digitalWrite(pinRx, LED_OFF);
}
}
if(countRx != 255) { countRx--; }
if(countTx && countTx != 255) { if (pinTx >= 0)
// switch led on {
digitalWrite(pinTx, LOW); if(countTx && countTx != 255) {
} else if(!countTx) { // switch led on
// switching off digitalWrite(pinTx, LED_ON);
digitalWrite(pinTx, HIGH); } else if(!countTx) {
} // switching off
if(countTx != 255) { countTx--; } digitalWrite(pinTx, LED_OFF);
else if(inclusionMode) { countTx = 8; } }
}
if(countErr && countErr != 255) { if(countTx != 255) { countTx--; }
// switch led on else if(inclusionMode) { countTx = 8; }
digitalWrite(pinEr, LOW);
} else if(!countErr) {
// switching off
digitalWrite(pinEr, HIGH);
}
if(countErr != 255) { countErr--; }
if (pinEr >= 0)
{
if(countErr && countErr != 255) {
// switch led on
digitalWrite(pinEr, LED_ON);
} else if(!countErr) {
// switching off
digitalWrite(pinEr, LED_OFF);
}
}
if(countErr != 255) { countErr--; }
} }
void MyGateway::rxBlink(uint8_t cnt) { void MyGateway::rxBlink(uint8_t cnt) {
@@ -296,4 +310,3 @@ void MyGateway::txBlink(uint8_t cnt) {
void MyGateway::errBlink(uint8_t cnt) { void MyGateway::errBlink(uint8_t cnt) {
if(countErr == 255) { countErr = cnt; } if(countErr == 255) { countErr = cnt; }
} }
+6 -6
View File
@@ -30,13 +30,13 @@ class MyGateway : public MySensor
* @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9) * @param _cepin The pin attached to RF24 Chip Enable on the RF module (default 9)
* @param _cspin The pin attached to RF24 Chip Select (defualt 10) * @param _cspin The pin attached to RF24 Chip Select (defualt 10)
* @param _inclusion_time Time of inclusion mode (in minutes, default 1) * @param _inclusion_time Time of inclusion mode (in minutes, default 1)
* @param _inclusion_pin Digital pin that triggers inclusion mode * @param _inclusion_pin Digital pin that triggers inclusion mode, negative value disables functionality.
* @param _rx Digital pin for receive led * @param _rx Digital pin for receive led, negative value disables functionality.
* @param _tx Digital pin for transfer led * @param _tx Digital pin for transfer led, negative value disables functionality.
* @param _er Digital pin for error led * @param _er Digital pin for error led, negative value disables functionality.
* *
*/ */
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); 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);
/* Use this and pass a function that should be called when you want to process commands that arrive from radio network */ /* Use this and pass a function that should be called when you want to process commands that arrive from radio network */
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); 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
unsigned long inclusionStartTime; unsigned long inclusionStartTime;
boolean useWriteCallback; boolean useWriteCallback;
void (*dataCallback)(char *); void (*dataCallback)(char *);
uint8_t pinInclusion; int8_t pinInclusion;
uint8_t inclusionTime; uint8_t inclusionTime;
uint8_t h2i(char c); uint8_t h2i(char c);