Console Serial IO con display OLED e seriale asincrona

Dependencies:   mbed BufferedSerial AserialIOFuncLib SSD1306 TerminalPlusV2

Fork of SerialIO by Max Scordamaglia

Console Serial IO con display OLED e seriale asincrona

Files at this revision

API Documentation at this revision

Comitter:
MaxScorda
Date:
Tue Jun 02 00:51:43 2015 +0000
Parent:
7:f57abb3f0d3f
Child:
9:9ad85b6bd9cf
Commit message:
Parsing, funzioni video e EOS

Changed in this revision

Functions.h Show annotated file Show diff for this revision Revisions of this file
IOFuncLib.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Functions.h	Sun May 31 22:00:40 2015 +0000
+++ b/Functions.h	Tue Jun 02 00:51:43 2015 +0000
@@ -12,62 +12,71 @@
 
 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
+    bool errp=1;
+    //pad a 4
+    strIn=fnzAdd.padstr(strIn,5,' ');
     strIn=fnzAdd.addEOS(strIn);
-    //strIn=strIn+"\n";
+    //split
     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
+    param=strIn.substr(2,3);
+    //write param
+    sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(func)),2,8,15);
+    sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),22,8,15);
+    sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(param)),42,8,15);
+    //write input string
+    sc.writeScreen(fnzAdd.string2char(strIn),2,20,20);
+    //sc.writeScreen((char*)func.c_str() ,02,07); funziona anche cosi'
 
-    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();
+   //led
+    if (func=="l") {
+        if (funcnum=="1") {
+            if (param=="on ") {
+                sc.writeScreen("ON \n",2,14,3);
+                sc.writeScreen("Led ACCESO \n",42,20,99);
+                ardser.printf("\nLed ACCESO \n\r");
+                led.onOff(1); //Accende il led
+                errp=0;
+            }
+            if (param=="off") {
+                sc.writeScreen("OFF \n",2,14);
+                sc.writeScreen("Led SPENTO! \n",42,20,99);
+                ardser.printf("\nLed SPENTO! \n\r");
+                led.onOff(0); //Spegne il led
+                errp=0;
+            }
+        }
     }
-    //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();
+    //virtual
+    if (func=="v") {
+        if (funcnum=="1") {
+            if (param=="on ") {
+                sc.writeScreen("ON \n",22,14);
+                sc.writeScreen("Virtual ACCESO \n",42,20,99);
+                ardser.printf("\nVirtual ACCESO \n\r");
+                errp=0;
+            }
+            if (param=="off") {
+                sc.writeScreen("OFF \n",22,14);
+                sc.writeScreen("Virtual SPENTO! \n",42,20,99);
+                ardser.printf("\nVirtual SPENTO! \n\r");
+                errp=0;
+            }
+        }
     }
+
+    // comando fuori parsing
     if (errp==1) {
         // pc.printf("Bad command\n\r");
-        sc.writeScreen("Bad Command\n",2,10);
+        sc.writeScreen("Bad Command\n",42,20,99);
         ardser.printf("\nBad command\n\r");
-        sc.commitScreen();
+       // sc.commitScreen();
     }
+     sc.commitScreen();
 }
 
 
@@ -78,3 +87,4 @@
 }
 
 
+
--- a/IOFuncLib.lib	Sun May 31 22:00:40 2015 +0000
+++ b/IOFuncLib.lib	Tue Jun 02 00:51:43 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/MaxScorda/code/IOFuncLib/#6c6446382bb2
+http://developer.mbed.org/users/MaxScorda/code/IOFuncLib/#eae942db86db
--- a/main.cpp	Sun May 31 22:00:40 2015 +0000
+++ b/main.cpp	Tue Jun 02 00:51:43 2015 +0000
@@ -48,9 +48,14 @@
         } else {
             pc.printf("\n\r");
             buffer[i]=0; //se è un CR inserisci un carattere nullo nel buffer per delimitare la stringa
+            //controlla di non  mandare solo un CR
+            if (i>0) {
+                ardser.printf("\ncmd Ready\n\r");
+                parser(buffer);
+            }
+            else sc.commitScreen();
             i=0; //azzera la posizione del puntatore del buffer pronto per la ricezione di una nuova stringa
-            ardser.printf("\ncmd Ready\n\r");
-            parser(buffer);
+
         }
     }
 }