linetrace saikyou

Dependencies:   RemoteIR TextLCD

Revision:
4:3f80c0180e2f
Parent:
3:2ae6218973be
Child:
5:3fffb364744b
--- a/main.cpp	Wed Jul 29 01:24:51 2020 +0000
+++ b/main.cpp	Wed Jul 29 03:10:44 2020 +0000
@@ -103,20 +103,21 @@
 void trace(void const *argument);
 void watchsurrounding();
 int watch();
-void bChange(void const *argument);
+void bChange(/*void const *argument*/);
 void display();
 void lcdBacklight(void const *argument);
-Thread thread1(decodeIR, NULL, osPriorityAboveNormal);
-Thread thread2(motor, NULL, osPriorityNormal);
-Thread thread3(avoidance, NULL, osPriorityLow);
-Thread thread4(trace, NULL, osPriorityLow);
-Thread thread5(bChange, NULL, osPriorityIdle);
+Thread thread1(decodeIR, NULL, osPriorityRealtime);//+3
+Thread thread2(motor, NULL, osPriorityHigh);//+2
+Thread thread3(avoidance, NULL, osPriorityHigh);//+2
+Thread thread4(trace, NULL, osPriorityHigh);//+2
+//Thread thread5(bChange, NULL, osPriorityBelowNormal);//-1
 RtosTimer bTimer(lcdBacklight, osTimerPeriodic);
 
 
-void decodeIR(void const *argument){  
-    while(1){  
+ void decodeIR(void const *argument){  
+   while(1){  
         // 受信待ち
+        pc.printf("decodeIR\r\n");
         if (ir.getState() == ReceiverIR::Received) {
             // コード受信
             bitcount = ir.getData(&format, buf, sizeof(buf) * 8);
@@ -135,6 +136,9 @@
                     case 0x40bf27d8://クイック
                         pc.printf("mode = SPEED\r\n");
                         mode = SPEED;
+                        changeSpeed();
+                        display();  
+                        mode = beforeMode;
                         break;
                     case 0x40be34cb://レグザリンク
                         pc.printf("mode = INE_TRACE\r\n");
@@ -181,8 +185,20 @@
                 }
             }
         }
-        ThisThread::sleep_for(10);
-    }        
+        if(viewTimer.read_ms()>=3000){
+            //pc.printf("a");
+            viewTimer.stop();
+            //defaultView();
+            viewTimer.reset();
+            display();
+            //flaga=0;
+        }
+        //pc.printf("                                    main2\r\n");
+        //if(viewTimer.read_ms()==0){
+         //   display();
+        //}
+        ThisThread::sleep_for(90);
+    }       
 }
 void motor(void const *argument){
     while(true){
@@ -223,7 +239,7 @@
                 break;
         }
         pc.printf("                motor\r\n");
-        ThisThread::sleep_for(50);
+        ThisThread::sleep_for(30);
     }
 }
 void changeSpeed(){
@@ -276,9 +292,9 @@
                     break;
             }
             pc.printf("                          line trace\r\n");
-            ThisThread::sleep_for(50);
+            ThisThread::sleep_for(30);
         }else{          
-            ThisThread::sleep_for(50);
+            ThisThread::sleep_for(1);
         }
     }
 }
@@ -369,7 +385,7 @@
             watchsurrounding();
             pc.printf("                avoidance\r\n");
         }else{  
-            ThisThread::sleep_for(50);
+            ThisThread::sleep_for(1);
         }
     }   
 }
@@ -508,7 +524,7 @@
     flag_b = !flag_b;
 }
 
-void bChange(void const *argument){
+void bChange(/*void const *argument*/){
     /*while(1){
         pc.printf("                                                                              bChange1\r\n");
         lcd.setBacklight(TextLCD::LightOn);
@@ -528,11 +544,13 @@
     lcd.setBacklight(TextLCD::LightOn);
     while(1){
         pc.printf("                                                                              bChange1\r\n");
-        b = (int)((battery.read()* MAX_V - MIN_V)/0.067 + 0.5)*10;
-        if(b < 0){//すべての機能停止
-            lcd.setBacklight(TextLCD::LightOff);
+        b = (int)(((battery.read() * 3.3 - MIN_V)/0.67)*10+0.5)*10;
+        pc.printf("%f",battery.read());
+        if(b < 0){//すべての機能停止(今はなし)
+            /*lcd.setBacklight(TextLCD::LightOff);
             bTimer.stop();
-            exit(1);
+            exit(1);*/
+            b = 0;
         }else if(b > 100){
             b = 100;
         }
@@ -554,19 +572,21 @@
             }
         }
     }
-        
+    ThisThread::sleep_for(500);    
 }
 int main() {
     mode = READY;
     beforeMode = READY;
     run = STOP;
     flag_sp = NORMAL;
+    display();
     //defaultView();
     
     while(1){
         pc.printf("                                    main1\r\n");
-        switch(mode){
-            /*case ADVANCE:
+        // 受信待ち
+        /*switch(mode){
+            case ADVANCE:
                 run = ADVANCE;
                 break;
             case RIGHT:
@@ -583,15 +603,15 @@
                 break;
             case READY:
                 run = STOP;
-                break;*/
+                break;
             case SPEED:
                 changeSpeed();
                 display();  
                 mode = beforeMode;
                 break;            
-        }
+        }*/
 
-        if(viewTimer.read_ms()>=3000){
+/*        if(viewTimer.read_ms()>=3000){
             pc.printf("a");
             viewTimer.stop();
             //defaultView();
@@ -601,8 +621,9 @@
         pc.printf("                                    main2\r\n");
         if(viewTimer.read_ms()==0){
             display();
-        }
+        }*/
+        bChange();
         pc.printf("                                    main3\r\n");
-        ThisThread::sleep_for(10);
+        ThisThread::sleep_for(1);
     }
 }
\ No newline at end of file