De hoofdcontroller van het TLS2 project.

Dependencies:   RPCInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
RichardHoekstra
Date:
Wed Nov 16 18:52:03 2016 +0000
Parent:
2:c3918fd40472
Child:
4:02a2cfa49219
Commit message:
Ready to start stringing everything together once commands are known.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Nov 16 13:02:56 2016 +0000
+++ b/main.cpp	Wed Nov 16 18:52:03 2016 +0000
@@ -1,23 +1,17 @@
 #include "mbed.h"
 #include "mbed_rpc.h"
 #include "SerialRPCInterface.h"
-//Example
-//RPCVariable<float>  RPCbrightness(&brightness, "brightness");
-
-//Hoofdcontroller TODO:
-//1. Switch tussen drukgestuurd en flowgestuurd
-//2. Ondersteuning voor meerdere druksensors en temperatuur sensors
-//3. Opvragen van recente sensor data voor het LabView gebruikersinterface
-//4. I2C communicatie met andere controllers
 
 
+//Labview Communication Variables/Settings
 float brightness = 0;
 RPCVariable<float>  RPCbrightness(&brightness, "brightness");
-
+Serial pc(USBTX, USBRX); //Enable USB communication
 
 //I2C settings
 #define SDA D14
 #define SCL D15
+#define I2C_BUFFER_SIZE 10
 I2C master(SDA,SCL);
 
 //Controller addresses
@@ -25,9 +19,7 @@
 #define interface_addr 0x92
 #define sensor_addr 0x93
 
-#define buffer_size 12
 
-Serial pc(USBTX, USBRX);
 
 //Handles all the RPC communication. 
 //Taken from the example at developer.mbed.org/cookbook
@@ -38,14 +30,24 @@
     RPC::call(buf, outbuf); 
     pc.printf("%s\n", outbuf);
 }
+//Split an integer into two char
+void int_to_2_char(char* arr, int val, int first_element = 0){
+    arr[first_element] = val>>8;
+    arr[first_element+1] = val&255;
+}
+//Join two char to make an integer. 
+int 2_char_to_int(char* arr, int first_element = 0){
+    return (arr[first_element]<<8)+arr[first_element+1];
+}
 
 int main() {
-    char buf[buffer_size];    
+    char buf[I2C_BUFFER_SIZE];    
     while(1) {
         RPC_routine();
-        //i2c
-        buf[0] = (char)(brightness*255.0);
-        master.write(interface_addr, buf, 1);
+        //I2C Routine
+        //Take info from sensor
+        //Prepare for RPC
+        //Send info to motorcontroller
         wait_ms(1);
     }
 }
\ No newline at end of file