Browse Source

fridge control on the way

phyto 6 months ago
parent
commit
ac89d9fe7d
3 changed files with 88 additions and 13 deletions
  1. 54
    3
      simulator/rdtemp/cli.ino
  2. 31
    8
      simulator/rdtemp/rdtemp.ino
  3. 3
    2
      simulator/rdtemp/storage.ino

+ 54
- 3
simulator/rdtemp/cli.ino View File

@@ -77,13 +77,59 @@ static void clihelp()
77 77
  prtln("d\tdisplay config");
78 78
  prtln("r\tread config");
79 79
  prtln("w\twrite config");
80
+ prtln("T\ttest relay");
81
+ prtln("0/1\tcontrole frigo");
80 82
  prtln("h\thexdump config");
81 83
 }
82 84
 /* --------------------------------------------------------------- */
83
-void setvalue(char *cmdline)
85
+void setvalue(char *cmdline, Global *param)
84 86
 {
85
-hexdump(cmdline, 10); 
87
+char    key, *sptr, *vptr;
88
+short   value;
86 89
 
90
+// hexdump((unsigned char *)cmdline, 10); 
91
+key = *(sptr = strtok(NULL, " "));
92
+// hexdump((unsigned char *)cmdline, 10);
93
+vptr = strtok(NULL, " ");
94
+value = atoi(vptr);
95
+
96
+prt(key); prt(' '); prtln(value);
97
+
98
+switch(key) {
99
+  case 'd':     param->delai = value;         break;
100
+  case 'h':     param->temp_maxi = value;     break;
101
+  case 'l':     param->temp_mini = value;     break;
102
+
103
+  default:    prtln("GNI ?");
104
+  }
105
+
106
+}
107
+/* --------------------------------------------------------------- */
108
+
109
+void test_relais(short nb) {
110
+short foo;
111
+prtln("test du relais frigo");
112
+
113
+for (foo=0; foo<nb; foo++) {    
114
+  digitalWrite(RELAIS_FRIGO, HIGH); 
115
+  delay(parametres.delai);
116
+             
117
+  digitalWrite(RELAIS_FRIGO, LOW); 
118
+  delay(parametres.delai);
119
+  }
120
+}
121
+/* --------------------------------------------------------------- */
122
+void controle_frigo(char on_off)
123
+{
124
+if (on_off) {
125
+  prtln("M frigo ON");
126
+  digitalWrite(RELAIS_FRIGO, HIGH);
127
+  }
128
+else {
129
+  prtln("M frigo OFF");
130
+  digitalWrite(RELAIS_FRIGO, LOW);
131
+  }
132
+prtln("...");  
87 133
 }
88 134
 /* --------------------------------------------------------------- */
89 135
 
@@ -99,7 +145,7 @@ static char separators[] = " \t";
99 145
 prtln("entering cli, '?' to help, 'x' to quit.");   
100 146
 
101 147
 do  {
102
-  prt(" + ");
148
+  prt("$ ");
103 149
   ret = readline(line,TLINE);
104 150
 #if DEBUG > 1
105 151
   hexdump((unsigned char *)line, ret);
@@ -115,7 +161,12 @@ do  {
115 161
     case 'w':  write_config(0, &parametres);           break;
116 162
     case 'h':  hexdump((unsigned char *)&parametres,
117 163
                             sizeof(Global));           break;
164
+    case 's':  setvalue(line, &parametres);            break;
165
+    case 'T':  test_relais(5);                         break; 
118 166
 
167
+    case '+':   controle_frigo(1);                     break;
168
+    case '-':   controle_frigo(0);                     break;
169
+       
119 170
     default:    prtln("gni ?");                        break;
120 171
     }
121 172
   

+ 31
- 8
simulator/rdtemp/rdtemp.ino View File

@@ -4,9 +4,15 @@
4 4
  */
5 5
 /* -------------------------------------------------- */
6 6
 
7
+// short write_config(short num, Global *from);
8
+
9
+/* -------------------------------------------------- */
10
+
7 11
 #define NBVAL   4
8 12
 #define DELAI   1000
9 13
 
14
+#define RELAIS_FRIGO  42
15
+
10 16
 typedef struct {
11 17
   unsigned short    magic;
12 18
   char              tag[4];
@@ -22,7 +28,9 @@ Global parametres;
22 28
 void setup() {
23 29
   Serial.begin(9600);
24 30
   pinMode(LED_BUILTIN, OUTPUT);
25
-  
31
+ 
32
+  pinMode(RELAIS_FRIGO, OUTPUT);
33
+ 
26 34
   Serial.print("\n");  
27 35
   /* XXX */
28 36
   /*  changing the voltage reference of the ADC
@@ -31,7 +39,8 @@ void setup() {
31 39
    */
32 40
   analogReference(INTERNAL1V1); // Pour Arduino Mega2560
33 41
   Serial.print("\n");
34
-  delay(1000);
42
+  read_config(0, &parametres);
43
+  // display_config(&parametres);  
35 44
   Serial.print("M running now\n");
36 45
   
37 46
 }
@@ -94,6 +103,8 @@ void update_and_send(void)
94 103
 /* ================================================== */
95 104
 void loop() {
96 105
   static int foo = 0;
106
+  int         key;
107
+  
97 108
   update_and_send();
98 109
 
99 110
   if (foo++ > 5) {
@@ -101,12 +112,24 @@ void loop() {
101 112
     }
102 113
 
103 114
  /* check for CLI request */
104
- if (Serial.available() && 0x55==Serial.read())
105
-    {
106
-    Serial.println("M cli request");
107
-    phytocli();
108
-    }
109
- 
115
+ if (Serial.available()) {
116
+    key = Serial.read();
117
+    switch (key) {
118
+      case 'U':
119
+          Serial.println("M cli request");
120
+          phytocli();
121
+          break;
122
+      case '+':           /* allume le frigo */
123
+          controle_frigo(1);
124
+          break;
125
+      case '-':           /* eteint le frigo */
126
+          controle_frigo(0);
127
+          break;
128
+      default:
129
+          Serial.print("M bad control code");
130
+          break;          
131
+      }
132
+ } 
110 133
   delay(DELAI);
111 134
 }
112 135
 

+ 3
- 2
simulator/rdtemp/storage.ino View File

@@ -25,7 +25,7 @@ unsigned short magic;
25 25
 prtln(">>> read config");
26 26
 #endif
27 27
 magic = 0;
28
-prt("magic is "); prtln(magic);
28
+
29 29
 EEPROM.get(0, magic);
30 30
 prt("magic is "); prtln(magic);
31 31
 if (0xfde9 != magic) return -1;
@@ -37,8 +37,9 @@ short write_config(short num, Global *from)
37 37
 {
38 38
 from->magic = 0xfde9;
39 39
 memcpy(from->tag, "aaaa", 4);
40
+from->control++;
40 41
 
41
-
42
+EEPROM.put(0, *from);
42 43
 
43 44
 return -1;
44 45
 }

Loading…
Cancel
Save