mbed_robotcar / Mbed 2 deprecated lpc1768_Wifi_compleat

Dependencies:   mbed

Revision:
4:28985bd8dd06
Parent:
3:d4d9cc252417
--- a/main.cpp	Mon Aug 03 07:13:36 2020 +0000
+++ b/main.cpp	Mon Aug 03 08:13:03 2020 +0000
@@ -14,15 +14,30 @@
 DigitalOut  led2(LED2);    // (PTB19)
 DigitalOut  led3(LED3);     // (PTD1)
 
+enum MODE {
+    READY = -1,
+    ADVANCE = 1,
+    RIGHT,
+    LEFT,
+    BACK,
+    STOP,
+    LINE_TRACE,     //  6:ライントレース
+    AVOIDANCE,      //  7:障害物回避
+    SPEED,          //  8:スピード制御
+};
 // Digital Out and In pins, can be configured to any suitable pin depending on Platform
 AnalogIn   Ain1(p18);//battery
 
 Timer t1;
 Timer t2;
 
+int flag_sp = 0;
+
 struct tm t;
 
-int bufflen, DataRX, count, getcount, replycount, servreq, timeout;
+int mode = ADVANCE;
+int beforeMode = mode;
+int bufflen, DataRX, ount, getcount, replycount, servreq, timeout;
 int bufl, ipdLen, linkID, weberror, webcounter;
 float temperature, AdcIn, Ht;
 float R1=100000, R2=10000; // resistor values to give a 10:1 reduction of measured AnalogIn voltage
@@ -42,7 +57,7 @@
 //char webbuff[4096*4];     // Currently using 1986 characters, Increase this if more web page data added
 
 void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck(),touchuan();
-void gettime(),gettemp(),getbattery(),setRTC(),beep();
+void gettime(),getbattery(),setRTC();
 
 // manual set RTC values
 int minute      =00;    // 0-59
@@ -63,8 +78,8 @@
     //pc.printf("\n\r------------ callback is being called --------------\n\r");
     led3=1;
     while (esp.readable()) {
-        webbuff[count] = esp.getc();
-        count++;
+        webbuff[ount] = esp.getc();
+        ount++;
     }
     if(strlen(webbuff)>bufflen) {
         pc.printf("\f\n\r------------ webbuff over bufflen --------------\n\r");
@@ -75,12 +90,10 @@
 
 int main()
 {
-    reset=0;
     pc.baud(115200);
 
     pc.printf("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r");
     wait(0.5);
-    reset=1;
     led1=1,led2=0,led3=0;
     timeout=6000;
     getcount=500;
@@ -89,7 +102,6 @@
     if (time(NULL) < 1420070400) {
         setRTC();
     }
-    beep();
     startserver();
 
     while(1) {
@@ -97,7 +109,6 @@
             pc.printf("\f\n\r------------ main while > if --------------\n\r");
 
             ReadWebData();
-            beep();
             if (servreq == 1 && weberror == 0) {
                 pc.printf("\f\n\r------------ befor send page --------------\n\r");
                 sendpage();
@@ -115,7 +126,6 @@
 // Static WEB page
 void sendpage()
 {
-    gettemp();
     getbattery();
     gettime();
 
@@ -244,7 +254,7 @@
             strcat(webbuff, "AVOIDANCE</button></td><td>");
             strcat(webbuff, "<button id='tracebtn' type='button' class=\"light\" value=\"LINE TRACE\"  onClick='send_mes_fun(this.id,this.value)' >LINE TRACE");
             break;
-    default:
+        default:
             strcat(webbuff, "<button id='gobtn' type='button' class=\"noselect\"  value=\"GO\"  onClick='send_mes(this.id,this.value)'>GO");
             strcat(webbuff, "</button></td><td></td></tr><tr><td>");
             strcat(webbuff, "<button id='leftbtn' type='button' class=\"noselect\" value=\"LEFT\"  onClick='send_mes(this.id,this.value)' >LEFT");
@@ -264,32 +274,36 @@
     strcat(webbuff, "</button></td></tr></table>");
     strcat(webbuff, "<strong>Speed</strong>");
     strcat(webbuff, "<table><tr><td>");
-//ready示速度だけ点灯
-    switch (flag_sp%3) {
+    //ready示速度だけ点灯
+    switch (flag_sp) {
         case 0:
             strcat(webbuff, "<button id='sp1btn' type='button' class=\"light\" value=\"SLOW\"  onClick='send_mes_spe(this.id,this.value)' >SLOW");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"FAST\"  onClick='send_mes_spe(this.id,this.value)' >FAST");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"FLY\"  onClick='send_mes_spe(this.id,this.value)' >FLY");
+            break;
         case 1:
             strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"SLOW\"  onClick='send_mes_spe(this.id,this.value)' >SLOW");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp2btn' type='button' class=\"light\" value=\"FAST\"  onClick='send_mes_spe(this.id,this.value)' >FAST");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"FLY\"  onClick='send_mes_spe(this.id,this.value)' >FLY");
+            break;
         case 2:
             strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"SLOW\"  onClick='send_mes_spe(this.id,this.value)' >SLOW");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"FAST\"  onClick='send_mes_spe(this.id,this.value)' >FAST");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp3btn' type='button' class=\"light\" value=\"FLY\"  onClick='send_mes_spe(this.id,this.value)' >FLY");
+            break;
         default:
             strcat(webbuff, "<button id='sp1btn' type='button' class=\"noselect\" value=\"SLOW\"  onClick='send_mes_spe(this.id,this.value)' >SLOW");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp2btn' type='button' class=\"noselect\" value=\"FAST\"  onClick='send_mes_spe(this.id,this.value)' >FAST");
             strcat(webbuff, "</button></td><td>");
             strcat(webbuff, "<button id='sp3btn' type='button' class=\"noselect\" value=\"FLY\"  onClick='send_mes_spe(this.id,this.value)' >FLY");
+            break;
     }
     strcat(webbuff, "</button></td></tr></table>");
 
@@ -312,15 +326,13 @@
     strcat(webbuff, "htmlacs(url);");
     strcat(webbuff, "console.log(url);");
     strcat(webbuff, "}");
-    strcat(webbuff, "}");
     strcat(webbuff, "function send_mes_fun(btnmes,btnval){");
     strcat(webbuff, "var url = \"http://\" + window.location.hostname + \"/cargo?a=\" + btnval;");
     strcat(webbuff, "htmlacs(url);");
     strcat(webbuff, "console.log(url);");
     strcat(webbuff, "}");
-    strcat(webbuff, "}");
     strcat(webbuff, "</script>");
-// end of WEB page data
+    // end of WEB page data
     bufl = strlen(webbuff); // get total page buffer length
     //sprintf(cmdbuff,"AT+CIPSEND=%d,%d\r\n", linkID, bufl); // send IPD link channel and buffer character length.
 
@@ -457,7 +469,7 @@
 {
     wait_ms(200);
     esp.attach(NULL);
-    count=0;
+    ount=0;
     DataRX=0;
     weberror=0;
     memset(webdata, '\0', sizeof(webdata));
@@ -474,78 +486,78 @@
 
         if( strstr(webdata, "GO") != NULL ) {
             pc.printf("+++++++++++++++++前進+++++++++++++++++++++\r\n");
-            run = ADVANCE;           // 前進
+            //run = ADVANCE;           // 前進
             mode = READY;            // モードs変更
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
 
         }
 
         if( strstr(webdata, "LEFT") != NULL ) {
             pc.printf("+++++++++++++++++左折+++++++++++++++++++++\r\n");
-            run = LEFT;
+            //run = LEFT;
             mode = READY;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
         }
 
         if( strstr(webdata, "STOP") != NULL ) {
             pc.printf("+++++++++++++++++停止+++++++++++++++++++++\r\n");
-            run = STOP;
+//            run = STOP;
             mode = READY;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
         }
 
         if( strstr(webdata, "RIGHT") != NULL ) {
             pc.printf("+++++++++++++++++右折+++++++++++++++++++++\r\n");
-            run = RIGHT;
+//            run = RIGHT;
             mode = READY;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
         }
 
         if( strstr(webdata, "BACK") != NULL ) {
             pc.printf("+++++++++++++++++後進+++++++++++++++++++++\r\n");
-            run = BACK;
+//            run = BACK;
             mode = READY;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
         }
         pc.printf("+++++++++++++++++succed+++++++++++++++++++++");
 
         if( strstr(webdata, "AVOIDANCE") != NULL ) {
             pc.printf("+++++++++++++++++AVOIDANCE+++++++++++++++++++++");
             mode=AVOIDANCE;
-            run = ADVANCE;
-            display();          // ディスプレイ表示
+//            run = ADVANCE;
+//            display();          // ディスプレイ表示
         }
         if( strstr(webdata, "LINE TRACE") != NULL ) {
             pc.printf("+++++++++++++++++LINET RACE+++++++++++++++++++++");
             mode=LINE_TRACE;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
         }
         if( strstr(webdata, "DEFAULT") != NULL ) {//プログラムなくね
             pc.printf("+++++++++++++++++DEFAULT+++++++++++++++++++++");
-            run = STOP;
+//            run = STOP;
             mode = READY;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
 
         }
         if( strstr(webdata, "SLOW") != NULL ) {
             pc.printf("++++++++++++++++++SLOW++++++++++++++++++++");
             mode = SPEED;       // スピードモード
             flag_sp = 0;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
             mode = beforeMode;  // 現在のモードに前回のモードを設定
         }
         if( strstr(webdata, "FAST") != NULL ) {
             pc.printf("++++++++++++++++++++FAST++++++++++++++++++");
             mode = SPEED;       // スピードモード
             flag_sp = 1;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
             mode = beforeMode;  // 現在のモードに前回のモードを設定
         }
         if( strstr(webdata, "FLY") != NULL ) {
             pc.printf("+++++++++++++++++++BERYFAST+++++++++++++++++++");
             mode = SPEED;       // スピードモード d
             flag_sp = 2;
-            display();          // ディスプレイ表示
+//            display();          // ディスプレイ表示
             mode = beforeMode;  // 現在のモードに前回のモードを設定
         }
         sprintf(channel, "%d",linkID);
@@ -566,7 +578,6 @@
 // Starts and restarts webserver if errors detected.
 void startserver()
 {
-    gettemp();
     gettime();
     pc.printf("\n\n RTC time   %s\r\n\n",timebuf);
     pc.printf("++++++++++ Resetting ESP ++++++++++\r\n");
@@ -576,7 +587,7 @@
     SendCMD();
     getreply();
     pc.printf(replybuff);
-    pc.printf("%d",count);
+    pc.printf("%d",ount);
     if (strstr(replybuff, "OK") != NULL) {
         pc.printf("\n++++++++++ Starting Server ++++++++++\r\n");
         strcpy(cmdbuff, "AT+CIPMUX=1\r\n");  // set multiple connections.
@@ -618,7 +629,7 @@
         pc.printf(webdata);
         led2=1;
         bufflen=200;
-        count=0;
+        ount=0;
         pc.printf("\n\n++++++++++ Ready ++++++++++\r\n\n");
         esp.attach(&callback);
     } else {
@@ -627,7 +638,6 @@
     }
     t2.reset();
     t2.start();
-    beep();
 }
 // ESP Command data send
 void SendCMD()