Nathaniel Honka / Mbed 2 deprecated Data-Management-Honka

Dependencies:   ExoController MODSERIAL SDFileSystem_HelloWorld UI-Honka mbed

Fork of Data Management by HEL's Angels

Revision:
6:784990d5180a
Parent:
4:46d4917f2464
Child:
7:66a5ec0c5c26
--- a/main.cpp	Wed Jan 14 23:20:26 2015 +0000
+++ b/main.cpp	Wed Jan 14 23:42:14 2015 +0000
@@ -4,71 +4,53 @@
 #include "UI.h"
 
 Timer t_debug;
+int dataIn[4], dataOut[4], buffer;
+int counter=0;
+int ii=0;
+
+void slaveComm()
+{
+    __disable_irq();
+    while(!comm.receive());
+    buffer=comm.read();
+
+    if(buffer==0xFE) { //end of message
+        ii=0;
+        dataIn[3]=buffer;
+        comm.reply(5);
+        counter++;
+        if(BMS.read(msg)) {
+            if(msg.id==0x18FF8320) {
+                //pc.printf("%x\r\n",msg.data[0]);
+            }
+        }
+        phone.attachment();
+    } else if(buffer==0xFF) { //beginning of message
+        ii=1;
+        dataIn[0]=buffer;
+        comm.reply(UI);
+    } else if(ii==1) {
+        ii++;
+        dataIn[1]=buffer;
+        comm.reply(52);
+    } else if(ii==2) {
+        ii++;
+        dataIn[2]=buffer;
+        comm.reply(25);
+    }
+    __enable_irq();
+}
 
 int main()
 {
-    int dataIn[4], dataOut[4], buffer;
     dataOut[0]=7;
     dataOut[1]=30;
     mainPower=1;//Don't turn on for initial testing
     initializeDatabed();
     comm.reply(dataOut[0]);//make this the first message
+    ssel.fall(&slaveComm);
     pc.printf("DataBed On!\r\n");
-    int counter=0;
-    int ii=0;
-    //float blah=1;
-    //t_debug.start();
     while (1) { //Run these functions as fast as possible
-
-        /*if(comm.receive()) {
-            dataIn[0] = comm.read();
-            comm.reply(UI);         // Make this the next reply
-            while(dataIn[0]==7) {
-                if(comm.receive()) {
-                    dataIn[1]=comm.read();
-                    comm.reply(22);
-                    break;
-                    dataIn[0]=0;
-                }
-            }
-            while(dataIn[1]==30) {
-                if(comm.receive()) {
-                    dataIn[2]=comm.read();
-                    comm.reply(5);
-                    pc.printf("Fault: %d, %d ", leftFault.read(), rightFault.read());
-                    pc.printf("Data1: %u, Data2: %u, Data3: %u\r\n", dataIn[0], dataIn[1], dataIn[2]);
-                    dataIn[1]=0;
-                    break;
-                }
-            }*/
-        if(comm.receive()) {
-            buffer = comm.read();
-            if(buffer==0xFE) { //end of message
-                ii=0;
-                dataIn[3]=buffer;
-                comm.reply(5);
-                counter++;
-                if(BMS.read(msg)) {
-                    if(msg.id==0x18FF8320) {
-                        //pc.printf("%x\r\n",msg.data[0]);
-                    }
-                }
-                phone.attachment();
-            } else if(buffer==0xFF) { //beginning of message
-                ii=1;
-                dataIn[0]=buffer;
-                comm.reply(UI);
-            } else if(ii==1) {
-                ii++;
-                dataIn[1]=buffer;
-                comm.reply(52);
-            } else if(ii==2) {
-                ii++;
-                dataIn[2]=buffer;
-                comm.reply(25);
-            }
-
-        }
         if(counter>=10) {
             UI=0;//set the UI to 0 unless it's changed in checkUI_Xbee()
             readBuffer();
@@ -77,8 +59,5 @@
             counter=0;
             pc.printf("UI: %d\r\n", UI);
         }
-        //counter++;
-        //}
-
     }
 }
\ No newline at end of file