Console Serial IO con display OLED e seriale asincrona

Dependencies:   mbed BufferedSerial AserialIOFuncLib SSD1306 TerminalPlusV2

Fork of SerialIO by Max Scordamaglia

Console Serial IO con display OLED e seriale asincrona

Functions.h

Committer:
MaxScorda
Date:
2015-09-19
Revision:
31:abff828992d7
Parent:
29:bfb815540de7
Child:
32:b7859f48942a

File content as of revision 31:abff828992d7:

#include <string>
#include "IOFuncLib.h"
genFunctions fnzAdd; //messa qui rende la raccolta funzioni indipendente

void callback()
{
    // Note: you need to actually read from the serial to clear the RX interrupt
    // ardser.printf("%d \n", cont++);
//  myled2 = !myled2;
}

void scsa()
{
    //Funzione per screensaver
    inverseDisp(dispType);
}


void parserVT100(char stringa[])
{
    string func; //funzione l=led
    string funcnum; //funzione ordinata 1,2,3 ecc
    string param; //parametro on, off
    string strIn = string(stringa);
    bool errp=1;
    //pad a 4
    strIn=fnzAdd.padstr(strIn,5,' ');
    strIn=fnzAdd.addEOS(strIn);
    //split
    func=strIn.substr(0,1);
    funcnum=strIn.substr(1,1);
    param=strIn.substr(2,3);
    //write param
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func)),11,4,10);
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),39,4,10);
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),61,4,10);
    //write input string
    term.formatPrintf(fnzAdd.string2char(strIn),21,10,10);
    //term.formatPrintf(((char*)func.c_str() ,02,07); funziona anche cosi'

    //extra serial output (output reale su arduino default true)
    if (func=="s") {
        if (funcnum=="r") {
            if (param=="on ") {
                realExtraSerial=true;
                term.formatPrintf("ON \n",62,13,3);
                errp=0;
            }
            if (param=="off") {
                realExtraSerial=false;
                term.formatPrintf("OFF\n",62,13);
                errp=0;
            }
        }
    }

    //led
    if (func=="l") {
        if (funcnum=="1") {
            if (param=="on ") {
                term.formatPrintf("ON \n",21,6,3);
                term.formatPrintf("Led ACCESO \n",61,6,99);
                if (realExtraSerial==false)  ardser.printf("\nLed ACCESO \n\r");
                printDisp(dispType,"Led ACCESO \n\r");
                led.onOff(1); //Accende il led
                errp=0;
            }
            if (param=="off") {
                term.formatPrintf("OFF \n",21,6,3);
                term.formatPrintf("Led SPENTO! \n",61,6,99);
                if (realExtraSerial==false)  ardser.printf("\nLed SPENTO! \n\r");
                printDisp(dispType,"Led SPENTO \n\r");
                led.onOff(0); //Spegne il led
                errp=0;
            }
        }
    }
    //virtual
    if (func=="v") {
        if (funcnum=="1") {
            if (param=="on ") {
                term.formatPrintf("ON \n",22,13);
                term.formatPrintf("Virtual ACCESO \n",42,16,99);
                if (realExtraSerial==false) ardser.printf("Virtual On\r");
                printDisp(dispType,"Virtual ACCESO \n\r");
                errp=0;
            }
            if (param=="off") {
                term.formatPrintf("OFF \n",22,13);
                term.formatPrintf("Virtual SPENTO! \n",42,16,99);
                if (realExtraSerial==false) ardser.printf("Virtual Off\r");
                printDisp(dispType,"Virtual SPENTO \n\r");
                errp=0;
            }
        }
    }

    //command SYNTH
    if ((func>="0") && (func<="9")) {
        if ((funcnum>="0") && (funcnum<="9")) {
            term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),42,13,4);
            term.formatPrintf("Arduino Command \n",42,16,99);
            ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+funcnum+param+"\r")));
            printDisp(dispType,"Arduino Command \n\r");
            printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS("  "+func+funcnum+param+"\r")));
            //ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)));
            errp=0;
        }
    }

    // comando fuori parsing
    if (errp==1) {
        // pc.printf("Bad command\n\r");
        term.formatPrintf("Bad Command\n",42,16,99);
        if (realExtraSerial==false) ardser.printf("Bad command\n\r");
        printDisp(dispType,"** Bad command ** \n\r");
    }
    term.readypos();
}


void parser(char stringa[])
{
    string func; //funzione l=led
    string funcnum; //funzione ordinata 1,2,3 ecc
    string param; //parametro on, off
    string strIn = string(stringa);
    bool errp=1;
    //pad a 4
    strIn=fnzAdd.padstr(strIn,5,' ');
    strIn=fnzAdd.addEOS(strIn);
    //split
    func=strIn.substr(0,1);
    funcnum=strIn.substr(1,1);
    param=strIn.substr(2,3);
    //write param
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func)),2,8,10);
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),22,8,10);
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),42,8,15);
    //write input string
    term.formatPrintf(fnzAdd.string2char(strIn),20,10,10);
    //term.formatPrintf((char*)func.c_str() ,02,07); funziona anche cosi'

    //extra serial output (output reale su arduino default true)
    if (func=="s") {
        if (funcnum=="r") {
            if (param=="on ") {
                realExtraSerial=true;
                term.formatPrintf("ON \n",62,13,3);
                errp=0;
            }
            if (param=="off") {
                realExtraSerial=false;
                term.formatPrintf("OFF\n",62,13);
                errp=0;
            }
        }
    }

    //led
    if (func=="l") {
        if (funcnum=="1") {
            if (param=="on ") {
                term.formatPrintf("ON \n",2,13,3);
                term.formatPrintf("Led ACCESO \n",42,16,99);
                if (realExtraSerial==false)  ardser.printf("\nLed ACCESO \n\r");
                printDisp(dispType,"Led ACCESO \n\r");
                led.onOff(1); //Accende il led
                errp=0;
            }
            if (param=="off") {
                term.formatPrintf("OFF \n",2,13);
                term.formatPrintf("Led SPENTO! \n",42,16,99);
                if (realExtraSerial==false)  ardser.printf("\nLed SPENTO! \n\r");
                printDisp(dispType,"Led SPENTO \n\r");
                led.onOff(0); //Spegne il led
                errp=0;
            }
        }
    }
    //virtual
    if (func=="v") {
        if (funcnum=="1") {
            if (param=="on ") {
                term.formatPrintf("ON \n",22,13);
                term.formatPrintf("Virtual ACCESO \n",42,16,99);
                if (realExtraSerial==false) ardser.printf("Virtual On\r");
                printDisp(dispType,"Virtual ACCESO \n\r");
                errp=0;
            }
            if (param=="off") {
                term.formatPrintf("OFF \n",22,13);
                term.formatPrintf("Virtual SPENTO! \n",42,16,99);
                if (realExtraSerial==false) ardser.printf("Virtual Off\r");
                printDisp(dispType,"Virtual SPENTO \n\r");
                errp=0;
            }
        }
    }

    //command SYNTH
    if ((func>="0") && (func<="9")) {
        if ((funcnum>="0") && (funcnum<="9")) {
            term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),42,13,4);
            term.formatPrintf("Arduino Command \n",42,16,99);
            ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+funcnum+param+"\r")));
            printDisp(dispType,"Arduino Command \n\r");
            printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS("  "+func+funcnum+param+"\r")));
            //ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)));
            errp=0;
        }
    }

    // comando fuori parsing
    if (errp==1) {
        // pc.printf("Bad command\n\r");
        term.formatPrintf("Bad Command\n",42,16,99);
        if (realExtraSerial==false) ardser.printf("Bad command\n\r");
        printDisp(dispType,"** Bad command ** \n\r");
    }
    term.readypos();
}

void writeInput(char stringa[])
{
    string strIn = string(stringa);
    strIn=fnzAdd.addEOS(strIn);
    //ardser.printf(strIn+" \n\r");
    term.formatPrintf(fnzAdd.string2char(strIn),2,21,2);
    term.readypos();
}


void pressed()
{
    //vedere come rimediare
    sc.pressed();
}