PES 4 - Smart Medication Dispenser / PES4_ProgrammeforDesignReview2

Dependencies:   SDFileSystem mbed

Fork of PES4_Programme by PES 4 - Smart Medication Dispenser

source/main.cpp

Committer:
cittecla
Date:
2018-03-30
Revision:
53:1c61cadbcb35
Parent:
52:701d0c2f47d7
Child:
55:bdab541f434d

File content as of revision 53:1c61cadbcb35:

#include "main.h"


int state = 44;
int oldState;

Serial pc(USBTX, USBRX); // tx, rx

/* PWM Test Tool */
int channel;
int dutyCycle;

int main()
{
    pc.baud(460800);
    printf("start...\r\n");

    while(1) {
        if(state != oldState) {
            printf("state: %d\r\n",state);
            oldState = state;
        }
        switch (state) {
            case 0:
                printf("Hello World");
                state = 47;
                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;

            case 10:
                break;
            case 11:
                break;

            case 15:
                break;
            case 16:
                break;
            case 17:
                break;

            case 25:
                break;
            case 26:
                break;
            case 27:
                break;
            case 28:
                break;


            case 35:
                break;
            case 36:
                break;
            case 37:
                break;
            case 38:
                break;

                /**************************************************************/
                /* Test Zone */

                /* init PWM board */
            case 44:
                pc.printf("Init PWM\r\n");
                initPWM(50);
                enableOutput();
                state = 47;
                break;

                /* Time test tool: set Time */
            case 45:
                s_time time;
                time.second     =   30;
                time.minute     =   53;
                time.hour       =   12;
                time.day        =   27;
                time.weekday    =   2;
                time.month      =   3;
                time.year       =   18;
                pc.printf("set now time\r\n");
                setTime(&time);
                pc.printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday);
                state = 47;
                pc.printf("change state to: %d\r\n",state);
                break;

                /* Time test tool: get Time */
            case 46:
                wait(5);
                time = getTime();
                pc.printf("read time: %02d:%02d:%02d, %02d.%02d.20%02d, weekday: %d\r\n",time.hour, time.minute, time.second, time.day, time.month, time.year, time.weekday);
                state = 47;
                break;

                /* Console State Switch */
            case 47:
                pc.printf("\n\rState Switch: Enter next State: \n\r");
                pc.printf("45\tset Time\n\r46\tread Time\n\r47\tState Switch\n\r48\tServo Board Test Tool\n\r49\tenable servo output\n\r50\tdisable servo output\n\r51\ttest SD Card\n\r52\tread medication\n\r");
                pc.scanf("%d", &state);
                pc.printf("Switch to State %d\n\r",state);
                fflush(stdin);
                break;

                /* Servo-Board Test Tool */
            case 48:
                pc.printf("\n\r\n\rServo-Board Test Tool\n\rEnter Channel Number and then Duty Cycle\n\r");
                pc.printf("for exit, enter Channel > 15\n\r");
                channel = 0;
                while (channel < 16) {
                    pc.printf("Channel Number: ");
                    pc.scanf("%d", &channel);
                    pc.printf("\r\nchannel: %d\n\rDuty Cycle 0..4095: ",channel);
                    pc.scanf("%d", &dutyCycle);
                    pc.printf("\n\r%d\n\r",dutyCycle);
                    setPWM((char)channel, (int)dutyCycle);
                    fflush(stdin);
                }
                pc.printf("leave Servo-Board Test Tool\n\r");
                state = 47;
                break;

            case 49:
                enableOutput();
                pc.printf("Servo output enabled\r\n\n");
                state = 47;
                break;

            case 50:
                disableOutput();
                pc.printf("Servo output disabled\r\n\n");
                state = 47;
                break;

            case 51:
                testSd();
                pc.printf("\rSD Card test finished\r\n\n");
                state = 47;
                break;
                
            case 52:
                readMedication(0);
                pc.printf("\rMedication testread finished\r\n\n");
                state = 47;
                break;

            default:
                state = 47; /* Go to State Switch */
                break;
        }
    }
    pc.printf("exit while 1 loop");
}