Workshop demo program
Dependencies: PinDetect mbed LoRaWAN-lib SX1272Lib
Revision 19:31fc997c460b, committed 2017-05-03
- Comitter:
- Brandond200
- Date:
- Wed May 03 16:51:28 2017 +0000
- Parent:
- 18:326069443137
- Commit message:
- added a new timer to make sure the sending bool never gets stuck in the transmitting position. changed the uint8_t counting cycles for checkAlarm to a uint16_t
Changed in this revision
app/app.cpp | Show annotated file Show diff for this revision Revisions of this file |
app/app.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 326069443137 -r 31fc997c460b app/app.cpp --- a/app/app.cpp Wed May 03 15:55:42 2017 +0000 +++ b/app/app.cpp Wed May 03 16:51:28 2017 +0000 @@ -42,19 +42,22 @@ bool button_pressed = false; //last state of the button bool alarmThresholdTriggered = false; //last state on the alarm uint8_t flashCount = 0; //how many more times to flash the LED -uint8_t checkCount = 0; +uint16_t checkCount = 0; //timers -TimerEvent_t txTimer; //timer so schedule heartbeat transmissions +TimerEvent_t heartbeatTimer; //timer so schedule heartbeat transmissions TimerEvent_t ledTimer; //timer to blink LED +TimerEvent_t txEndTimer; void onDownlinkConfirmation(){ flashLED(BLINK_COUNT_DOWNLINK_CONFIRMATION); + TimerStop(&txEndTimer); sending = false; } void onDownlinkUnconfirmed(){ + TimerStop(&txEndTimer); sending = false; } @@ -64,6 +67,11 @@ //initilize LED flash timer TimerInit(&ledTimer, flashLEDCallback); TimerSetValue( &ledTimer, TWO_HUNDRED_MILLISECONDS ); + + //initilize txTimeout timer + TimerInit(&txEndTimer, txTimeoutCallback); + TimerSetValue( &txEndTimer, 1000*1000*15 ); + } //this loop will start to be called as soon as the device successfully joins the network @@ -118,9 +126,9 @@ //start heartbeat timer. pass in how often in seconds it should transmit void startHeartbeat(uint8_t time){ - TimerInit(&txTimer, timerCallback); - TimerSetValue( &txTimer, time * 1000 * 1000); - TimerStart(&txTimer); + TimerInit(&heartbeatTimer, timerCallback); + TimerSetValue( &heartbeatTimer, time * 1000 * 1000); + TimerStart(&heartbeatTimer); } //Transmit rotory position and alarm status @@ -132,6 +140,7 @@ setDataToSend(data, dataLength); //set data to be transmitted sendLoraTransmission(); //queue transmission dataLength = 0; //reset data length so new data starts back at begining + TimerStart(&txEndTimer); } } @@ -189,4 +198,9 @@ void timerCallback(){ flashLED(BLINK_COUNT_TIMER_TRANSMIT); transmitData(rotary.read_u16()); +} + +void txTimeoutCallback(){ + sending = false; + TimerStop(&txEndTimer); } \ No newline at end of file
diff -r 326069443137 -r 31fc997c460b app/app.h --- a/app/app.h Wed May 03 15:55:42 2017 +0000 +++ b/app/app.h Wed May 03 16:51:28 2017 +0000 @@ -25,7 +25,7 @@ void flashLED(uint8_t times); -void flashLEDCallback(); +void flashLEDCallback(void); void addAlarmData(uint16_t positionArg); @@ -41,6 +41,6 @@ void startHeartbeat(uint8_t time); -void flashLEDCallback(void); +void txTimeoutCallback(void); #endif \ No newline at end of file