DD2-monitor/simulator/rdtemp/storage.ino

68 lines
1.5 KiB
Arduino
Raw Normal View History

2019-04-30 02:46:14 +11:00
/* --------------------------------------------------------------- */
#include <EEPROM.h>
/* --------------------------------------------------------------- */
2019-05-13 23:26:05 +11:00
short init_storage(Global *what)
2019-04-30 02:46:14 +11:00
{
2019-05-01 01:49:21 +11:00
short foo;
2019-04-30 02:46:14 +11:00
Serial.print("eeprom length: ");
Serial.println(EEPROM.length());
2019-05-01 01:49:21 +11:00
Serial.print("global length: ");
Serial.println(sizeof(Global));
2019-05-13 23:26:05 +11:00
memset(what, 0, sizeof(Global));
what->magic = 0xfde9;
EEPROM.put(0, *what);
return 0;
2019-05-01 01:49:21 +11:00
}
/* --------------------------------------------------------------- */
short read_config(short num, Global *where)
{
2019-05-13 23:26:05 +11:00
unsigned short magic;
2019-05-01 01:49:21 +11:00
#if DEBUG
prtln(">>> read config");
#endif
2019-05-13 23:26:05 +11:00
magic = 0;
2019-05-14 02:49:21 +11:00
2019-05-13 23:26:05 +11:00
EEPROM.get(0, magic);
prt("magic is "); prtln(magic);
if (0xfde9 != magic) return -1;
EEPROM.get(0, *where);
return -2;
2019-05-01 01:49:21 +11:00
}
/* --------------------------------------------------------------- */
short write_config(short num, Global *from)
{
from->magic = 0xfde9;
memcpy(from->tag, "aaaa", 4);
2019-05-14 02:49:21 +11:00
from->control++;
2019-04-30 02:46:14 +11:00
2019-05-14 02:49:21 +11:00
EEPROM.put(0, *from);
2019-05-13 23:26:05 +11:00
2019-05-01 01:49:21 +11:00
return -1;
2019-04-30 02:46:14 +11:00
}
/* --------------------------------------------------------------- */
2019-05-01 01:49:21 +11: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 23:26:05 +11:00
prt("Temp mini : "); prtln(what->temp_mini);
prt("Temp maxi : "); prtln(what->temp_maxi);
2019-05-01 01:49:21 +11:00
return -1;
}
2019-04-30 02:46:14 +11:00
/* --------------------------------------------------------------- */