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

Committer:
MaxScorda
Date:
Fri Nov 06 22:31:17 2015 +0000
Revision:
37:befd2fe96ee3
Parent:
36:9ecb98d7c2cd
Child:
38:d88296cbb39c
Revision definitiva (da controllare)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MaxScorda 7:f57abb3f0d3f 1 #include <string>
MaxScorda 7:f57abb3f0d3f 2 #include "IOFuncLib.h"
MaxScorda 36:9ecb98d7c2cd 3 #include "choiceFunctions.h"
MaxScorda 7:f57abb3f0d3f 4
MaxScorda 37:befd2fe96ee3 5
MaxScorda 37:befd2fe96ee3 6 void bannerAdv()
MaxScorda 37:befd2fe96ee3 7 {
MaxScorda 37:befd2fe96ee3 8 //spostato qui per lasciare in pace la libreria
MaxScorda 37:befd2fe96ee3 9 term.reset();
MaxScorda 37:befd2fe96ee3 10 term.cls();
MaxScorda 37:befd2fe96ee3 11 term.frame(0, 0, 79, 22,1);
MaxScorda 37:befd2fe96ee3 12 term.forgcol(3);
MaxScorda 37:befd2fe96ee3 13 term.bold();
MaxScorda 37:befd2fe96ee3 14 term.formatPrintf("_____ Glass Project Console _____\n",22,1);
MaxScorda 37:befd2fe96ee3 15 term.formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2);
MaxScorda 37:befd2fe96ee3 16
MaxScorda 37:befd2fe96ee3 17 term.resetattrib();
MaxScorda 37:befd2fe96ee3 18 term.forgcol(7);
MaxScorda 37:befd2fe96ee3 19 //3-4
MaxScorda 37:befd2fe96ee3 20 term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,3,1); //top 1/2
MaxScorda 37:befd2fe96ee3 21 term.forgcol(6);
MaxScorda 37:befd2fe96ee3 22 term.formatPrintf("Funzione \n",2,4); //p01
MaxScorda 37:befd2fe96ee3 23 term.formatPrintf("Numero \n",32,4); //p02
MaxScorda 37:befd2fe96ee3 24 term.formatPrintf("Parametro \n",51,4); //p03
MaxScorda 37:befd2fe96ee3 25 //5-6
MaxScorda 37:befd2fe96ee3 26 term.formatPrintf("Pattern 0......... \n",2,6); //p11
MaxScorda 37:befd2fe96ee3 27 term.formatPrintf("Pattern 1......... \n",42,6); //p12
MaxScorda 37:befd2fe96ee3 28 //7-8
MaxScorda 37:befd2fe96ee3 29 term.formatPrintf("Pattern 2......... \n",2,8); //p21
MaxScorda 37:befd2fe96ee3 30 term.formatPrintf("Random Act (r1o/f) \n",42,8); //p22
MaxScorda 37:befd2fe96ee3 31 //9-10
MaxScorda 37:befd2fe96ee3 32 term.formatPrintf("Serial Real(sro/f) \n",2,10); //p31
MaxScorda 37:befd2fe96ee3 33 //11-12
MaxScorda 37:befd2fe96ee3 34 term.formatPrintf("Note Pattern......\n",2,12,99); //p41
MaxScorda 37:befd2fe96ee3 35 //13-14
MaxScorda 37:befd2fe96ee3 36 term.formatPrintf("Input string...... \n",2,14); //p51
MaxScorda 37:befd2fe96ee3 37 term.formatPrintf("Command Type...... \n",42,14); //p52
MaxScorda 37:befd2fe96ee3 38 //15-16
MaxScorda 37:befd2fe96ee3 39 term.forgcol(7);
MaxScorda 37:befd2fe96ee3 40 term.formatPrintf("Serial Feedback \n",2,21);
MaxScorda 37:befd2fe96ee3 41
MaxScorda 37:befd2fe96ee3 42
MaxScorda 37:befd2fe96ee3 43 // grigino
MaxScorda 37:befd2fe96ee3 44
MaxScorda 37:befd2fe96ee3 45 term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,5); //top 3/4
MaxScorda 37:befd2fe96ee3 46 term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,9); //top 7/8
MaxScorda 37:befd2fe96ee3 47 term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,13); //top 11/12
MaxScorda 37:befd2fe96ee3 48 term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,15,1); //bottom pot
MaxScorda 37:befd2fe96ee3 49 term.formatPrintf(fnzAdd.string2char(fnzAdd.padstr("\n",78,char(196))),1,20); //azzo funziona...
MaxScorda 37:befd2fe96ee3 50
MaxScorda 37:befd2fe96ee3 51 term.forgcol(2);
MaxScorda 37:befd2fe96ee3 52 term.formatPrintf("Pattern: da 031 a 252 - Traccia 0-2, Note 3-6, Len 1-2 \n",2,16); //help
MaxScorda 37:befd2fe96ee3 53 term.formatPrintf("Stato random: r1on-r1off \n",2,17); //help
MaxScorda 37:befd2fe96ee3 54 term.formatPrintf("Cambia Note: da n01 a n53 - Nota 0-5, Val 1-3 \n",2,18); //help
MaxScorda 37:befd2fe96ee3 55 term.formatPrintf("start, stop, dstop (delay) - rl: reload value\n",2,19); //help
MaxScorda 37:befd2fe96ee3 56 term.forgcol(7);
MaxScorda 37:befd2fe96ee3 57 term.locate(0, 23);
MaxScorda 37:befd2fe96ee3 58 printf("Command: > ");
MaxScorda 37:befd2fe96ee3 59
MaxScorda 37:befd2fe96ee3 60 // extra da attivare forse
MaxScorda 37:befd2fe96ee3 61 // formatPrintf("Pattern \n",2,5);
MaxScorda 37:befd2fe96ee3 62 // formatPrintf(string2char(padstr("\n",78,char(196))),1,7); //top 5/6
MaxScorda 37:befd2fe96ee3 63 // formatPrintf(string2char(padstr("\n",78,char(196))),1,11); //top 9/10
MaxScorda 37:befd2fe96ee3 64 // formatPrintf("Serial \n",2,9);
MaxScorda 37:befd2fe96ee3 65 // formatPrintf("HELP \n",2,15); //help
MaxScorda 37:befd2fe96ee3 66 }
MaxScorda 37:befd2fe96ee3 67
MaxScorda 37:befd2fe96ee3 68
MaxScorda 37:befd2fe96ee3 69
MaxScorda 7:f57abb3f0d3f 70 void callback()
MaxScorda 7:f57abb3f0d3f 71 {
MaxScorda 7:f57abb3f0d3f 72 // Note: you need to actually read from the serial to clear the RX interrupt
MaxScorda 7:f57abb3f0d3f 73 // ardser.printf("%d \n", cont++);
MaxScorda 7:f57abb3f0d3f 74 // myled2 = !myled2;
MaxScorda 7:f57abb3f0d3f 75 }
MaxScorda 7:f57abb3f0d3f 76
MaxScorda 23:b7bd85345617 77 void scsa()
MaxScorda 23:b7bd85345617 78 {
MaxScorda 23:b7bd85345617 79 //Funzione per screensaver
MaxScorda 23:b7bd85345617 80 inverseDisp(dispType);
MaxScorda 23:b7bd85345617 81 }
MaxScorda 7:f57abb3f0d3f 82
MaxScorda 29:bfb815540de7 83
MaxScorda 29:bfb815540de7 84 void parserVT100(char stringa[])
MaxScorda 29:bfb815540de7 85 {
MaxScorda 29:bfb815540de7 86 string func; //funzione l=led
MaxScorda 29:bfb815540de7 87 string funcnum; //funzione ordinata 1,2,3 ecc
MaxScorda 29:bfb815540de7 88 string param; //parametro on, off
MaxScorda 29:bfb815540de7 89 string strIn = string(stringa);
MaxScorda 29:bfb815540de7 90 bool errp=1;
MaxScorda 29:bfb815540de7 91 //pad a 4
MaxScorda 29:bfb815540de7 92 strIn=fnzAdd.padstr(strIn,5,' ');
MaxScorda 29:bfb815540de7 93 strIn=fnzAdd.addEOS(strIn);
MaxScorda 29:bfb815540de7 94 //split
MaxScorda 29:bfb815540de7 95 func=strIn.substr(0,1);
MaxScorda 29:bfb815540de7 96 funcnum=strIn.substr(1,1);
MaxScorda 29:bfb815540de7 97 param=strIn.substr(2,3);
MaxScorda 29:bfb815540de7 98 //write param
MaxScorda 35:e9e9d518c354 99 term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(func)),11,4,10,1); //p01
MaxScorda 35:e9e9d518c354 100 term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),39,4,10,1); //p02
MaxScorda 35:e9e9d518c354 101 term.formatPrintf(fnzAdd.string2char(fnzAdd.addEOS(param)),61,4,10,1); //p03
MaxScorda 29:bfb815540de7 102 //write input string
MaxScorda 35:e9e9d518c354 103 term.formatPrintf(fnzAdd.string2char(strIn),21,14,10,1); //p51
MaxScorda 29:bfb815540de7 104 //term.formatPrintf(((char*)func.c_str() ,02,07); funziona anche cosi'
MaxScorda 29:bfb815540de7 105
MaxScorda 29:bfb815540de7 106 //extra serial output (output reale su arduino default true)
MaxScorda 36:9ecb98d7c2cd 107 if ((func=="s") && (funcnum=="r") ) {
MaxScorda 36:9ecb98d7c2cd 108 errp=Sfunc(func, funcnum,param);
MaxScorda 36:9ecb98d7c2cd 109 }
MaxScorda 36:9ecb98d7c2cd 110
MaxScorda 36:9ecb98d7c2cd 111 //Random Activate
MaxScorda 36:9ecb98d7c2cd 112 else if (func=="r") {
MaxScorda 36:9ecb98d7c2cd 113 errp=RfuncOut(func, funcnum,param);
MaxScorda 36:9ecb98d7c2cd 114 }
MaxScorda 36:9ecb98d7c2cd 115
MaxScorda 36:9ecb98d7c2cd 116 //led for test
MaxScorda 36:9ecb98d7c2cd 117 else if (func=="l") {
MaxScorda 36:9ecb98d7c2cd 118 errp=Lfunc(func, funcnum,param);
MaxScorda 36:9ecb98d7c2cd 119 }
MaxScorda 36:9ecb98d7c2cd 120
MaxScorda 36:9ecb98d7c2cd 121 //command SYNTH Tracce
MaxScorda 36:9ecb98d7c2cd 122 else if ((func>="0") && (func<="9")) {
MaxScorda 36:9ecb98d7c2cd 123 errp=s09funcOut(func, funcnum,param,stringa[0]);
MaxScorda 29:bfb815540de7 124 }
MaxScorda 36:9ecb98d7c2cd 125
MaxScorda 36:9ecb98d7c2cd 126 //command SYNTH Note
MaxScorda 36:9ecb98d7c2cd 127 else if (func=="n") {
MaxScorda 36:9ecb98d7c2cd 128 errp=NfuncOut(func, funcnum,param, stringa);
MaxScorda 36:9ecb98d7c2cd 129 }
MaxScorda 36:9ecb98d7c2cd 130
MaxScorda 36:9ecb98d7c2cd 131 //start
MaxScorda 36:9ecb98d7c2cd 132 else if (strIn.substr(0,5)=="start") {
MaxScorda 36:9ecb98d7c2cd 133 errp=StartfuncOut();
MaxScorda 29:bfb815540de7 134 }
MaxScorda 29:bfb815540de7 135
MaxScorda 36:9ecb98d7c2cd 136 //stop
MaxScorda 36:9ecb98d7c2cd 137 else if (strIn.substr(0,4)=="stop") {
MaxScorda 36:9ecb98d7c2cd 138 errp=StopfuncOut();
MaxScorda 36:9ecb98d7c2cd 139 }
MaxScorda 36:9ecb98d7c2cd 140
MaxScorda 36:9ecb98d7c2cd 141 //delay stop
MaxScorda 36:9ecb98d7c2cd 142 else if (strIn.substr(0,5)=="dstop") {
MaxScorda 36:9ecb98d7c2cd 143 errp=DelayStopfuncOut();
MaxScorda 36:9ecb98d7c2cd 144 }
MaxScorda 36:9ecb98d7c2cd 145
MaxScorda 36:9ecb98d7c2cd 146
MaxScorda 29:bfb815540de7 147 // comando fuori parsing
MaxScorda 29:bfb815540de7 148 if (errp==1) {
MaxScorda 32:b7859f48942a 149 term.forgcol(1);
MaxScorda 36:9ecb98d7c2cd 150 term.formatPrintf("Bad Command\n",61,14,99,1); //p52
MaxScorda 32:b7859f48942a 151 term.forgcol(9);
MaxScorda 29:bfb815540de7 152 if (realExtraSerial==false) ardser.printf("Bad command\n\r");
MaxScorda 29:bfb815540de7 153 printDisp(dispType,"** Bad command ** \n\r");
MaxScorda 29:bfb815540de7 154 }
MaxScorda 36:9ecb98d7c2cd 155
MaxScorda 29:bfb815540de7 156 term.readypos();
MaxScorda 29:bfb815540de7 157 }
MaxScorda 29:bfb815540de7 158
MaxScorda 29:bfb815540de7 159
MaxScorda 28:f7a59cee5f0d 160 void writeInput(char stringa[])
MaxScorda 28:f7a59cee5f0d 161 {
MaxScorda 36:9ecb98d7c2cd 162 string func; //funzione l=led
MaxScorda 36:9ecb98d7c2cd 163 string funcnum; //funzione ordinata 1,2,3 ecc
MaxScorda 36:9ecb98d7c2cd 164 string param; //parametro on, off
MaxScorda 28:f7a59cee5f0d 165 string strIn = string(stringa);
MaxScorda 36:9ecb98d7c2cd 166 bool errp=1;
MaxScorda 36:9ecb98d7c2cd 167 //pad a 4
MaxScorda 36:9ecb98d7c2cd 168 strIn=fnzAdd.padstr(strIn,5,' ');
MaxScorda 28:f7a59cee5f0d 169 strIn=fnzAdd.addEOS(strIn);
MaxScorda 36:9ecb98d7c2cd 170 //split
MaxScorda 36:9ecb98d7c2cd 171 func=strIn.substr(0,1);
MaxScorda 36:9ecb98d7c2cd 172 funcnum=strIn.substr(1,1);
MaxScorda 36:9ecb98d7c2cd 173 param=strIn.substr(2,3);
MaxScorda 36:9ecb98d7c2cd 174
MaxScorda 36:9ecb98d7c2cd 175 //Random Activate
MaxScorda 36:9ecb98d7c2cd 176 if (func=="r") {
MaxScorda 36:9ecb98d7c2cd 177 errp=RfuncIn(func, funcnum,param);
MaxScorda 36:9ecb98d7c2cd 178 }
MaxScorda 36:9ecb98d7c2cd 179 //command SYNTH Tracce
MaxScorda 36:9ecb98d7c2cd 180 else if ((func>="0") && (func<="9")) {
MaxScorda 36:9ecb98d7c2cd 181 errp=s09funcIn(func, funcnum,param,stringa[0]);
MaxScorda 36:9ecb98d7c2cd 182 //ardser.printf(strIn+" \n\r");
MaxScorda 36:9ecb98d7c2cd 183 }
MaxScorda 36:9ecb98d7c2cd 184 //command SYNTH Note
MaxScorda 36:9ecb98d7c2cd 185 else if (func=="n") {
MaxScorda 36:9ecb98d7c2cd 186 errp=NfuncIn(func, funcnum,param, stringa);
MaxScorda 36:9ecb98d7c2cd 187 }
MaxScorda 36:9ecb98d7c2cd 188 //start
MaxScorda 36:9ecb98d7c2cd 189 else if (strIn.substr(0,4)=="start") {
MaxScorda 36:9ecb98d7c2cd 190 errp=StartfuncIn();
MaxScorda 36:9ecb98d7c2cd 191 }
MaxScorda 36:9ecb98d7c2cd 192 //stop
MaxScorda 36:9ecb98d7c2cd 193 else if (strIn.substr(0,3)=="stop") {
MaxScorda 36:9ecb98d7c2cd 194 errp=StopfuncIn();
MaxScorda 36:9ecb98d7c2cd 195 }
MaxScorda 36:9ecb98d7c2cd 196
MaxScorda 36:9ecb98d7c2cd 197 //delay stop
MaxScorda 36:9ecb98d7c2cd 198 else if (strIn.substr(0,4)=="dstop") {
MaxScorda 36:9ecb98d7c2cd 199 errp=DelayStopfuncIn();
MaxScorda 36:9ecb98d7c2cd 200 }
MaxScorda 36:9ecb98d7c2cd 201
MaxScorda 36:9ecb98d7c2cd 202 //Boot
MaxScorda 36:9ecb98d7c2cd 203 else if (strIn.substr(0,4)=="boot") {
MaxScorda 36:9ecb98d7c2cd 204 errp=bootfuncIn();
MaxScorda 36:9ecb98d7c2cd 205 }
MaxScorda 36:9ecb98d7c2cd 206
MaxScorda 36:9ecb98d7c2cd 207 term.formatPrintf(fnzAdd.string2char(">"+fnzAdd.subEOS(string(stringa))+"<"),18,21,99,1);
MaxScorda 36:9ecb98d7c2cd 208 term.readypos();
MaxScorda 36:9ecb98d7c2cd 209 }
MaxScorda 36:9ecb98d7c2cd 210
MaxScorda 36:9ecb98d7c2cd 211 void preloadValue()
MaxScorda 36:9ecb98d7c2cd 212 {
MaxScorda 36:9ecb98d7c2cd 213 string func; //funzione l=led
MaxScorda 36:9ecb98d7c2cd 214 string funcnum; //funzione ordinata 1,2,3 ecc
MaxScorda 36:9ecb98d7c2cd 215 string param; //parametro on, off
MaxScorda 36:9ecb98d7c2cd 216 string strIn;
MaxScorda 36:9ecb98d7c2cd 217
MaxScorda 36:9ecb98d7c2cd 218 //pattern
MaxScorda 36:9ecb98d7c2cd 219 for (int i = 0; i < 3; i++) {
MaxScorda 36:9ecb98d7c2cd 220 strIn=fnzAdd.i2s(i)+"-"+fnzAdd.i2s(i+3)+"-"+fnzAdd.i2s(2);
MaxScorda 36:9ecb98d7c2cd 221 term.formatPrintf(fnzAdd.string2char(strIn),21+(i%2)*40,6+(2*(i/2)),8,1); //p11 //p12 //p21
MaxScorda 36:9ecb98d7c2cd 222 }
MaxScorda 36:9ecb98d7c2cd 223 //real serial
MaxScorda 36:9ecb98d7c2cd 224 term.formatPrintf("OFF\n",21,10,3,1); //p31
MaxScorda 36:9ecb98d7c2cd 225 //random
MaxScorda 36:9ecb98d7c2cd 226 term.formatPrintf("ON\n",61,8,99,1); //p22
MaxScorda 36:9ecb98d7c2cd 227 // note
MaxScorda 36:9ecb98d7c2cd 228 term.formatPrintf("60 64 67 71 74 77\n",21,12,99,1); //p41
MaxScorda 29:bfb815540de7 229 term.readypos();
MaxScorda 29:bfb815540de7 230 }
MaxScorda 28:f7a59cee5f0d 231
MaxScorda 7:f57abb3f0d3f 232
MaxScorda 36:9ecb98d7c2cd 233
MaxScorda 7:f57abb3f0d3f 234 void pressed()
MaxScorda 7:f57abb3f0d3f 235 {
MaxScorda 36:9ecb98d7c2cd 236 ardser.printf("rl\r");
MaxScorda 36:9ecb98d7c2cd 237 term.formatPrintf("rl\n",21,14,8,1); //p51
MaxScorda 36:9ecb98d7c2cd 238 term.formatPrintf("Ask for reload\n",61,14,99,1); //p52
MaxScorda 36:9ecb98d7c2cd 239 led.flash(2);
MaxScorda 35:e9e9d518c354 240 }
MaxScorda 7:f57abb3f0d3f 241
MaxScorda 7:f57abb3f0d3f 242
MaxScorda 8:3f1d8c55b3a0 243
MaxScorda 9:9ad85b6bd9cf 244