v1.19 Release

Dependencies:   nRF51822

Revision:
51:53fe9aff625a
Parent:
50:8dca54c1e3fd
Child:
52:23cc9f576e4a
--- a/Source/main.cpp	Fri Sep 11 19:27:20 2020 +0000
+++ b/Source/main.cpp	Fri Sep 18 21:15:41 2020 +0000
@@ -45,9 +45,9 @@
     #define debug(...) 
 #endif
 
-
 LowPowerTicker periodic_ticker; // this handle the RTC
-
+LowPowerTicker capofffast_ticker; // this handle accellerated polling of the cap if CAP_THRESHOLD_OFF1 is passed
+ 
 float tick_rate = FAST_TICK_SEC;
 
 bool log_enable = true;     // turn off event logging when false (engineering function) – DEW
@@ -85,6 +85,10 @@
 
 state_t state = INIT;
 
+volatile uint8_t veryfasttick_on = 0;
+
+void fastcap_tick(void);
+
 /// Light detected interrupt
 void light_interrupt(void)
 { // dark to light transition
@@ -122,16 +126,31 @@
     { // cap was on
         uint16_t off_threshold; // there are two cap off thresholds, normal use and EOL, this provides a variable for the proper value - FTD 08212020
         // test for proper threshold needed for EOL - FTD 08212020
-        if(NV_NOT_EOL) off_threshold = CAP_THRESHOLD_OFF;
+        if(NV_NOT_EOL) off_threshold = CAP_THRESHOLD_OFF2;
         else    off_threshold = CAP_THRESHOLD_OFF_EOL;
         
         if(on_reading < off_reading + off_threshold)
         { // cap is now off
             is_cap_off = 1;
+            capofffast_ticker.detach();
+            veryfasttick_on = 0;
             #if ENABLE_LED        
                 led = 1;
             #endif 
+            //BLE_UART_xmit("2");
         }
+        else if(NV_NOT_EOL && on_reading < off_reading + CAP_THRESHOLD_OFF1) // check for cap moving toward off
+        { // cap is almost off, start fast ticks (turns off after next regular periodic tick, or if full cap off is detected)
+            if(veryfasttick_on==0)
+            {
+                capofffast_ticker.detach();
+                capofffast_ticker.attach(&fastcap_tick ,VERY_FAST_TICK_SEC);
+                veryfasttick_on = VERY_FAST_TICK_ON_TIME_SEC;
+            }
+            //BLE_UART_xmit("1");
+        }
+    
+
     }
     
     // if adapting enabled and cap is on then adapt
@@ -151,10 +170,22 @@
     last_cap_off = is_cap_off;
 }
 
+void fastcap_tick(void)
+{
+    eventQueue.call(test_cap); // starts as non-interrupt task so we can use wait();
+    //test_cap();
+}
+
 void periodic_tick_task(void)
 {
+    //BLE_UART_xmit("+");
     test_cap();
     process_state();
+    if(veryfasttick_on)
+    {
+        veryfasttick_on--;
+        if(veryfasttick_on==0) capofffast_ticker.detach();
+    }
 }
 
 /// this interrupt is run every PERIODIC_TICK_SEC seconds