new battery bar

Dependencies:   CAN_IDs CanControl Dashboard PinDetect PowerControl mbed-rtos mbed

Revision:
16:c5427db9edf0
Parent:
15:56b25cffa523
Child:
17:91ba27c14991
--- a/main.cpp	Mon May 22 17:21:08 2017 +0000
+++ b/main.cpp	Mon May 22 18:12:08 2017 +0000
@@ -25,6 +25,8 @@
 #include "pinout.h"
 #include "CAN_IDs.h"
 #include "PowerControl.h"
+#include "TelemetryAndDaq.h"
+#include "Dashboard.h"
 
 #define SPEED_THRESH 0.02 //threshold for setting speed to prevent CAN spam
 
@@ -49,56 +51,23 @@
 DigitalOut buckScreen(BUCK4);
 DigitalOut buck24V(BUCK5);
 
-
-// Thread 1 - Power
-void power(){
-    PowerControl powercontrol(PUSH_GREEN); 
-    
-#ifdef DEBUG
-    pc.printf("Thread 1 - Power started\r\n ");
-#endif
-
-    Thread::wait(osWaitForever);
-}
+//external classes
+extern DataAcquisition daq;
 
-// Thread X - Test
-void test(){
-    ledError = 0;
-    ledSD = 0;
-    ledFona = 0 ;
-    led24V=1;
+//external variables
+extern long long int starttime;
 
-//DigitalOut buckCan(BUCK2);
-    buckXSens = 0;
-    buckScreen = 0;
-    buck24V = 1;
-}
+//external threads
+extern Thread threadbg;
 
 //global var for speed; ugly solution but works
 float speed = 0;
-//send motor command
-void sendMotorSpeed(float throttle) {
-    if ((abs(throttle - speed)) > SPEED_THRESH) {
-        union {
-            char msg[4];
-            float value;
-        } packet;
-        packet.value = throttle;
-        can.write(CANMessage(MOTOR_COMMAND, packet.msg));
-        printf("Sent motor speed: %f\r\n", packet.value);
-        speed = throttle;
-    }
-}
 
-//throttle thread
-void readThrottle() {
-    float throttleread;
-    while(1) {
-        throttleread = 2*(0.5 - analogThrottle.read());
-        sendMotorSpeed(throttleread);
-        Thread::wait(10);   
-    }
-}  
+//thread function declarations
+void readThrottle();
+void power();
+void test();
+void background();
 
 // Thread 0 - DO NOT CHANGE THIS!
 int main() {  
@@ -116,15 +85,67 @@
     
     // start threads
     threadpower.start(&power);
+    threadbg.start(&background);
     threadtest.start(&test);
     threadthrottle.start(&readThrottle);
     
-    //stop this thread while keeping the other threads running
-    CANMessage msg;
+    daq.enable(starttime);
+    
+    //BMS message parser, now imlpemented in DAQ lib
+    /*CANMessage msg;
     while(1) {
         if(can.read(msg)) {
             pc.printf("Message received: 0x %x; %u %u%u %d%d %c %u %u\n", msg.id, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5], msg.data[6], msg.data[7]);
-        } 
+        }
+        Thread::wait(10); 
+    }*/
+    Thread::wait(osWaitForever);
+}
+
+//send motor command
+void sendMotorSpeed(float throttle) {
+    if ((abs(throttle - speed)) > SPEED_THRESH) {
+        union {
+            char msg[4];
+            float value;
+        } packet;
+        packet.value = throttle;
+        can.write(CANMessage(MOTOR_COMMAND, packet.msg));
+        printf("Sent motor speed: %f\r\n", packet.value);
+        speed = throttle;
     }
+}
+
+//thread functions
+void readThrottle() {
+    float throttleread;
+    while(1) {
+        throttleread = 2*(0.5 - analogThrottle.read());
+        sendMotorSpeed(throttleread);
+        Thread::wait(10);   
+    }
+}  
+
+
+
+void power() {
+    PowerControl powercontrol(PUSH_GREEN); 
+    
+#ifdef DEBUG
+    pc.printf("Thread 1 - Power started\r\n ");
+#endif
+
     Thread::wait(osWaitForever);
-}
\ No newline at end of file
+}
+
+void test() {
+    ledError = 0;
+    ledSD = 0;
+    ledFona = 0 ;
+    led24V=1;
+
+//DigitalOut buckCan(BUCK2);
+    buckXSens = 0;
+    buckScreen = 0;
+    buck24V = 1;
+}