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 7:f57abb3f0d3f, committed 2015-05-31
- Comitter:
- MaxScorda
- Date:
- Sun May 31 22:00:40 2015 +0000
- Parent:
- 6:f8865b6d592a
- Child:
- 8:3f1d8c55b3a0
- Commit message:
- Avanzamento parsing
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Functions.h Sun May 31 22:00:40 2015 +0000 @@ -0,0 +1,80 @@ +#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 parser(char stringa[]) +{ + /* + char func[4]; + char param[4] + + //assumiamo che func sia 2 e param 2 + strncpy(func,stringa,2); + strcpy(param,fnz.substr(stringa, 2, 2)); + func[2]='\n'; + param[2]='\n'; + sc.writeScreen(func,2,15); + sc.writeScreen(param,20,15); + sc.writeScreen((char*)str.c_str() ,10,16); + */ + string func; //funzione l=led + string funcnum; //funzione ordinata 1,2,3 ecc + string param; //parametro on, off + string strIn = string(stringa); + strIn.insert(strIn.size(), 4 - strIn.size(), '.'); //pad + strIn=fnzAdd.addEOS(strIn); + //strIn=strIn+"\n"; + func=strIn.substr(0,1); + funcnum=strIn.substr(1,1); + param=strIn.substr(2,2); + sc.writeScreen(fnzAdd.string2char(func),2,15); + sc.writeScreen(fnzAdd.string2char(param),20,15); + sc.writeScreen((char*)strIn.c_str() ,10,16); + + //switch + + bool errp=1; +//confronta la stringa ricevuta con le costanti accettate per il comando di accensione del led +//la funzione strcmp fa parte della libreria string standard del C e confronta 2 stringhe +//restituendo 0 se le stringhe sono uguali. + if ((strcmp(stringa,"on")==0) ||(strcmp(stringa,"acceso")==0) ||(strcmp(stringa,"apriti sesamo")==0)) { + // pc.printf("Led ACCESO \n\r"); + sc.writeScreen("Led ACCESO \n",2,10); + ardser.printf("\nLed ACCESO \n\r"); + led.onOff(1); //Accende il led + errp=0; + sc.commitScreen(); + } + //Confronto per i comandi di spegnimento del led + if ((strcmp(stringa,"off")==0) ||(strcmp(stringa,"spento")==0) ||(strcmp(stringa,"chiuditi sesamo")==0)) { + // pc.printf("Led SPENTO !\n\r"); + sc.writeScreen("Led SPENTO! \n",2,10); + ardser.printf("\nLed SPENTO! \n\r"); + led.onOff(0); // spegne il led + errp=0; + sc.commitScreen(); + } + if (errp==1) { + // pc.printf("Bad command\n\r"); + sc.writeScreen("Bad Command\n",2,10); + ardser.printf("\nBad command\n\r"); + sc.commitScreen(); + } +} + + +void pressed() +{ + //vedere come rimediare + sc.pressed(); +} + +
--- a/IOFuncLib.lib Thu May 28 14:52:30 2015 +0000 +++ b/IOFuncLib.lib Sun May 31 22:00:40 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/MaxScorda/code/IOFuncLib/#8e723d99838e +http://developer.mbed.org/users/MaxScorda/code/IOFuncLib/#6c6446382bb2
--- a/config.h Thu May 28 14:52:30 2015 +0000 +++ b/config.h Sun May 31 22:00:40 2015 +0000 @@ -7,6 +7,7 @@ #define screenRow 24 #define screenColumn 80 +#define EOS "\n" const int test_length = 20; @@ -14,3 +15,4 @@ #endif +
--- a/main.cpp Thu May 28 14:52:30 2015 +0000 +++ b/main.cpp Sun May 31 22:00:40 2015 +0000 @@ -2,6 +2,8 @@ #include "config.h" #include "IOFuncLib.h" + + //init standard InterruptIn mybutton(USER_BUTTON); Serial pc(SERIAL_TX, SERIAL_RX); //Apertura della seriale 2 @@ -9,55 +11,17 @@ //init funzioni personal lib Flasher led(LED1); Screen sc(&pc); +genFunctions fnz; + //var int cont=0; //------------ Funzioni ------------- -void pressed() -{ - sc.pressed(); -} - - -void callback() -{ - // Note: you need to actually read from the serial to clear the RX interrupt - // ardser.printf("%d \n", cont++); -// myled2 = !myled2; -} +#include "Functions.h" -void parser(char stringa[]) -{ - bool errp=1; -//confronta la stringa ricevuta con le costanti accettate per il comando di accensione del led -//la funzione strcmp fa parte della libreria string standard del C e confronta 2 stringhe -//restituendo 0 se le stringhe sono uguali. - if ((strcmp(stringa,"on")==0) ||(strcmp(stringa,"acceso")==0) ||(strcmp(stringa,"apriti sesamo")==0)) { - // pc.printf("Led ACCESO \n\r"); - sc.writeScreen("Led ACCESO \n",2,10); - ardser.printf("\nLed ACCESO \n\r"); - led.onOff(1); //Accende il led - errp=0; - sc.commitScreen(); - } - //Confronto per i comandi di spegnimento del led - if ((strcmp(stringa,"off")==0) ||(strcmp(stringa,"spento")==0) ||(strcmp(stringa,"chiuditi sesamo")==0)) { - // pc.printf("Led SPENTO !\n\r"); - sc.writeScreen("Led SPENTO! \n",2,10); - ardser.printf("\nLed SPENTO! \n\r"); - led.onOff(0); // spegne il led - errp=0; - sc.commitScreen(); - } - if (errp==1) { - // pc.printf("Bad command\n\r"); - sc.writeScreen("Bad Command\n",2,10); - ardser.printf("\nBad command\n\r"); - sc.commitScreen(); - } -} + //-------------- fine funzioni int main()