premier pas integration cli de config

This commit is contained in:
phyto 2019-04-29 11:40:22 +02:00
förälder 431e94fb48
incheckning a65e28aa67
2 ändrade filer med 105 tillägg och 0 borttagningar

102
simulator/rdtemp/cli.ino Normal file
Visa fil

@ -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);
}
/* --------------------------------------------------------------- */

Visa fil

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