ECE3872 HW/SW Project Code

Dependencies:   mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1

Revision:
23:34aed77d5b2c
Parent:
22:fd48dd707e4f
--- a/main.cpp	Sat Apr 11 16:40:50 2020 +0000
+++ b/main.cpp	Sat Apr 11 16:43:11 2020 +0000
@@ -1,19 +1,11 @@
 #include "mbed.h"
 #include <iostream>
-#include "Speakerout2.h"
+#include "audio_out.h"
 #include "PinDetect.h"
 #include "uLCD_4DGL.h"
-DigitalOut myled1(LED1);
-DigitalOut myled2(LED1);
-DigitalOut myled3(LED1);
-DigitalOut myled4(LED1);
-// LCD init
-uLCD_4DGL guLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
-// Push buttons init
-PinDetect pb1(p16); 
-PinDetect pb2(p17);  
-PinDetect pb3(p18); 
-PinDetect pb4(p19); 
+DigitalOut myled(LED1);
+//Serial mac(USBTX,USBRX);
+
 // States 
 #define sRESET 1
 #define sSTOP 2
@@ -29,7 +21,6 @@
 
 
 
-
 void reset(){ 
     /* reset state:
         Initial state upon powering up the device
@@ -50,7 +41,7 @@
         3. Mute all audio
     */
 }
-//void record(){
+void record(){
     /* record state:
         Initiated by rotary switch
         1. Cease all motion
@@ -59,7 +50,7 @@
         4. Append to list of frequencies
         5. 
     */
-//}
+}
 void play(){
     /* play state:
         Initiated by rotary switch
@@ -75,50 +66,95 @@
     */
 }
 
+
+
+
 void state_machine_mgr(){
-    int curr_state =  sRESET;
+    pc.printf("SM\n");
+    char curr_state =  1;
+    X = 1;
+    S = 0;
+    R = 0;
+    P = 0;
+    E = 0;
     while(1) {
+        if (pc.readable()) {                // if they have pressed a key
+            curr_state = pc.getc();
+            if('1') X=!X;   //toggle reset
+            if('2') S=!S;   //toggle stop
+            if('3') R=!R;   //toogle record
+            if('4') P=!P;   //toggle play
+            if('5') E=!E;   //toggle erase
+        }
+        
+        // Implementing state machine logical transitions based on what states can exit to other states
+        if(X){
+            if(E){
+                curr_state = 5;
+                X = !X;
+            }else if(S){
+                curr_state = 2;
+                X = !X;
+            }
+        }else if(S){
+            if(X){
+                curr_state = 1;
+                S = !S;
+            }else if(R){
+                curr_state = 3;
+                S = !S;
+            }else if(P){
+                curr_state = 4;
+                S = !S;
+            }
+        }else if(R){
+            if(X){
+                curr_state = 1;
+                R = !R;
+            }else if(S){
+                curr_state = 2;
+                R = !R;
+            }
+        }else if(P){
+            if(X){
+                curr_state = 1;
+                P = !P;
+            }else if(S){
+                curr_state = 2;
+                P = !P;
+            }
+        }else if(E){
+            if(X){
+                curr_state = 1;
+                E = !E;
+            }
+        }
         switch(curr_state){
-            case sRESET:
-                if(S) curr_state = sSTOP;
-                break;
-            case sSTOP:
-                if(X){
-                    curr_state = sRESET;
-                }else if(S&R){
-                    curr_state = sRECORD;
-                }else if(S&P){
-                    curr_state = sPLAY;
-                }
+            case 1:
+                pc.printf("RESET\n");
+                reset();
                 break;
-            case sRECORD:
-                if(X){
-                    curr_state = sRESET;
-                }else if(R&S){
-                    curr_state = sSTOP;
-                }else if(R&P){
-                    curr_state = sPLAY;
-                }
+            case 2:
+                pc.printf("STOP\n");
+                stop();
+                break;
+            case 3:
+                pc.printf("RECORD\n");
+                record();
                 break;
-            case sPLAY:
-                if(X){
-                    curr_state = sRESET;
-                }else if(P&S){
-                    curr_state = sSTOP;
-                }else if(P&R){
-                    curr_state = sPLAY;
-                }
+            case 4:
+                pc.printf("PLAY\n");
+                play();
                 break;
-            case sERASE:
-                if(X){
-                    curr_state = sRESET;
-                }
+            case 5:
+                pc.printf("ERASE\n");
+                erase();
+                break;
         }
     }
 }
 
 int main() {
-    //hardware_init();
-    //state_machine_mgr();
-    record();
+    pc.printf("MAIN\n");
+    state_machine_mgr();
 }