Console Serial IO con display OLED e seriale asincrona
Dependencies: mbed BufferedSerial AserialIOFuncLib SSD1306 TerminalPlusV2
Fork of SerialIO by
Console Serial IO con display OLED e seriale asincrona
Revision 39:0d7165083e7a, committed 2015-12-27
- Comitter:
- MaxScorda
- Date:
- Sun Dec 27 23:15:53 2015 +0000
- Parent:
- 38:d88296cbb39c
- Child:
- 40:48422add4537
- Commit message:
- Interfaccia statica ma funzionante
Changed in this revision
--- a/AserialIOFuncLib.lib Thu Dec 24 01:38:56 2015 +0000 +++ b/AserialIOFuncLib.lib Sun Dec 27 23:15:53 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/MaxScorda/code/AserialIOFuncLib/#93274a65f664 +https://developer.mbed.org/users/MaxScorda/code/AserialIOFuncLib/#46de8943071a
--- a/Functions.h Thu Dec 24 01:38:56 2015 +0000 +++ b/Functions.h Sun Dec 27 23:15:53 2015 +0000 @@ -3,6 +3,7 @@ #include "choiceFunctions.h" //Valori di Menu +int p16, p17; int p01, p02, p03; int p51, p52; @@ -27,13 +28,17 @@ 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 */ + //16 + p16=16; + p17=16; + term.formatPrintf("Status \n",2,p16); //p16 + term.formatPrintf("Random \n",32,p17); //p17 //18-19 p51=18; p52=18; @@ -52,19 +57,18 @@ // 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.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.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,15,1); //bottom pot 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); @@ -73,7 +77,6 @@ } - void callback() { // Note: you need to actually read from the serial to clear the RX interrupt @@ -110,21 +113,17 @@ term.formatPrintf(fnzAdd.string2char(strIn),21,p51,10,1); //p51 //term.formatPrintf(((char*)func.c_str() ,02,07); funziona anche cosi' - //command Cambia Funzione + //in arrivo e carica funzioni da Arduino 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 + //in arrivo e carica menu da Arduino else if (func=="m") { errp=menuOut(func, funcnum,param, string(stringa)); } @@ -134,23 +133,22 @@ errp=RfuncOut(func, funcnum,param); } - //start + //start DA FARE!!!!!!!!! else if (strIn.substr(0,5)=="start") { errp=StartfuncOut(); } - //stop + //stop DA FARE!!!!!!!!! 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"); + ardser.printf("Bad command\n\r"); printDisp(dispType,"** Bad command ** \n\r"); } @@ -172,6 +170,7 @@ funcnum=strIn.substr(1,1); param=strIn.substr(2,3); + //Descrizione Menu in input if (func=="m") { errp=menuIn(func, stringa); @@ -189,6 +188,7 @@ errp=StopfuncIn(); } +//writeLogInput( strIn{ term.formatPrintf(fnzAdd.string2char(">"+fnzAdd.subEOS(string(stringa))+"<"),18,21,99,1); term.readypos(); } @@ -208,23 +208,15 @@ 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"; + 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 - */ + status=false; //accensione + randomActivate=true; + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS("Off")),11,p16,10,1); + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS("True")),39,p17,10,1); + term.readypos(); } @@ -232,6 +224,7 @@ void pressed() { + term.erasesquare(1, 4, 78, 14); ardser.printf("rl\r"); term.formatPrintf("rl\n",21,p51,8,1); //p51 term.formatPrintf("Ask for reload\n",61,p52,99,1); //p52
--- a/TerminalPlus.lib Thu Dec 24 01:38:56 2015 +0000 +++ b/TerminalPlus.lib Sun Dec 27 23:15:53 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#09eb30497e78 +https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#3da6173413b7
--- a/choiceFunctions.h Thu Dec 24 01:38:56 2015 +0000 +++ b/choiceFunctions.h Sun Dec 27 23:15:53 2015 +0000 @@ -1,3 +1,50 @@ +// istanze di funzioni per metterle poi dove si vuole +bool funcfromMenu(int); +//------------------------------------------------- + +void choiceVideoSettings() +{ + string prefix; + //stampo menu + menuidx=3; + for (int i = 0; i<10 ; i++) { + if (i==menuidx) { + term.bold(); + prefix="*"; + } else { + term.resetattrib(); + //term.forgcol(7); + prefix=" "; + } + term.formatPrintf(fnzAdd.string2char(prefix+menu_main[i]),1,4+i,19); + } + //info terminale + term.formatPrintf("Menu Add \n",61,p52,19,1); //p52 + //setto asterisco + // term.formatPrintf("*",1,4+menuidx,1); + //setto funzioni e scelta + funcfromMenu(menuidx); +} + +void writeLogInput(string strIn) +{ + // stampa i splitta i parametri in ingesso + //write param + string func; + string funcnum; + string param; + func=strIn.substr(0,1); + funcnum=strIn.substr(1,1); + param=strIn.substr(2,3); + 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.substr(0,17)),21,p51,10,1); //p51 +//--------------------------------------------------------------------------------------------- +} + + bool funcOut(string func, string funcnum, string param, string sstr) { //fare @@ -17,18 +64,6 @@ } return errp; } -//********************* Init: chiama Arduino al boot e chiama i paramtri -bool initFunc(string func, string funcnum, string param) -{ - bool errp=1; - - if (funcnum=="1") { - // errp=menuIn("0", param); - - } - return errp; -} - //********************* Led bool Lfunc(string func, string funcnum, string param) @@ -38,14 +73,14 @@ if (funcnum=="1") { if (param=="on ") { term.formatPrintf("Led ACCESO \n",61,p52,99,1); //p52 - if (realExtraSerial==false) ardser.printf("\nLed ACCESO \n\r"); + 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("Led SPENTO! \n",61,p52,99,1); //p52 - if (realExtraSerial==false) ardser.printf("\nLed SPENTO! \n\r"); + ardser.printf("\nLed SPENTO! \n\r"); printDisp(dispType,"Led SPENTO \n\r"); led.onOff(0); //Spegne il led errp=0; @@ -57,38 +92,39 @@ //********************** cambio menu -bool funcfromMenu(string func, string funcnum, string param, string sstr) +bool funcfromMenu(int funcnum) { // funzione di load funzioni da menu scelto bool errp=1; - char funcc; - char tempm; - int ccmenu=0; - int ccfun=0; + int tempm; + int ccmenu=0; //indice vettore funzioni selezionate + int ccfun=0; //indice vettore funzione principale string funzionen; - funcc=*fnzAdd.string2char(fnzAdd.addEOS(funcnum)); - //filtro vettore funzioni in base la menu - do { + funzionen=menu_function[ccmenu]; + while ((funzionen.substr(0,1)!="Z") && (ccmenu<=99)) { // confronto il primo carattere dell vettore funzioni col primo carattere del menu - funzionen=menu_function[ccmenu]; - tempm=*fnzAdd.string2char(funzionen.substr(0,1)); + tempm=atoi(fnzAdd.string2char(funzionen.substr(0,1))); // se = metto il valore del vettore funzioni nel vettore funzioni scelte - if (tempm==funcc) { + if (menuidx==tempm) { menu_funcChoice[ccfun]=menu_function[ccmenu]; ccfun++; } ccmenu++; - } while ((ccmenu<10) && (funcc!='z')) ; + funzionen=menu_function[ccmenu]; //assegna la stringa del menu + } + menu_funcChoice[ccfun]="Z.Z"; //setto lo stop + if (ccfun>0) { //non dovrebbe avvenire diversamente perche' 1 ci deve esere ma e' da trappare + //azzero da dove sono in giu' + for (int i = funcidx+1; i <ccfun ; i++) { + term.formatPrintf("*",42,4+i,38); + } + //scrico dalla prima allo scelto + for (int i = 0; i <ccfun ; i++) { + term.formatPrintf(fnzAdd.string2char(menu_funcChoice[i]),42,4+i,38); + } + } funcidx=0; - //azzero da dove sono in giu' - for (int i = fnzAdd.c2i(funcc)+1; i <=funcidx ; i++) { - term.formatPrintf("\n",42,4+i,38); - } - //scrico dalla prima allo scelto - for (int i = 0; i <=fnzAdd.c2i(funcc) ; i++) { - term.formatPrintf(fnzAdd.string2char(menu_funcChoice[i]),42,4+i,38); - } errp=0; //per ora non fa nulla, vedere se tenere a uso futuro return errp; } @@ -106,8 +142,8 @@ menuidx= fnzAdd.c2i(funcc); term.formatPrintf("*\n",2,4+menuidx,1); printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS("Menu "+funcnum+"\r"))); - //chiama la cernita delle funzioni - errp=funcfromMenu(func, funcnum, param, sstr); //ritorna sempre 0 (e va bene cosi) + //chiama la cernita delle funzioni + errp=funcfromMenu(menuidx); //ritorna sempre 0 (e va bene cosi) } return errp; } @@ -168,22 +204,29 @@ bool menuIn(string func, string sstr) { bool errp=1; - int funcn; - // char funcc=fnzAdd.string2char(sstr.substr(2,1)); - char funcc; - funcc=*fnzAdd.string2char(fnzAdd.addEOS(sstr.substr(2,1))); - if (funcc!='z') { + int funcn=0; + string funcc; + funcc=sstr.substr(3,1); + + if ((funcc>="0") && (funcc<="9")) { //trasformo in intero - funcn=fnzAdd.c2i(funcc); + funcn=atoi(fnzAdd.string2char(funcc)); //assegno menu al vettore - menu_main[funcn]=fnzAdd.addEOS(sstr); + menu_main[funcn]=fnzAdd.addEOS(sstr.substr(3,20)); + //*** tolti in attesa di regolare la sincronizzazione //stampo in posizione - term.formatPrintf(fnzAdd.string2char(menu_main[funcn]),2,4+funcn,38); + ///term.formatPrintf(fnzAdd.string2char(menu_main[funcn]),2,4+funcn,38); + //info terminale + ///term.formatPrintf("Menu Add \n",61,p52,99,1); //p52 + //****** //display - printDisp(dispType,"Menu In \n\r"); + printDisp(dispType,"Menu Add \n\r"); printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+sstr.substr(0,3)+"\r"))); errp=0; } + if (funcc=="9") { + // writeLogInput( sstr); //solo al 9 stampo il log. Ha poi senso? + } return errp; } @@ -191,18 +234,26 @@ bool functionIn(string func, string sstr) { bool errp=1; - int funcn; - char funcc= *fnzAdd.string2char(sstr.substr(2,1)); - - if (funcc!='z') { - //trasformo in intero - funcn=fnzAdd.c2i(funcc); + string funcc; + funcc=sstr.substr(3,1); + if (funcc!="Z") { //assegno menu al vettore - menu_function[funcn]=fnzAdd.addEOS(sstr.substr(2,1)); //??? sicuri? + menu_function[funccontidx]=fnzAdd.addEOS(sstr.substr(1,20)); + //stampo in posizione + //term.formatPrintf(fnzAdd.string2char( menu_function[funccontidx]),42,4+(funccontidx%20),38); + //info terminale + term.formatPrintf("Function In \n",61,p52,99,1); //p52 //display printDisp(dispType,"Function In \n\r"); printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+sstr.substr(0,3)+"\r"))); + funccontidx++; //incremento il contatore generale delle funzioni errp=0; + } else { + menu_function[funccontidx]="Z.Z"; //carico lo stop + funccontidx=0; //azzero il contatore generale delle funzioni + writeLogInput( sstr); //solo allo z stampo il log. Ha poi senso? + //set default video + choiceVideoSettings(); } return errp; } @@ -226,7 +277,7 @@ } -//********************* Synth Note +//********************* ????????????????????????????? bool NfuncIn(string func, string funcnum, string param, char* arr) { bool errp=1;
--- a/main.cpp Thu Dec 24 01:38:56 2015 +0000 +++ b/main.cpp Sun Dec 27 23:15:53 2015 +0000 @@ -21,18 +21,20 @@ //var int cont=0; int dispType=0; //0:oled 1:lcd -bool realExtraSerial=true; //se true manda fuori solo le info reali senno demo -bool randomActivate=true; //se true attiva sul sequencer il cambio di note casuali +bool status=false; //accensione +bool randomActivate=true; //se true attiva sul sequencer il cambio di valori casuali string menu_main[10]; -string menu_funcChoice[10]; +string menu_funcChoice[100]; //no 100 string menu_function[99]; int menuidx=0; int funcidx=0; +int funccontidx=0; //contatore di posizione durante caricamento //---------- extern // dichiarando qui le variabili extern, posso inizializzarle in qualunque parte del programma. In teoria parrebbe inutile ma in questo modo posso un domani istanziarle ovunque extern int p01,p02,p03; +extern int p16, p17; extern int p51, p52; //------------ Funzioni ------------- @@ -65,6 +67,8 @@ //terminal bannerAdv(); preloadValue(); + //richiedi menu + ardser.printf("rl\r"); while(1) { // ardser.attach(&callback);