ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
Diff: main.cpp
- Revision:
- 18:0e0edd4f9e4d
- Parent:
- 16:62976c3c029e
- Child:
- 25:7764baddb7bc
--- a/main.cpp Mon Apr 13 02:23:16 2020 +0000 +++ b/main.cpp Mon Apr 13 02:43:08 2020 +0000 @@ -1,7 +1,6 @@ #include "mbed.h" #include <iostream> -#include "audio_out.h" -#include "PinDetect.h" +#include "speaker_out.h" #include "uLCD_4DGL.h" #include "motor_ctl.h" DigitalOut myled1(LED1); @@ -9,13 +8,6 @@ DigitalOut myled3(LED3); DigitalOut myled4(LED4); -// Push buttons init -PinDetect pb1(p16); -PinDetect pb2(p17); -PinDetect pb3(p18); -PinDetect pb4(p19); -// States - // State Machine control global variables bool X; //reset bool P; //play @@ -25,7 +17,6 @@ enum sm_state {sRESET, sSTOP, sRECORD, sPLAY, sERASE}; - void reset(){ /* reset state: Initial state upon powering up the device @@ -71,90 +62,99 @@ */ } - - -void pb1_hit_callback (void) -{ - myled1 = !myled1; - //guLCD.printf("REEST"); -} - -void pb2_hit_callback (void) -{ - myled2 = !myled2; - //guLCD.printf("STOP"); -} - -void pb3_hit_callback (void) -{ - myled3 = !myled3; - //guLCD.printf("RECORD"); -} - -void pb4_hit_callback (void) -{ - myled4 = !myled4; - //guLCD.printf("PLAY"); -} -void hardware_init(){ - // Push buttons init - pb1.mode(PullUp); - pb2.mode(PullUp); - pb3.mode(PullUp); - pb4.mode(PullUp); - pb1.attach_deasserted(&pb1_hit_callback); - pb2.attach_deasserted(&pb2_hit_callback); - pb3.attach_deasserted(&pb3_hit_callback); - pb4.attach_deasserted(&pb4_hit_callback); - pb1.setSampleFrequency(); - pb2.setSampleFrequency(); - pb3.setSampleFrequency(); - pb4.setSampleFrequency(); -} - void state_machine_mgr(){ - sm_state curr_state = sRESET; + char curr_state = 1; + char key_input; + X = 1; + S = 0; + R = 0; + P = 0; + E = 0; while(1) { + if (pc.readable()) { // if they have pressed a key + key_input = pc.getc(); + if(key_input == '1') X=1; //toggle reset + if(key_input == '2') S=1; //toggle stop + if(key_input == '3') R=1; //toogle record + if(key_input == '4') P=1; //toggle play + if(key_input == '5') E=1; //toggle erase + } + //pc.printf("X: %d\n",X); +// pc.printf("S: %d\n",S); +// pc.printf("R: %d\n",R); +// pc.printf("P: %d\n",P); +// pc.printf("E: %d\n",E); +// pc.printf("Current State %d\n",curr_state); switch(curr_state){ - case sRESET: - if(S) curr_state = sSTOP; + case 1: + pc.printf("RESET\n"); + P = 0; + R = 0; + if(E){ + curr_state = 5; + X = 0; + }else if(S){ + curr_state = 2; + X = 0; + } + reset(); break; - case sSTOP: - if(X){ - curr_state = sRESET; - }else if(S&R){ - curr_state = sRECORD; - }else if(S&P){ - curr_state = sPLAY; - } - break; - case sRECORD: + case 2: + pc.printf("STOP\n"); + E = 0; if(X){ - curr_state = sRESET; - }else if(R&S){ - curr_state = sSTOP; - }else if(R&P){ - curr_state = sPLAY; + curr_state = 1; + S = 0; + }else if(R){ + curr_state = 3; + S = 0; + }else if(P){ + curr_state = 4; + S = 0; } + stop(); break; - case sPLAY: + case 3: + pc.printf("RECORD\n"); + E = 0; + P = 0; if(X){ - curr_state = sRESET; - }else if(P&S){ - curr_state = sSTOP; - }else if(P&R){ - curr_state = sPLAY; + curr_state = 1; + R = 0; + }else if(S){ + curr_state = 2; + R = 0; } + record(); break; - case sERASE: + case 4: + pc.printf("PLAY\n"); + E = 0; + R = 0; if(X){ - curr_state = sRESET; + curr_state = 1; + P = 0; + }else if(S){ + curr_state = 2; + P = 0; } + play(); + break; + case 5: + pc.printf("ERASE\n"); + S = 0; + P = 0; + R = 0; + if(X){ + curr_state = 1; + E = 0; + } + erase(); + break; } } } - int main() { myled1 = 1; //hardware_init();