Compare commits

..

No commits in common. "75e851a2ebe8241c849bc786c66d06ac0ad1139b" and "4232bef7c3936d7e323dd333528e3b46e73ec8d7" have entirely different histories.

2 changed files with 133 additions and 133 deletions

View File

@ -59,9 +59,9 @@ unsigned long virtual_interupt_timer[VINT_COUNT];
#define PWM_COUNT 16
const uint8_t pwm_pins[PWM_COUNT] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
bool pwm_states[PWM_COUNT];
uint8_t pwm_states_fram[PWM_COUNT];
uint8_t pwm_states_eeprom[PWM_COUNT];
uint16_t pwm_values[PWM_COUNT];
uint8_t pwm_values_fram[PWM_COUNT * 2];
uint8_t pwm_values_eeprom[PWM_COUNT * 2];
// output = m*input+c
const float pwm_linear_scaling_m[PWM_COUNT] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const float pwm_linear_scaling_c[PWM_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@ -118,28 +118,28 @@ char DAC_STATE_TOPIC[75];
char DAC_VALUE_TOPIC[75];
#endif
// FRAM ADDRESS
#define FRAM_ADDRESS_AC_MODE 0 // 01bytes
#define FRAM_ADDRESS_AC_TEMPERATURE 1 // 01bytes
#define FRAM_ADDRESS_AC_FAN_SPEED 2 // 01bytes
#define FRAM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18
#define FRAM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50
#define FRAM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79
#define FRAM_ADDRESS_TOPIC 80 // 20bytes, thru 99
#define FRAM_ADDRESS_IP 100 // 04bytes, thru 103
#define FRAM_ADDRESS_SUBNET 104 // 04bytes, thru 107
#define FRAM_ADDRESS_GATEWAY 108 // 04bytes, thru 111
#define FRAM_ADDRESS_DNS 112 // 04bytes, thru 115
#define FRAM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119
#define FRAM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121
#define FRAM_ADDRESS_MQTT_USERNAME 122 // 32bytes, thru 153
#define FRAM_ADDRESS_MQTT_PASSWORD 154 // 32bytes, thru 185
#define FRAM_ADDRESS_MQTT_USEAUTH 186 // 1bytes
#define FRAM_ADDRESS_ADC_REPORT_STATE 187 // 8bytes, thru 194
#define FRAM_ADDRESS_DAC_STATE 195 // 4bytes, thru 198
#define FRAM_ADDRESS_DAC_VALUE 199 // 8bytes, thru 206
#define FRAM_ADDRESS_WEBUI_USERNAME 207 // 32bytes, thru 238
#define FRAM_ADDRESS_WEBUI_PASSWORD 239 // 32bytes, thru 270
// EEPROM ADDRESS
#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes
#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes
#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes
#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18
#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50
#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79
#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99
#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103
#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107
#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111
#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115
#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119
#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121
#define EEPROM_ADDRESS_MQTT_USERNAME 122 // 32bytes, thru 153
#define EEPROM_ADDRESS_MQTT_PASSWORD 154 // 32bytes, thru 185
#define EEPROM_ADDRESS_MQTT_USEAUTH 186 // 1bytes
#define EEPROM_ADDRESS_ADC_REPORT_STATE 187 // 8bytes, thru 194
#define EEPROM_ADDRESS_DAC_STATE 195 // 4bytes, thru 198
#define EEPROM_ADDRESS_DAC_VALUE 199 // 8bytes, thru 206
#define EEPROM_ADDRESS_WEBUI_USERNAME 207 // 32bytes, thru 238
#define EEPROM_ADDRESS_WEBUI_PASSWORD 239 // 32bytes, thru 270
char PWM_STATE_TOPIC[75];
char PWM_VALUE_TOPIC[75];
@ -154,10 +154,10 @@ DHTNEW env_sensor(DHT22_PIN);
Thread mqtt_reconnector = Thread();
Thread environment_reporter = Thread();
Thread fram_pwm_updater = Thread();
Thread eeprom_pwm_updater = Thread();
Thread user_timer_tick = Thread();
Thread analog_handler = Thread();
StaticThreadController<5> thread_controller(&mqtt_reconnector, &environment_reporter, &fram_pwm_updater, &user_timer_tick, &analog_handler);
StaticThreadController<5> thread_controller(&mqtt_reconnector, &environment_reporter, &eeprom_pwm_updater, &user_timer_tick, &analog_handler);
#ifdef ENABLE_INTERNAL_LCD
Thread top_bar_updater = Thread();
@ -186,7 +186,7 @@ void setup()
#ifdef VIRTUAL_INTERRUPT_PRELOAD
virtual_interrupt_preload();
#endif
fram_retrieve_init();
eeprom_retrieve_init();
user_pre_init();
#ifdef ENABLE_INTERNAL_LCD
lcd_send_stop_bit();
@ -244,52 +244,52 @@ void loop()
}
/**
* @brief Retrieves data from FRAM and initializes various variables and topics.
* @brief Retrieves data from EEPROM and initializes various variables and topics.
*
*/
void fram_retrieve_init()
void eeprom_retrieve_init()
{
#ifdef ENABLE_WEBUI
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
ESPMega_FRAM.read(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
ESPMega_FRAM.read(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
if(strlen(WEBUI_USERNAME)==0) {
strcpy(WEBUI_USERNAME,"admin");
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
}
if(strlen(WEBUI_PASSWORD)==0) {
strcpy(WEBUI_PASSWORD,"admin");
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
}
#endif
// FRAM Data Retrival
// EEPROM Data Retrival
#ifdef ENABLE_CLIMATE_MODULE
ac_mode = ESPMega_FRAM.read8(FRAM_ADDRESS_AC_MODE);
ac_temperature = ESPMega_FRAM.read8(FRAM_ADDRESS_AC_TEMPERATURE);
ac_fan_speed = ESPMega_FRAM.read8(FRAM_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);
#endif
// FRAM Data Retrival Validation
// EEPROM Data Retrival Validation
#ifdef ENABLE_CLIMATE_MODULE
if (ac_mode > 2)
{
ac_mode = 0;
ESPMega_FRAM.write8(FRAM_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_FRAM.write8(FRAM_ADDRESS_AC_TEMPERATURE, ac_temperature);
ESPMega_FRAM.write8(EEPROM_ADDRESS_AC_TEMPERATURE, ac_temperature);
}
if (ac_fan_speed > 3)
{
ac_fan_speed = 0;
ESPMega_FRAM.write8(FRAM_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);
#endif
ESPMega_FRAM.read(FRAM_ADDRESS_PWM_STATE, pwm_states_fram, 16);
memcpy(pwm_states, pwm_states_fram, 16);
ESPMega_FRAM.read(FRAM_ADDRESS_PWM_VALUE, pwm_values_fram, 32);
memcpy(pwm_values, pwm_values_fram, 32);
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_STATE, pwm_states_eeprom, 16);
memcpy(pwm_states, pwm_states_eeprom, 16);
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++)
{
if (pwm_states[i] <= 1)
@ -301,18 +301,18 @@ void fram_retrieve_init()
else
pwm_set_value(i, 0);
}
IP = fram_ip_retrieve(FRAM_ADDRESS_IP);
SUBNET = fram_ip_retrieve(FRAM_ADDRESS_SUBNET);
GATEWAY = fram_ip_retrieve(FRAM_ADDRESS_GATEWAY);
DNS = fram_ip_retrieve(FRAM_ADDRESS_DNS);
MQTT_SERVER = fram_ip_retrieve(FRAM_ADDRESS_MQTT_SERVER);
fram_hostname_retrieve();
fram_mqtt_port_retrieve();
fram_mqtt_useauth_retrieve();
fram_mqtt_username_retrieve();
fram_mqtt_password_retrieve();
IP = eeprom_ip_retrieve(EEPROM_ADDRESS_IP);
SUBNET = eeprom_ip_retrieve(EEPROM_ADDRESS_SUBNET);
GATEWAY = eeprom_ip_retrieve(EEPROM_ADDRESS_GATEWAY);
DNS = eeprom_ip_retrieve(EEPROM_ADDRESS_DNS);
MQTT_SERVER = eeprom_ip_retrieve(EEPROM_ADDRESS_MQTT_SERVER);
eeprom_hostname_retrieve();
eeprom_mqtt_port_retrieve();
eeprom_mqtt_useauth_retrieve();
eeprom_mqtt_username_retrieve();
eeprom_mqtt_password_retrieve();
mqtt.setServer(MQTT_SERVER, MQTT_PORT);
fram_basetopic_retrieve();
eeprom_basetopic_retrieve();
base_topic_length = strlen(MQTT_BASE_TOPIC) + 1;
memcpy(STATE_REQUEST_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(STATE_REQUEST_TOPIC, "/requeststate");
@ -361,9 +361,9 @@ void fram_retrieve_init()
strcat(DAC_STATE_TOPIC, "/dac/00/state");
memcpy(DAC_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(DAC_VALUE_TOPIC, "/dac/00/value");
ESPMega_FRAM.read(FRAM_ADDRESS_ADC_REPORT_STATE, (uint8_t *)adc_report_enable, 8);
ESPMega_FRAM.read(FRAM_ADDRESS_DAC_STATE, (uint8_t *)dac_states, 4);
ESPMega_FRAM.read(FRAM_ADDRESS_DAC_VALUE, (uint8_t *)dac_values, 8);
ESPMega_FRAM.read(EEPROM_ADDRESS_ADC_REPORT_STATE, (uint8_t *)adc_report_enable, 8);
ESPMega_FRAM.read(EEPROM_ADDRESS_DAC_STATE, (uint8_t *)dac_states, 4);
ESPMega_FRAM.read(EEPROM_ADDRESS_DAC_VALUE, (uint8_t *)dac_values, 8);
for (int i = 0; i < DAC_COUNT; i++)
{
dac_set_state(i, dac_states[i]);
@ -463,9 +463,9 @@ void ota_begin()
if(!value.compareTo("yes"))
use_auth = true;
} else if(!arg.compareTo("webui_username")) {
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)value.c_str(), value.length()+1);
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)value.c_str(), value.length()+1);
} else if(!arg.compareTo("webui_password")) {
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)value.c_str(), value.length()+1);
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)value.c_str(), value.length()+1);
}
}
set_mqtt_useauth(use_auth);
@ -748,7 +748,7 @@ void mqtt_callback(char *topic, byte *payload, unsigned int length)
}
/**
* @brief Initializes the threads for various tasks such as MQTT connection, environment reporting, FRAM PWM update, and user timer tick.
* @brief Initializes the threads for various tasks such as MQTT connection, environment reporting, EEPROM PWM update, and user timer tick.
*
*/
void thread_initialization()
@ -761,8 +761,8 @@ void thread_initialization()
environment_reporter.onRun(publish_env_state);
environment_reporter.setInterval(5000);
#endif
fram_pwm_updater.onRun(fram_pwm_update);
fram_pwm_updater.setInterval(1000);
eeprom_pwm_updater.onRun(eeprom_pwm_update);
eeprom_pwm_updater.setInterval(1000);
user_timer_tick.onRun(timer_tick_callback);
user_timer_tick.setInterval(15000);
#ifdef ENABLE_ANALOG_MODULE
@ -1559,34 +1559,34 @@ void trigger15()
#endif // End Internal LCD Code Block
/**
* @brief Updates the PWM states and values in FRAM if they have changed.
* @brief Updates the PWM states and values in EEPROM if they have changed.
*
* If the current PWM states or values are different from the ones stored in FRAM,
* this function updates the FRAM with the current values.
* If the current PWM states or values are different from the ones stored in EEPROM,
* this function updates the EEPROM with the current values.
*/
void fram_pwm_update()
void eeprom_pwm_update()
{
if (memcmp(pwm_states, pwm_states_fram, 16))
if (memcmp(pwm_states, pwm_states_eeprom, 16))
{
memcpy(pwm_states_fram, pwm_states, 16);
ESPMega_FRAM.write(3, pwm_states_fram, 16);
memcpy(pwm_states_eeprom, pwm_states, 16);
ESPMega_FRAM.write(3, pwm_states_eeprom, 16);
}
if (memcmp(pwm_values, pwm_values_fram, 32))
if (memcmp(pwm_values, pwm_values_eeprom, 32))
{
memcpy(pwm_values_fram, pwm_values, 32);
ESPMega_FRAM.write(19, pwm_values_fram, 32);
memcpy(pwm_values_eeprom, pwm_values, 32);
ESPMega_FRAM.write(19, pwm_values_eeprom, 32);
}
}
/**
* @brief Sets the IP address and updates it in FRAM.
* @brief Sets the IP address and updates it in EEPROM.
*
* @param address The IP address to set.
*/
void set_ip(String address)
{
IP.fromString(address);
fram_ip_update(FRAM_ADDRESS_IP, IP[0], IP[1], IP[2], IP[3]);
eeprom_ip_update(EEPROM_ADDRESS_IP, IP[0], IP[1], IP[2], IP[3]);
}
/**
@ -1597,7 +1597,7 @@ void set_ip(String address)
void set_netmask(String address)
{
SUBNET.fromString(address);
fram_ip_update(FRAM_ADDRESS_SUBNET, SUBNET[0], SUBNET[1], SUBNET[2], SUBNET[3]);
eeprom_ip_update(EEPROM_ADDRESS_SUBNET, SUBNET[0], SUBNET[1], SUBNET[2], SUBNET[3]);
}
/**
@ -1607,33 +1607,33 @@ void set_netmask(String address)
void set_dns(String address)
{
DNS.fromString(address);
fram_ip_update(FRAM_ADDRESS_DNS, DNS[0], DNS[1], DNS[2], DNS[3]);
eeprom_ip_update(EEPROM_ADDRESS_DNS, DNS[0], DNS[1], DNS[2], DNS[3]);
}
/**
* @brief Sets the gateway IP address and updates the FRAM.
* @brief Sets the gateway IP address and updates the EEPROM.
*
* @param address The gateway IP address as a String.
*/
void set_gw(String address)
{
GATEWAY.fromString(address);
fram_ip_update(FRAM_ADDRESS_GATEWAY, GATEWAY[0], GATEWAY[1], GATEWAY[2], GATEWAY[3]);
eeprom_ip_update(EEPROM_ADDRESS_GATEWAY, GATEWAY[0], GATEWAY[1], GATEWAY[2], GATEWAY[3]);
}
/**
* @brief Sets the MQTT server address and updates the FRAM.
* @brief Sets the MQTT server address and updates the EEPROM.
*
* @param address The MQTT server address as a String.
*/
void set_mqtt_server(String address)
{
MQTT_SERVER.fromString(address);
fram_ip_update(FRAM_ADDRESS_MQTT_SERVER, MQTT_SERVER[0], MQTT_SERVER[1], MQTT_SERVER[2], MQTT_SERVER[3]);
eeprom_ip_update(EEPROM_ADDRESS_MQTT_SERVER, MQTT_SERVER[0], MQTT_SERVER[1], MQTT_SERVER[2], MQTT_SERVER[3]);
}
/**
* @brief Updates the IP address in FRAM at the specified ROM address.
* @brief Updates the IP address in EEPROM at the specified ROM address.
*
* @param rom_address The ROM address where the IP address is stored.
* @param byte1 The first byte of the IP address.
@ -1641,19 +1641,19 @@ void set_mqtt_server(String address)
* @param byte3 The third byte of the IP address.
* @param byte4 The fourth byte of the IP address.
*/
void fram_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
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_FRAM.write(rom_address, addressblock, 4);
}
/**
* @brief Retrieves an IP address from FRAM memory.
* @brief Retrieves an IP address from EEPROM memory.
*
* @param rom_address The address in FRAM memory where the IP address is stored.
* @param rom_address The address in EEPROM memory where the IP address is stored.
* @return The retrieved IP address.
*/
IPAddress fram_ip_retrieve(uint16_t rom_address)
IPAddress eeprom_ip_retrieve(uint16_t rom_address)
{
uint8_t addressblock[4];
ESPMega_FRAM.read(rom_address, addressblock, 4);
@ -1668,40 +1668,40 @@ IPAddress fram_ip_retrieve(uint16_t rom_address)
void set_hostname(String hostname)
{
hostname.toCharArray(HOSTNAME, 15);
ESPMega_FRAM.write(FRAM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
ESPMega_FRAM.write(EEPROM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
}
/**
* @brief Retrieves the hostname from FRAM and stores it in the HOSTNAME variable.
* @brief Retrieves the hostname from EEPROM and stores it in the HOSTNAME variable.
*
*/
void fram_hostname_retrieve()
void eeprom_hostname_retrieve()
{
ESPMega_FRAM.read(FRAM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
ESPMega_FRAM.read(EEPROM_ADDRESS_HOSTNAME, (uint8_t *)HOSTNAME, 15);
}
/**
* @brief Sets the base topic for MQTT communication and writes it to FRAM.
* @brief Sets the base topic for MQTT communication and writes it to EEPROM.
*
* @param topic The base topic to set.
*/
void set_basetopic(String topic)
{
topic.toCharArray(MQTT_BASE_TOPIC, 20);
ESPMega_FRAM.write(FRAM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
ESPMega_FRAM.write(EEPROM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
}
/**
* @brief Retrieves the MQTT base topic from FRAM and stores it in MQTT_BASE_TOPIC array.
* @brief Retrieves the MQTT base topic from EEPROM and stores it in MQTT_BASE_TOPIC array.
*
*/
void fram_basetopic_retrieve()
void eeprom_basetopic_retrieve()
{
ESPMega_FRAM.read(FRAM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
ESPMega_FRAM.read(EEPROM_ADDRESS_TOPIC, (uint8_t *)MQTT_BASE_TOPIC, 20);
}
/**
* @brief Sets the MQTT port in the FRAM.
* @brief Sets the MQTT port in the EEPROM.
*
* @param port The MQTT port to be set.
*/
@ -1709,16 +1709,16 @@ void mqtt_port_set(uint16_t port)
{
uint8_t port_arr[2];
memcpy(port_arr, &port, 2);
ESPMega_FRAM.write(FRAM_ADDRESS_MQTT_PORT, port_arr, 2);
ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PORT, port_arr, 2);
}
/**
* @brief Retrieves the MQTT port from FRAM and stores it in the MQTT_PORT variable.
* @brief Retrieves the MQTT port from EEPROM and stores it in the MQTT_PORT variable.
*
*/
void fram_mqtt_port_retrieve()
void eeprom_mqtt_port_retrieve()
{
uint8_t port_arr[2];
ESPMega_FRAM.read(FRAM_ADDRESS_MQTT_PORT, port_arr, 2);
ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_PORT, port_arr, 2);
memcpy(&MQTT_PORT, port_arr, 2);
}
@ -1786,67 +1786,67 @@ uint8_t ac_get_fan_speed()
#endif
/**
* @brief Retrieves the MQTT username from FRAM and stores it in the MQTT_USERNAME global variable.
* @brief Retrieves the MQTT username from EEPROM and stores it in the MQTT_USERNAME global variable.
*
*/
void fram_mqtt_username_retrieve()
void eeprom_mqtt_username_retrieve()
{
ESPMega_FRAM.read(FRAM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 32);
ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 32);
}
/**
* @brief Retrieves the MQTT password from FRAM and stores it in the MQTT_PASSWORD global variable.
* @brief Retrieves the MQTT password from EEPROM and stores it in the MQTT_PASSWORD global variable.
*
*/
void fram_mqtt_password_retrieve()
void eeprom_mqtt_password_retrieve()
{
ESPMega_FRAM.read(FRAM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 32);
ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 32);
}
/**
* @brief Sets the MQTT username and writes it to the FRAM.
* @brief Sets the MQTT username and writes it to the EEPROM.
*
* @param username The MQTT username to set.
*/
void set_mqtt_username(String username)
{
username.toCharArray(MQTT_USERNAME, 32);
ESPMega_FRAM.write(FRAM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 20);
ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 20);
}
/**
* @brief Sets the MQTT password and writes it to the FRAM.
* @brief Sets the MQTT password and writes it to the EEPROM.
*
* @param password The MQTT password to set.
*/
void set_mqtt_password(String password)
{
password.toCharArray(MQTT_PASSWORD, 32);
ESPMega_FRAM.write(FRAM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 20);
ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 20);
}
void fram_mqtt_useauth_retrieve()
void eeprom_mqtt_useauth_retrieve()
{
MQTT_USE_AUTH = ESPMega_FRAM.read8(FRAM_ADDRESS_MQTT_USEAUTH);
MQTT_USE_AUTH = ESPMega_FRAM.read8(EEPROM_ADDRESS_MQTT_USEAUTH);
}
/**
* @brief Sets the MQTT_USE_AUTH flag and writes it to the FRAM.
* @brief Sets the MQTT_USE_AUTH flag and writes it to the EEPROM.
*
* @param use_auth A boolean value indicating whether to use authentication for MQTT.
*/
void set_mqtt_useauth(bool use_auth)
{
MQTT_USE_AUTH = use_auth;
ESPMega_FRAM.write8(FRAM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
}
void set_webui_username(String username)
{
username.toCharArray(WEBUI_USERNAME, 32);
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
}
void set_webui_password(String password)
{
password.toCharArray(WEBUI_PASSWORD, 32);
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
}
/**
@ -1920,20 +1920,20 @@ void check_boot_reset()
void enable_adc(int id)
{
adc_report_enable[id] = true;
ESPMega_FRAM.write8(FRAM_ADDRESS_ADC_REPORT_STATE + id, 1);
ESPMega_FRAM.write8(EEPROM_ADDRESS_ADC_REPORT_STATE + id, 1);
publish_adc_state(id);
}
/**
* @brief Disables the ADC reporting for the specified ID.
*
* This function sets the adc_report_enable flag to false for the specified ID and writes the state to the FRAM.
* This function sets the adc_report_enable flag to false for the specified ID and writes the state to the EEPROM.
*
* @param id The ID of the ADC to disable reporting for.
*/
void disable_adc(int id)
{
adc_report_enable[id] = false;
ESPMega_FRAM.write8(FRAM_ADDRESS_ADC_REPORT_STATE + id, 0);
ESPMega_FRAM.write8(EEPROM_ADDRESS_ADC_REPORT_STATE + id, 0);
publish_adc_state(id);
}
@ -2122,7 +2122,7 @@ void dac_set_value(int id, int value)
{
dac_values[id] = value;
ESPMega_dacWrite(id, dac_values[id] * dac_states[id]);
ESPMega_FRAM.write16(FRAM_ADDRESS_DAC_VALUE + id * 2, dac_values[id]);
ESPMega_FRAM.write16(EEPROM_ADDRESS_DAC_VALUE + id * 2, dac_values[id]);
publish_dac_value(id);
}
@ -2130,7 +2130,7 @@ void dac_set_value(int id, int value)
* @brief Sets the state of a DAC channel.
*
* This function updates the state of a DAC channel and writes the new state to the DAC output.
* It also saves the state to the FRAM for persistence across power cycles.
* It also saves the state to the EEPROM for persistence across power cycles.
*
* @param id The ID of the DAC channel.
* @param state The new state of the DAC channel.
@ -2139,7 +2139,7 @@ void dac_set_state(int id, bool state)
{
dac_states[id] = state;
ESPMega_dacWrite(id, dac_values[id] * dac_states[id]);
ESPMega_FRAM.write8(FRAM_ADDRESS_DAC_STATE + id, dac_states[id]);
ESPMega_FRAM.write8(EEPROM_ADDRESS_DAC_STATE + id, dac_states[id]);
publish_dac_state(id);
}

View File

@ -105,8 +105,8 @@ void trigger13();
void trigger14();
void trigger15();
void fram_retrieve_init();
void fram_pwm_update();
void eeprom_retrieve_init();
void eeprom_pwm_update();
void lcd_ac_refresh_fan();
void lcd_ac_refresh_mode();
@ -116,19 +116,19 @@ void set_netmask(String address);
void set_dns(String address);
void set_gw(String address);
void set_mqtt_server(String address);
void fram_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
IPAddress fram_ip_retrieve(uint16_t rom_address);
void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
IPAddress eeprom_ip_retrieve(uint16_t rom_address);
void set_hostname(String hostname);
void fram_hostname_retrieve();
void eeprom_hostname_retrieve();
void set_basetopic(String topic);
void fram_basetopic_retrieve();
void eeprom_basetopic_retrieve();
void mqtt_port_set(uint16_t port);
void fram_mqtt_port_retrieve();
void fram_mqtt_username_retrieve();
void fram_mqtt_password_retrieve();
void eeprom_mqtt_port_retrieve();
void eeprom_mqtt_username_retrieve();
void eeprom_mqtt_password_retrieve();
void set_mqtt_username(String username);
void set_mqtt_password(String password);
void fram_mqtt_useauth_retrieve();
void eeprom_mqtt_useauth_retrieve();
void set_mqtt_useauth(bool use_auth);
void factory_reset();