TRR 2018 / Mbed 2 deprecated biniou-TRR2019

Dependencies:   mbed MPU6050

Revision:
9:1b54bac6d9a7
Child:
10:e63fe4080760
diff -r f23601373e8b -r 1b54bac6d9a7 log.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/log.cpp	Thu Oct 03 23:28:56 2019 +0000
@@ -0,0 +1,41 @@
+#include "log.h"
+
+Timer t_loggingTimer;
+int i_logging_duration;
+bool b_LOG_READY = false;
+Serial rs_LOG_pc(USBTX, USBRX);
+
+
+s_Sample s_LOG_history[LOG_SIZE];
+int i_LOG_index_data = 0;
+bool b_LOG_flag = false;
+
+void log_start(int duration_ms)
+{
+    b_LOG_flag = true;
+    b_LOG_READY = false;
+    t_loggingTimer.start();
+    i_logging_duration = duration_ms;
+    t_loggingTimer.reset();
+}
+
+void log_check()
+{
+    if(t_loggingTimer.read_ms() > i_logging_duration) {
+        b_LOG_READY = true;
+        b_LOG_flag = false;
+        t_loggingTimer.stop();
+        t_loggingTimer.reset();
+    }
+    if(b_LOG_flag && i_LOG_index_data < LOG_SIZE) {
+        s_LOG_history[i_LOG_index_data].timestamp = t_loggingTimer.read_ms();
+        i_LOG_index_data + 1;
+    }
+}
+void log_pc()
+{
+    rs_LOG_pc.printf("timestamp;left_90;right_90;left_45;right_45;pwm_dir;odom;speed;\r\n");
+    for(int i = 0; i<LOG_SIZE; i++) {
+        rs_LOG_pc.printf("%d;%f;%f;%f;%f;%d;%f;%f;\r\n",s_LOG_history[i_LOG_index_data].timestamp,s_LOG_history[i_LOG_index_data].left_90,s_LOG_history[i_LOG_index_data].right_90,s_LOG_history[i_LOG_index_data].left_45,s_LOG_history[i_LOG_index_data].right_45,s_LOG_history[i_LOG_index_data].pwm_dir,s_LOG_history[i_LOG_index_data].odom,s_LOG_history[i_LOG_index_data].speed);
+    }
+}