![](/media/cache/profiles/21d8f4e662816f8cb42c92e2c5884a64.jpg.50x50_q85.jpg)
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
Diff: Functions.h
- Revision:
- 7:f57abb3f0d3f
- Child:
- 8:3f1d8c55b3a0
--- /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(); +} + +