Migrate EEPROM to FRAM
This commit is contained in:
parent
95d968a920
commit
c96ce8a67b
|
@ -12,7 +12,7 @@
|
|||
platform = espressif32
|
||||
board = wt32-eth01
|
||||
framework = arduino
|
||||
lib_deps = siwats/ESPMegaPROR3@^1.2.2
|
||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
||||
knolleary/PubSubClient@^2.8
|
||||
ivanseidel/ArduinoThread@^2.1.1
|
||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
||||
|
@ -20,5 +20,6 @@ lib_deps = siwats/ESPMegaPROR3@^1.2.2
|
|||
z3t0/IRremote@^4.2.0
|
||||
robtillaart/DHTNEW@^0.4.18
|
||||
seithan/Easy Nextion Library@^1.0.6
|
||||
robtillaart/FRAM_I2C@^0.6.1
|
||||
monitor_speed = 115200
|
||||
board_build.partitions = no_ota.csv
|
|
@ -4,13 +4,8 @@
|
|||
#define EMG_LCD_ENABLED
|
||||
|
||||
void lcd_send_stop_bit();
|
||||
int lcd_get_int();
|
||||
float lcd_get_float();
|
||||
String lcd_get_str();
|
||||
String lcd_set_var(String var, String value);
|
||||
void lcd_send_command(String command);
|
||||
String lcd_wait_response();
|
||||
void lcd_touch_callback(int page, int id);
|
||||
void lcd_reset();
|
||||
void lcd_init();
|
||||
#endif
|
48
src/main.cpp
48
src/main.cpp
|
@ -12,6 +12,10 @@
|
|||
#include <EasyNextionLibrary.h>
|
||||
#include <lcd.hpp>
|
||||
|
||||
|
||||
// OS Configuration
|
||||
#define FASTBOOT
|
||||
|
||||
// Network Connectivity
|
||||
char HOSTNAME[15];
|
||||
IPAddress IP(0, 0, 0, 0);
|
||||
|
@ -235,29 +239,29 @@ void loop()
|
|||
void eeprom_retrieve_init()
|
||||
{
|
||||
// EEPROM Data Retrival
|
||||
ac_mode = ESPMega_EEPROM.readByte(EEPROM_ADDRESS_AC_MODE);
|
||||
ac_temperature = ESPMega_EEPROM.readByte(EEPROM_ADDRESS_AC_TEMPERATURE);
|
||||
ac_fan_speed = ESPMega_EEPROM.readByte(EEPROM_ADDRESS_AC_FAN_SPEED);
|
||||
ac_mode = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_MODE);
|
||||
ac_temperature = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_TEMPERATURE);
|
||||
ac_fan_speed = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_FAN_SPEED);
|
||||
// EEPROM Data Retrival Validation
|
||||
if (ac_mode > 2)
|
||||
{
|
||||
ac_mode = 0;
|
||||
ESPMega_EEPROM.writeByte(EEPROM_ADDRESS_AC_MODE, ac_mode);
|
||||
ESPMega_FRAM.write8(EEPROM_ADDRESS_AC_MODE, ac_mode);
|
||||
}
|
||||
if (ac_temperature > AC_MAX_TEMPERATURE || ac_temperature < AC_MIN_TEMPERATURE)
|
||||
{
|
||||
ac_temperature = AC_MAX_TEMPERATURE;
|
||||
ESPMega_EEPROM.writeByte(EEPROM_ADDRESS_AC_TEMPERATURE, ac_temperature);
|
||||
ESPMega_FRAM.write8(EEPROM_ADDRESS_AC_TEMPERATURE, ac_temperature);
|
||||
}
|
||||
if (ac_fan_speed > 3)
|
||||
{
|
||||
ac_fan_speed = 0;
|
||||
ESPMega_EEPROM.writeByte(EEPROM_ADDRESS_AC_TEMPERATURE, ac_fan_speed);
|
||||
ESPMega_FRAM.write8(EEPROM_ADDRESS_AC_TEMPERATURE, ac_fan_speed);
|
||||
}
|
||||
ac_set_state(ac_mode, ac_temperature, ac_fan_speed);
|
||||
ESPMega_EEPROM.readBlock(EEPROM_ADDRESS_PWM_STATE, pwm_states_eeprom, 16);
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_STATE, pwm_states_eeprom, 16);
|
||||
memcpy(pwm_states, pwm_states_eeprom, 16);
|
||||
ESPMega_EEPROM.readBlock(EEPROM_ADDRESS_PWM_VALUE, pwm_values_eeprom, 32);
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_VALUE, pwm_values_eeprom, 32);
|
||||
memcpy(pwm_values, pwm_values_eeprom, 32);
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
|
@ -323,6 +327,7 @@ void network_begin()
|
|||
ETH.begin();
|
||||
ETH.setHostname(HOSTNAME);
|
||||
ETH.config(IP, GATEWAY, SUBNET, DNS, DNS);
|
||||
#ifndef FASTBOOT
|
||||
delay(1000);
|
||||
lcd_send_command("boot_state.txt=\"Ethernet Core Initializing \"");
|
||||
delay(500);
|
||||
|
@ -334,6 +339,7 @@ void network_begin()
|
|||
delay(500);
|
||||
lcd_send_command("boot_state.txt=\"NTP Core Initializing . . .\"");
|
||||
delay(500);
|
||||
#endif
|
||||
char ntp[19];
|
||||
MQTT_SERVER.toString().toCharArray(ntp,19);
|
||||
ESPMega_configNTP(utc_offset*3600,0,ntp);
|
||||
|
@ -400,7 +406,7 @@ void thread_initialization()
|
|||
environment_reporter.onRun(publish_env_state);
|
||||
environment_reporter.setInterval(5000);
|
||||
eeprom_pwm_updater.onRun(eeprom_pwm_update);
|
||||
eeprom_pwm_updater.setInterval(5000);
|
||||
eeprom_pwm_updater.setInterval(1000);
|
||||
}
|
||||
|
||||
void pwm_state_callback(String topic, String message)
|
||||
|
@ -708,7 +714,7 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
|||
}
|
||||
publish_ac_state();
|
||||
uint8_t ac_datablock[3] = {ac_mode, ac_temperature, ac_fan_speed};
|
||||
ESPMega_EEPROM.writeBlock(0, ac_datablock, 3);
|
||||
ESPMega_FRAM.write(0, ac_datablock, 3);
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
|
@ -836,7 +842,7 @@ void lcd_ac_refresh_mode()
|
|||
// auto high mid low
|
||||
panel.writeNum("mode_cool.pic", ac_mode == 1 ? 12 : 13);
|
||||
panel.writeNum("mode_fan.pic", ac_mode == 2 ? 22 : 23);
|
||||
panel.writeNum("mode_off.pic", ac_mode == 0 ? 24 : 23);
|
||||
panel.writeNum("mode_off.pic", ac_mode == 0 ? 24 : 25);
|
||||
}
|
||||
|
||||
void lcd_ac_refresh_fan()
|
||||
|
@ -944,13 +950,13 @@ void eeprom_pwm_update()
|
|||
if (memcmp(pwm_states, pwm_states_eeprom, 16))
|
||||
{
|
||||
memcpy(pwm_states_eeprom, pwm_states, 16);
|
||||
ESPMega_EEPROM.writeBlock(3, pwm_states_eeprom, 16);
|
||||
ESPMega_FRAM.write(3, pwm_states_eeprom, 16);
|
||||
lcd_send_stop_bit();
|
||||
}
|
||||
if (memcmp(pwm_values, pwm_values_eeprom, 32))
|
||||
{
|
||||
memcpy(pwm_values_eeprom, pwm_values, 32);
|
||||
ESPMega_EEPROM.writeBlock(19, pwm_values_eeprom, 32);
|
||||
ESPMega_FRAM.write(19, pwm_values_eeprom, 32);
|
||||
lcd_send_stop_bit();
|
||||
}
|
||||
}
|
||||
|
@ -983,46 +989,46 @@ void set_mqtt_server(String address)
|
|||
void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
|
||||
{
|
||||
uint8_t addressblock[4] = {byte1, byte2, byte3, byte4};
|
||||
ESPMega_EEPROM.writeBlockVerify(rom_address, addressblock, 4);
|
||||
ESPMega_FRAM.write(rom_address, addressblock, 4);
|
||||
}
|
||||
IPAddress eeprom_ip_retrieve(uint16_t rom_address)
|
||||
{
|
||||
uint8_t addressblock[4];
|
||||
ESPMega_EEPROM.readBlock(rom_address, addressblock, 4);
|
||||
ESPMega_FRAM.read(rom_address, addressblock, 4);
|
||||
return IPAddress(addressblock[0], addressblock[1], addressblock[2], addressblock[3]);
|
||||
}
|
||||
|
||||
void set_hostname(String hostname)
|
||||
{
|
||||
hostname.toCharArray(HOSTNAME, 15);
|
||||
ESPMega_EEPROM.writeBlock(EEPROM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
|
||||
ESPMega_FRAM.write(EEPROM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
|
||||
}
|
||||
|
||||
void eeprom_hostname_retrieve()
|
||||
{
|
||||
ESPMega_EEPROM.readBlock(EEPROM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
|
||||
}
|
||||
|
||||
void set_basetopic(String topic)
|
||||
{
|
||||
topic.toCharArray(MQTT_BASE_TOPIC, 20);
|
||||
ESPMega_EEPROM.writeBlock(EEPROM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
|
||||
ESPMega_FRAM.write(EEPROM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
|
||||
}
|
||||
|
||||
void eeprom_basetopic_retrieve()
|
||||
{
|
||||
ESPMega_EEPROM.readBlock(EEPROM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
|
||||
}
|
||||
|
||||
void mqtt_port_set(uint16_t port)
|
||||
{
|
||||
uint8_t port_arr[2];
|
||||
memcpy(port_arr, &port, 2);
|
||||
ESPMega_EEPROM.writeBlock(EEPROM_ADDRESS_MQTT_PORT, port_arr, 2);
|
||||
ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PORT, port_arr, 2);
|
||||
}
|
||||
void eeprom_mqtt_port_retrieve()
|
||||
{
|
||||
uint8_t port_arr[2];
|
||||
ESPMega_EEPROM.readBlock(EEPROM_ADDRESS_MQTT_PORT, port_arr, 2);
|
||||
ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_PORT, port_arr, 2);
|
||||
memcpy(&MQTT_PORT, port_arr, 2);
|
||||
}
|
Loading…
Reference in New Issue