State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Revision:
4:5a44ab7e94b3
Parent:
3:4b19b6cf6cc7
Child:
5:2632dfc8454c
--- a/main.cpp	Tue Oct 30 11:40:00 2018 +0000
+++ b/main.cpp	Tue Oct 30 11:52:50 2018 +0000
@@ -33,11 +33,17 @@
 
 void do_state_waiting()
 {
+    if(last_state != current_state) {
+        last_state = current_state;
+        // State just changed to this one.
+
+        led_green = 1;
+        screen.display_state_name("Waiting");
+    }
+    
     if (ud_button.is_pressed()) {
         current_state = calib_motor;
     }
-
-    led_green = 1;
 }
 
 void do_state_calib_motor()
@@ -47,6 +53,7 @@
         // State just changed to this one.
 
         led_green = 0;
+        screen.display_state_name("Motor calib");
     }
 }
 
@@ -90,6 +97,7 @@
         // Update the display.
         led_red = 0;
         led_green = 1;
+        screen.display_state_name("Error!");
     }
 
     // Stop the motors!
@@ -139,10 +147,9 @@
 
     // Start in the waiting state.
     current_state = waiting;
-    last_state = waiting;
-    
-    screen.get_screen_handle().printf("OLED Display\r\n");
-    screen.display();
+    // Pretend we come from the operation state.
+    // So that the waiting state knows it just got started.
+    last_state = operation;
 
     while (true) {
         main_loop();