premier pas integration cli de config

This commit is contained in:
phyto 2019-04-29 11:40:22 +02:00
parent 431e94fb48
commit a65e28aa67
2 changed files with 105 additions and 0 deletions

102
simulator/rdtemp/cli.ino Normal file
View File

@ -0,0 +1,102 @@
/*
* Phytotron
* configuration par la console
*/
/* -------------------------------------------------- */
#include <stdlib.h>
#include <string.h>
#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<nbre; foo++) {
Serial.print(ptr[foo], HEX);
Serial.print(' ');
}
prtln("");
}
/* --------------------------------------------------------------- */
static void clihelp()
{
prtln("x\texit cli");
}
/* --------------------------------------------------------------- */
void phytocli(void)
{
char flag_exit = 0;
char ret, key;
#define TLINE 40
char line[TLINE+1], *sptr;
static char separators[] = " \t";
prtln("entering cli, '?' to help, 'x' to quit.");
do {
prt(" + ");
ret = readline(line,TLINE);
#if DEBUG
hexdump((unsigned char *)line, ret);
#endif
key = *(sptr = strtok(line, " "));
switch(key) {
case 'x': flag_exit=1; break;
case '?': clihelp(); break;
}
} while (!flag_exit);
}
/* --------------------------------------------------------------- */

View File

@ -1,4 +1,5 @@
/* /*
* Phytotron
* lecture des capteurs de temperature LM35 * lecture des capteurs de temperature LM35
*/ */
/* -------------------------------------------------- */ /* -------------------------------------------------- */
@ -12,6 +13,8 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
Serial.print("\n"); Serial.print("\n");
phytocli();
/* XXX */ /* XXX */
/* changing the voltage reference of the ADC /* changing the voltage reference of the ADC