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 32:b7859f48942a, committed 2015-09-23
- Comitter:
- MaxScorda
- Date:
- Wed Sep 23 00:04:55 2015 +0000
- Parent:
- 31:abff828992d7
- Child:
- 33:19d1d8bc5891
- Commit message:
- Corretto formato input da seriale e layout; Resta ancrora latenza
Changed in this revision
--- a/Functions.h Sat Sep 19 01:08:34 2015 +0000 +++ b/Functions.h Wed Sep 23 00:04:55 2015 +0000 @@ -39,16 +39,21 @@ //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 (func=="r") { + if (funcnum=="s") { if (param=="on ") { realExtraSerial=true; - term.formatPrintf("ON \n",62,13,3); + term.formatPrintf("ON \n",62,8,3); + term.formatPrintf("SR Attiva \n",61,10,99); + printDisp(dispType,"SR Attiva \n\r"); errp=0; } if (param=="off") { realExtraSerial=false; - term.formatPrintf("OFF\n",62,13); + term.formatPrintf("OFF\n",8,13); + term.formatPrintf("SR Disattivata \n",61,10,99); + if (realExtraSerial==false) ardser.printf("\nSR OFF \n\r"); + printDisp(dispType,"SR Disattivata \n\r"); errp=0; } } @@ -59,7 +64,7 @@ if (funcnum=="1") { if (param=="on ") { term.formatPrintf("ON \n",21,6,3); - term.formatPrintf("Led ACCESO \n",61,6,99); + term.formatPrintf("Led ACCESO \n",61,10,99); if (realExtraSerial==false) ardser.printf("\nLed ACCESO \n\r"); printDisp(dispType,"Led ACCESO \n\r"); led.onOff(1); //Accende il led @@ -67,7 +72,7 @@ } if (param=="off") { term.formatPrintf("OFF \n",21,6,3); - term.formatPrintf("Led SPENTO! \n",61,6,99); + term.formatPrintf("Led SPENTO! \n",61,10,99); if (realExtraSerial==false) ardser.printf("\nLed SPENTO! \n\r"); printDisp(dispType,"Led SPENTO \n\r"); led.onOff(0); //Spegne il led @@ -79,15 +84,15 @@ if (func=="v") { if (funcnum=="1") { if (param=="on ") { - term.formatPrintf("ON \n",22,13); - term.formatPrintf("Virtual ACCESO \n",42,16,99); + term.formatPrintf("ON \n",61,6,3); + term.formatPrintf("Virtual ACCESO \n",61,10,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); + term.formatPrintf("OFF \n",61,6); + term.formatPrintf("Virtual SPENTO! \n",61,10,99); if (realExtraSerial==false) ardser.printf("Virtual Off\r"); printDisp(dispType,"Virtual SPENTO \n\r"); errp=0; @@ -96,10 +101,10 @@ } //command SYNTH - if ((func>="0") && (func<="9")) { + if (((func>="0") && (func<="9")) || (func=="n")) { 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); + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),61,10,4); + term.formatPrintf("Arduino Command \n",21,8,5); 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"))); @@ -111,7 +116,9 @@ // comando fuori parsing if (errp==1) { // pc.printf("Bad command\n\r"); - term.formatPrintf("Bad Command\n",42,16,99); + term.forgcol(1); + term.formatPrintf("Bad Command\n",21,8,5); + term.forgcol(9); if (realExtraSerial==false) ardser.printf("Bad command\n\r"); printDisp(dispType,"** Bad command ** \n\r"); } @@ -119,114 +126,12 @@ } -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.formatPrintf(fnzAdd.string2char(strIn),18,21,10); term.readypos(); }
--- a/TerminalPlus.lib Sat Sep 19 01:08:34 2015 +0000 +++ b/TerminalPlus.lib Wed Sep 23 00:04:55 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#80096ab72764 +https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#e3c6d6322506
--- a/main.cpp Sat Sep 19 01:08:34 2015 +0000 +++ b/main.cpp Wed Sep 23 00:04:55 2015 +0000 @@ -4,9 +4,6 @@ #include "BufferedSerial.h" #include "Terminal.h" - - - //init standard InterruptIn mybutton(USER_BUTTON); @@ -62,7 +59,7 @@ if (pc.readable()) { c[0]=pc.getc(); //legge un carattere dalla seriale term.putc(c[0]); //redirect to terminal - if (c[0] != 13) { + if (c[0] != 13) { buffer[0][i[0]]=c[0]; // se il carattere è diverso da CarriageReturn (ASCII 13) lo memorizza nel buffer i[0]++; // incrementa il puntatore al buffer led.flash(2); @@ -79,10 +76,11 @@ i[0]=0; //azzera la posizione del puntatore del buffer pronto per la ricezione di una nuova stringa } } + //seriale esterna if (ardser.readable()) { c[1]=ardser.getc(); //legge un carattere dalla seriale - if (c[1] != 13) { + if ((c[1] != 10) && (c[1] != 13)) { buffer[1][i[1]]=c[1]; // se il carattere è diverso da CarriageReturn (ASCII 13) lo memorizza nel buffer i[1]++; // incrementa il puntatore al buffer led.flash(2);