Funzioni di IO varie con seriale asincrona
Dependents: Nucleo_AsyncSerialIO
Fork of IOFuncLib by
Diff: IOFuncLib.cpp
- Revision:
- 4:eae942db86db
- Parent:
- 3:6c6446382bb2
- Child:
- 5:0dd768073f59
--- a/IOFuncLib.cpp Sun May 31 22:00:17 2015 +0000 +++ b/IOFuncLib.cpp Tue Jun 02 00:51:20 2015 +0000 @@ -34,10 +34,20 @@ void Screen::banner() { - // _ps->printf("\f"); - - writeScreen("----- Boot screen -----\n",1,1); - writeScreen("--- Nucleo Scorda IO Test ---\n",1,2); + genFunctions fA; + writeScreen("_____ Boot screen _____\n",25,1); + writeScreen("___ Nucleo Scorda IO Test ___\n",22,2); + writeScreen(fA.string2char(fA.padstr("-\n",78,'-')),1,5); //azzo funziona... + writeScreen("Parsing \n",2,5); + writeScreen("Funzione\n",2,7); + writeScreen("Numero\n",22,7); + writeScreen("Parametro\n",42,7); + writeScreen(fA.string2char(fA.padstr("-\n",78,'-')),1,11); //azzo funziona... + writeScreen("Status \n",2,11); + writeScreen("Led 1 \n",2,13); + writeScreen("Virtual Led \n",22,13); + writeScreen("Input string\n",2,19); + writeScreen("Result\n",42,19); commitScreen(); } @@ -60,7 +70,7 @@ } } -void Screen::writeScreen(char sstr[], char xx, char yy) +void Screen::writeScreen(char sstr[], char xx, char yy, int padb) { char i=0; while ((sstr[i]!='\n') && (i<(screenColumn-xx+1))) { @@ -68,6 +78,12 @@ svec[xx+i][yy]=sstr[i]; i++; } + //prosegui col pad + while ((padb>0) && (i<(screenColumn-xx-1))) { + svec[xx+i][yy]=' '; + i++; + padb--; + } } @@ -88,7 +104,6 @@ void Screen::clearScreen(char upperx, char uppery, char loverx, char lowery) { //controllare margini - for (int j = uppery; j <= lowery; j++) { for (int i = upperx; i <= loverx; i++) { svec[i][j]=' ' ; @@ -98,8 +113,9 @@ // general -char* genFunctions::xsubstr(char* arr, int begin, int len) +char* genFunctions::subchar(char* arr, int begin, int len) { + //non funziona char* res = new char[len]; for (int i = 0; i < len; i++) res[i] = *(arr + begin + i); @@ -107,6 +123,24 @@ return res; } +string genFunctions::padstr(string sttde, int maxlen, char fillchar) +{ + bool flagEOS=false; + string ret=sttde; + if (ret.size()>0) { + //se ha EOS lo tolgo + if (ret.substr(ret.size()-1,1) == EOS) { + ret=ret.substr(0,ret.size()-1); + flagEOS=true; + } + //pad + if (maxlen> ret.size()) ret.insert(ret.size(), maxlen - ret.size(), fillchar); + //se aveva EOS, lo rimetto + if (flagEOS==true) ret=addEOS(ret); + } + return ret; +} + string genFunctions::addEOS(string sttde) { string ret=sttde; @@ -127,6 +161,8 @@ sttde=addEOS(sttde); char *cstr = new char[sttde.length() + 1]; strcpy(cstr, sttde.c_str()); - delete [] cstr; + // delete [] cstr; return cstr; -} \ No newline at end of file +} + +