premier pas integration cli de config
This commit is contained in:
parent
431e94fb48
commit
a65e28aa67
102
simulator/rdtemp/cli.ino
Normal file
102
simulator/rdtemp/cli.ino
Normal 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);
|
||||
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Phytotron
|
||||
* lecture des capteurs de temperature LM35
|
||||
*/
|
||||
/* -------------------------------------------------- */
|
||||
@ -13,6 +14,8 @@ void setup() {
|
||||
|
||||
Serial.print("\n");
|
||||
|
||||
phytocli();
|
||||
|
||||
/* XXX */
|
||||
/* changing the voltage reference of the ADC
|
||||
* greatly increase the prcision on the limited
|
||||
|
Loading…
Reference in New Issue
Block a user