From a65e28aa67ffc8c88932750a4e1b4a25b7e7163c Mon Sep 17 00:00:00 2001 From: phyto Date: Mon, 29 Apr 2019 11:40:22 +0200 Subject: [PATCH] premier pas integration cli de config --- simulator/rdtemp/cli.ino | 102 ++++++++++++++++++++++++++++++++++++ simulator/rdtemp/rdtemp.ino | 3 ++ 2 files changed, 105 insertions(+) create mode 100644 simulator/rdtemp/cli.ino diff --git a/simulator/rdtemp/cli.ino b/simulator/rdtemp/cli.ino new file mode 100644 index 0000000..255b45f --- /dev/null +++ b/simulator/rdtemp/cli.ino @@ -0,0 +1,102 @@ +/* + * Phytotron + * configuration par la console + */ +/* -------------------------------------------------- */ + +#include +#include + +#define DEBUG 1 +/* -------------------------------------------------- */ +/* some interesting macros */ +#define prt(a) Serial.print(a) +#define prtln(a) Serial.println(a) + +/* -------------------------------------------------- */ +char waitkey(char echo) +{ +char key; +while (!Serial.available()); +key = Serial.read(); +if (echo) Serial.write(key); +return key; +} +/* -------------------------------------------------- */ +short readline(char *where, short sz) +{ +char key; +short count = 0; +for(;;) { + /* check for end of buffer */ + if (count==sz) { + where[count] = '\0'; + return -1; + } + key = waitkey(1); +#if DEBUG > 1 + prtln((int)key); +#endif + + if ((0x08==key) && count) { + /* we have got a backspace */ + count--; + where[count] = '\0'; +#if DEBUG + prt("< "); prtln(count); +#endif + continue; + } + if ('\r' == key) { + prt('\n'); + where[count] = '\0'; + return count; + } + where[count++] = key; + } +/* NOTREACHED */ +} +/* --------------------------------------------------------------- */ +void hexdump(unsigned char *ptr, short nbre) +{ +short foo; +for (foo=0; foo