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:
Mon Sep 14 21:33:42 2015 +0000
Parent:
28:f7a59cee5f0d
Child:
30:373376dfb1c6
Commit message:
VT100: fase1

Changed in this revision

Functions.h Show annotated file Show diff for this revision Revisions of this file
TerminalPlus.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	Wed Sep 09 20:07:24 2015 +0000
+++ b/Functions.h	Mon Sep 14 21:33:42 2015 +0000
@@ -15,6 +15,110 @@
     inverseDisp(dispType);
 }
 
+
+void parserVT100(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,15);
+    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),22,8,15);
+    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),42,8,15);
+    //write input string
+    term.formatPrintf(fnzAdd.string2char(strIn),2,16,20);
+    //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 parser(char stringa[])
 {
     string func; //funzione l=led
@@ -30,24 +134,24 @@
     funcnum=strIn.substr(1,1);
     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);
+    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func)),2,8,15);
+    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),22,8,15);
+    term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),42,8,15);
     //write input string
-    sc.writeScreen(fnzAdd.string2char(strIn),2,16,20);
-    //sc.writeScreen((char*)func.c_str() ,02,07); funziona anche cosi'
+    term.formatPrintf(fnzAdd.string2char(strIn),2,16,20);
+    //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;
-                sc.writeScreen("ON \n",62,13,3);
+                term.formatPrintf("ON \n",62,13,3);
                 errp=0;
             }
             if (param=="off") {
                 realExtraSerial=false;
-                sc.writeScreen("OFF\n",62,13);
+                term.formatPrintf("OFF\n",62,13);
                 errp=0;
             }
         }
@@ -57,16 +161,16 @@
     if (func=="l") {
         if (funcnum=="1") {
             if (param=="on ") {
-                sc.writeScreen("ON \n",2,13,3);
-                sc.writeScreen("Led ACCESO \n",42,16,99);
+                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") {
-                sc.writeScreen("OFF \n",2,13);
-                sc.writeScreen("Led SPENTO! \n",42,16,99);
+                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
@@ -78,15 +182,15 @@
     if (func=="v") {
         if (funcnum=="1") {
             if (param=="on ") {
-                sc.writeScreen("ON \n",22,13);
-                sc.writeScreen("Virtual ACCESO \n",42,16,99);
+                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") {
-                sc.writeScreen("OFF \n",22,13);
-                sc.writeScreen("Virtual SPENTO! \n",42,16,99);
+                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;
@@ -97,8 +201,8 @@
     //command SYNTH
     if ((func>="0") && (func<="9")) {
         if ((funcnum>="0") && (funcnum<="9")) {
-            sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),42,13,4);
-            sc.writeScreen("Arduino Command \n",42,16,99);
+            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")));
@@ -110,11 +214,11 @@
     // comando fuori parsing
     if (errp==1) {
         // pc.printf("Bad command\n\r");
-        sc.writeScreen("Bad Command\n",42,16,99);
+        term.formatPrintf("Bad Command\n",42,16,99);
         if (realExtraSerial==false) ardser.printf("Bad command\n\r");
         printDisp(dispType,"** Bad command ** \n\r");
     }
-    sc.commitScreen();
+    term.readypos();
 }
 
 void writeInput(char stringa[])
@@ -122,8 +226,9 @@
     string strIn = string(stringa);
     strIn=fnzAdd.addEOS(strIn);
     //ardser.printf(strIn+" \n\r");
-    sc.writeScreen(fnzAdd.string2char(strIn),2,20,20);
- }
+    term.formatPrintf(fnzAdd.string2char(strIn),2,20,20);
+    term.readypos();
+}
 
 
 void pressed()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TerminalPlus.lib	Mon Sep 14 21:33:42 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/MaxScorda/code/TerminalPlus/#d045e3561533
--- a/main.cpp	Wed Sep 09 20:07:24 2015 +0000
+++ b/main.cpp	Mon Sep 14 21:33:42 2015 +0000
@@ -2,12 +2,15 @@
 #include "config.h"
 #include "IOFuncLib.h"
 #include "BufferedSerial.h"
+#include "Terminal.h"
+
+
 
 
 //init standard
 InterruptIn mybutton(USER_BUTTON);
-//Serial pc(SERIAL_TX, SERIAL_RX); //Apertura della seriale 2
-//Serial ardser(PA_11, PA_12); //Apertura della seriale 1 *opzionale vedi sotto
+
+Terminal term(USBTX, USBRX); // tx, rx
 BufferedSerial pc(SERIAL_TX, SERIAL_RX); //Apertura della seriale 2
 BufferedSerial ardser(PA_11, PA_12); //Apertura della seriale 1 *opzionale vedi sotto
 //init funzioni personal lib
@@ -36,14 +39,16 @@
     char i[4]= {0,0,0,0}; // variabile di comodo per il conteggio dei caratteri
 
     //Serial config
-    pc.baud(SERIAL1BAUD);
+   // pc.baud(SERIAL1BAUD);
+    pc.baud(9600);
     ardser.baud(SERIALARDBAUD);
     //pc.format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1)
 
     mybutton.fall(&pressed);
     ScreenSaver.attach(&scsa,60);
-    sc.emptyFrame();
-    sc.banner();
+    // sc.emptyFrame(); ////////////////////////// rimettere
+
+    term.banner();
     //ardser
     ardser.printf("Connected\r");
     // display
@@ -56,19 +61,21 @@
         //seriale interna
         if (pc.readable()) {
             c[0]=pc.getc(); //legge un carattere dalla seriale
+            term.putc(c[0]); //redirect to terminal
             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);
             } else {
-                pc.printf("\n\r");
+                //pc.printf("\n\r");
                 buffer[0][i[0]]=0; //se è un CR inserisci un carattere nullo nel buffer per delimitare la stringa
                 //controlla di non  mandare solo un CR
                 if (i[0]>0) {
                    // if (realExtraSerial==false) ardser.printf("cmd Ready\n\r");
                     for(int ii=0; ii<=i[0]; ii++) bufferTemp[ii]=buffer[0][ii];
-                    parser(bufferTemp);
-                } else sc.commitScreen();
+                    parserVT100(bufferTemp);
+                } 
+                 else sc.commitScreen();
                 i[0]=0; //azzera la posizione del puntatore del buffer pronto per la ricezione di una nuova stringa
             }
         }
@@ -86,7 +93,8 @@
                 if (i[1]>0) {
                     for(int ii=0; ii<=i[1]; ii++) bufferTemp[ii]=buffer[1][ii];
                     writeInput(bufferTemp);                    
-                } else sc.commitScreen();
+                }
+                 else term.readypos();
                 i[1]=0; //azzera la posizione del puntatore del buffer pronto per la ricezione di una nuova stringa
             }
         }