Kiko Ishimoto / Mbed 2 deprecated sotuken_mother_2

Dependencies:   ds3_si mbed omuni solenoid

Fork of 2017_Robocon_mother by gaku takasawa

Revision:
7:c24e61f00404
Parent:
6:f5f0b60cd380
Child:
8:030080071a4a
--- a/main.cpp	Fri Oct 13 10:22:35 2017 +0000
+++ b/main.cpp	Mon Oct 16 11:12:46 2017 +0000
@@ -14,13 +14,21 @@
 Serial master(p13,p14);
 Serial pc(USBTX, USBRX);
 
+BusOut serialsel(p19,p20,LED1,LED2);
 Timer serialtimer;
+Ticker readtimer;
 
 char ConData[2][12];
 char offset[4];
 
+void mbedreset()
+{
+    NVIC_SystemReset();
+}
+
 void GetData()
 {
+    readtimer.attach(&mbedreset, 1);
     static bool main_flag = 1 ;
     if ( con.getc() == 'H' ) {
          ConData[0][0] = 'H';
@@ -48,6 +56,7 @@
             offset[1] = ConData[0][2];
             offset[2] = ConData[1][1];
             offset[3] = ConData[1][2];
+            serialtimer.start();
             main_flag = 0;
         }
         ConData[0][1] -= offset[0];
@@ -57,15 +66,25 @@
         
         if( (char)255 - CON_OFFSET < ConData[1][1] || ConData[1][1] < CON_OFFSET)
             ConData[1][1] = 0;
+            
+        serialtimer.reset();
     }
+    readtimer.detach();
 }
 
+
 int main() {
+        serialsel = 0x05;
         con.baud(115200);
         master.baud(115200);
         pc.baud(115200);
         con.attach(&GetData,Serial::RxIrq);
         
+        serialtimer.stop();
+        serialtimer.reset();
+        
+        pc.printf("start\n\n\n\n");
+        
         while(1){
             
             char MotorData[] = {'H', ConData[0][1], ConData[0][2], ConData[1][1], ConData[1][2]};
@@ -73,6 +92,12 @@
 
             char soldata = ((ConData[0][3] << 2) + ConData[1][3]) << 4;
             sol = soldata;
+            
+            if(serialtimer.read_ms() > 500)
+            {
+                serialsel = ~serialsel;
+                serialtimer.reset();
+            }
 
             #ifdef DEBUG 
             for(int i = 0; i < 12; i++)
@@ -82,7 +107,7 @@
             for(int i = 0; i < 12; i++)
             {
                     pc.printf("%3d ",ConData[1][i]);
-            }
+            } 
             pc.printf("\n\r");
             
             for(int i = 0; i < 4; i++)
@@ -93,6 +118,5 @@
             
             printf("%d\n",soldata);
             #endif
-
         }  
 }