first publish

Dependents:   CleaningMachine_Betago CleaningMachine_Betago clean_V1 CleaningM-Palm ... more

Debug.cpp

Committer:
icyzkungz
Date:
2016-02-15
Revision:
0:26532a4397da

File content as of revision 0:26532a4397da:

#include "Debug.h"


Debug::Debug(PinName tx, PinName rx) : debug(tx, rx)
{
    debug.baud(115200);
    scan_input_data = 9999;
    change = false;
    first_time = true;

    debug.printf("****************\n*  Debug Mode  *\n****************\n");
}

int Debug::ScanInputData(int save)
{
    float temp;
    debug.scanf("%f",&temp);
    if(save==1) {
        scan_input_data = temp;
        return scan_input_data;
    } else if(save==0) return temp;
}

int Debug::ScanInputDataInLoop()
{
    float temp;
    debug.scanf("%f",&temp);
    scan_input_data_loop = temp;
    return scan_input_data_loop;
}

void Debug::PrintListMode()
{
    debug.printf("\n\n1) \n");
    debug.printf("2) \n");
    debug.printf("3) \n");
}

/*int Debug::Mode()
{
    //return 0 for 1-time
    //return 1 for more than 1-time loop

    int temp;
    int num = (int)scan_input_data;

    switch((int)scan_input_data) {
        case 1 :
            debug.printf("Case 1 : Return 0 \n");
            return 0;

        case 2 :
            debug.printf("Case 2 : Loop of Loop \n");

            return 1;

        case 3 :
            debug.printf("Case 3 : \n");
            return 0;

        default :
            debug.printf("Invalid Input\n");
            return 0;
    }

}*/

/*int Debug::SelectMode(int option)
{
    if(option == 1) {
        do {
            temp = Mode1();
            PrintAll(temp);
        } while(temp!=9999);
    }

    else if(option == 2) {
        do {
            if(first_time==false) {
                temp = Mode2();
                PrintAll(temp);
            } else {
                temp = Mode2();
                if(temp!=0) first_time = false;
            }

            if(temp==9999) first_time = true;
        } while(temp!=9999);
    }
    setChange();
}*/

int Debug::Mode1()
{
    debug.printf("Mode 1 : Input data\n");
    return ScanInputData(1);
}

int Debug::Mode2()
{
    if(change == false) {
        debug.printf("Mode 2 : \n1) Left \n2) Right\n");
        temp_state = ScanInputData(0);
        if(temp_state==1||temp_state==2)
            change = true;
        else return 0;
    } else {
        if(temp_state == 1) {
            debug.printf("Input Left : ");
            return ScanInputData(1);

        } else if(temp_state == 2) {
            debug.printf("Input Right : ");
            return ScanInputData(1);
        }
    }


}