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 36:9ecb98d7c2cd, committed 2015-11-06
- Comitter:
- MaxScorda
- Date:
- Fri Nov 06 20:15:54 2015 +0000
- Parent:
- 35:e9e9d518c354
- Child:
- 37:befd2fe96ee3
- Commit message:
- Final release. Waiting for some adds
Changed in this revision
--- a/AserialIOFuncLib.lib Sat Sep 26 01:02:23 2015 +0000 +++ b/AserialIOFuncLib.lib Fri Nov 06 20:15:54 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/MaxScorda/code/AserialIOFuncLib/#e2a2e0dd6c1b +https://developer.mbed.org/users/MaxScorda/code/AserialIOFuncLib/#9a7f30cb244d
--- a/Functions.h Sat Sep 26 01:02:23 2015 +0000 +++ b/Functions.h Fri Nov 06 20:15:54 2015 +0000 @@ -1,6 +1,6 @@ #include <string> #include "IOFuncLib.h" -genFunctions fnzAdd; //messa qui rende la raccolta funzioni indipendente +#include "choiceFunctions.h" void callback() { @@ -39,90 +39,139 @@ //term.formatPrintf(((char*)func.c_str() ,02,07); funziona anche cosi' //extra serial output (output reale su arduino default true) - if (func=="r") { - if (funcnum=="s") { - if (param=="on ") { - realExtraSerial=true; - term.formatPrintf("ON \n",62,10,3,1); //p31 - term.formatPrintf("RS Attiva \n",61,14,99,1); //p52 - printDisp(dispType,"RS Attiva \n\r"); - errp=0; - } - if (param=="off") { - realExtraSerial=false; - term.formatPrintf("OFF\n",62,10,3,1); //p31 - term.formatPrintf("RS Disattivata \n",61,14,99); //p52 - if (realExtraSerial==false) ardser.printf("\nRS OFF \n\r"); - printDisp(dispType,"RS Disattivata \n\r"); - errp=0; - } - } + if ((func=="s") && (funcnum=="r") ) { + errp=Sfunc(func, funcnum,param); + } + + //Random Activate + else if (func=="r") { + errp=RfuncOut(func, funcnum,param); + } + + //led for test + else if (func=="l") { + errp=Lfunc(func, funcnum,param); + } + + //command SYNTH Tracce + else if ((func>="0") && (func<="9")) { + errp=s09funcOut(func, funcnum,param,stringa[0]); } - - //led for test - if (func=="l") { - if (funcnum=="1") { - if (param=="on ") { - term.formatPrintf("Led ACCESO \n",61,14,99,1); //p52 - 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("Led SPENTO! \n",61,14,99); //p52 - if (realExtraSerial==false) ardser.printf("\nLed SPENTO! \n\r"); - printDisp(dispType,"Led SPENTO \n\r"); - led.onOff(0); //Spegne il led - errp=0; - } - } - } - - //command SYNTH - if (((func>="0") && (func<="9")) || (func=="n")) { - if ((funcnum>="0") && (funcnum<="9")) { - term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),21,14,8,1); //p51 - term.formatPrintf("Arduino Command \n",61,14,10,1); //p52 - 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; - } + + //command SYNTH Note + else if (func=="n") { + errp=NfuncOut(func, funcnum,param, stringa); + } + + //start + else if (strIn.substr(0,5)=="start") { + errp=StartfuncOut(); } + //stop + else if (strIn.substr(0,4)=="stop") { + errp=StopfuncOut(); + } + + //delay stop + else if (strIn.substr(0,5)=="dstop") { + errp=DelayStopfuncOut(); + } + + // comando fuori parsing if (errp==1) { term.forgcol(1); - term.formatPrintf("Bad Command\n",61,14,10,1); //p52 + term.formatPrintf("Bad Command\n",61,14,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; + //pad a 4 + strIn=fnzAdd.padstr(strIn,5,' '); strIn=fnzAdd.addEOS(strIn); - //ardser.printf(strIn+" \n\r"); - term.formatPrintf(fnzAdd.string2char(strIn),18,21,10,1); + //split + func=strIn.substr(0,1); + funcnum=strIn.substr(1,1); + param=strIn.substr(2,3); + + //Random Activate + if (func=="r") { + errp=RfuncIn(func, funcnum,param); + } + //command SYNTH Tracce + else if ((func>="0") && (func<="9")) { + errp=s09funcIn(func, funcnum,param,stringa[0]); + //ardser.printf(strIn+" \n\r"); + } + //command SYNTH Note + else if (func=="n") { + errp=NfuncIn(func, funcnum,param, stringa); + } + //start + else if (strIn.substr(0,4)=="start") { + errp=StartfuncIn(); + } + //stop + else if (strIn.substr(0,3)=="stop") { + errp=StopfuncIn(); + } + + //delay stop + else if (strIn.substr(0,4)=="dstop") { + errp=DelayStopfuncIn(); + } + + //Boot + else if (strIn.substr(0,4)=="boot") { + errp=bootfuncIn(); + } + + 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; + + //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() { - //vedere come rimediare - term.forgcol(1); - term.formatPrintf("Button \n",21,8,5,10); - term.forgcol(9); - printDisp(dispType,"Button pressed\n\r"); - term.readypos(); - led.flash(4); + ardser.printf("rl\r"); + term.formatPrintf("rl\n",21,14,8,1); //p51 + term.formatPrintf("Ask for reload\n",61,14,99,1); //p52 + led.flash(2); }
--- a/TerminalPlus.lib Sat Sep 26 01:02:23 2015 +0000 +++ b/TerminalPlus.lib Fri Nov 06 20:15:54 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#60b9f0462d03 +https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#92f65f10a510
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/choiceFunctions.h Fri Nov 06 20:15:54 2015 +0000 @@ -0,0 +1,251 @@ + +//********************* Serial 4 real +bool Sfunc(string func, string funcnum, string param) +{ + bool errp=1; + if (param=="on ") { + realExtraSerial=true; + term.formatPrintf("ON \n",21,10,3,1); //p31 + term.formatPrintf("RS Attiva \n",61,14,99,1); //p52 + printDisp(dispType,"RS Attiva \n\r"); + errp=0; + } + if (param=="off") { + realExtraSerial=false; + term.formatPrintf("OFF\n",21,10,3,1); //p31 + term.formatPrintf("RS Disattivata \n",61,14,99); //p52 + if (realExtraSerial==false) ardser.printf("\nRS OFF \n\r"); + printDisp(dispType,"RS Disattivata \n\r"); + errp=0; + } + return errp; +} + +//************************ Random Out +bool RfuncOut(string func, string funcnum, string param) +{ + bool errp=1; + if (funcnum=="1") { + if (param=="on ") { + term.formatPrintf("ON \n",61,8,99,1); //p22 + ardser.printf(fnzAdd.string2char(fnzAdd.addEOS("R11\r"))); + printDisp(dispType,"Random On \n\r"); + randomActivate=true; + errp=0; + } + if (param=="off") { + term.formatPrintf("OFF\n",61,8,99,1); //p22 + ardser.printf(fnzAdd.string2char(fnzAdd.addEOS("R10\r"))); + printDisp(dispType,"Random OFF\n\r"); + randomActivate=false; + errp=0; + } + } + term.formatPrintf("\n",61,14,99,1); //p52 + return errp; +} + +//********************* Led +bool Lfunc(string func, string funcnum, string param) +{ + bool errp=1; + + if (funcnum=="1") { + if (param=="on ") { + term.formatPrintf("Led ACCESO \n",61,14,99,1); //p52 + 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("Led SPENTO! \n",61,14,99,1); //p52 + if (realExtraSerial==false) ardser.printf("\nLed SPENTO! \n\r"); + printDisp(dispType,"Led SPENTO \n\r"); + led.onOff(0); //Spegne il led + errp=0; + } + } + return errp; +} + +//********************* Synth Tracce +bool s09funcOut(string func, string funcnum, string param, char sstr) +{ + bool errp=1; + int funcn; + + if ((funcnum>="0") && (funcnum<="9")) { + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),21,14,8,1); //p51 + // vale la pena creare una funzione di parametri da formalizzare + funcn=fnzAdd.c2i(sstr); + funcn=fnzAdd.constrain(funcn,0,2); + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),21+(funcn%2)*40,6+(2*(funcn/2)),8,1); //p11 //p12 //p21 + term.formatPrintf("Tracks Command \n",61,14,99,1); //p52 + ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+funcnum+param+"\r"))); + printDisp(dispType,"Tracks Command \n\r"); + printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+func+funcnum+param+"\r"))); + //ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param))); + errp=0; + } + return errp; +} + +//********************* Synth Note +bool NfuncOut(string func, string funcnum, string param, char* arr) +{ + bool errp=1; + int funcn; + + if ((funcnum>="0") && (funcnum<="9")) { + if (((arr[2]>='0') && (arr[2]<='9')) || (arr[2]=='-')) { + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),21,14,8,1); //p51 + // vale la pena creare una funzione di parametri da formalizzare + funcn=fnzAdd.c2i(arr[2]); + //funcn=fnzAdd.constrain(funcn,0,2); + term.formatPrintf("Note Command \n",61,14,99,1); //p52 + ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+funcnum+param+"\r"))); + printDisp(dispType,"Note Command \n\r"); + printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+func+funcnum+param+"\r"))); + errp=0; + } + } + return errp; +} + +//********************* Start +bool StartfuncOut() +{ + term.formatPrintf("Start\n",21,14,8,1); //p51 + term.formatPrintf("Start H-Ard\n",61,14,99,1); //p52 + ardser.printf("start\r"); + printDisp(dispType,"Start H-Ard\n\r"); + return 0; +} + +//********************* Stop +bool StopfuncOut() +{ + term.formatPrintf("Stop\n",21,14,8,1); //p51 + term.formatPrintf("Stop H-Ard\n",61,14,99,1); //p52 + ardser.printf("stop\r"); + printDisp(dispType,"Stop H-Ard\n\r"); + return 0; +} + +//********************* Delay Stop +bool DelayStopfuncOut() +{ + term.formatPrintf("DStop\n",21,14,8,1); //p51 + term.formatPrintf("Delay Stop H-Ard\n",61,14,99,1); //p52 + ardser.printf("dstop\r"); + printDisp(dispType,"DlyStop H-Ard\n\r"); + return 0; +} + + + +/************************ IN Function *****************************/ +/******************************************************************/ +/******************************************************************/ + + +//************************ Random + + +bool RfuncIn(string func, string funcnum, string param) +{ + bool errp=1; + if (funcnum=="1") { + if (param=="on ") { + printDisp(dispType,"Random On \n\r"); + term.formatPrintf("ON \n",65,8,99,1); //p22 + printDisp(dispType,"RfuncInOn \n\r"); + errp=0; + } + if (param=="off") { + term.formatPrintf("OFF\n",65,8,99,1); //p22 + printDisp(dispType,"RfuncInOFF\n\r"); + errp=0; + } + } + return errp; +} + +//********************* Synth Tracce +bool s09funcIn(string func, string funcnum, string param, char sstr) +{ + bool errp=1; + int funcn; + + if ((funcnum>="0") && (funcnum<="9")) { + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),21,14,8,1); //p51 + // vale la pena creare una funzione di parametri da formalizzare + funcn=fnzAdd.c2i(sstr); + funcn=fnzAdd.constrain(funcn,0,2); + //azzera flag di ricezione + for (int i = 0; i < 3; i++) term.formatPrintf(" \n",31+(i%2)*40,6+(2*(i/2)),8,1); //p11 //p12 //p21 + term.formatPrintf("*\n",31+(funcn%2)*40,6+(2*(funcn/2)),8,1); //p11 //p12 //p21 + printDisp(dispType,"s09funcIn \n\r"); + printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+func+funcnum+param+"\r"))); + errp=0; + } + return errp; +} + +//********************* Synth Note +bool NfuncIn(string func, string funcnum, string param, char* arr) +{ + bool errp=1; + int funcn; + if ((funcnum>="0") && (funcnum<="9")) { + term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),21,14,8,1); //p51 + // vale la pena creare una funzione di parametri da formalizzare + funcn=fnzAdd.c2i(arr[2]+arr[3]); + for (int i = 0; i < 6; i++) term.formatPrintf(" ",23+(i*4),12,1,1); + term.formatPrintf(fnzAdd.string2char(param.substr(0,2)+"*"),21+(fnzAdd.c2i(arr[1])*4),12,1,1); //p11 //p12 //p21 + printDisp(dispType,"NFuncIn\n\r"); + printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+func+funcnum+param+"\r"))); + //ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param))); + errp=0; + // } + } + return errp; +} + +//********************* Start +bool StartfuncIn() +{ + term.formatPrintf("*\n",26,14,8,1); //p51 + // term.formatPrintf("Start H-Ard\n",61,14,99,1); //p52 + // printDisp(dispType,"InStart H-Ard\n\r"); + return 1; +} + +//********************* Start +bool StopfuncIn() +{ + term.formatPrintf("*\n",26,14,8,1); //p51 + // term.formatPrintf("Start H-Ard\n",61,14,99,1); //p52 + // printDisp(dispType,"InStop H-Ard\n\r"); + return 1; +} + +//********************* Start +bool DelayStopfuncIn() +{ + term.formatPrintf("*\n",26,14,8,1); //p51 + // term.formatPrintf("Start H-Ard\n",61,14,99,1); //p52 + // printDisp(dispType,"InStop H-Ard\n\r"); + return 1; +} + +//********************* Start +bool bootfuncIn() +{ + term.formatPrintf("*\n",26,14,8,1); //p51 + term.formatPrintf("boot\n",21,14,8,1); //p51 + term.formatPrintf("Arduino Boot\n",61,14,99,1); //p52 + ardser.printf("rl\r"); + return 1; +} \ No newline at end of file
--- a/main.cpp Sat Sep 26 01:02:23 2015 +0000 +++ b/main.cpp Fri Nov 06 20:15:54 2015 +0000 @@ -13,13 +13,15 @@ //init funzioni personal lib Flasher led(LED1); Screen sc(&pc); -genFunctions fnz; +//genFunctions fnz; +genFunctions fnzAdd; //messa qui rende la raccolta funzioni indipendente Ticker ScreenSaver; //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 //------------ Funzioni ------------- @@ -51,6 +53,7 @@ bannerDisp(dispType); //terminal term.bannerAdv(); + preloadValue(); while(1) { // ardser.attach(&callback); @@ -70,7 +73,7 @@ // if (realExtraSerial==false) ardser.printf("cmd Ready\n\r"); for(int ii=0; ii<=i[0]; ii++) bufferTemp[ii]=buffer[0][ii]; parserVT100(bufferTemp); - } else sc.commitScreen(); + } else term.readypos(); i[0]=0; //azzera la posizione del puntatore del buffer pronto per la ricezione di una nuova stringa } } @@ -78,7 +81,7 @@ //seriale esterna if (ardser.readable()) { c[1]=ardser.getc(); //legge un carattere dalla seriale - if ((c[1] != 10) && (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 } else {
--- a/mbed.bld Sat Sep 26 01:02:23 2015 +0000 +++ b/mbed.bld Fri Nov 06 20:15:54 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file