new battery bar

Dependencies:   CAN_IDs CanControl Dashboard PinDetect PowerControl mbed-rtos mbed

Revision:
1:c5d8ea5d049b
Child:
3:b164662f9740
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 10 17:14:02 2017 +0000
@@ -0,0 +1,169 @@
+/*******************************************************************************
+This software is especially designed for Solarboat Twente for the use in their solarboat v1.0
+
+Written by:
+Niels Leijen, Jesse van Rhijn, Bram Seinhorst
+
+Thanks to:
+Jasper Admiraal, Hidde Pik (hihihihi), Lisa Postma, Heleen Jeurink, Ruben Peters,
+Martijn Groot Jebbink, Martijn Wilpshaar, Bram Seinhorst, Robert Geels, Arnoud Meutstege,
+Jeroen te Braake, Ids de Vos, Jesse van Rhijn, Sam Benou and Niels Leijen
+
+DISCLAIMER:
+THIS SOFTWARE IS SUPPLIED "AS IS" WITHOUT ANY WARRANTIES AND SUPPORT. 
+SOLARBOATTWENTE ASSUMES NO RESPONSIBILITY OR LIABILITY FOR THE USE OF THE SOFTWARE.
+*******************************************************************************/
+
+// uncomment to send debug information
+#define DEBUG
+
+//include 3rd party libraries
+#include "mbed.h"
+#include "rtos.h"
+
+// include Solarboat libraries
+#include "pinout.h"
+#include "PowerControl.h"
+
+// initialize serial connection for debug
+#ifdef DEBUG
+Serial pc(SERIAL_TX, SERIAL_RX);
+#endif
+
+// initialize canbus
+CAN can(CAN_RD, CAN_TD);
+DigitalOut canEnable(CAN_ENABLE);
+
+// initialze onboard leds
+DigitalOut ledError(LED3);
+DigitalOut ledRelay(LED2);
+DigitalOut ledSD(LED1);
+DigitalOut ledFona(LED5);
+DigitalOut led24V(LED4);
+
+// initialeze buck converters
+DigitalOut buckCan(BUCK2);
+DigitalOut buckXSens(BUCK3);
+DigitalOut buckScreen(BUCK4);
+DigitalOut buck24V(BUCK5);
+
+// global variables
+// Thread 1
+//static bool goSleep = true;
+
+
+
+
+/*
+// Thread 1 - Power - Functions
+void greenButtonPressed(){
+#ifdef DEBUG
+    printf("green button pressed\r\n ");
+#endif
+
+}
+    if(goSleep){
+#ifdef DEBUG
+        printf("waking up\n");
+#endif
+
+        goSleep = false;
+        
+        canEnable = 1;
+        buckCan = 1;
+        wait_ms(200);
+        can.write(CANMessage(0x033, "1"));
+        ledRelay = 1;
+        wait_ms(300);
+        buckXSens = 1;
+        buckScreen = 1;
+        buck24V = 1;
+        led24V = 1;
+
+#ifdef DEBUG
+        printf("fully awake\n");
+#endif
+    }
+}
+   
+void redButtonPressed(){
+#ifdef DEBUG
+    printf("red button pressed\r\n ");
+#endif
+#ifdef DEBUG
+    printf("going to sleep\n");
+#endif
+    
+    goSleep = true;
+    can.write(CANMessage(0x033, "0"));
+    
+    ledRelay = 0;
+    wait_ms(200);
+    buckXSens = 0;
+    buckScreen = 0;
+    buck24V = 0;
+    led24V = 0;
+    wait_ms(300);
+    canEnable = 0;
+    buckCan = 0;
+    
+#ifdef DEBUG
+    printf("entering sleep mode\n");
+#endif
+    
+    //sleep();
+}
+*/
+
+// Thread 1 - Power
+void power(){
+#ifdef DEBUG
+    printf("Thread 1 - Power start\r\n ");
+#endif
+
+    PowerControl powercontrol(PUSH_GREEN, PUSH_RED); 
+    #ifdef DEBUG
+    printf("Thread 1 - started\r\n ");
+#endif
+    
+    //sleep();
+    
+    while(1){
+        //if(!goSleep){
+          //  can.write(CANMessage(0x033, "1"));
+        //}
+        ledError = !ledError;
+        Thread::wait(1000);
+    }
+}
+
+
+// Thread 0 - DO NOT CHANGE THIS!
+int main() {  
+#ifdef DEBUG
+    pc.baud(115200);
+    printf("Starting SOS V1.0\n");
+#endif
+    // change CAN frequency
+    can.frequency(250000);
+    
+    // initialze threads
+    Thread thread1;
+    //Thread thread2;
+    //Thread thread3;
+    //Thread thread4;
+    //Thread thread5;
+    
+    // change thread priority
+    //thread2.set_priority(osPriorityBelowNormal);
+    
+    // start threads
+    thread1.start(&power);
+    //thread2.start(&calcPi);
+    //thread3.start(&motorTest);
+    //thread4.start(&canReceive);
+    //thread5.start(&relaisOn);
+    
+    //stop this thread while keeping the other threads running
+    Thread::wait(osWaitForever);
+}
\ No newline at end of file