From ac89d9fe7d63b859806066a9940453fb1a45a5f4 Mon Sep 17 00:00:00 2001 From: phyto Date: Mon, 13 May 2019 17:49:21 +0200 Subject: [PATCH] fridge control on the way --- simulator/rdtemp/cli.ino | 57 ++++++++++++++++++++++++++++++++++-- simulator/rdtemp/rdtemp.ino | 39 +++++++++++++++++++----- simulator/rdtemp/storage.ino | 5 ++-- 3 files changed, 88 insertions(+), 13 deletions(-) diff --git a/simulator/rdtemp/cli.ino b/simulator/rdtemp/cli.ino index 44670cf..19930d5 100644 --- a/simulator/rdtemp/cli.ino +++ b/simulator/rdtemp/cli.ino @@ -77,13 +77,59 @@ static void clihelp() prtln("d\tdisplay config"); prtln("r\tread config"); prtln("w\twrite config"); + prtln("T\ttest relay"); + prtln("0/1\tcontrole frigo"); prtln("h\thexdump config"); } /* --------------------------------------------------------------- */ -void setvalue(char *cmdline) +void setvalue(char *cmdline, Global *param) { -hexdump(cmdline, 10); +char key, *sptr, *vptr; +short value; +// hexdump((unsigned char *)cmdline, 10); +key = *(sptr = strtok(NULL, " ")); +// hexdump((unsigned char *)cmdline, 10); +vptr = strtok(NULL, " "); +value = atoi(vptr); + +prt(key); prt(' '); prtln(value); + +switch(key) { + case 'd': param->delai = value; break; + case 'h': param->temp_maxi = value; break; + case 'l': param->temp_mini = value; break; + + default: prtln("GNI ?"); + } + +} +/* --------------------------------------------------------------- */ + +void test_relais(short nb) { +short foo; +prtln("test du relais frigo"); + +for (foo=0; foo 1 hexdump((unsigned char *)line, ret); @@ -115,7 +161,12 @@ do { case 'w': write_config(0, ¶metres); break; case 'h': hexdump((unsigned char *)¶metres, sizeof(Global)); break; + case 's': setvalue(line, ¶metres); break; + case 'T': test_relais(5); break; + case '+': controle_frigo(1); break; + case '-': controle_frigo(0); break; + default: prtln("gni ?"); break; } diff --git a/simulator/rdtemp/rdtemp.ino b/simulator/rdtemp/rdtemp.ino index f3ce364..fde57c8 100644 --- a/simulator/rdtemp/rdtemp.ino +++ b/simulator/rdtemp/rdtemp.ino @@ -4,9 +4,15 @@ */ /* -------------------------------------------------- */ +// short write_config(short num, Global *from); + +/* -------------------------------------------------- */ + #define NBVAL 4 #define DELAI 1000 +#define RELAIS_FRIGO 42 + typedef struct { unsigned short magic; char tag[4]; @@ -22,7 +28,9 @@ Global parametres; void setup() { Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); - + + pinMode(RELAIS_FRIGO, OUTPUT); + Serial.print("\n"); /* XXX */ /* changing the voltage reference of the ADC @@ -31,7 +39,8 @@ void setup() { */ analogReference(INTERNAL1V1); // Pour Arduino Mega2560 Serial.print("\n"); - delay(1000); + read_config(0, ¶metres); + // display_config(¶metres); Serial.print("M running now\n"); } @@ -94,6 +103,8 @@ void update_and_send(void) /* ================================================== */ void loop() { static int foo = 0; + int key; + update_and_send(); if (foo++ > 5) { @@ -101,12 +112,24 @@ void loop() { } /* check for CLI request */ - if (Serial.available() && 0x55==Serial.read()) - { - Serial.println("M cli request"); - phytocli(); - } - + if (Serial.available()) { + key = Serial.read(); + switch (key) { + case 'U': + Serial.println("M cli request"); + phytocli(); + break; + case '+': /* allume le frigo */ + controle_frigo(1); + break; + case '-': /* eteint le frigo */ + controle_frigo(0); + break; + default: + Serial.print("M bad control code"); + break; + } + } delay(DELAI); } diff --git a/simulator/rdtemp/storage.ino b/simulator/rdtemp/storage.ino index a9ba793..0fcec9f 100644 --- a/simulator/rdtemp/storage.ino +++ b/simulator/rdtemp/storage.ino @@ -25,7 +25,7 @@ unsigned short magic; prtln(">>> read config"); #endif magic = 0; -prt("magic is "); prtln(magic); + EEPROM.get(0, magic); prt("magic is "); prtln(magic); if (0xfde9 != magic) return -1; @@ -37,8 +37,9 @@ short write_config(short num, Global *from) { from->magic = 0xfde9; memcpy(from->tag, "aaaa", 4); +from->control++; - +EEPROM.put(0, *from); return -1; }