ボタンを押すと、 バッテリ更新を停止し、 他のボタンもロックさせる

Dependencies:   RemoteIR TextLCD

Revision:
48:7be823ac7eb8
Parent:
47:8a5a4275480a
Child:
49:14b3dba5bd56
--- a/main.cpp	Mon Aug 24 02:04:01 2020 +0000
+++ b/main.cpp	Tue Aug 25 05:15:48 2020 +0000
@@ -123,6 +123,7 @@
 void watchsurrounding3();
 void watchsurrounding5();
 int watch();
+char battery_ch[8];
 void bChange();
 void display();
 void lcdBacklight(void const *argument);
@@ -755,18 +756,19 @@
  
     strcpy(webbuff, "<!DOCTYPE html>");
     strcat(webbuff, "<html><head><title>RobotCar</title><meta name='viewport' content='width=device-width'/>");
-    strcat(webbuff, "<meta http-equiv=\"refresh\" content=\"5\"; >");
+    //strcat(webbuff, "<meta http-equiv=\"refresh\" content=\"5\"; >");
     strcat(webbuff, "<style type=\"text/css\">.noselect{ width:100px;height:60px;}.light{ width:100px;height:60px;background-color:#00ff66;}.load{ width: 50px; height: 30px;font-size:10px}</style>");
     strcat(webbuff, "</head><body><center><p><strong>Robot Car Remote Controller");
     strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level ");
+    /*
     if(b > 30) {    //残電量表示
         sprintf(webbuff, "%s%3d", webbuff, b);
     } else {        //30%より下の場合残電量を赤文字
         strcat(webbuff, "<font color=\"red\">");
         sprintf(webbuff, "%s%3d", webbuff, b);
         strcat(webbuff, "</font>");
-    }
-    strcat(webbuff, "%</strong>");
+    }*/
+    strcat(webbuff, "<input type=\"text\" id=\"leftms\" size=4 value=250>%</strong>");
     strcat(webbuff, "<button id=\"reloadbtn\" type=\"button\" class=\"load\" onclick=\"rel()\">RELOAD</button>");
     strcat(webbuff, "</td></p>");
     strcat(webbuff, "<br>");
@@ -953,6 +955,47 @@
     strcat(webbuff, "xhr.send(\"\");");
     strcat(webbuff, "}");
     
+    
+    //0825
+//
+//0824 battery update auto
+strcat(webbuff, "function battery_update() {");
+strcat(webbuff, "var url1 =  \"http://\" + window.location.hostname+ \"/cargo?a=responseBattery\";");
+strcat(webbuff, "var xhr1 = new XMLHttpRequest();");
+strcat(webbuff, "xhr1.open(\"GET\", url1);");
+//0820
+strcat(webbuff, "xhr1.onreadystatechange = function(){");
+            //strcat(webbuff, "console.log(\"onready function is being reload!\");");
+            strcat(webbuff, "if(this.readyState == 4 && this.status == 200){");
+            //strcat(webbuff, "console.log(\"state is being reload!\");");
+                strcat(webbuff, "var res1 = xhr1.responseText;");
+
+//color                
+                strcat(webbuff, "var battery_num=res1;");
+    strcat(webbuff, "if(battery_num>0 && battery_num<31){");
+         strcat(webbuff, "document.getElementById('leftms').style.color=\"red\";");
+    strcat(webbuff, "}");
+    strcat(webbuff, "if(battery_num>39 && battery_num<61){");
+         strcat(webbuff, "document.getElementById('leftms').style.color=\"orange\";");
+    strcat(webbuff, "}");
+    strcat(webbuff, "if(battery_num>69 && battery_num<101){");
+         strcat(webbuff, "document.getElementById('leftms').style.color=\"blue\";");
+    strcat(webbuff, "}");
+//color
+                                         strcat(webbuff, "document.getElementById('leftms').value=res1;}};");
+       
+                
+                //strcat(webbuff, "console.log(res);}};");
+//0820
+
+strcat(webbuff, "xhr1.send();");
+strcat(webbuff, "}");
+strcat(webbuff, "setInterval(battery_update,15000);");
+
+//0824 battery update auto
+//0825
+    
+    
     strcat(webbuff, "function send_mes(btnmes,btnval){");       //mode変更ボタン入力時の点灯消灯判定
     strcat(webbuff, "console.log(btnval);");
  
@@ -1018,7 +1061,7 @@
             if(((i%2047)==0) && (i>0)) {
                 //wait_ms(10);
                 ThisThread::sleep_for(10);
-                sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl-2048)>2048?2048:(bufl-2048)); // send IPD link channel and buffer character length.
+                sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl-2048*(i/2047))>2048?2048:(bufl-2048*(i/2047))); // send IPD link channel and buffer character length.
                 //pc.printf("\r\n++++++++++ AT+CIPSENDBUF=%d,%d ++++++++++\r\n", linkID, (bufl-2048)>2048?2048:(bufl-2048));
                 timeout=600;
                 getcount=50;
@@ -1035,6 +1078,42 @@
     pc.printf("\n++++++++++ send web i= %dinfo ++++++++++\r\n",i);
 }
  
+
+void sendpage2()
+{
+// WEB page data
+
+//strcpy(webbuff, "<script language=\"javascript\" type=\"text/javascript\">");
+//strcat(webbuff, "document.getElementById('leftms').value=\"100\";");
+
+sprintf(battery_ch,"%d",b);
+//sprintf(battery_ch,"%d",30);
+strcpy(webbuff, battery_ch);
+
+//strcpy(webbuff, "document.getElementById('leftms').value=\"100\";");
+
+//strcat(webbuff, "</script>");
+// 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.
+    
+    sprintf(cmdbuff,"AT+CIPSENDBUF=%d,%d\r\n", linkID, (bufl>2048?2048:bufl)); // send IPD link channel and buffer character length.
+    timeout=500;
+    getcount=40;
+    SendCMD();
+    getreply();
+    pc.printf(replybuff);
+    pc.printf("\n++++++++++ AT+CIPSENDBUF=%d,%d+++++++++\r\n", linkID, (bufl>2048?2048:bufl));
+    
+    pc.printf("\n++++++++++ bufl is %d ++++++++++\r\n",bufl);
+    
+    //pastthrough mode
+    SendWEB();  // send web page
+    pc.printf("\n++++++++++ webbuff clear  ++++++++++\r\n");
+  
+    memset(webbuff, '\0', sizeof(webbuff));
+    sendcheck();
+}
  
 void sendcheck()
 {
@@ -1093,6 +1172,14 @@
         pc.printf("+++++++++++++++++succed rec begin+++++++++++++++++++++\r\n");
         pc.printf("%s",webdata);
         pc.printf("+++++++++++++++++succed rec end+++++++++++++++++++++\r\n");
+        
+         if( strstr(webdata, "responseBattery") != NULL ) {
+             click_flag = 0;
+             led4=!led4;
+             pc.printf("\r\n++++++++++++++mode = LEFT++++++++++++++\r\n");
+             sendpage2();
+            }
+        
         if( strstr(webdata, "Normal") != NULL ) {
             pc.printf("++++++++++++++++++Normal++++++++++++++++++++");
             mode = SPEED;       // スピードモード