Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
utils.h
- Committer:
- gwappa
- Date:
- 2018-05-14
- Revision:
- 1:871d3066c2ab
- Child:
- 8:973dcd190672
File content as of revision 1:871d3066c2ab:
#ifndef UTILS_H_ #define UTILS_H_ #include "IO.h" inline bool isWhitespace(const char& ch) { return (ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n') || (ch == '\v') || (ch == '\f'); } template <typename V> V parseUnsignedFromSerial(const V& defaultvalue) { V value = 0; while(true) { int readChar = IO::getc(); // only accepts digits if ((readChar >= 48) && (readChar <= 57)) { value = value * 10 + (readChar - 48); // continues parsing } else if ( isWhitespace((char)readChar) || (readChar == 59) ) { // space or ';' // ends parsing break; } else { IO::error("%c",(char)readChar); // set value back to original value = defaultvalue; break; } } return value; } #endif