Browse Source

premier pas integration cli de config

phyto 1 year ago
parent
commit
a65e28aa67
2 changed files with 105 additions and 0 deletions
  1. 102
    0
      simulator/rdtemp/cli.ino
  2. 3
    0
      simulator/rdtemp/rdtemp.ino

+ 102
- 0
simulator/rdtemp/cli.ino View File

@@ -0,0 +1,102 @@
1
+/*
2
+ *          Phytotron
3
+ * configuration par la console
4
+ */
5
+/* -------------------------------------------------- */
6
+
7
+#include  <stdlib.h>
8
+#include  <string.h>
9
+
10
+#define DEBUG 1
11
+/* -------------------------------------------------- */
12
+/* some interesting macros */
13
+#define prt(a)      Serial.print(a)
14
+#define prtln(a)    Serial.println(a)
15
+
16
+/* -------------------------------------------------- */
17
+char waitkey(char echo)
18
+{
19
+char    key;
20
+while (!Serial.available());
21
+key = Serial.read();
22
+if (echo) Serial.write(key);
23
+return key;
24
+}
25
+/* -------------------------------------------------- */
26
+short readline(char *where, short sz)
27
+{
28
+char  key;
29
+short  count = 0;
30
+for(;;)  {
31
+    /* check for end of buffer */
32
+    if (count==sz) {
33
+      where[count] = '\0';
34
+      return -1;
35
+      }
36
+    key = waitkey(1);
37
+#if DEBUG > 1
38
+    prtln((int)key);
39
+#endif
40
+
41
+    if ((0x08==key) && count) {
42
+      /* we have got a backspace */
43
+      count--;
44
+      where[count] = '\0';
45
+#if DEBUG
46
+      prt("< "); prtln(count);
47
+#endif
48
+      continue;
49
+      }
50
+    if ('\r' == key) {
51
+      prt('\n');
52
+      where[count] = '\0';
53
+      return count;
54
+      }
55
+    where[count++] = key;
56
+    }
57
+/* NOTREACHED */
58
+}
59
+/* --------------------------------------------------------------- */
60
+void hexdump(unsigned char *ptr, short nbre)
61
+{
62
+short    foo;
63
+for (foo=0; foo<nbre; foo++) {
64
+    Serial.print(ptr[foo], HEX);
65
+    Serial.print(' ');
66
+    }
67
+prtln("");
68
+}
69
+/* --------------------------------------------------------------- */
70
+static void clihelp()
71
+{
72
+ prtln("x\texit cli"); 
73
+}
74
+/* --------------------------------------------------------------- */
75
+void phytocli(void)
76
+{
77
+char     flag_exit = 0;
78
+char     ret, key;
79
+
80
+#define TLINE 40
81
+char     line[TLINE+1], *sptr;
82
+static char separators[] = " \t";
83
+
84
+prtln("entering cli, '?' to help, 'x' to quit.");   
85
+
86
+do  {
87
+  prt(" + ");
88
+  ret = readline(line,TLINE);
89
+#if DEBUG
90
+  hexdump((unsigned char *)line, ret);
91
+#endif
92
+  key = *(sptr = strtok(line, " "));
93
+
94
+  switch(key) {
95
+    case 'x':  flag_exit=1;                     break;
96
+    case '?':  clihelp();                       break;
97
+    }
98
+  
99
+  } while (!flag_exit);
100
+
101
+}
102
+/* --------------------------------------------------------------- */

+ 3
- 0
simulator/rdtemp/rdtemp.ino View File

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

Loading…
Cancel
Save