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

Dependencies:   RemoteIR TextLCD

Revision:
43:243c1455f88a
Parent:
42:56022456ef23
Child:
44:721432d6ee4b
--- a/main.cpp	Wed Aug 19 06:34:15 2020 +0000
+++ b/main.cpp	Thu Aug 20 01:44:17 2020 +0000
@@ -128,13 +128,15 @@
 void display();
 void lcdBacklight(void const *argument);
 void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck(),touchuan();
-void wifi(void const *argument);
+void wifi(/*void const *argument*/);
 Thread *deco_thread;                                      // decodeIRをスレッド化 :+3
-Thread wifi_thread(wifi,NULL,osPriorityRealtime);         // wifiをスレッド化
+Thread *wifi_thread;
+//wifi_thread(wifi,NULL,osPriorityHigh);         // wifiをスレッド化
 Thread *motor_thread;                                     // motorをスレッド化    :+2
 //Thread avoi_thread(avoidance, NULL, osPriorityHigh);    // avoidanceをスレッド化:+2
 //Thread trace_thread(trace, NULL, osPriorityHigh);       // traceをスレッド化    :+2
 RtosTimer bTimer(lcdBacklight, osTimerPeriodic);          // lcdBacklightをタイマー割り込みで設定
+//Ticker bTimer;
 Thread *avoi_thread;
 Thread *trace_thread;
 
@@ -148,6 +150,7 @@
     deco_thread -> set_priority(osPriorityRealtime);
     motor_thread = new Thread(motor);
     motor_thread -> set_priority(osPriorityHigh);
+    wifi_thread -> set_priority(osPriorityRealtime);
     display();
 }
 
@@ -678,11 +681,13 @@
     mutex.unlock();                  // ミューテックスアンロック                 
     if(b <= 30){                     // バッテリー残量30%以下なら
         if(flag_t == 0){             // バックライトタイマーフラグが0なら
+            //bTimer.attach(lcdBacklight,0.5);
             bTimer.start(500);       // 0.5秒周期でバックライトタイマー割り込み
             flag_t = 1;              // バックライトタイマーフラグを1に切り替え
         }
     }else{
         if(flag_t == 1){             // バックライトタイマーフラグが1なら
+            //bTimer.detach();
             bTimer.stop();           // バックライトタイマーストップ
             lcd.setBacklight(TextLCD::LightOn); // バックライトON
             flag_t = 0;              // バックライトタイマーフラグを0に切り替え
@@ -706,7 +711,7 @@
     }
 }
  
-void wifi(void const *argument)
+void wifi(/*void const *argument*/)
 {
     pc.printf("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r");
     ThisThread::sleep_for(100);
@@ -759,7 +764,7 @@
     } else {        //30%より下の場合残電量を赤文字
         strcat(webbuff, "<font color=\"red\">");
         sprintf(webbuff, "%s%3d", webbuff, b);
-        strcat(webbuff, "<\font>");
+        strcat(webbuff, "</font>");
     }
     strcat(webbuff, "%</strong>");
     strcat(webbuff, "<button id=\"reloadbtn\" type=\"button\" class=\"load\" onclick=\"rel()\">RELOAD</button>");
@@ -955,7 +960,7 @@
     strcat(webbuff, "htmlacs(url);");
     strcat(webbuff, "console.log(url);");
     strcat(webbuff, "var buttons = document.getElementsByTagName(\"button\");");
-    strcat(webbuff, "for(var i=0;i<7;i++){");
+    strcat(webbuff, "for(var i=1;i<8;i++){");
     strcat(webbuff, "if(buttons[i].value == btnval){");
     strcat(webbuff, "buttons[i].className=\"light\";");
     strcat(webbuff, "}else{");
@@ -969,7 +974,7 @@
     strcat(webbuff, "htmlacs(url);");
     strcat(webbuff, "console.log(url);");
     strcat(webbuff, "var buttons = document.getElementsByTagName(\"button\");");
-    strcat(webbuff, "for(var i=7;i<10;i++){");
+    strcat(webbuff, "for(var i=8;i<11;i++){");
     strcat(webbuff, "if(buttons[i].value == btnval){");
     strcat(webbuff, "buttons[i].className=\"light\";");
     strcat(webbuff, "}else{");
@@ -1088,6 +1093,27 @@
         pc.printf("+++++++++++++++++succed rec begin+++++++++++++++++++++\r\n");
         pc.printf("%s",webdata);
         pc.printf("+++++++++++++++++succed rec end+++++++++++++++++++++\r\n");
+        if( strstr(webdata, "Normal") != NULL ) {
+            pc.printf("++++++++++++++++++Normal++++++++++++++++++++");
+            mode = SPEED;       // スピードモード
+            flag_sp = 0;
+            display();          // ディスプレイ表示
+            mode = beforeMode;  // 現在のモードに前回のモードを設定
+        }else if( strstr(webdata, "VeryFast") != NULL ) {
+            pc.printf("+++++++++++++++++++VeryFast+++++++++++++++++++");
+            mode = SPEED;       // スピードモード 
+            flag_sp = 2;
+            display();          // ディスプレイ表示
+            mode = beforeMode;  // 現在のモードに前回のモードを設定
+        }else if( strstr(webdata, "Fast") != NULL ) {
+            pc.printf("++++++++++++++++++++Fast++++++++++++++++++");
+            mode = SPEED;       // スピードモード
+            flag_sp = 1;
+            display();          // ディスプレイ表示
+            mode = beforeMode;  // 現在のモードに前回のモードを設定
+        }else{
+            beforeMode = mode;
+        }
         if( strstr(webdata, "GO") != NULL ) {
             pc.printf("+++++++++++++++++前進+++++++++++++++++++++\r\n");
             //delete avoi_thread;     //障害物回避スレッド停止
@@ -1156,27 +1182,6 @@
             mode=LINE_TRACE;
             display();          // ディスプレイ表示
         }
-        if( strstr(webdata, "Normal") != NULL ) {
-            pc.printf("++++++++++++++++++Normal++++++++++++++++++++");
-            mode = SPEED;       // スピードモード
-            flag_sp = 0;
-            display();          // ディスプレイ表示
-            mode = beforeMode;  // 現在のモードに前回のモードを設定
-        }
-        if( strstr(webdata, "Fast") != NULL ) {
-            pc.printf("++++++++++++++++++++Fast++++++++++++++++++");
-            mode = SPEED;       // スピードモード
-            flag_sp = 1;
-            display();          // ディスプレイ表示
-            mode = beforeMode;  // 現在のモードに前回のモードを設定
-        }
-        if( strstr(webdata, "VeryFast") != NULL ) {
-            pc.printf("+++++++++++++++++++VeryFast+++++++++++++++++++");
-            mode = SPEED;       // スピードモード 
-            flag_sp = 2;
-            display();          // ディスプレイ表示
-            mode = beforeMode;  // 現在のモードに前回のモードを設定
-        }
         if(mode != LINE_TRACE && trace_thread->get_state() != Thread::Deleted){
             trace_thread->terminate();
         }
@@ -1238,7 +1243,9 @@
         getcount=200;
         while(weberror==0) {
             SendCMD();
+            pc.printf("\nここだ\r\n");
             getreply();
+            pc.printf("\nどこだ\r\n");
             if (strstr(replybuff, "0.0.0.0") == NULL) {
                 weberror=1;   // wait for valid IP
             }
@@ -1281,9 +1288,13 @@
 // Get Command and ESP status replies
 void getreply()
 {
+    pc.printf("a\r\n");
     memset(replybuff, '\0', sizeof(replybuff));
+    pc.printf("b\r\n");
     time1.reset();
+    pc.printf("c\r\n");
     time1.start();
+    pc.printf("d\r\n");
     replycount=0;
     while(time1.read_ms()< timeout && replycount < getcount) {
         if(esp.readable()) {
@@ -1297,6 +1308,8 @@
 /* mainスレッド */
 int main() {
     /* 初期設定 */
+    wifi_thread = new Thread(wifi);
+    wifi_thread -> set_priority(osPriorityHigh);
     avoi_thread = new Thread(avoidance);
     avoi_thread->terminate();
     trace_thread = new Thread(trace);