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

Dependencies:   RemoteIR TextLCD

Revision:
33:a6f1090e0174
Parent:
32:049d9ba081d4
Child:
34:040474bf6fe0
--- a/main.cpp	Thu Aug 06 06:25:50 2020 +0000
+++ b/main.cpp	Thu Aug 06 07:09:11 2020 +0000
@@ -117,8 +117,8 @@
 
 
 /* プロトタイプ宣言 */
-void decodeIR(void const *argument);
-void motor(void const *argument);
+void decodeIR(/*void const *argument*/);
+void motor(/*void const *argument*/);
 void changeSpeed();
 void avoidance(/*void const *argument*/);
 void trace(/*void const *argument*/);
@@ -129,12 +129,12 @@
 void lcdBacklight(void const *argument);
 void SendCMD(),getreply(),ReadWebData(),startserver(),sendpage(),SendWEB(),sendcheck(),touchuan();
 void wifi(void const *argument);
-Thread deco_thread(decodeIR, NULL, osPriorityRealtime); // decodeIRをスレッド化 :+3
-Thread wifi_thread(wifi,NULL,osPriorityRealtime);       // wifiをスレッド化
-Thread motor_thread(motor, NULL, osPriorityHigh);       // motorをスレッド化    :+2
+Thread *deco_thread;                                      // decodeIRをスレッド化 :+3
+Thread wifi_thread(wifi,NULL,osPriorityRealtime);         // 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をタイマー割り込みで設定
+RtosTimer bTimer(lcdBacklight, osTimerPeriodic);          // lcdBacklightをタイマー割り込みで設定
 Thread *avoi_thread;
 Thread *trace_thread;
 
@@ -143,8 +143,16 @@
 DigitalOut  led3(LED3);
 DigitalOut  led4(LED4);
 
+void setup(){
+    deco_thread = new Thread(decodeIR);
+    deco_thread -> set_priority(osPriorityRealtime);
+    motor_thread = new Thread(motor);
+    motor_thread -> set_priority(osPriorityHigh);
+    display();
+}
+
 /* リモコン受信スレッド */
-void decodeIR(void const *argument){ 
+void decodeIR(/*void const *argument*/){ 
    while(1){ 
         // 受信待ち
         if (ir.getState() == ReceiverIR::Received){ // コード受信
@@ -239,7 +247,7 @@
 }
 
 /* モーター制御スレッド */
-void motor(void const *argument){
+void motor(/*void const *argument*/){
     while(1){
         /* 走行状態の場合分け */
         switch(run){
@@ -646,7 +654,7 @@
 void wifi(void const *argument)
 {
     pc.printf("\f\n\r------------ ESP8266 Hardware Reset psq --------------\n\r");
-    ThisThread::sleep_for(500);
+    ThisThread::sleep_for(100);
     led1=1,led2=0,led3=0;
     timeout=6000;
     getcount=500;
@@ -690,7 +698,14 @@
     strcat(webbuff, "<style type=\"text/css\">.noselect{ width:100px;height:60px;}.light{ width:100px;height:60px;background-color:#00ff66;}</style>");
     strcat(webbuff, "</head><body><center><p><strong>Robot Car Remote Controller");
     strcat(webbuff, "</strong></p><td style='vertical-align:top;'><strong>Battery level ");
-    strcat(webbuff, "<input type=\"text\" id=\"leftms\" size=4 value=250>%</strong>");
+    if(b > 30) {
+        sprintf(webbuff, "%s%3d", webbuff, b);
+    } else {
+        strcat(webbuff, "<font color=\"red\">");
+        sprintf(webbuff, "%s%3d", webbuff, b);
+        strcat(webbuff, "<\font>");
+    }
+    strcat(webbuff, "%</strong>");
     strcat(webbuff, "</td></p>");
     strcat(webbuff, "<br>");
     strcat(webbuff, "<table><tr><td></td><td>");
@@ -1139,7 +1154,7 @@
         SendCMD();
         getreply();
         pc.printf(replybuff);
-        ThisThread::sleep_for(1000);
+        ThisThread::sleep_for(500);
         sprintf(cmdbuff,"AT+CIPSTO=%d\r\n",SERVtimeout);
         timeout=500;
         getcount=50;
@@ -1169,6 +1184,7 @@
         //bufflen=100;
         ount=0;
         pc.printf("\n\n++++++++++ Ready ++++++++++\r\n\n");
+        setup();
         esp.attach(&callback);
     } else {
         pc.printf("\n++++++++++ ESP8266 error, check power/connections ++++++++++\r\n");
@@ -1220,7 +1236,9 @@
     run = STOP;             // 停止
     flag_sp = NORMAL;       // スピード(普通)
     lcd.setBacklight(TextLCD::LightOn);  // バックライトON
-    display();              // ディスプレイ表示
+    lcd.setAddress(0,1);
+    lcd.printf("Mode:SetUp");
+    //display();              // ディスプレイ表示
     
     while(1){
         bChange();          // バッテリー残量更新