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
Functions.h@16:4c893ec05fc6, 2015-08-16 (annotated)
- Committer:
- MaxScorda
- Date:
- Sun Aug 16 23:30:57 2015 +0000
- Revision:
- 16:4c893ec05fc6
- Parent:
- 15:7d756492af23
- Child:
- 17:7c8c37fbec9f
ok6;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MaxScorda | 7:f57abb3f0d3f | 1 | #include <string> |
MaxScorda | 7:f57abb3f0d3f | 2 | #include "IOFuncLib.h" |
MaxScorda | 7:f57abb3f0d3f | 3 | genFunctions fnzAdd; //messa qui rende la raccolta funzioni indipendente |
MaxScorda | 7:f57abb3f0d3f | 4 | |
MaxScorda | 7:f57abb3f0d3f | 5 | void callback() |
MaxScorda | 7:f57abb3f0d3f | 6 | { |
MaxScorda | 7:f57abb3f0d3f | 7 | // Note: you need to actually read from the serial to clear the RX interrupt |
MaxScorda | 7:f57abb3f0d3f | 8 | // ardser.printf("%d \n", cont++); |
MaxScorda | 7:f57abb3f0d3f | 9 | // myled2 = !myled2; |
MaxScorda | 7:f57abb3f0d3f | 10 | } |
MaxScorda | 7:f57abb3f0d3f | 11 | |
MaxScorda | 7:f57abb3f0d3f | 12 | |
MaxScorda | 7:f57abb3f0d3f | 13 | void parser(char stringa[]) |
MaxScorda | 7:f57abb3f0d3f | 14 | { |
MaxScorda | 7:f57abb3f0d3f | 15 | string func; //funzione l=led |
MaxScorda | 7:f57abb3f0d3f | 16 | string funcnum; //funzione ordinata 1,2,3 ecc |
MaxScorda | 7:f57abb3f0d3f | 17 | string param; //parametro on, off |
MaxScorda | 7:f57abb3f0d3f | 18 | string strIn = string(stringa); |
MaxScorda | 8:3f1d8c55b3a0 | 19 | bool errp=1; |
MaxScorda | 8:3f1d8c55b3a0 | 20 | //pad a 4 |
MaxScorda | 8:3f1d8c55b3a0 | 21 | strIn=fnzAdd.padstr(strIn,5,' '); |
MaxScorda | 7:f57abb3f0d3f | 22 | strIn=fnzAdd.addEOS(strIn); |
MaxScorda | 8:3f1d8c55b3a0 | 23 | //split |
MaxScorda | 7:f57abb3f0d3f | 24 | func=strIn.substr(0,1); |
MaxScorda | 7:f57abb3f0d3f | 25 | funcnum=strIn.substr(1,1); |
MaxScorda | 8:3f1d8c55b3a0 | 26 | param=strIn.substr(2,3); |
MaxScorda | 8:3f1d8c55b3a0 | 27 | //write param |
MaxScorda | 8:3f1d8c55b3a0 | 28 | sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(func)),2,8,15); |
MaxScorda | 8:3f1d8c55b3a0 | 29 | sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(funcnum)),22,8,15); |
MaxScorda | 8:3f1d8c55b3a0 | 30 | sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(param)),42,8,15); |
MaxScorda | 8:3f1d8c55b3a0 | 31 | //write input string |
MaxScorda | 8:3f1d8c55b3a0 | 32 | sc.writeScreen(fnzAdd.string2char(strIn),2,20,20); |
MaxScorda | 8:3f1d8c55b3a0 | 33 | //sc.writeScreen((char*)func.c_str() ,02,07); funziona anche cosi' |
MaxScorda | 7:f57abb3f0d3f | 34 | |
MaxScorda | 13:92303a41947a | 35 | //led |
MaxScorda | 8:3f1d8c55b3a0 | 36 | if (func=="l") { |
MaxScorda | 8:3f1d8c55b3a0 | 37 | if (funcnum=="1") { |
MaxScorda | 8:3f1d8c55b3a0 | 38 | if (param=="on ") { |
MaxScorda | 8:3f1d8c55b3a0 | 39 | sc.writeScreen("ON \n",2,14,3); |
MaxScorda | 8:3f1d8c55b3a0 | 40 | sc.writeScreen("Led ACCESO \n",42,20,99); |
MaxScorda | 8:3f1d8c55b3a0 | 41 | ardser.printf("\nLed ACCESO \n\r"); |
MaxScorda | 15:7d756492af23 | 42 | printDisp(dispType,"Led ACCESO \n\r"); |
MaxScorda | 8:3f1d8c55b3a0 | 43 | led.onOff(1); //Accende il led |
MaxScorda | 8:3f1d8c55b3a0 | 44 | errp=0; |
MaxScorda | 8:3f1d8c55b3a0 | 45 | } |
MaxScorda | 8:3f1d8c55b3a0 | 46 | if (param=="off") { |
MaxScorda | 8:3f1d8c55b3a0 | 47 | sc.writeScreen("OFF \n",2,14); |
MaxScorda | 8:3f1d8c55b3a0 | 48 | sc.writeScreen("Led SPENTO! \n",42,20,99); |
MaxScorda | 8:3f1d8c55b3a0 | 49 | ardser.printf("\nLed SPENTO! \n\r"); |
MaxScorda | 15:7d756492af23 | 50 | printDisp(dispType,"Led SPENTO \n\r"); |
MaxScorda | 8:3f1d8c55b3a0 | 51 | led.onOff(0); //Spegne il led |
MaxScorda | 8:3f1d8c55b3a0 | 52 | errp=0; |
MaxScorda | 8:3f1d8c55b3a0 | 53 | } |
MaxScorda | 8:3f1d8c55b3a0 | 54 | } |
MaxScorda | 7:f57abb3f0d3f | 55 | } |
MaxScorda | 8:3f1d8c55b3a0 | 56 | //virtual |
MaxScorda | 8:3f1d8c55b3a0 | 57 | if (func=="v") { |
MaxScorda | 8:3f1d8c55b3a0 | 58 | if (funcnum=="1") { |
MaxScorda | 8:3f1d8c55b3a0 | 59 | if (param=="on ") { |
MaxScorda | 8:3f1d8c55b3a0 | 60 | sc.writeScreen("ON \n",22,14); |
MaxScorda | 8:3f1d8c55b3a0 | 61 | sc.writeScreen("Virtual ACCESO \n",42,20,99); |
MaxScorda | 8:3f1d8c55b3a0 | 62 | ardser.printf("\nVirtual ACCESO \n\r"); |
MaxScorda | 15:7d756492af23 | 63 | printDisp(dispType,"Virtual ACCESO \n\r"); |
MaxScorda | 8:3f1d8c55b3a0 | 64 | errp=0; |
MaxScorda | 8:3f1d8c55b3a0 | 65 | } |
MaxScorda | 8:3f1d8c55b3a0 | 66 | if (param=="off") { |
MaxScorda | 8:3f1d8c55b3a0 | 67 | sc.writeScreen("OFF \n",22,14); |
MaxScorda | 8:3f1d8c55b3a0 | 68 | sc.writeScreen("Virtual SPENTO! \n",42,20,99); |
MaxScorda | 8:3f1d8c55b3a0 | 69 | ardser.printf("\nVirtual SPENTO! \n\r"); |
MaxScorda | 15:7d756492af23 | 70 | printDisp(dispType,"Virtual SPENTO \n\r"); |
MaxScorda | 8:3f1d8c55b3a0 | 71 | errp=0; |
MaxScorda | 8:3f1d8c55b3a0 | 72 | } |
MaxScorda | 8:3f1d8c55b3a0 | 73 | } |
MaxScorda | 7:f57abb3f0d3f | 74 | } |
MaxScorda | 13:92303a41947a | 75 | |
MaxScorda | 9:9ad85b6bd9cf | 76 | //command SYNTH |
MaxScorda | 9:9ad85b6bd9cf | 77 | if ((func>="1") && (func<="9")) { |
MaxScorda | 9:9ad85b6bd9cf | 78 | if ((funcnum>="1") && (funcnum<="9")) { |
MaxScorda | 9:9ad85b6bd9cf | 79 | sc.writeScreen(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param)),42,14,4); |
MaxScorda | 9:9ad85b6bd9cf | 80 | sc.writeScreen("Arduino Command \n",42,20,99); |
MaxScorda | 9:9ad85b6bd9cf | 81 | ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+funcnum+param))); |
MaxScorda | 16:4c893ec05fc6 | 82 | printDisp(dispType,"Arduino Command \n\r"); |
MaxScorda | 16:4c893ec05fc6 | 83 | printDisp(dispType,fnzAdd.string2char(fnzAdd.addEOS(" "+func+funcnum+param+"\r"))); |
MaxScorda | 9:9ad85b6bd9cf | 84 | //ardser.printf(fnzAdd.string2char(fnzAdd.addEOS(func+"-"+funcnum+"-"+param))); |
MaxScorda | 9:9ad85b6bd9cf | 85 | errp=0; |
MaxScorda | 9:9ad85b6bd9cf | 86 | } |
MaxScorda | 13:92303a41947a | 87 | } |
MaxScorda | 8:3f1d8c55b3a0 | 88 | |
MaxScorda | 8:3f1d8c55b3a0 | 89 | // comando fuori parsing |
MaxScorda | 7:f57abb3f0d3f | 90 | if (errp==1) { |
MaxScorda | 7:f57abb3f0d3f | 91 | // pc.printf("Bad command\n\r"); |
MaxScorda | 8:3f1d8c55b3a0 | 92 | sc.writeScreen("Bad Command\n",42,20,99); |
MaxScorda | 7:f57abb3f0d3f | 93 | ardser.printf("\nBad command\n\r"); |
MaxScorda | 16:4c893ec05fc6 | 94 | printDisp(dispType,"** Bad command ** \n\r"); |
MaxScorda | 7:f57abb3f0d3f | 95 | } |
MaxScorda | 13:92303a41947a | 96 | sc.commitScreen(); |
MaxScorda | 7:f57abb3f0d3f | 97 | } |
MaxScorda | 7:f57abb3f0d3f | 98 | |
MaxScorda | 7:f57abb3f0d3f | 99 | |
MaxScorda | 7:f57abb3f0d3f | 100 | void pressed() |
MaxScorda | 7:f57abb3f0d3f | 101 | { |
MaxScorda | 7:f57abb3f0d3f | 102 | //vedere come rimediare |
MaxScorda | 7:f57abb3f0d3f | 103 | sc.pressed(); |
MaxScorda | 7:f57abb3f0d3f | 104 | } |
MaxScorda | 7:f57abb3f0d3f | 105 | |
MaxScorda | 7:f57abb3f0d3f | 106 | |
MaxScorda | 8:3f1d8c55b3a0 | 107 | |
MaxScorda | 9:9ad85b6bd9cf | 108 |