fridge control on the way

This commit is contained in:
phyto 2019-05-13 17:49:21 +02:00
parent 06b5603b8b
commit ac89d9fe7d
3 changed files with 88 additions and 13 deletions

View File

@ -77,13 +77,59 @@ static void clihelp()
prtln("d\tdisplay config"); prtln("d\tdisplay config");
prtln("r\tread config"); prtln("r\tread config");
prtln("w\twrite config"); prtln("w\twrite config");
prtln("T\ttest relay");
prtln("0/1\tcontrole frigo");
prtln("h\thexdump config"); 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<nb; foo++) {
digitalWrite(RELAIS_FRIGO, HIGH);
delay(parametres.delai);
digitalWrite(RELAIS_FRIGO, LOW);
delay(parametres.delai);
}
}
/* --------------------------------------------------------------- */
void controle_frigo(char on_off)
{
if (on_off) {
prtln("M frigo ON");
digitalWrite(RELAIS_FRIGO, HIGH);
}
else {
prtln("M frigo OFF");
digitalWrite(RELAIS_FRIGO, LOW);
}
prtln("...");
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
@ -99,7 +145,7 @@ static char separators[] = " \t";
prtln("entering cli, '?' to help, 'x' to quit."); prtln("entering cli, '?' to help, 'x' to quit.");
do { do {
prt(" + "); prt("$ ");
ret = readline(line,TLINE); ret = readline(line,TLINE);
#if DEBUG > 1 #if DEBUG > 1
hexdump((unsigned char *)line, ret); hexdump((unsigned char *)line, ret);
@ -115,6 +161,11 @@ do {
case 'w': write_config(0, &parametres); break; case 'w': write_config(0, &parametres); break;
case 'h': hexdump((unsigned char *)&parametres, case 'h': hexdump((unsigned char *)&parametres,
sizeof(Global)); break; sizeof(Global)); break;
case 's': setvalue(line, &parametres); break;
case 'T': test_relais(5); break;
case '+': controle_frigo(1); break;
case '-': controle_frigo(0); break;
default: prtln("gni ?"); break; default: prtln("gni ?"); break;
} }

View File

@ -4,9 +4,15 @@
*/ */
/* -------------------------------------------------- */ /* -------------------------------------------------- */
// short write_config(short num, Global *from);
/* -------------------------------------------------- */
#define NBVAL 4 #define NBVAL 4
#define DELAI 1000 #define DELAI 1000
#define RELAIS_FRIGO 42
typedef struct { typedef struct {
unsigned short magic; unsigned short magic;
char tag[4]; char tag[4];
@ -23,6 +29,8 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
pinMode(RELAIS_FRIGO, OUTPUT);
Serial.print("\n"); Serial.print("\n");
/* XXX */ /* XXX */
/* changing the voltage reference of the ADC /* changing the voltage reference of the ADC
@ -31,7 +39,8 @@ void setup() {
*/ */
analogReference(INTERNAL1V1); // Pour Arduino Mega2560 analogReference(INTERNAL1V1); // Pour Arduino Mega2560
Serial.print("\n"); Serial.print("\n");
delay(1000); read_config(0, &parametres);
// display_config(&parametres);
Serial.print("M running now\n"); Serial.print("M running now\n");
} }
@ -94,6 +103,8 @@ void update_and_send(void)
/* ================================================== */ /* ================================================== */
void loop() { void loop() {
static int foo = 0; static int foo = 0;
int key;
update_and_send(); update_and_send();
if (foo++ > 5) { if (foo++ > 5) {
@ -101,12 +112,24 @@ void loop() {
} }
/* check for CLI request */ /* check for CLI request */
if (Serial.available() && 0x55==Serial.read()) if (Serial.available()) {
{ key = Serial.read();
Serial.println("M cli request"); switch (key) {
phytocli(); 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); delay(DELAI);
} }

View File

@ -25,7 +25,7 @@ unsigned short magic;
prtln(">>> read config"); prtln(">>> read config");
#endif #endif
magic = 0; magic = 0;
prt("magic is "); prtln(magic);
EEPROM.get(0, magic); EEPROM.get(0, magic);
prt("magic is "); prtln(magic); prt("magic is "); prtln(magic);
if (0xfde9 != magic) return -1; if (0xfde9 != magic) return -1;
@ -37,8 +37,9 @@ short write_config(short num, Global *from)
{ {
from->magic = 0xfde9; from->magic = 0xfde9;
memcpy(from->tag, "aaaa", 4); memcpy(from->tag, "aaaa", 4);
from->control++;
EEPROM.put(0, *from);
return -1; return -1;
} }