GIU\ZF

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

Fork of rtos_basic by mbed official

Revision:
13:ab52f46c98ab
Child:
14:8a6c20435523
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tasks/task_group1.cpp	Tue Mar 27 15:56:27 2018 +0000
@@ -0,0 +1,50 @@
+#include "core.h"
+
+namespace task_group_1{
+    Thread thread;
+    const float freq = 2.0f; //hz
+    
+
+    void runTask(){
+        Timer executionTimer,sleepTimer;
+        executionTimer.reset();
+        sleepTimer.reset();
+        display::init();
+        
+        const int const_delay = int((1000.0f/freq)+0.5f);
+        int dynamic_delay = const_delay;
+        
+        while(true){
+            sleepTimer.stop();
+            executionTimer.start();
+            
+            
+            int sleepTime = sleepTimer.read_ms();
+            const int drift = ((sleepTime - dynamic_delay) > 0)?
+                                        (sleepTime - dynamic_delay) : 0;
+            
+            
+            // Run all tasks
+            display::hotLoop();
+            
+            
+            executionTimer.stop();
+            int exec_time = executionTimer.read_ms();
+            
+            #if DEBUG_MODE
+            runTimeParams::liveAccess.lock();
+            //runTimeParams::debugLog += "GROUP_1," + to_string(executionTimer.read_ms()) + ","
+//                        + to_string(sleepTimer.read_ms()) + ", \n";
+            runTimeParams::odometer = float(sleepTime);
+            runTimeParams::avgSpeed = float(exec_time);
+            runTimeParams::liveAccess.unlock();
+            #endif
+            
+            executionTimer.reset();
+            sleepTimer.reset();
+            sleepTimer.start();
+            dynamic_delay = const_delay - (exec_time + drift);
+            Thread::wait(dynamic_delay);
+        }   
+    }
+}
\ No newline at end of file