fixed climate card fram bug
This commit is contained in:
parent
091dc183fe
commit
c635427d64
|
@ -86,10 +86,9 @@ void ClimateCard::setFRAMAutoSave(bool autoSave)
|
|||
|
||||
void ClimateCard::saveStateToFRAM()
|
||||
{
|
||||
// fram->write8(fram_address, state.ac_temperature);
|
||||
// fram->write8(fram_address + 1, state.ac_mode);
|
||||
// fram->write8(fram_address + 2, state.ac_fan_speed);
|
||||
fram->writeObject(fram_address, state);
|
||||
fram->write8(fram_address, state.ac_temperature);
|
||||
fram->write8(fram_address + 1, state.ac_mode);
|
||||
fram->write8(fram_address + 2, state.ac_fan_speed);
|
||||
Serial.println("Saved state to FRAM");
|
||||
Serial.write(0xFF);
|
||||
Serial.write(0xFF);
|
||||
|
@ -98,10 +97,24 @@ void ClimateCard::saveStateToFRAM()
|
|||
|
||||
void ClimateCard::loadStateFromFRAM()
|
||||
{
|
||||
// state.ac_temperature = fram->read8(fram_address);
|
||||
// state.ac_mode = fram->read8(fram_address + 1);
|
||||
// state.ac_fan_speed = fram->read8(fram_address + 2);
|
||||
fram->readObject(fram_address, state);
|
||||
Serial.print("Loading temperature from FRAM at address ");
|
||||
Serial.print(fram_address);
|
||||
Serial.print(": ");
|
||||
Serial.println(fram->read8(fram_address));
|
||||
state.ac_temperature = fram->read8(fram_address);
|
||||
Serial.print("Loading mode from FRAM at address ");
|
||||
Serial.print(fram_address + 1);
|
||||
Serial.print(": ");
|
||||
Serial.println(fram->read8(fram_address + 1));
|
||||
state.ac_mode = fram->read8(fram_address + 1);
|
||||
Serial.print("Loading fan speed from FRAM at address ");
|
||||
Serial.print(fram_address + 2);
|
||||
Serial.print(": ");
|
||||
Serial.println(fram->read8(fram_address + 2));
|
||||
state.ac_fan_speed = fram->read8(fram_address + 2);
|
||||
Serial.write(0xFF);
|
||||
Serial.write(0xFF);
|
||||
Serial.write(0xFF);
|
||||
// if (state.ac_temperature > ac.max_temperature)
|
||||
// state.ac_temperature = ac.max_temperature;
|
||||
// else if (state.ac_temperature < ac.min_temperature)
|
||||
|
|
|
@ -84,7 +84,7 @@ class ClimateCard : public ExpansionCard {
|
|||
float room_temperature;
|
||||
// FRAM variables
|
||||
FRAM *fram;
|
||||
uint8_t fram_address;
|
||||
uint16_t fram_address;
|
||||
bool fram_auto_save;
|
||||
uint16_t* getIrIndex(uint8_t mode, uint8_t fan_speed, uint8_t temperature);
|
||||
};
|
||||
|
|
|
@ -314,33 +314,33 @@ void ESPMegaIoT::setNetworkConfig(NetworkConfig network_config)
|
|||
void ESPMegaIoT::loadNetworkConfig()
|
||||
{
|
||||
// Load the network config from FRAM
|
||||
network_config.ip = fram->read32(FRAM_ADDRESS);
|
||||
network_config.gateway = fram->read32(FRAM_ADDRESS + 4);
|
||||
network_config.subnet = fram->read32(FRAM_ADDRESS + 8);
|
||||
network_config.dns1 = fram->read32(FRAM_ADDRESS + 12);
|
||||
network_config.dns2 = fram->read32(FRAM_ADDRESS + 16);
|
||||
fram->read(FRAM_ADDRESS + 20, (uint8_t*)network_config.hostname, 32);
|
||||
network_config.useStaticIp = fram->read8(FRAM_ADDRESS + 52);
|
||||
network_config.useWifi = fram->read8(FRAM_ADDRESS + 53);
|
||||
network_config.wifiUseAuth = fram->read8(FRAM_ADDRESS + 54);
|
||||
fram->read(FRAM_ADDRESS + 55, (uint8_t*)network_config.ssid, 32);
|
||||
fram->read(FRAM_ADDRESS + 87, (uint8_t*)network_config.password, 32);
|
||||
network_config.ip = fram->read32(IOT_FRAM_ADDRESS);
|
||||
network_config.gateway = fram->read32(IOT_FRAM_ADDRESS + 4);
|
||||
network_config.subnet = fram->read32(IOT_FRAM_ADDRESS + 8);
|
||||
network_config.dns1 = fram->read32(IOT_FRAM_ADDRESS + 12);
|
||||
network_config.dns2 = fram->read32(IOT_FRAM_ADDRESS + 16);
|
||||
fram->read(IOT_FRAM_ADDRESS + 20, (uint8_t*)network_config.hostname, 32);
|
||||
network_config.useStaticIp = fram->read8(IOT_FRAM_ADDRESS + 52);
|
||||
network_config.useWifi = fram->read8(IOT_FRAM_ADDRESS + 53);
|
||||
network_config.wifiUseAuth = fram->read8(IOT_FRAM_ADDRESS + 54);
|
||||
fram->read(IOT_FRAM_ADDRESS + 55, (uint8_t*)network_config.ssid, 32);
|
||||
fram->read(IOT_FRAM_ADDRESS + 87, (uint8_t*)network_config.password, 32);
|
||||
}
|
||||
|
||||
void ESPMegaIoT::saveNetworkConfig()
|
||||
{
|
||||
// Save the network config to FRAM
|
||||
fram->write32(FRAM_ADDRESS, network_config.ip);
|
||||
fram->write32(FRAM_ADDRESS + 4, network_config.gateway);
|
||||
fram->write32(FRAM_ADDRESS + 8, network_config.subnet);
|
||||
fram->write32(FRAM_ADDRESS + 12, network_config.dns1);
|
||||
fram->write32(FRAM_ADDRESS + 16, network_config.dns2);
|
||||
fram->write(FRAM_ADDRESS + 20, (uint8_t*)network_config.hostname, 32);
|
||||
fram->write8(FRAM_ADDRESS + 52, network_config.useStaticIp);
|
||||
fram->write8(FRAM_ADDRESS + 53, network_config.useWifi);
|
||||
fram->write8(FRAM_ADDRESS + 54, network_config.wifiUseAuth);
|
||||
fram->write(FRAM_ADDRESS + 55, (uint8_t*)network_config.ssid, 32);
|
||||
fram->write(FRAM_ADDRESS + 87, (uint8_t*)network_config.password, 32);
|
||||
fram->write32(IOT_FRAM_ADDRESS, network_config.ip);
|
||||
fram->write32(IOT_FRAM_ADDRESS + 4, network_config.gateway);
|
||||
fram->write32(IOT_FRAM_ADDRESS + 8, network_config.subnet);
|
||||
fram->write32(IOT_FRAM_ADDRESS + 12, network_config.dns1);
|
||||
fram->write32(IOT_FRAM_ADDRESS + 16, network_config.dns2);
|
||||
fram->write(IOT_FRAM_ADDRESS + 20, (uint8_t*)network_config.hostname, 32);
|
||||
fram->write8(IOT_FRAM_ADDRESS + 52, network_config.useStaticIp);
|
||||
fram->write8(IOT_FRAM_ADDRESS + 53, network_config.useWifi);
|
||||
fram->write8(IOT_FRAM_ADDRESS + 54, network_config.wifiUseAuth);
|
||||
fram->write(IOT_FRAM_ADDRESS + 55, (uint8_t*)network_config.ssid, 32);
|
||||
fram->write(IOT_FRAM_ADDRESS + 87, (uint8_t*)network_config.password, 32);
|
||||
|
||||
}
|
||||
|
||||
|
@ -353,22 +353,22 @@ void ESPMegaIoT::loadMqttConfig()
|
|||
{
|
||||
// Load the mqtt config from FRAM
|
||||
// We skip bytes 119-127 because they are reserved for the network config
|
||||
mqtt_config.mqtt_port = fram->read16(FRAM_ADDRESS + 128);
|
||||
fram->read(FRAM_ADDRESS + 130, (uint8_t*)mqtt_config.mqtt_server, 32);
|
||||
fram->read(FRAM_ADDRESS + 162, (uint8_t*)mqtt_config.mqtt_user, 32);
|
||||
fram->read(FRAM_ADDRESS + 194, (uint8_t*)mqtt_config.mqtt_password, 32);
|
||||
mqtt_config.mqtt_useauth = fram->read8(FRAM_ADDRESS + 226);
|
||||
fram->read(FRAM_ADDRESS + 227, (uint8_t*)mqtt_config.base_topic, 32);
|
||||
mqtt_config.mqtt_port = fram->read16(IOT_FRAM_ADDRESS + 128);
|
||||
fram->read(IOT_FRAM_ADDRESS + 130, (uint8_t*)mqtt_config.mqtt_server, 32);
|
||||
fram->read(IOT_FRAM_ADDRESS + 162, (uint8_t*)mqtt_config.mqtt_user, 32);
|
||||
fram->read(IOT_FRAM_ADDRESS + 194, (uint8_t*)mqtt_config.mqtt_password, 32);
|
||||
mqtt_config.mqtt_useauth = fram->read8(IOT_FRAM_ADDRESS + 226);
|
||||
fram->read(IOT_FRAM_ADDRESS + 227, (uint8_t*)mqtt_config.base_topic, 32);
|
||||
}
|
||||
|
||||
void ESPMegaIoT::saveMqttConfig()
|
||||
{
|
||||
fram->write16(FRAM_ADDRESS + 128, mqtt_config.mqtt_port);
|
||||
fram->write(FRAM_ADDRESS + 130, (uint8_t*)mqtt_config.mqtt_server, 32);
|
||||
fram->write(FRAM_ADDRESS + 162, (uint8_t*)mqtt_config.mqtt_user, 32);
|
||||
fram->write(FRAM_ADDRESS + 194, (uint8_t*)mqtt_config.mqtt_password, 32);
|
||||
fram->write8(FRAM_ADDRESS + 226, mqtt_config.mqtt_useauth);
|
||||
fram->write(FRAM_ADDRESS + 227, (uint8_t*)mqtt_config.base_topic, 32);
|
||||
fram->write16(IOT_FRAM_ADDRESS + 128, mqtt_config.mqtt_port);
|
||||
fram->write(IOT_FRAM_ADDRESS + 130, (uint8_t*)mqtt_config.mqtt_server, 32);
|
||||
fram->write(IOT_FRAM_ADDRESS + 162, (uint8_t*)mqtt_config.mqtt_user, 32);
|
||||
fram->write(IOT_FRAM_ADDRESS + 194, (uint8_t*)mqtt_config.mqtt_password, 32);
|
||||
fram->write8(IOT_FRAM_ADDRESS + 226, mqtt_config.mqtt_useauth);
|
||||
fram->write(IOT_FRAM_ADDRESS + 227, (uint8_t*)mqtt_config.base_topic, 32);
|
||||
}
|
||||
|
||||
void ESPMegaIoT::connectToMqtt()
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
// Starts from 34
|
||||
// Ends at 300 (inclusive)
|
||||
// Total of 267 bytes
|
||||
#define FRAM_ADDRESS 34
|
||||
#define IOT_FRAM_ADDRESS 34
|
||||
|
||||
struct NetworkConfig
|
||||
{
|
||||
|
|
|
@ -129,3 +129,18 @@ void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
|||
ESP_LOGD("ESPMegaPRO", "Internal Display Enabled");
|
||||
|
||||
}
|
||||
|
||||
void ESPMegaPRO::dumpFRAMtoSerial(uint16_t start, uint16_t end) {
|
||||
for (int i = start; i <=end; i++) {
|
||||
if (i % 16 == 0) {
|
||||
Serial.printf("\n%03d: ", i);
|
||||
}
|
||||
Serial.printf("%03d ", this->fram.read8(i));
|
||||
}
|
||||
}
|
||||
|
||||
void ESPMegaPRO::dumpFRAMtoSerialASCII(uint16_t start, uint16_t end) {
|
||||
for (int i = 0; i < 500; i++) {
|
||||
Serial.printf("%d: %c\n", i,this->fram.read8(i));
|
||||
}
|
||||
}
|
|
@ -31,6 +31,8 @@ class ESPMegaPRO {
|
|||
void enableIotModule();
|
||||
void enableInternalDisplay(HardwareSerial *serial);
|
||||
rtctime_t getTime();
|
||||
void dumpFRAMtoSerial(uint16_t start, uint16_t end);
|
||||
void dumpFRAMtoSerialASCII(uint16_t start, uint16_t end);
|
||||
void setTime(int hours, int minutes, int seconds, int day, int month, int year);
|
||||
ExpansionCard* getCard(uint8_t slot);
|
||||
FRAM fram;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include <ESPMegaPRO_OOP.hpp>
|
||||
|
||||
ESPMegaPRO espmega = ESPMegaPRO();
|
||||
|
||||
void setup() {
|
||||
espmega.begin();
|
||||
//espmega.fram.write8(301, 25);
|
||||
// Dump FRAM to a prettified table
|
||||
for (int i = 0; i < 500; i++) {
|
||||
if (i % 16 == 0) {
|
||||
Serial.printf("\n%03d: ", i);
|
||||
}
|
||||
Serial.printf("%03d ", espmega.fram.read8(i));
|
||||
}
|
||||
|
||||
// Dump FRAM again but treat it as a long string
|
||||
Serial.printf("\n\n");
|
||||
for (int i = 0; i < 500; i++) {
|
||||
Serial.printf("%d: %c\n", i,espmega.fram.read8(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
espmega.loop();
|
||||
}
|
|
@ -107,6 +107,18 @@ void setup() {
|
|||
Serial.println(sizeof(NetworkConfig));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Every 20 seconds, dump FRAM 0-500 to serial
|
||||
void loop() {
|
||||
espmega.loop();
|
||||
static uint32_t last_fram_dump = 0;
|
||||
if (millis() - last_fram_dump >= 20000) {
|
||||
last_fram_dump = millis();
|
||||
Serial.println("Dumping FRAM");
|
||||
espmega.dumpFRAMtoSerial(0, 500);
|
||||
Serial.println("Dumping FRAM ASCII");
|
||||
espmega.dumpFRAMtoSerialASCII(0, 500);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue