This commit is contained in:
phyto 2019-05-13 14:26:05 +02:00
parent 0a83be585a
commit cce90eb60e
3 changed files with 39 additions and 22 deletions

View File

@ -7,7 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define DEBUG 1 #define DEBUG 0
/* -------------------------------------------------- */ /* -------------------------------------------------- */
/* some interesting macros */ /* some interesting macros */
#define prt(a) Serial.print(a) #define prt(a) Serial.print(a)
@ -70,13 +70,23 @@ prtln("");
static void clihelp() static void clihelp()
{ {
prtln("x\texit cli"); prtln("x\texit cli");
prtln("I\tinit storage"); prtln("I\tinit storage"); /* dangerous !!! */
prtln("s d N\tset delay");
prtln("s l N\tset lo temp");
prtln("s h N\tset hi temp");
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("H\thexdump config"); prtln("h\thexdump config");
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
void setvalue(char *cmdline)
{
hexdump(cmdline, 10);
}
/* --------------------------------------------------------------- */
void phytocli(void) void phytocli(void)
{ {
char flag_exit = 0; char flag_exit = 0;
@ -99,11 +109,11 @@ do {
switch(key) { switch(key) {
case 'x': flag_exit=1; break; case 'x': flag_exit=1; break;
case '?': clihelp(); break; case '?': clihelp(); break;
case 'I': init_storage(); break; case 'I': init_storage(&parametres); break;
case 'd': display_config(&parametres); break; case 'd': display_config(&parametres); break;
case 'r': read_config(0, &parametres); break; case 'r': read_config(0, &parametres); break;
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;
default: prtln("gni ?"); break; default: prtln("gni ?"); break;

View File

@ -11,6 +11,9 @@ typedef struct {
unsigned short magic; unsigned short magic;
char tag[4]; char tag[4];
short delai; short delai;
short temp_maxi;
short temp_mini;
short control;
} Global; } Global;
Global parametres; Global parametres;
@ -21,16 +24,13 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
Serial.print("\n"); Serial.print("\n");
phytocli(); /* XXX */
/* XXX */ /* XXX */
/* changing the voltage reference of the ADC /* changing the voltage reference of the ADC
* greatly increase the prcision on the limited * greatly increase the prcision on the limited
* range of our temperatures. * range of our temperatures.
*/ */
analogReference(INTERNAL1V1); // Pour Arduino Mega2560 analogReference(INTERNAL1V1); // Pour Arduino Mega2560
Serial.print("\n\n"); Serial.print("\n");
delay(1000); delay(1000);
Serial.print("M running now\n"); Serial.print("M running now\n");

View File

@ -1,40 +1,45 @@
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
#include <EEPROM.h> #include <EEPROM.h>
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
short init_storage(void) short init_storage(Global *what)
{ {
short foo; short foo;
Serial.println(__func__);
Serial.print("eeprom length: "); Serial.print("eeprom length: ");
Serial.println(EEPROM.length()); Serial.println(EEPROM.length());
Serial.print("global length: "); Serial.print("global length: ");
Serial.println(sizeof(Global)); Serial.println(sizeof(Global));
memset(what, 0, sizeof(Global));
what->magic = 0xfde9;
EEPROM.put(0, *what);
return 0;
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
short read_config(short num, Global *where) short read_config(short num, Global *where)
{ {
unsigned short magic;
#if DEBUG #if DEBUG
prtln(">>> read config"); prtln(">>> read config");
#endif #endif
magic = 0;
prt("magic is "); prtln(magic);
EEPROM.get(0, magic);
prt("magic is "); prtln(magic);
return -1; if (0xfde9 != magic) return -1;
EEPROM.get(0, *where);
return -2;
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
short write_config(short num, Global *from) short write_config(short num, Global *from)
{ {
#if DEBUG
prtln(">>> write config");
#endif
from->magic = 0xfde9; from->magic = 0xfde9;
memcpy(from->tag, "aaaa", 4); memcpy(from->tag, "aaaa", 4);
return -1; return -1;
} }
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
@ -53,6 +58,8 @@ for (foo=0; foo<4; foo++) {
} }
prtln(""); prtln("");
prt("Delay : "); prtln(what->delai); prt("Delay : "); prtln(what->delai);
prt("Temp mini : "); prtln(what->temp_mini);
prt("Temp maxi : "); prtln(what->temp_maxi);
return -1; return -1;
} }