phyto 1 year ago
parent
commit
cce90eb60e
3 changed files with 39 additions and 22 deletions
  1. 15
    5
      simulator/rdtemp/cli.ino
  2. 5
    5
      simulator/rdtemp/rdtemp.ino
  3. 19
    12
      simulator/rdtemp/storage.ino

+ 15
- 5
simulator/rdtemp/cli.ino View File

@@ -7,7 +7,7 @@
7 7
 #include  <stdlib.h>
8 8
 #include  <string.h>
9 9
 
10
-#define DEBUG 1
10
+#define DEBUG 0
11 11
 /* -------------------------------------------------- */
12 12
 /* some interesting macros */
13 13
 #define prt(a)      Serial.print(a)
@@ -70,13 +70,23 @@ prtln("");
70 70
 static void clihelp()
71 71
 {
72 72
  prtln("x\texit cli");
73
- prtln("I\tinit storage");
73
+ prtln("I\tinit storage");        /* dangerous !!! */
74
+ prtln("s d N\tset delay");
75
+ prtln("s l N\tset lo temp");
76
+ prtln("s h N\tset hi temp");
74 77
  prtln("d\tdisplay config");
75 78
  prtln("r\tread config");
76 79
  prtln("w\twrite config");
77
- prtln("H\thexdump config");
80
+ prtln("h\thexdump config");
78 81
 }
79 82
 /* --------------------------------------------------------------- */
83
+void setvalue(char *cmdline)
84
+{
85
+hexdump(cmdline, 10); 
86
+
87
+}
88
+/* --------------------------------------------------------------- */
89
+
80 90
 void phytocli(void)
81 91
 {
82 92
 char     flag_exit = 0;
@@ -99,11 +109,11 @@ do  {
99 109
   switch(key) {
100 110
     case 'x':  flag_exit=1;                            break;
101 111
     case '?':  clihelp();                              break;
102
-    case 'I':  init_storage();                         break;
112
+    case 'I':  init_storage(&parametres);              break;
103 113
     case 'd':  display_config(&parametres);            break;
104 114
     case 'r':  read_config(0, &parametres);            break;
105 115
     case 'w':  write_config(0, &parametres);           break;
106
-    case 'H':  hexdump((unsigned char *)&parametres,
116
+    case 'h':  hexdump((unsigned char *)&parametres,
107 117
                             sizeof(Global));           break;
108 118
 
109 119
     default:    prtln("gni ?");                        break;

+ 5
- 5
simulator/rdtemp/rdtemp.ino View File

@@ -11,6 +11,9 @@ typedef struct {
11 11
   unsigned short    magic;
12 12
   char              tag[4];
13 13
   short             delai;
14
+  short             temp_maxi;
15
+  short             temp_mini;
16
+  short             control;
14 17
   } Global;
15 18
 
16 19
 Global parametres;
@@ -20,17 +23,14 @@ void setup() {
20 23
   Serial.begin(9600);
21 24
   pinMode(LED_BUILTIN, OUTPUT);
22 25
   
23
-  Serial.print("\n");
24
-
25
-  phytocli();         /* XXX */
26
-  
26
+  Serial.print("\n");  
27 27
   /* XXX */
28 28
   /*  changing the voltage reference of the ADC
29 29
    *  greatly increase the prcision on the limited
30 30
    *  range of our temperatures.
31 31
    */
32 32
   analogReference(INTERNAL1V1); // Pour Arduino Mega2560
33
-  Serial.print("\n\n");
33
+  Serial.print("\n");
34 34
   delay(1000);
35 35
   Serial.print("M running now\n");
36 36
   

+ 19
- 12
simulator/rdtemp/storage.ino View File

@@ -1,40 +1,45 @@
1 1
 /* --------------------------------------------------------------- */
2 2
 #include <EEPROM.h>
3 3
 /* --------------------------------------------------------------- */
4
-short init_storage(void)
4
+short init_storage(Global *what)
5 5
 {
6 6
 short     foo;
7 7
 
8
-Serial.println(__func__);
9
-
10 8
 Serial.print("eeprom length: ");
11 9
 Serial.println(EEPROM.length());
12 10
 Serial.print("global length: ");
13 11
 Serial.println(sizeof(Global));
14 12
 
13
+memset(what, 0, sizeof(Global));
14
+what->magic = 0xfde9;
15
+EEPROM.put(0, *what);
16
+
17
+return 0;
15 18
 }
16 19
 /* --------------------------------------------------------------- */
17 20
 short read_config(short num, Global *where)
18 21
 {
22
+unsigned short magic;
23
+  
19 24
 #if DEBUG
20 25
 prtln(">>> read config");
21 26
 #endif
22
-
23
-
24
-
25
-
26
-return -1;
27
+magic = 0;
28
+prt("magic is "); prtln(magic);
29
+EEPROM.get(0, magic);
30
+prt("magic is "); prtln(magic);
31
+if (0xfde9 != magic) return -1;
32
+EEPROM.get(0, *where);
33
+return -2;
27 34
 }
28 35
 /* --------------------------------------------------------------- */
29 36
 short write_config(short num, Global *from)
30 37
 {
31
-#if DEBUG
32
-prtln(">>> write config");
33
-#endif
34
-
35 38
 from->magic = 0xfde9;
36 39
 memcpy(from->tag, "aaaa", 4);
37 40
 
41
+
42
+
38 43
 return -1;
39 44
 }
40 45
 /* --------------------------------------------------------------- */
@@ -53,6 +58,8 @@ for (foo=0; foo<4; foo++) {
53 58
   }
54 59
 prtln("");
55 60
 prt("Delay     : ");    prtln(what->delai);
61
+prt("Temp mini : ");    prtln(what->temp_mini);
62
+prt("Temp maxi : ");    prtln(what->temp_maxi);
56 63
 
57 64
 return -1;
58 65
 }

Loading…
Cancel
Save