Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Terminal by
Terminal.cpp@7:80096ab72764, 2015-09-19 (annotated)
- Committer:
- MaxScorda
- Date:
- Sat Sep 19 01:08:02 2015 +0000
- Revision:
- 7:80096ab72764
- Parent:
- 6:f8c90e147000
- Child:
- 8:e3c6d6322506
sistemazione pad e correzioni minori
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MaxScorda | 7:80096ab72764 | 1 | /** mbed TerminalPlus Library, for ANSI/VT200 Terminals and ecape codes |
| MaxScorda | 7:80096ab72764 | 2 | * Copyright (c) 2015, Max Scordamaglia , https//developer.mbed.org/users/MaxScorda/ |
| MaxScorda | 7:80096ab72764 | 3 | * fork from Terminal Library |
| simon | 2:85184c13476c | 4 | * Copyright (c) 2007-2010, sford, http://mbed.org |
| simon | 1:96ae39e58792 | 5 | * |
| simon | 1:96ae39e58792 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| simon | 1:96ae39e58792 | 7 | * of this software and associated documentation files (the "Software"), to deal |
| simon | 1:96ae39e58792 | 8 | * in the Software without restriction, including without limitation the rights |
| simon | 1:96ae39e58792 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| simon | 1:96ae39e58792 | 10 | * copies of the Software, and to permit persons to whom the Software is |
| simon | 1:96ae39e58792 | 11 | * furnished to do so, subject to the following conditions: |
| simon | 1:96ae39e58792 | 12 | * |
| simon | 1:96ae39e58792 | 13 | * The above copyright notice and this permission notice shall be included in |
| simon | 1:96ae39e58792 | 14 | * all copies or substantial portions of the Software. |
| simon | 1:96ae39e58792 | 15 | * |
| simon | 1:96ae39e58792 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| simon | 1:96ae39e58792 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| simon | 1:96ae39e58792 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| simon | 1:96ae39e58792 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| simon | 1:96ae39e58792 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| simon | 1:96ae39e58792 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| simon | 1:96ae39e58792 | 22 | * THE SOFTWARE. |
| simon | 0:2bf27af3c759 | 23 | */ |
| simon | 0:2bf27af3c759 | 24 | |
| MaxScorda | 6:f8c90e147000 | 25 | |
| MaxScorda | 6:f8c90e147000 | 26 | /* |
| MaxScorda | 6:f8c90e147000 | 27 | Porre il terminate in VT100 e set di caratteri cp437 |
| MaxScorda | 6:f8c90e147000 | 28 | */ |
| MaxScorda | 6:f8c90e147000 | 29 | |
| simon | 0:2bf27af3c759 | 30 | #include "Terminal.h" |
| simon | 0:2bf27af3c759 | 31 | #include "mbed.h" |
| simon | 0:2bf27af3c759 | 32 | |
| simon | 0:2bf27af3c759 | 33 | Terminal::Terminal(PinName tx, PinName rx) : Serial(tx, rx) {} |
| simon | 0:2bf27af3c759 | 34 | |
| MaxScorda | 3:e72f2addfaf8 | 35 | void Terminal::cls() |
| MaxScorda | 3:e72f2addfaf8 | 36 | { |
| simon | 0:2bf27af3c759 | 37 | this->printf("\033[2J"); |
| simon | 0:2bf27af3c759 | 38 | } |
| simon | 0:2bf27af3c759 | 39 | |
| MaxScorda | 3:e72f2addfaf8 | 40 | void Terminal::locate(int column, int row) |
| MaxScorda | 3:e72f2addfaf8 | 41 | { |
| simon | 0:2bf27af3c759 | 42 | // Cursor Home <ESC>[{ROW};{COLUMN}H |
| MaxScorda | 3:e72f2addfaf8 | 43 | |
| MaxScorda | 3:e72f2addfaf8 | 44 | // this->printf("\033[%d;%dH%c", row + 1, column + 1); //original |
| MaxScorda | 5:d045e3561533 | 45 | this->printf("\033[%d;%dH", row+1 , column+1 ); |
| simon | 0:2bf27af3c759 | 46 | } |
| simon | 0:2bf27af3c759 | 47 | |
| MaxScorda | 3:e72f2addfaf8 | 48 | static int rgb888tobgr111(int colour) |
| MaxScorda | 3:e72f2addfaf8 | 49 | { |
| simon | 0:2bf27af3c759 | 50 | int r = (colour >> 23) & 1; |
| simon | 0:2bf27af3c759 | 51 | int g = (colour >> 15) & 1; |
| simon | 0:2bf27af3c759 | 52 | int b = (colour >> 7) & 1; |
| simon | 0:2bf27af3c759 | 53 | return (b << 2) | (g << 1) | (r << 0); |
| simon | 0:2bf27af3c759 | 54 | } |
| simon | 0:2bf27af3c759 | 55 | |
| MaxScorda | 3:e72f2addfaf8 | 56 | void Terminal::foreground(int colour) |
| MaxScorda | 3:e72f2addfaf8 | 57 | { |
| simon | 0:2bf27af3c759 | 58 | // Set Attribute Mode <ESC>[{n}m |
| simon | 0:2bf27af3c759 | 59 | // Foreground Colours : 30 + bgr |
| simon | 0:2bf27af3c759 | 60 | int c = 30 + rgb888tobgr111(colour); |
| simon | 0:2bf27af3c759 | 61 | this->printf("\033[%dm", c); |
| simon | 0:2bf27af3c759 | 62 | } |
| simon | 0:2bf27af3c759 | 63 | |
| MaxScorda | 6:f8c90e147000 | 64 | void Terminal::forgcol(int color) |
| MaxScorda | 6:f8c90e147000 | 65 | { |
| MaxScorda | 6:f8c90e147000 | 66 | /*colori da 0 a 7 |
| MaxScorda | 6:f8c90e147000 | 67 | [ 3 0 m setaf 0 Set foreground to color #0 - black |
| MaxScorda | 6:f8c90e147000 | 68 | [ 3 1 m setaf 1 Set foreground to color #1 - red |
| MaxScorda | 6:f8c90e147000 | 69 | [ 3 2 m setaf 2 Set foreground to color #2 - green |
| MaxScorda | 6:f8c90e147000 | 70 | [ 3 3 m setaf 3 Set foreground to color #3 - yellow |
| MaxScorda | 6:f8c90e147000 | 71 | [ 3 4 m setaf 4 Set foreground to color #4 - blue |
| MaxScorda | 6:f8c90e147000 | 72 | [ 3 5 m setaf 5 Set foreground to color #5 - magenta |
| MaxScorda | 6:f8c90e147000 | 73 | [ 3 6 m setaf 6 Set foreground to color #6 - cyan |
| MaxScorda | 6:f8c90e147000 | 74 | [ 3 7 m setaf 7 Set foreground to color #7 - white |
| MaxScorda | 6:f8c90e147000 | 75 | [ 3 9 m setaf 9 Set default color as foreground color |
| MaxScorda | 6:f8c90e147000 | 76 | */ |
| MaxScorda | 6:f8c90e147000 | 77 | |
| MaxScorda | 6:f8c90e147000 | 78 | if ((color<0) || (color>7)) color =7; //normalizza |
| MaxScorda | 6:f8c90e147000 | 79 | color=color+30; |
| MaxScorda | 6:f8c90e147000 | 80 | this->printf("\033[%dm", color); |
| MaxScorda | 6:f8c90e147000 | 81 | } |
| MaxScorda | 6:f8c90e147000 | 82 | |
| MaxScorda | 6:f8c90e147000 | 83 | void Terminal::bckgcol(int color) |
| MaxScorda | 6:f8c90e147000 | 84 | { |
| MaxScorda | 6:f8c90e147000 | 85 | /*colori da 0 a 7 |
| MaxScorda | 6:f8c90e147000 | 86 | [ 4 0 m setab 0 Set background to color #0 - black |
| MaxScorda | 6:f8c90e147000 | 87 | [ 4 1 m setab 1 Set background to color #1 - red |
| MaxScorda | 6:f8c90e147000 | 88 | [ 4 2 m setab 2 Set background to color #2 - green |
| MaxScorda | 6:f8c90e147000 | 89 | [ 4 3 m setab 3 Set background to color #3 - yellow |
| MaxScorda | 6:f8c90e147000 | 90 | [ 4 4 m setab 4 Set background to color #4 - blue |
| MaxScorda | 6:f8c90e147000 | 91 | [ 4 5 m setab 5 Set background to color #5 - magenta |
| MaxScorda | 6:f8c90e147000 | 92 | [ 4 6 m setab 6 Set background to color #6 - cyan |
| MaxScorda | 6:f8c90e147000 | 93 | [ 4 7 m setab 7 Set background to color #7 - white |
| MaxScorda | 6:f8c90e147000 | 94 | [ 4 9 m setaf 9 Set default color as background color |
| MaxScorda | 6:f8c90e147000 | 95 | */ |
| MaxScorda | 6:f8c90e147000 | 96 | |
| MaxScorda | 6:f8c90e147000 | 97 | if ((color<0) || (color>7)) color =0; //normalizza |
| MaxScorda | 6:f8c90e147000 | 98 | color=color+40; |
| MaxScorda | 6:f8c90e147000 | 99 | this->printf("\033[%dm", color); |
| MaxScorda | 6:f8c90e147000 | 100 | } |
| MaxScorda | 6:f8c90e147000 | 101 | |
| MaxScorda | 6:f8c90e147000 | 102 | |
| MaxScorda | 3:e72f2addfaf8 | 103 | void Terminal::background(int colour) |
| MaxScorda | 3:e72f2addfaf8 | 104 | { |
| simon | 0:2bf27af3c759 | 105 | // Set Attribute Mode <ESC>[{n}m |
| simon | 0:2bf27af3c759 | 106 | // Background Colours : 40 + bgr |
| simon | 0:2bf27af3c759 | 107 | int c = 40 + rgb888tobgr111(colour); |
| simon | 0:2bf27af3c759 | 108 | this->printf("\033[%dm", c); |
| simon | 0:2bf27af3c759 | 109 | } |
| MaxScorda | 3:e72f2addfaf8 | 110 | |
| MaxScorda | 5:d045e3561533 | 111 | void Terminal::reset() |
| MaxScorda | 5:d045e3561533 | 112 | { |
| MaxScorda | 5:d045e3561533 | 113 | // Reset Screen |
| MaxScorda | 5:d045e3561533 | 114 | this->printf("\033c"); |
| MaxScorda | 5:d045e3561533 | 115 | } |
| MaxScorda | 5:d045e3561533 | 116 | |
| MaxScorda | 5:d045e3561533 | 117 | void Terminal::eraseline() |
| MaxScorda | 5:d045e3561533 | 118 | { |
| MaxScorda | 7:80096ab72764 | 119 | // Erase full line, cursor save |
| MaxScorda | 5:d045e3561533 | 120 | this->printf("\033[2K"); |
| MaxScorda | 5:d045e3561533 | 121 | } |
| MaxScorda | 5:d045e3561533 | 122 | |
| MaxScorda | 7:80096ab72764 | 123 | void Terminal::resetattrib() |
| MaxScorda | 7:80096ab72764 | 124 | { |
| MaxScorda | 7:80096ab72764 | 125 | // reset attrib |
| MaxScorda | 7:80096ab72764 | 126 | this->printf("\033[0m"); |
| MaxScorda | 7:80096ab72764 | 127 | } |
| MaxScorda | 5:d045e3561533 | 128 | |
| MaxScorda | 7:80096ab72764 | 129 | void Terminal::bold() |
| MaxScorda | 7:80096ab72764 | 130 | { |
| MaxScorda | 7:80096ab72764 | 131 | // font bold |
| MaxScorda | 7:80096ab72764 | 132 | this->printf("\033[1m"); |
| MaxScorda | 7:80096ab72764 | 133 | } |
| MaxScorda | 7:80096ab72764 | 134 | |
| MaxScorda | 7:80096ab72764 | 135 | void Terminal::underscore() |
| MaxScorda | 7:80096ab72764 | 136 | { |
| MaxScorda | 7:80096ab72764 | 137 | // underscore |
| MaxScorda | 7:80096ab72764 | 138 | this->printf("\033[4m"); |
| MaxScorda | 7:80096ab72764 | 139 | } |
| MaxScorda | 7:80096ab72764 | 140 | |
| MaxScorda | 7:80096ab72764 | 141 | void Terminal::blink() |
| MaxScorda | 7:80096ab72764 | 142 | { |
| MaxScorda | 7:80096ab72764 | 143 | // font blink |
| MaxScorda | 7:80096ab72764 | 144 | this->printf("\033[5m"); |
| MaxScorda | 7:80096ab72764 | 145 | } |
| MaxScorda | 7:80096ab72764 | 146 | |
| MaxScorda | 7:80096ab72764 | 147 | void Terminal::reverse() |
| MaxScorda | 7:80096ab72764 | 148 | { |
| MaxScorda | 7:80096ab72764 | 149 | // font reverse |
| MaxScorda | 7:80096ab72764 | 150 | this->printf("\033[7m"); |
| MaxScorda | 7:80096ab72764 | 151 | } |
| MaxScorda | 5:d045e3561533 | 152 | //************************************* |
| MaxScorda | 5:d045e3561533 | 153 | void Terminal::formatPrintf(char sstr[], int xx, int yy, int padb) |
| MaxScorda | 5:d045e3561533 | 154 | { |
| MaxScorda | 7:80096ab72764 | 155 | int i=0; //mettere lungo come stringa |
| MaxScorda | 7:80096ab72764 | 156 | //string tempstr=string(sstr); |
| MaxScorda | 7:80096ab72764 | 157 | int screenColumn=78; //per ora lo forziamo |
| MaxScorda | 5:d045e3561533 | 158 | |
| MaxScorda | 7:80096ab72764 | 159 | locate(xx, yy); |
| MaxScorda | 7:80096ab72764 | 160 | this->printf(sstr); |
| MaxScorda | 7:80096ab72764 | 161 | if (yy!=23) this->printf("\033[1A"); // fa davvero cagare. Torna su col cursore per evitare il \n eccetto l'ultima riga. Servirebbe togliere il \n |
| MaxScorda | 7:80096ab72764 | 162 | while ((sstr[i]!='\n') && (i<(screenColumn-xx+1))) { |
| MaxScorda | 7:80096ab72764 | 163 | i++; |
| MaxScorda | 7:80096ab72764 | 164 | } |
| MaxScorda | 7:80096ab72764 | 165 | |
| MaxScorda | 7:80096ab72764 | 166 | //prosegui col pad |
| MaxScorda | 7:80096ab72764 | 167 | while ((padb>0) && (i<(screenColumn-xx-1))) { |
| MaxScorda | 7:80096ab72764 | 168 | this->printf(" "); //migliorare con stringa unica |
| MaxScorda | 7:80096ab72764 | 169 | i++; |
| MaxScorda | 7:80096ab72764 | 170 | padb--; |
| MaxScorda | 7:80096ab72764 | 171 | } |
| MaxScorda | 5:d045e3561533 | 172 | } |
| MaxScorda | 5:d045e3561533 | 173 | |
| MaxScorda | 5:d045e3561533 | 174 | |
| MaxScorda | 4:ee2311717b80 | 175 | void Terminal::frame(int x, int y, int w, int h, int boxtype) |
| MaxScorda | 3:e72f2addfaf8 | 176 | { |
| MaxScorda | 4:ee2311717b80 | 177 | char B_H=0, B_V=0, B_TL=0, B_TR=0, B_BL=0, B_BR=0 ; |
| MaxScorda | 4:ee2311717b80 | 178 | // draw frame |
| MaxScorda | 4:ee2311717b80 | 179 | // BLOCK=219; SE SI VORRA' USARE IL FILL |
| MaxScorda | 3:e72f2addfaf8 | 180 | switch (boxtype) { |
| MaxScorda | 3:e72f2addfaf8 | 181 | case 0: //singolo |
| MaxScorda | 6:f8c90e147000 | 182 | B_H =196; |
| MaxScorda | 4:ee2311717b80 | 183 | B_V =186; |
| MaxScorda | 4:ee2311717b80 | 184 | B_TL =201; |
| MaxScorda | 4:ee2311717b80 | 185 | B_TR =187; |
| MaxScorda | 4:ee2311717b80 | 186 | B_BL= 200; |
| MaxScorda | 4:ee2311717b80 | 187 | B_BR =188; |
| MaxScorda | 3:e72f2addfaf8 | 188 | break; |
| MaxScorda | 3:e72f2addfaf8 | 189 | |
| MaxScorda | 3:e72f2addfaf8 | 190 | case 1: //doppio |
| MaxScorda | 3:e72f2addfaf8 | 191 | B_H =205; |
| MaxScorda | 3:e72f2addfaf8 | 192 | B_V =186; |
| MaxScorda | 3:e72f2addfaf8 | 193 | B_TL =201; |
| MaxScorda | 3:e72f2addfaf8 | 194 | B_TR =187; |
| MaxScorda | 3:e72f2addfaf8 | 195 | B_BL= 200; |
| MaxScorda | 3:e72f2addfaf8 | 196 | B_BR =188; |
| MaxScorda | 3:e72f2addfaf8 | 197 | break; |
| MaxScorda | 3:e72f2addfaf8 | 198 | } |
| MaxScorda | 3:e72f2addfaf8 | 199 | //riga superiore |
| MaxScorda | 7:80096ab72764 | 200 | formatPrintf(createStr(B_TL) ,x,y); |
| MaxScorda | 7:80096ab72764 | 201 | formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y); |
| MaxScorda | 6:f8c90e147000 | 202 | //for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y); |
| MaxScorda | 7:80096ab72764 | 203 | formatPrintf(createStr(B_TR),x+w,y); |
| MaxScorda | 3:e72f2addfaf8 | 204 | //corpo |
| MaxScorda | 3:e72f2addfaf8 | 205 | for(int i=y+1; i<y+h; i++) { |
| MaxScorda | 7:80096ab72764 | 206 | formatPrintf(createStr(B_V),x,i); |
| MaxScorda | 7:80096ab72764 | 207 | formatPrintf(createStr(B_V),x+w,i); |
| MaxScorda | 3:e72f2addfaf8 | 208 | } |
| MaxScorda | 3:e72f2addfaf8 | 209 | //riga inferiore |
| MaxScorda | 7:80096ab72764 | 210 | formatPrintf(createStr(B_BL),x,y+h); |
| MaxScorda | 7:80096ab72764 | 211 | // for(int i=x+1; i<x+w; i++) formatPrintf(&B_H,i,y+h); |
| MaxScorda | 7:80096ab72764 | 212 | formatPrintf(string2char(padstr("\n",78,char(B_H))),x+1,y+h); |
| MaxScorda | 7:80096ab72764 | 213 | formatPrintf(createStr(B_BR),x+w,y+h); |
| MaxScorda | 5:d045e3561533 | 214 | } |
| MaxScorda | 3:e72f2addfaf8 | 215 | |
| MaxScorda | 5:d045e3561533 | 216 | void Terminal::banner() |
| MaxScorda | 5:d045e3561533 | 217 | { |
| MaxScorda | 6:f8c90e147000 | 218 | cls(); |
| MaxScorda | 6:f8c90e147000 | 219 | frame(0, 0, 79, 22,1); |
| MaxScorda | 6:f8c90e147000 | 220 | forgcol(3); |
| MaxScorda | 7:80096ab72764 | 221 | bold(); |
| MaxScorda | 6:f8c90e147000 | 222 | formatPrintf("_____ Boot screen _____\n",27,1); |
| MaxScorda | 6:f8c90e147000 | 223 | formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2); |
| MaxScorda | 6:f8c90e147000 | 224 | forgcol(9); |
| MaxScorda | 6:f8c90e147000 | 225 | formatPrintf(string2char(padstr("\n",78,char(196))),1,5); //azzo funziona... |
| MaxScorda | 5:d045e3561533 | 226 | formatPrintf("Parsing \n",2,5); |
| MaxScorda | 5:d045e3561533 | 227 | formatPrintf("Funzione\n",2,7); |
| MaxScorda | 5:d045e3561533 | 228 | formatPrintf("Numero\n",22,7); |
| MaxScorda | 5:d045e3561533 | 229 | formatPrintf("Parametro\n",42,7); |
| MaxScorda | 6:f8c90e147000 | 230 | formatPrintf(string2char(padstr("\n",78,char(196))),1,10); //azzo funziona... |
| MaxScorda | 5:d045e3561533 | 231 | formatPrintf("Status \n",2,10); |
| MaxScorda | 5:d045e3561533 | 232 | formatPrintf("Led 1 \n",2,12); |
| MaxScorda | 5:d045e3561533 | 233 | formatPrintf("Virtual Led \n",22,12); |
| MaxScorda | 5:d045e3561533 | 234 | formatPrintf("Other Commands \n",42,12); |
| MaxScorda | 5:d045e3561533 | 235 | formatPrintf("Real Out Serial\n",62,12); |
| MaxScorda | 5:d045e3561533 | 236 | formatPrintf("Input string\n",2,15); |
| MaxScorda | 5:d045e3561533 | 237 | formatPrintf("Result\n",42,15); |
| MaxScorda | 6:f8c90e147000 | 238 | formatPrintf(string2char(padstr("\n",78,char(196))),1,18); //azzo funziona... |
| MaxScorda | 6:f8c90e147000 | 239 | formatPrintf("Serial Feedback \n",2,18); |
| MaxScorda | 7:80096ab72764 | 240 | resetattrib(); |
| MaxScorda | 6:f8c90e147000 | 241 | } |
| MaxScorda | 7:80096ab72764 | 242 | |
| MaxScorda | 7:80096ab72764 | 243 | void Terminal::bannerAdv() |
| MaxScorda | 7:80096ab72764 | 244 | { |
| MaxScorda | 7:80096ab72764 | 245 | cls(); |
| MaxScorda | 7:80096ab72764 | 246 | frame(0, 0, 79, 22,1); |
| MaxScorda | 7:80096ab72764 | 247 | forgcol(3); |
| MaxScorda | 7:80096ab72764 | 248 | bold(); |
| MaxScorda | 7:80096ab72764 | 249 | formatPrintf("_____ Boot screen _____\n",27,1); |
| MaxScorda | 7:80096ab72764 | 250 | formatPrintf("___ Nucleo Scorda IO Terminal ___\n",22,2); |
| MaxScorda | 7:80096ab72764 | 251 | forgcol(9); |
| MaxScorda | 7:80096ab72764 | 252 | |
| MaxScorda | 7:80096ab72764 | 253 | formatPrintf(string2char(padstr("\n",78,char(196))),1,3); //top 1/2 |
| MaxScorda | 7:80096ab72764 | 254 | formatPrintf("Funzione \n",2,4); |
| MaxScorda | 7:80096ab72764 | 255 | formatPrintf("Numero \n",32,4); |
| MaxScorda | 7:80096ab72764 | 256 | formatPrintf("Parametro \n",51,4); |
| MaxScorda | 7:80096ab72764 | 257 | //3-4 |
| MaxScorda | 7:80096ab72764 | 258 | formatPrintf("Status Led 1...... \n",2,6); |
| MaxScorda | 7:80096ab72764 | 259 | formatPrintf("Status Virtual Led \n",42,6); |
| MaxScorda | 7:80096ab72764 | 260 | //5-6 |
| MaxScorda | 7:80096ab72764 | 261 | formatPrintf("Other Commands.... \n",2,8); |
| MaxScorda | 7:80096ab72764 | 262 | formatPrintf("Real Out Serial... \n",42,8); |
| MaxScorda | 7:80096ab72764 | 263 | //7-8 |
| MaxScorda | 7:80096ab72764 | 264 | formatPrintf("Input string...... \n",2,10); |
| MaxScorda | 7:80096ab72764 | 265 | formatPrintf("Result............ \n",42,10); |
| MaxScorda | 7:80096ab72764 | 266 | //9-10 |
| MaxScorda | 7:80096ab72764 | 267 | //11-12 |
| MaxScorda | 7:80096ab72764 | 268 | formatPrintf(string2char(padstr("\n",78,char(196))),1,15); //bottom pot |
| MaxScorda | 7:80096ab72764 | 269 | |
| MaxScorda | 7:80096ab72764 | 270 | formatPrintf(string2char(padstr("\n",78,char(196))),1,19); //azzo funziona... |
| MaxScorda | 7:80096ab72764 | 271 | formatPrintf("Serial Feedback \n",2,20); |
| MaxScorda | 7:80096ab72764 | 272 | |
| MaxScorda | 7:80096ab72764 | 273 | // grigino |
| MaxScorda | 7:80096ab72764 | 274 | foreground(0x0f0f0f); |
| MaxScorda | 7:80096ab72764 | 275 | formatPrintf(string2char(padstr("\n",78,char(196))),1,5); //top 3/4 |
| MaxScorda | 7:80096ab72764 | 276 | formatPrintf(string2char(padstr("\n",78,char(196))),1,7); //top 5/6 |
| MaxScorda | 7:80096ab72764 | 277 | formatPrintf(string2char(padstr("\n",78,char(196))),1,9); //top 7/8 |
| MaxScorda | 7:80096ab72764 | 278 | formatPrintf(string2char(padstr("\n",78,char(196))),1,11); //top 9/10 |
| MaxScorda | 7:80096ab72764 | 279 | formatPrintf(string2char(padstr("\n",78,char(196))),1,13); //top 11/12 |
| MaxScorda | 7:80096ab72764 | 280 | |
| MaxScorda | 7:80096ab72764 | 281 | resetattrib(); |
| MaxScorda | 7:80096ab72764 | 282 | } |
| MaxScorda | 7:80096ab72764 | 283 | |
| MaxScorda | 6:f8c90e147000 | 284 | void Terminal::readypos() |
| MaxScorda | 6:f8c90e147000 | 285 | { |
| MaxScorda | 6:f8c90e147000 | 286 | formatPrintf("Command: > ",1,23); |
| MaxScorda | 3:e72f2addfaf8 | 287 | } |
| MaxScorda | 6:f8c90e147000 | 288 | |
| MaxScorda | 6:f8c90e147000 | 289 | |
| MaxScorda | 6:f8c90e147000 | 290 | //------------------------------------------------ |
| MaxScorda | 6:f8c90e147000 | 291 | string Terminal::padstr(string sttde, int maxlen, char fillchar) |
| MaxScorda | 6:f8c90e147000 | 292 | { |
| MaxScorda | 6:f8c90e147000 | 293 | bool flagEOS=false; |
| MaxScorda | 6:f8c90e147000 | 294 | string ret=sttde; |
| MaxScorda | 6:f8c90e147000 | 295 | if (ret.size()>0) { |
| MaxScorda | 6:f8c90e147000 | 296 | //se ha EOS lo tolgo |
| MaxScorda | 6:f8c90e147000 | 297 | if (ret.substr(ret.size()-1,1) == "\n") { |
| MaxScorda | 6:f8c90e147000 | 298 | ret=ret.substr(0,ret.size()-1); |
| MaxScorda | 6:f8c90e147000 | 299 | flagEOS=true; |
| MaxScorda | 6:f8c90e147000 | 300 | } |
| MaxScorda | 6:f8c90e147000 | 301 | //pad |
| MaxScorda | 6:f8c90e147000 | 302 | if (maxlen> ret.size()) ret.insert(ret.size(), maxlen - ret.size(), fillchar); |
| MaxScorda | 6:f8c90e147000 | 303 | //se aveva EOS, lo rimetto |
| MaxScorda | 6:f8c90e147000 | 304 | if (flagEOS==true) ret=addEOS(ret); |
| MaxScorda | 6:f8c90e147000 | 305 | } |
| MaxScorda | 6:f8c90e147000 | 306 | return ret; |
| MaxScorda | 6:f8c90e147000 | 307 | } |
| MaxScorda | 6:f8c90e147000 | 308 | |
| MaxScorda | 6:f8c90e147000 | 309 | string Terminal::addEOS(string sttde) |
| MaxScorda | 6:f8c90e147000 | 310 | { |
| MaxScorda | 6:f8c90e147000 | 311 | string ret=sttde; |
| MaxScorda | 6:f8c90e147000 | 312 | if (sttde.substr(sttde.size()-1,1) != "\n") ret=sttde+"\n"; |
| MaxScorda | 6:f8c90e147000 | 313 | return ret; |
| MaxScorda | 6:f8c90e147000 | 314 | } |
| MaxScorda | 6:f8c90e147000 | 315 | |
| MaxScorda | 6:f8c90e147000 | 316 | char* Terminal::string2char(string sttde) |
| MaxScorda | 6:f8c90e147000 | 317 | { |
| MaxScorda | 6:f8c90e147000 | 318 | //ora aggiunge comunque l'EOS. Decidere se parametrizzare |
| MaxScorda | 6:f8c90e147000 | 319 | sttde=addEOS(sttde); |
| MaxScorda | 6:f8c90e147000 | 320 | char *cstr = new char[sttde.length() + 1]; |
| MaxScorda | 6:f8c90e147000 | 321 | strcpy(cstr, sttde.c_str()); |
| MaxScorda | 6:f8c90e147000 | 322 | // delete [] cstr; |
| MaxScorda | 6:f8c90e147000 | 323 | return cstr; |
| MaxScorda | 7:80096ab72764 | 324 | } |
| MaxScorda | 7:80096ab72764 | 325 | |
| MaxScorda | 7:80096ab72764 | 326 | char* Terminal::createStr(char car) |
| MaxScorda | 7:80096ab72764 | 327 | { |
| MaxScorda | 7:80096ab72764 | 328 | // unico modo in cui passo un varole ascii ad una funzione aggiungendo il ritorno a capo. |
| MaxScorda | 7:80096ab72764 | 329 | //se si potesse evitare sarebbe meglio |
| MaxScorda | 7:80096ab72764 | 330 | char *str = (char *) malloc(2 * sizeof(char)); |
| MaxScorda | 7:80096ab72764 | 331 | if(str == NULL) return NULL; |
| MaxScorda | 7:80096ab72764 | 332 | str[0] = car; |
| MaxScorda | 7:80096ab72764 | 333 | str[1] = '\0'; |
| MaxScorda | 7:80096ab72764 | 334 | return str; |
| MaxScorda | 6:f8c90e147000 | 335 | } |
