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-12-24
Revision:
38:d88296cbb39c
Parent:
37:befd2fe96ee3
Child:
39:0d7165083e7a

File content as of revision 38:d88296cbb39c:

#include <string>
#include "IOFuncLib.h"
#include "choiceFunctions.h"

//Valori di Menu
int p01, p02, p03;
int p51, p52;

void bannerAdv()
{
    //spostato qui per lasciare in pace la libreria
    term.reset();
    term.cls();
    term.frame(0, 0, 79, 22,1);
    term.forgcol(3);
    term.bold();
    term.formatPrintf("_____ H-Ard Synth Project Console _____\n",19,1);
    term.formatPrintf("______ Nucleo Scorda IO Terminal ______\n",19,2);

    term.resetattrib();
    term.forgcol(7);
//3-4
    term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,3,1); //top 1/2
    term.forgcol(6);
    /*
    //5-6
    term.formatPrintf("Pattern 0......... \n",2,6); //p11
    term.formatPrintf("Pattern 1......... \n",42,6); //p12
    //7-8
    term.formatPrintf("Pattern 2......... \n",2,8); //p21
    term.formatPrintf("Random Act (r1o/f) \n",42,8); //p22
    //9-10
    term.formatPrintf("Serial Real(sro/f) \n",2,10); //p31
    //11-12
    term.formatPrintf("Note Pattern......\n",2,12,99); //p41
    */
//18-19
    p51=18;
    p52=18;
    term.formatPrintf("Input string...... \n",2,p51); //p51
    term.formatPrintf("Command Type \n",48,p52); //p52
    p01=19;
    p02=19;
    p03=19;
    term.formatPrintf("Funzione \n",2,p01); //p01
    term.formatPrintf("Numero \n",32,p02); //p02
    term.formatPrintf("Parametro \n",51,p03);  //p03
//21
    term.forgcol(7);
    term.formatPrintf("Serial Feedback \n",2,21);


// grigino
    /*
        term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,5); //top 3/4
        term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,9); //top 7/8
        term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,13); //top 11/12



        term.forgcol(2);
        term.formatPrintf("Pattern: da 031 a 252 - Traccia 0-2, Note 3-6, Len 1-2 \n",2,16); //help
        term.formatPrintf("Stato random: r1on-r1off \n",2,17); //help
        term.formatPrintf("Cambia Note: da n01 a n53 - Nota 0-5, Val 1-3 \n",2,18); //help
        term.formatPrintf("start, stop, dstop (delay) - rl: reload value\n",2,19); //help
        term.forgcol(7);
        */
    term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,17,1); //bottom pot
    term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,20); //azzo funziona...
    term.locate(0, 23);
    printf("Command: > ");

}



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,p01,10,1);       //p01
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),39,p02,10,1);    //p02
    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),61,p03,10,1);      //p03
    //write input string
    term.formatPrintf(fnzAdd.string2char(strIn),21,p51,10,1); //p51
    //term.formatPrintf(((char*)func.c_str() ,02,07); funziona anche cosi'

    //command Cambia Funzione
    if (func=="f") {
        errp=funcOut(func, funcnum,param, string(stringa));
    }

    //init: al boot chiedi ad arduino i codici
    else if (func=="i") {
        errp=initFunc(func, funcnum,param);
    }
    //led for test
    else if (func=="l") {
        errp=Lfunc(func, funcnum,param);
    }

    //command Cambia menu
    else if (func=="m") {
        errp=menuOut(func, funcnum,param, string(stringa));
    }

    //Random Activate DA FARE!!!!!!!!!
    else if (func=="r") {
        errp=RfuncOut(func, funcnum,param);
    }

    //start
    else if (strIn.substr(0,5)=="start") {
        errp=StartfuncOut();
    }

    //stop
    else if (strIn.substr(0,4)=="stop") {
        errp=StopfuncOut();
    }


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

    term.readypos();
}


void writeInput(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;
    strIn=fnzAdd.padstr(strIn,5,' '); //non dovrebbe servire
    strIn=fnzAdd.addEOS(strIn);
    //split
    func=strIn.substr(0,1);
    funcnum=strIn.substr(1,1);
    param=strIn.substr(2,3);

    //Descrizione Menu in input
    if (func=="m") {
        errp=menuIn(func, stringa);
    }
    //Descrizione funzione in input
    else if (func=="f") {
        errp=functionIn(func, stringa);
    }
    //start
    else if (strIn.substr(0,4)=="start") {
        errp=StartfuncIn();
    }
    //stop
    else if (strIn.substr(0,3)=="stop") {
        errp=StopfuncIn();
    }

    term.formatPrintf(fnzAdd.string2char(">"+fnzAdd.subEOS(string(stringa))+"<"),18,21,99,1);
    term.readypos();
}

void preloadValue()
{
    string func; //funzione l=led
    string funcnum; //funzione ordinata 1,2,3 ecc
    string param; //parametro on, off
    string strIn;

    //azzero vettori
    for (int i = 0; i < 10; i++) {
        menu_main[i]="";
        menu_funcChoice[i]="";
    }
    for (int i = 0; i < 100; i++) {
        menu_function[i]="";
    }
    menu_main[0]="z.z"; //invero e' sbagliato. controllare cosa usa di stop
    menu_funcChoice[0]="z.z";
    menu_function[0]="z.z";

    //pattern
    /*
    for (int i = 0; i < 3; i++) {
        strIn=fnzAdd.i2s(i)+"-"+fnzAdd.i2s(i+3)+"-"+fnzAdd.i2s(2);
        term.formatPrintf(fnzAdd.string2char(strIn),21+(i%2)*40,6+(2*(i/2)),8,1); //p11 //p12 //p21
    }
    //real serial
    term.formatPrintf("OFF\n",21,10,3,1);  //p31
    //random
    term.formatPrintf("ON\n",61,8,99,1); //p22
    // note
    term.formatPrintf("60  64  67  71  74  77\n",21,12,99,1); //p41
    */
    term.readypos();
}



void pressed()
{
    ardser.printf("rl\r");
    term.formatPrintf("rl\n",21,p51,8,1); //p51
    term.formatPrintf("Ask for reload\n",61,p52,99,1);   //p52
    led.flash(2);
}