DD2-monitor/simulator/rdtemp/storage.ino

67 lines
1.5 KiB
Arduino
Raw Normal View History

2019-04-29 17:46:14 +02:00
/* --------------------------------------------------------------- */
#include <EEPROM.h>
/* --------------------------------------------------------------- */
2019-05-13 14:26:05 +02:00
short init_storage(Global *what)
2019-04-29 17:46:14 +02:00
{
2019-04-30 16:49:21 +02:00
short foo;
2019-04-29 17:46:14 +02:00
Serial.print("eeprom length: ");
Serial.println(EEPROM.length());
2019-04-30 16:49:21 +02:00
Serial.print("global length: ");
Serial.println(sizeof(Global));
2019-05-13 14:26:05 +02:00
memset(what, 0, sizeof(Global));
what->magic = 0xfde9;
EEPROM.put(0, *what);
return 0;
2019-04-30 16:49:21 +02:00
}
/* --------------------------------------------------------------- */
short read_config(short num, Global *where)
{
2019-05-13 14:26:05 +02:00
unsigned short magic;
2019-04-30 16:49:21 +02:00
#if DEBUG
prtln(">>> read config");
#endif
2019-05-13 14:26:05 +02:00
magic = 0;
prt("magic is "); prtln(magic);
EEPROM.get(0, magic);
prt("magic is "); prtln(magic);
if (0xfde9 != magic) return -1;
EEPROM.get(0, *where);
return -2;
2019-04-30 16:49:21 +02:00
}
/* --------------------------------------------------------------- */
short write_config(short num, Global *from)
{
from->magic = 0xfde9;
memcpy(from->tag, "aaaa", 4);
2019-04-29 17:46:14 +02:00
2019-05-13 14:26:05 +02:00
2019-04-30 16:49:21 +02:00
return -1;
2019-04-29 17:46:14 +02:00
}
/* --------------------------------------------------------------- */
2019-04-30 16:49:21 +02:00
short display_config(Global *what)
{
char foo, c;
#if DEBUG
prtln(">>> display config");
#endif
prt("Magic : "); prtln(what->magic);
prt("Id : ");
for (foo=0; foo<4; foo++) {
if (isprint(c=what->tag[foo])) prt(c);
else prt('?');
}
prtln("");
prt("Delay : "); prtln(what->delai);
2019-05-13 14:26:05 +02:00
prt("Temp mini : "); prtln(what->temp_mini);
prt("Temp maxi : "); prtln(what->temp_maxi);
2019-04-30 16:49:21 +02:00
return -1;
}
2019-04-29 17:46:14 +02:00
/* --------------------------------------------------------------- */