Workshop demo program

Dependencies:   PinDetect mbed LoRaWAN-lib SX1272Lib

Revision:
19:31fc997c460b
Parent:
18:326069443137
--- 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