ECE3872 HW/SW Project Code

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

main.cpp

Committer:
nnguyen99
Date:
2020-04-09
Revision:
10:f10105ec435f
Parent:
9:770effc3af2d
Child:
11:299f2c8a4092

File content as of revision 10:f10105ec435f:

#include "mbed.h"
#include <iostream>
#include "audio_out.h"
#include "PinDetect.h"
#include "uLCD_4DGL.h"
DigitalOut myled(LED1);
Serial mac(USBTX,USBRX);

// States 
#define sRESET 1
#define sSTOP 2
#define sRECORD 3
#define sPLAY 4
#define sERASE 5
//  State Machine control global variables
bool X;     //reset
bool P;     //play
bool S;     //stop
bool R;     //record
bool E;     //erase



void reset(){ 
    /* reset state:
        Initial state upon powering up the device
        1. Cease all motion
        2. Reset all motors to initial position
        3. Mutes all audio
        4. Goes to erase state if reset button is held down for at least 3 seconds
        5. Goes to stop state according to rotary switch input
        6. LED goes from green to red
        NOTE: ONLY exits to stop or erase state 
    */
}
void stop(){
    /* stop state:
        Initiated by rotary switch
        1. Cease all motion
        2. Stop recording
        3. Mute all audio
    */
}
void record(){
    /* record state:
        Initiated by rotary switch
        1. Cease all motion
        2. Begin recording ToF inputs (distance and time)
        3. Convert distances to corresponding audio frequencies
        4. Append to list of frequencies
        5. 
    */
}
void play(){
    /* play state:
        Initiated by rotary switch
        1. wait a few seconds
        2. begin reading list of frequencies while concurrently:
            - moving servo motors accordingly
            - playing corresponding sounds
    */
}
void erase(){
    /* erase state:
        erases entire audio recording
    */
}




void state_machine_mgr(){
    mac.printf("SM\n");
    int curr_state =  1;
    while(1) {
        switch(curr_state){
            case 1:
                S,R,P,E = 0;
                mac.printf("RESET\n");
                reset();
                if(S) curr_state = sSTOP;
                break;
            case 2:
                X,R,P,E = 0;
                mac.printf("STOP\n");
                stop();
                if(X){
                    curr_state = sRESET;
                }else if(S&R){
                    curr_state = sRECORD;
                }else if(S&P){
                    curr_state = sPLAY;
                }
                break;
            case 3:
                S,X,P,E = 0;
                mac.printf("RECORD\n");
                record();
                if(X){
                    curr_state = sRESET;
                }else if(R&S){
                    curr_state = sSTOP;
                }else if(R&P){
                    curr_state = sPLAY;
                }
                break;
            case 4:
                S,R,X,E = 0;
                mac.printf("PLAY\n");
                play();
                if(X){
                    curr_state = sRESET;
                }else if(P&S){
                    curr_state = sSTOP;
                }else if(P&R){
                    curr_state = sPLAY;
                }
                break;
            case 5:
                mac.printf("ERASE\n");
                erase();
                S,R,X,P = 0;
                if(X){
                    curr_state = sRESET;
                }
        }
        curr_state = mac.getc();
    }
}

int main() {
    mac.printf("MAIN\n");
    state_machine_mgr();
}