Brewery-Controller/eeprom_setup/eeprom_init.h
Chris Giacofei 288c7dfc80 Need to load struct items separately.
Byte array can't be assigned directly.
2022-01-24 08:30:31 -05:00

52 lines
1.5 KiB
C

#include <EEPROM.h>
#include "config.h"
void StoreEEPROM() {
unsigned char b, e = -1, *p = (uint8_t*)CompileTimeP - 1;
while( b = pgm_read_byte( ++p ) ){
if( b != EEPROM[++e] ){
Vessel BoilKettle;
strcpy(BoilKettle.name, "boil_kettle");
strcpy(BoilKettle.setpoint, BOIL_SETPOINT_TOPIC);
strcpy(BoilKettle.sensor, BOIL_ACTUAL_TOPIC);
BoilKettle.Rref = RREF_KETTLE;
BoilKettle.RNominal = RNOMINAL_KETTLE;
// Vessel MashTun {mashname, MASH_SETPOINT_TOPIC, MASH_ACTUAL_TOPIC, RREF_MASH, RNOMINAL_MASH};
Vessel MashTun;
strcpy(MashTun.name, "mash_tun");
strcpy(MashTun.setpoint, MASH_SETPOINT_TOPIC);
strcpy(MashTun.sensor, MASH_ACTUAL_TOPIC);
MashTun.Rref = RREF_MASH;
MashTun.RNominal = RNOMINAL_MASH;
Topic mqtt_topics;
strcpy(mqtt_topics.root,TOPIC_ROOT);
mqtt_topics.mash = MashTun;
mqtt_topics.boil = BoilKettle;
Mqtt mqtt_data;
mqtt_data.broker = MQTT_BROKER;
strcpy(mqtt_data.user, MQTT_USER);
strcpy(mqtt_data.password, MQTT_PASSWORD);
mqtt_data.topic = mqtt_topics;
ConfigData conf;
conf.mqtt = mqtt_data;
memcpy(conf.mac, mac, sizeof(mac[0])*6);
conf.ip = ip;
conf.interval = UpdateInterval;
conf.period = PeriodPWM;
conf.threshold = ThreshPWR;
conf.hysteresis = Hysteresis;
EEPROM.put(ConfAddress, conf);
Serial.println(conf.mqtt.broker);
while( b = pgm_read_byte( p++ ) ) EEPROM[e++] = b;
break;
}
}
}