From a0de32e67d8a71dd31b984e5207451f95bb2c9a2 Mon Sep 17 00:00:00 2001 From: barbudor Date: Thu, 13 Oct 2022 21:27:06 +0200 Subject: [PATCH 01/13] get correct topic var --- tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino index ce6d71ec9..66d699bab 100755 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino @@ -4769,7 +4769,7 @@ extern char *SML_GetSVal(uint32_t index); goto strexit; } if (!strncmp(vname, "topic", 5)) { - if (sp) strlcpy(sp, SettingsText(SET_MQTT_TOPIC), glob_script_mem.max_ssize); + if (sp) strlcpy(sp, TasmotaGlobal.mqtt_topic, glob_script_mem.max_ssize); goto strexit; } #ifdef USE_SCRIPT_TIMER From 8d59dd800f8f245279e3394cdd3c22c3e587dfbf Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 14 Oct 2022 15:32:57 +0200 Subject: [PATCH 02/13] rm Domoticz / ad Counter --- tasmota/include/tasmota_configurations_ESP32.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tasmota/include/tasmota_configurations_ESP32.h b/tasmota/include/tasmota_configurations_ESP32.h index 6521ab0f1..a78b7ec2c 100644 --- a/tasmota/include/tasmota_configurations_ESP32.h +++ b/tasmota/include/tasmota_configurations_ESP32.h @@ -204,19 +204,31 @@ #undef USE_I2C #undef USE_HOME_ASSISTANT #define USE_TASMOTA_DISCOVERY // Enable Tasmota Discovery support (+2k code) -#undef USE_COUNTER +#undef USE_DOMOTICZ +#undef USE_LIGHT +#undef USE_SERIAL_BRIDGE +#undef ROTARY_V1 #undef USE_IR_REMOTE +#undef USE_ADC #undef USE_AC_ZERO_CROSS_DIMMER #undef USE_PWM_DIMMER +#undef USE_PWM_DIMMER_REMOTE #undef USE_TUYA_MCU #undef USE_EMULATION_HUE #undef USE_EMULATION_WEMO +#undef USE_BUZZER #undef USE_ARILUX_RF #undef USE_DS18x20 +#undef USE_BMP +#undef USE_DHT +#undef USE_BH1750 #undef USE_WS2812 #undef USE_ENERGY_SENSOR +#undef USE_SHUTTER +#undef USE_DEVICE_GROUPS //#undef USE_BERRY // Disable Berry scripting language #undef USE_MI_ESP32 // (ESP32 only) Disable support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) +#undef USE_BLE_ESP32 #endif // FIRMWARE_WEBCAM /*********************************************************************************************\ From 65672b62aef3a5d2551601282b129d75cca9a0e4 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Fri, 14 Oct 2022 17:14:35 +0200 Subject: [PATCH 03/13] Berry add access to `restart_flag` --- .../tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino index a3ebc17f1..614c31a43 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino @@ -33,11 +33,12 @@ extern "C" { extern const be_ctypes_structure_t be_tasmota_global_struct = { sizeof(TasmotaGlobal), /* size in bytes */ - 3, /* number of elements */ + 4, /* number of elements */ nullptr, - (const be_ctypes_structure_item_t[3]) { + (const be_ctypes_structure_item_t[4]) { { "devices_present", offsetof(TasmotaGlobal_t, devices_present), 0, 0, ctypes_u8, 0 }, { "fast_loop_enabled", offsetof(TasmotaGlobal_t, berry_fast_loop_enabled), 0, 0, ctypes_u8, 0 }, + { "restart_flag", offsetof(TasmotaGlobal_t, restart_flag), 0, 0, ctypes_u8, 0 }, { "sleep", offsetof(TasmotaGlobal_t, sleep), 0, 0, ctypes_u8, 0 }, }}; From 6783a90ccc3d7d57c97daccd26b8b3a8330a7a9f Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Fri, 14 Oct 2022 17:31:15 +0200 Subject: [PATCH 04/13] Add bootcount --- .../tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino index 614c31a43..417bac186 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota_global.ino @@ -44,9 +44,10 @@ extern "C" { extern const be_ctypes_structure_t be_tasmota_settings_struct = { sizeof(TSettings), /* size in bytes */ - 1, /* number of elements */ + 2, /* number of elements */ nullptr, - (const be_ctypes_structure_item_t[1]) { + (const be_ctypes_structure_item_t[2]) { + { "bootcount", offsetof(TSettings, bootcount), 0, 0, ctypes_u16, 0 }, { "sleep", offsetof(TSettings, sleep), 0, 0, ctypes_u8, 0 }, }}; From ee55903e0da2015693df0c0472e231f8371d2898 Mon Sep 17 00:00:00 2001 From: Christian Karsch Date: Fri, 14 Oct 2022 23:37:30 +0200 Subject: [PATCH 05/13] [BP5758D] Fix Sleep If all channels are set to 0, disable all channels on the driver and then set the driver into sleep-mode Otherwise wake up the driver when it is sleeping and active all channels --- tasmota/tasmota_xlgt_light/xlgt_08_bp5758d.ino | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tasmota/tasmota_xlgt_light/xlgt_08_bp5758d.ino b/tasmota/tasmota_xlgt_light/xlgt_08_bp5758d.ino index e2e93fe97..f0035180f 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_08_bp5758d.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_08_bp5758d.ino @@ -29,7 +29,7 @@ #define XLGT_08 8 // Layout: Bits B[7:8]=10 (address selection identification bits), B[5:6] sleep mode if set to 00, B[0:4] Address selection -#define BP5758D_ADDR_SLEEP 0x86 //10 00 0110: Sleep mode bits set (OUT1 gray-scale level setup selected, ignored by chip) +#define BP5758D_ADDR_SLEEP 0x80 //10 00 xxxx: Set to sleep mode #define BP5758D_ADDR_SETUP 0x90 //10 01 0000: OUT1-5 enable/disable setup - used during init #define BP5758D_ADDR_OUT1_CR 0x91 //10 01 0001: OUT1 current range #define BP5758D_ADDR_OUT2_CR 0x92 //10 01 0010: OUT2 current range @@ -44,6 +44,7 @@ // Output enabled (OUT1-5, represented by lower 5 bits) #define BP5758D_ENABLE_OUTPUTS_ALL 0x1F +#define BP5758D_DISABLE_OUTPUTS_ALL 0x00 // Current values: Bit 6 to 0 represent 30mA, 32mA, 16mA, 8mA, 4mA, 2mA, 1mA respectively #define BP5758D_10MA 0x0A // 0 0001010 @@ -106,14 +107,25 @@ void Bp5758dStop(void) { /********************************************************************************************/ bool Bp5758dSetChannels(void) { + static bool bIsSleeping = false; //Save sleep state of Lamp uint16_t *cur_col_10 = (uint16_t*)XdrvMailbox.command; // If we receive 0 for all channels, we'll assume that the lightbulb is off, and activate BP5758d's sleep mode. if (cur_col_10[0]==0 && cur_col_10[1]==0 && cur_col_10[2]==0 && cur_col_10[3]==0 && cur_col_10[4]==0) { + Bp5758dStart(BP5758D_ADDR_SETUP); + Bp5758dWrite(BP5758D_DISABLE_OUTPUTS_ALL); Bp5758dStart(BP5758D_ADDR_SLEEP); Bp5758dStop(); + bIsSleeping = true; return true; } + + if (bIsSleeping) { + bIsSleeping = false; //No need to run it every time a val gets changed + Bp5758dStart(BP5758D_ADDR_SETUP); //Sleep mode gets disabled too since bits 5:6 get set to 01 + Bp5758dWrite(BP5758D_ENABLE_OUTPUTS_ALL); //Set all outputs to ON + Bp5758dStop(); + } // Even though we could address changing channels only, in practice we observed that the lightbulb always sets all channels. Bp5758dStart(BP5758D_ADDR_OUT1_GL); From 169e65a922bfda0d91fbfe22b8f42473d963105e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 15 Oct 2022 14:33:21 +0200 Subject: [PATCH 06/13] Add ESP32 non-persistent phy selection --- .../ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp | 15 ++++++++++++--- .../ESP32-to-ESP8266-compat/src/ESP8266WiFi.h | 6 ++++++ tasmota/tasmota.ino | 1 + tasmota/tasmota_support/support_command.ino | 8 ++++++-- tasmota/tasmota_support/support_wifi.ino | 5 +++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp index 9f932040c..b700f2955 100644 --- a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp +++ b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP32Wifi.cpp @@ -37,14 +37,23 @@ int WiFiClass32::getPhyMode() { int phy_mode = 0; // " BGNL" uint8_t protocol_bitmap; if (esp_wifi_get_protocol(WIFI_IF_STA, &protocol_bitmap) == ESP_OK) { - if (protocol_bitmap & 1) { phy_mode = 1; } // 11b - if (protocol_bitmap & 2) { phy_mode = 2; } // 11g - if (protocol_bitmap & 4) { phy_mode = 3; } // 11n + if (protocol_bitmap & 1) { phy_mode = WIFI_PHY_MODE_11B; } // 1 = 11b + if (protocol_bitmap & 2) { phy_mode = WIFI_PHY_MODE_11G; } // 2 = 11bg + if (protocol_bitmap & 4) { phy_mode = WIFI_PHY_MODE_11N; } // 3 = 11bgn if (protocol_bitmap & 8) { phy_mode = 4; } // Low rate } return phy_mode; } +bool WiFiClass32::setPhyMode(WiFiPhyMode_t mode) { + uint8_t protocol_bitmap = WIFI_PROTOCOL_11B; // 1 + switch (mode) { + case 3: protocol_bitmap |= WIFI_PROTOCOL_11N; // 4 + case 2: protocol_bitmap |= WIFI_PROTOCOL_11G; // 2 + } + return (ESP_OK == esp_wifi_set_protocol(WIFI_IF_STA, protocol_bitmap)); +} + void WiFiClass32::wps_disable() { } diff --git a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h index 97f9c842c..e7a760164 100644 --- a/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h +++ b/lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h @@ -32,6 +32,11 @@ #define WIFI_LIGHT_SLEEP 1 #define WIFI_MODEM_SLEEP 2 +typedef enum WiFiPhyMode +{ + WIFI_PHY_MODE_11B = 1, WIFI_PHY_MODE_11G = 2, WIFI_PHY_MODE_11N = 3 +} WiFiPhyMode_t; + class WiFiClass32 : public WiFiClass { public: @@ -41,6 +46,7 @@ public: } static void setSleepMode(int iSleepMode); static int getPhyMode(); + static bool setPhyMode(WiFiPhyMode_t mode); static void wps_disable(); static void setOutputPower(int n); diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 493028b1e..4a820a229 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -114,6 +114,7 @@ struct WIFI { uint8_t wifi_test_counter = 0; uint16_t save_data_counter = 0; uint8_t old_wificonfig = MAX_WIFI_OPTION; // means "nothing yet saved here" + uint8_t phy_mode = 0; bool wifi_test_AP_TIMEOUT = false; bool wifi_Test_Restart = false; bool wifi_Test_Save_SSID2 = false; diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index 8c1a1744e..6086572db 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -2478,10 +2478,14 @@ void CmndWifi(void) WifiEnable(); #endif } -#ifdef ESP8266 } else if ((XdrvMailbox.payload >= 2) && (XdrvMailbox.payload <= 4)) { - WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN + // Wifi 2 = B + // Wifi 3 = BG + // Wifi 4 = BGN +#ifdef ESP32 + Wifi.phy_mode = XdrvMailbox.payload - 1; #endif + WiFi.setPhyMode(WiFiPhyMode_t(XdrvMailbox.payload - 1)); // 1-B/2-BG/3-BGN } Response_P(PSTR("{\"" D_JSON_WIFI "\":\"%s\",\"" D_JSON_WIFI_MODE "\":\"11%c\"}"), GetStateText(Settings->flag4.network_wifi), pgm_read_byte(&kWifiPhyMode[WiFi.getPhyMode() & 0x3]) ); } diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index 9bce4cda4..0700fcc2d 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -217,6 +217,11 @@ void WifiBegin(uint8_t flag, uint8_t channel) WiFiSetSleepMode(); // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G +#ifdef ESP32 + if (Wifi.phy_mode) { + WiFi.setPhyMode(WiFiPhyMode_t(Wifi.phy_mode)); // 1-B/2-BG/3-BGN + } +#endif if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); } // WiFi.setAutoReconnect(true); switch (flag) { From e1af7ba12ac6cde84447e5836f8540ce4e9fcf79 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sat, 15 Oct 2022 16:26:02 +0200 Subject: [PATCH 07/13] `USE_LIGHT` needed for flashlight --- tasmota/include/tasmota_configurations_ESP32.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tasmota/include/tasmota_configurations_ESP32.h b/tasmota/include/tasmota_configurations_ESP32.h index a78b7ec2c..e5bd679c9 100644 --- a/tasmota/include/tasmota_configurations_ESP32.h +++ b/tasmota/include/tasmota_configurations_ESP32.h @@ -205,7 +205,6 @@ #undef USE_HOME_ASSISTANT #define USE_TASMOTA_DISCOVERY // Enable Tasmota Discovery support (+2k code) #undef USE_DOMOTICZ -#undef USE_LIGHT #undef USE_SERIAL_BRIDGE #undef ROTARY_V1 #undef USE_IR_REMOTE From 8742770fb4630d96cf3d9ed2c71833029b52f842 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Sun, 16 Oct 2022 00:03:07 +0200 Subject: [PATCH 08/13] take 1 --- tasmota/my_user_config.h | 1 + .../tasmota_xsns_sensor/xsns_13_ina219.ino | 202 ++++++++++-------- 2 files changed, 111 insertions(+), 92 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 751a48b44..98bd812fa 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -598,6 +598,7 @@ #define USE_VEML6070_SHOW_RAW // VEML6070, shows the raw value of UV-A // #define USE_ADS1115 // [I2cDriver13] Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code) // #define USE_INA219 // [I2cDriver14] Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code) + // #define INA219_SHUNT_RESISTOR (0.100) // 0.1 Ohm default shunt resistor, can be overriden in user_config_override or using Sensor13 // #define USE_INA226 // [I2cDriver35] Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code) // #define USE_SHT3X // [I2cDriver15] Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code) // #define USE_TSL2561 // [I2cDriver16] Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code) diff --git a/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino b/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino index 0684e3cee..8c6fc0fbc 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino @@ -31,7 +31,22 @@ #define XSNS_13 13 #define XI2C_14 14 // See I2CDEVICES.md +#ifndef INA219_MAX_COUNT #define INA219_MAX_COUNT 4 +#endif +#if (INA219_MAX_COUNT > 4) +#error "**** INA219_MAX_COUNT can't be greater than 4 ****" +#endif +#ifndef INA219_FIRST_ADDRESS +#define INA219_FIRST_ADDRESS (0) +#endif +#if ((INA219_FIRST_ADDRESS + INA219_MAX_COUNT) > 4) +#error "**** INA219 bad combination for FIRST_ADDRESS and MAX_COUNT ****" +#endif + +#ifndef INA219_SHUNT_RESISTOR +#define INA219_SHUNT_RESISTOR (0.100) // 0.1 Ohm default on most INA219 modules +#endif #define INA219_ADDRESS1 (0x40) // 1000000 (A0+A1=GND) #define INA219_ADDRESS2 (0x41) // 1000000 (A0=Vcc, A1=GND) @@ -101,34 +116,36 @@ #define ISL28022_REG_INTRSTATUS (0x08) #define ISL28022_REG_AUXCTRL (0x09) -#define INA219_DEFAULT_SHUNT_RESISTOR_MILLIOHMS (100.0) // 0.1 Ohm +#define INA219_BUS_ADC_LSB (0.004) // VBus ADC LSB=4mV=0.004V +#define INA219_SHUNT_ADC_LSB_MV (0.01) // VShunt ADC LSB=10µV=0.01mV + + #ifdef DEBUG_TASMOTA_SENSOR // temporary strings for floating point in debug messages -char __ina219_dbg1[10]; -char __ina219_dbg2[10]; +char __ina219_dbg1[FLOATSZ]; +char __ina219_dbg2[FLOATSZ]; #endif -#define INA219_ACTIVE 1 -#define ISL28022_ACTIVE 2 - -struct INA219_Channel_Data { - float voltage; - float current; - uint8_t active; - uint8_t valid; -}; +#define INA219_MODEL 1 +#define ISL28022_MODEL 2 struct INA219_Data { - struct INA219_Channel_Data chan[INA219_MAX_COUNT]; + float voltage; + float current; // The following multiplier is used to convert shunt voltage (in mV) to current (in A) // Current_A = ShuntVoltage_mV / ShuntResistor_milliOhms = ShuntVoltage_mV * ina219_current_multiplier // ina219_current_multiplier = 1 / ShuntResistor_milliOhms - float current_multiplier; - uint8_t count; + float current_multiplier; + uint8_t model; + uint8_t addr; }; struct INA219_Data *Ina219Data = nullptr; +uint8_t Ina219Count = 0; + +const char INA219_SENSORCMND_START[] PROGMEM = "{\"" D_CMND_SENSOR "%d\":{\"mode\":%d,\"rshunt\":["; +const char INA219_SENSORCMND_END[] PROGMEM = "]}}"; const char *INA219_TYPE[] = { "INA219", "ISL28022" }; const uint8_t INA219_ADDRESSES[] = { INA219_ADDRESS1, INA219_ADDRESS2, INA219_ADDRESS3, INA219_ADDRESS4 }; @@ -148,58 +165,60 @@ const uint8_t INA219_ADDRESSES[] = { INA219_ADDRESS1, INA219_ADDRESS2, INA219_AD * Note that some shunt values can be represented by 2 different encoded values such as * 11 or 100 both present 10 milliOhms * Because it is difficult to make a range check on such encoded value, none is performed - * +\*********************************************************************************************/ +void Ina219SetShuntMode(uint8_t index, uint8_t mode, float shunt) +{ + if (mode < 10) { + // All legacy modes: shunt is INA219_SHUNT_RESISTOR unless provided by `Sensor13 ` + // Shunt value provided this way is NOT stored in flash and requires an "on system#boot" rule + } else { + // Modes >= 10 allow to provide shunt values that is stored in flash but limited in possible + // values due to the encoding mode used to store the value in a single uint8_t + int mult = mode % 10; + int shunt_milliOhms = mode / 10; + shunt = shunt_milliOhms / 1000.0; + for ( ; mult > 0 ; mult-- ) + shunt *= 10.0; + } + Ina219Data[index].current_multiplier = 0.001 / shunt; + #ifdef DEBUG_TASMOTA_SENSOR + dtostrfd(shunt,6,__ina219_dbg1); + dtostrfd(Ina219Data[index].current_multiplier,5,__ina219_dbg2); + DEBUG_SENSOR_LOG("Ina219SetShuntMode[%d]: mode=%d, shunt=%s, cur_mul=%s", index, mode, __ina219_dbg1, __ina219_dbg2); + #endif +} + +float Ina219GetShunt(uint8_t index) +{ + return 0.001 / Ina219Data[index].current_multiplier; +} + +/*********************************************************************************************\ * Return 0 if configuration failed * Return 1 if chip identified as INA219 * Return 2 if chip identified as ISL28022 \*********************************************************************************************/ -uint8_t Ina219SetCalibration(uint8_t mode, uint16_t addr) +uint8_t Ina219Init(uint16_t addr) { uint16_t config = 0; - DEBUG_SENSOR_LOG("Ina219SetCalibration: mode=%d",mode); - if (mode < 5) - { - // All legacy modes 0..2 are handled the same and consider default 0.1 shunt resistor - Ina219Data->current_multiplier = 1.0 / INA219_DEFAULT_SHUNT_RESISTOR_MILLIOHMS; - #ifdef DEBUG_TASMOTA_SENSOR - dtostrfd(Ina219Data->current_multiplier,5,__ina219_dbg1); - DEBUG_SENSOR_LOG("Ina219SetCalibration: cur_mul=%s",__ina219_dbg1); - #endif - } - else if (mode >= 10) - { - int mult = mode % 10; - int shunt_milliOhms = mode / 10; - for ( ; mult > 0 ; mult-- ) - shunt_milliOhms *= 10; - Ina219Data->current_multiplier = 1.0 / shunt_milliOhms; - #ifdef DEBUG_TASMOTA_SENSOR - dtostrfd(Ina219Data->current_multiplier,5,__ina219_dbg1); - DEBUG_SENSOR_LOG("Ina219SetCalibration: shunt=%dmO => cur_mul=%s",shunt_milliOhms,__ina219_dbg1); - #endif - } config = ISL28022_CONFIG_BVOLTAGERANGE_60V // If INA219 0..32V, If ISL28022 0..60V | INA219_CONFIG_GAIN_8_320MV // Use max scale | INA219_CONFIG_BADCRES_12BIT_16S_8510US // use averaging to improve accuracy | INA219_CONFIG_SADCRES_12BIT_16S_8510US // use averaging to improve accuracy | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - #ifdef DEBUG_TASMOTA_SENSOR - AddLog(LOG_LEVEL_DEBUG, PSTR("Ina219SetCalibration: Config=0x%04X (%d)"), config, config); - #endif + DEBUG_SENSOR_LOG(PSTR("Ina219Init: Config=0x%04X (%d)"), config, config); // Set Config register to take into account the settings above if (!I2cWrite16(addr, INA219_REG_CONFIG, config)) return 0; uint16_t intr_reg = 0x0FFFF; bool status = I2cValidRead16(&intr_reg, addr, ISL28022_REG_INTRSTATUS); - #ifdef DEBUG_TASMOTA_SENSOR - AddLog(LOG_LEVEL_DEBUG, PSTR("Ina219: IntrReg=0x%04X (%d)"), intr_reg, status); - #endif + DEBUG_SENSOR_LOG(PSTR("Ina219Init: IntrReg=0x%04X (%d)"), intr_reg, status); if (status && 0 == intr_reg) - return ISL28022_ACTIVE; // ISL28022 - return INA219_ACTIVE; // INA219 + return ISL28022_MODEL; // ISL28022 + return INA219_MODEL; // INA219 } float Ina219GetShuntVoltage_mV(uint16_t addr) @@ -208,48 +227,39 @@ float Ina219GetShuntVoltage_mV(uint16_t addr) int16_t shunt_voltage = I2cReadS16(addr, INA219_REG_SHUNTVOLTAGE); DEBUG_SENSOR_LOG("Ina219GetShuntVoltage_mV: ShReg = 0x%04X (%d)",shunt_voltage, shunt_voltage); // convert to shunt voltage in mV (so +-327mV) (LSB=10µV=0.01mV) - return (float)shunt_voltage * 0.01; + return (float)shunt_voltage * INA219_SHUNT_ADC_LSB_MV; } float Ina219GetBusVoltage_V(uint16_t addr, uint8_t model) { uint16_t bus_voltage = I2cRead16(addr, INA219_REG_BUSVOLTAGE); - if (ISL28022_ACTIVE == model) { - // ISL2802 LSB is bit 2 - bus_voltage >>= 2; - DEBUG_SENSOR_LOG("Isl28022GetBusVoltage_V: BusReg = 0x%04X (%d)",bus_voltage, bus_voltage); - } - else { - // INA219 LSB is bit 3 - bus_voltage >>= 3; - DEBUG_SENSOR_LOG("Ina219GetBusVoltage_V: BusReg = 0x%04X (%d)",bus_voltage, bus_voltage); - } + bus_voltage >>= (ISL28022_MODEL == model) ? 2 : 3; + DEBUG_SENSOR_LOG("Ina219GetBusVoltage_V: BusReg = 0x%04X (%d)",bus_voltage, bus_voltage); // and multiply by LSB raw bus voltage to return bus voltage in volts (LSB=4mV=0.004V) - return (float)bus_voltage * 0.004; + return (float)bus_voltage * INA219_BUS_ADC_LSB; } bool Ina219Read(void) { - for (int i=0; ichan[i].active) { continue; } - uint16_t addr = INA219_ADDRESSES[i]; - float bus_voltage_V = Ina219GetBusVoltage_V(addr, Ina219Data->chan[i].active); + for (int i=0; ichan[i].voltage = bus_voltage_V + (shunt_voltage_mV / 1000); + Ina219Data[i].voltage = bus_voltage_V + (shunt_voltage_mV / 1000); // current is simply calculted from shunt voltage using pre-calculated multiplier - Ina219Data->chan[i].current = shunt_voltage_mV * Ina219Data->current_multiplier; + Ina219Data[i].current = shunt_voltage_mV * Ina219Data[i].current_multiplier; #ifdef DEBUG_TASMOTA_SENSOR - dtostrfd(Ina219Data->chan[i].voltage,5,__ina219_dbg1); - dtostrfd(Ina219Data->chan[i].current,5,__ina219_dbg2); - DEBUG_SENSOR_LOG("Ina219Read: V=%sV, I=%smA",__ina219_dbg1,__ina219_dbg2); + dtostrfd(Ina219Data[i].voltage,5,__ina219_dbg1); + dtostrfd(Ina219Data[i].current,5,__ina219_dbg2); + DEBUG_SENSOR_LOG("Ina219Read[%d]: V=%sV, I=%smA", i, __ina219_dbg1,__ina219_dbg2); #endif - Ina219Data->chan[i].valid = SENSOR_MAX_MISS; } return true; } @@ -260,11 +270,24 @@ bool Ina219Read(void) bool Ina219CommandSensor(void) { + char argument[XdrvMailbox.data_len]; + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 255)) { Settings->ina219_mode = XdrvMailbox.payload; - TasmotaGlobal.restart_flag = 2; + for (int i=0; i (i +1)) { + shunt = CharToFloat(ArgV(argument, 2 +i)); + } + Ina219SetShuntMode(i, Settings->ina219_mode, shunt); + } } - Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_13, Settings->ina219_mode); + Response_P(INA219_SENSORCMND_START, XSNS_13, Settings->ina219_mode); + for (int i = 0 ; i < Ina219Count ; i++ ) { + dtostrfd(Ina219GetShunt(i),5,argument); + ResponseAppend_P(PSTR("%s%c"), argument, ((i < (Ina219Count-1))?',':'\0')); + } + ResponseAppend_P(INA219_SENSORCMND_END); return true; } @@ -274,20 +297,22 @@ bool Ina219CommandSensor(void) void Ina219Detect(void) { for (uint32_t i = 0; i < INA219_MAX_COUNT; i++) { - uint16_t addr = INA219_ADDRESSES[i]; + uint16_t addr = INA219_ADDRESSES[INA219_FIRST_ADDRESS +i]; if (!I2cSetDevice(addr)) { continue; } if (!Ina219Data) { - Ina219Data = (struct INA219_Data*)calloc(1,sizeof(struct INA219_Data)); + Ina219Data = (struct INA219_Data*)calloc(INA219_MAX_COUNT,sizeof(struct INA219_Data)); if (!Ina219Data) { AddLog(LOG_LEVEL_ERROR,PSTR("INA219: Mem Error")); return; } } - int model = Ina219SetCalibration(Settings->ina219_mode, addr); + int model = Ina219Init(addr); if (model) { I2cSetActiveFound(addr, INA219_TYPE[model-1]); - Ina219Data->chan[i].active = model; - Ina219Data->count++; + Ina219SetShuntMode(Ina219Count, Settings->ina219_mode, INA219_SHUNT_RESISTOR); + Ina219Data[Ina219Count].model = model; + Ina219Data[Ina219Count].addr = addr; + Ina219Count++; } } } @@ -307,28 +332,21 @@ const char HTTP_SNS_INA219_DATA[] PROGMEM = void Ina219Show(bool json) { - int num_found=0; - for (int i=0; ichan[i].active && Ina219Data->chan[i].valid) - num_found++; - - int sensor_num = 0; - for (int i=0; ichan[i].active && !Ina219Data->chan[i].valid) + for (int i = 0; i < Ina219Count; i++) { + if (!Ina219Data[i].model) continue; - sensor_num++; char voltage[16]; - dtostrfd(Ina219Data->chan[i].voltage, Settings->flag2.voltage_resolution, voltage); + dtostrfd(Ina219Data[i].voltage, Settings->flag2.voltage_resolution, voltage); char current[16]; - dtostrfd(Ina219Data->chan[i].current, Settings->flag2.current_resolution, current); + dtostrfd(Ina219Data[i].current, Settings->flag2.current_resolution, current); char power[16]; - dtostrfd(Ina219Data->chan[i].voltage * Ina219Data->chan[i].current, Settings->flag2.wattage_resolution, power); + dtostrfd(Ina219Data[i].voltage * Ina219Data[i].current, Settings->flag2.wattage_resolution, power); char name[16]; - if (num_found>1) - snprintf_P(name, sizeof(name), PSTR("%s%c%d"), INA219_TYPE[Ina219Data->chan[i].active-1], IndexSeparator(), sensor_num); + if (Ina219Count>1) + snprintf_P(name, sizeof(name), PSTR("%s%c%d"), INA219_TYPE[Ina219Data[i].model-1], IndexSeparator(), i +1); else - snprintf_P(name, sizeof(name), PSTR("%s"), INA219_TYPE[Ina219Data->chan[i].active-1]); + snprintf_P(name, sizeof(name), PSTR("%s"), INA219_TYPE[Ina219Data[i].model-1]); if (json) { ResponseAppend_P(PSTR(",\"%s\":{\"Id\":%02x,\"" D_JSON_VOLTAGE "\":%s,\"" D_JSON_CURRENT "\":%s,\"" D_JSON_POWERUSAGE "\":%s}"), From 292183291291f199d36328ada64dc2b7e2c17325 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Sun, 16 Oct 2022 00:21:30 +0200 Subject: [PATCH 09/13] spacing --- tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino b/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino index 8c6fc0fbc..50e9a39e5 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_13_ina219.ino @@ -241,7 +241,7 @@ float Ina219GetBusVoltage_V(uint16_t addr, uint8_t model) bool Ina219Read(void) { - for (int i=0; i= 0) && (XdrvMailbox.payload <= 255)) { Settings->ina219_mode = XdrvMailbox.payload; - for (int i=0; i (i +1)) { shunt = CharToFloat(ArgV(argument, 2 +i)); From 5e0306688393897ffb00b3d69f8874a74b5ea1f0 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 16 Oct 2022 11:49:30 +0200 Subject: [PATCH 10/13] Resize FS to max at initial boot --- .../src/embedded/partition_core.be | 99 ++ .../src/solidify/solidified_partition_core.h | 1225 +++++++++++------ .../xdrv_52_7_berry_embedded.ino | 8 + 3 files changed, 908 insertions(+), 424 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/embedded/partition_core.be b/lib/libesp32/berry_tasmota/src/embedded/partition_core.be index 93b090e37..0c6623936 100644 --- a/lib/libesp32/berry_tasmota/src/embedded/partition_core.be +++ b/lib/libesp32/berry_tasmota/src/embedded/partition_core.be @@ -506,6 +506,105 @@ class Partition self.otadata.save() end + # Internal: returns which flash sector contains the partition definition + # Returns 0 or 1, or `nil` if something went wrong + # Note: partition flash sector vary from ESP32 to ESP32C3/S3 + static def get_flash_definition_sector() + import flash + for i:0..1 + var offset = i * 0x1000 + if flash.read(offset, 1) == bytes('E9') return offset end + end + end + + # Internal: returns the maximum flash size possible + # Returns max flash size ok kB + def get_max_flash_size_k() + var flash_size_k = tasmota.memory()['flash'] + var flash_size_real_k = tasmota.memory().find("flash_real", flash_size_k) + if (flash_size_k != flash_size_real_k) && self.get_flash_definition_sector() != nil + flash_size_k = flash_size_real_k # try to expand the flash size definition + end + return flash_size_k + end + + # Internal: returns the unallocated flash size (in kB) beyond the file-system + # this indicates that the file-system can be extended (although erased at the same time) + def get_unallocated_k() + var last_slot = self.slots[-1] + if last_slot.is_spiffs() + # verify that last slot is filesystem + var flash_size_k = self.get_max_flash_size_k() + var partition_end_k = (last_slot.start + last_slot.sz) / 1024 # last kb used for fs + if partition_end_k < flash_size_k + return flash_size_k - partition_end_k + end + end + return 0 + end + + #- ---------------------------------------------------------------------- -# + #- Resize flash definition if needed + #- ---------------------------------------------------------------------- -# + def resize_max_flash_size_k() + var flash_size_k = tasmota.memory()['flash'] + var flash_size_real_k = tasmota.memory().find("flash_real", flash_size_k) + var flash_definition_sector = self.get_flash_definition_sector() + if (flash_size_k != flash_size_real_k) && flash_definition_sector != nil + import flash + import string + + flash_size_k = flash_size_real_k # try to expand the flash size definition + + var flash_def = flash.read(flash_definition_sector, 4) + var size_before = flash_def[3] + + var flash_size_code + var flash_size_real_m = flash_size_real_k / 1024 # size in MB + if flash_size_real_m == 1 flash_size_code = 0x00 + elif flash_size_real_m == 2 flash_size_code = 0x10 + elif flash_size_real_m == 4 flash_size_code = 0x20 + elif flash_size_real_m == 8 flash_size_code = 0x30 + elif flash_size_real_m == 16 flash_size_code = 0x40 + end + + if flash_size_code != nil + # apply the update + var old_def = flash_def[3] + flash_def[3] = (flash_def[3] & 0x0F) | flash_size_code + flash.write(flash_definition_sector, flash_def) + tasmota.log(string.format("UPL: changing flash definition from 0x02X to 0x%02X", old_def, flash_def[3]), 3) + else + raise "internal_error", "wrong flash size "+str(flash_size_real_m) + end + end + end + + # Called at first boot + # Try to expand FS to max of flash size + def resize_fs_to_max() + import string + try + var unallocated = self.get_unallocated_k() + if unallocated <= 0 return nil end + + tasmota.log(string.format("BRY: Trying to expand FS by %i kB", unallocated), 2) + + self.resize_max_flash_size_k() # resize if needed + # since unallocated succeeded, we know the last slot is FS + var fs_slot = self.slots[-1] + fs_slot.sz += unallocated * 1024 + self.save() + self.invalidate_spiffs() # erase SPIFFS or data is corrupt + + # restart + tasmota.global.restart_flag = 2 + tasmota.log("BRY: Successfully resized FS, restarting", 2) + except .. as e, m + tasmota.log(string.format("BRY: Exception> '%s' - %s", e, m), 2) + end + end + #- invalidate SPIFFS partition to force format at next boot -# #- we simply erase the first byte of the first 2 blocks in the SPIFFS partition -# def invalidate_spiffs() diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h index d79d19cff..7c9686b98 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_partition_core.h @@ -499,11 +499,11 @@ be_local_class(Partition_otadata, ); /******************************************************************** -** Solidified function: tobytes +** Solidified function: save ********************************************************************/ -be_local_closure(Partition_tobytes, /* name */ +be_local_closure(Partition_save, /* name */ be_nested_proto( - 6, /* nstack */ + 7, /* nstack */ 1, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -511,55 +511,32 @@ be_local_closure(Partition_tobytes, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 9]) { /* constants */ - /* K0 */ be_nested_str(slots), - /* K1 */ be_nested_str(value_error), - /* K2 */ be_nested_str(Too_X20many_X20partiition_X20slots), - /* K3 */ be_nested_str(tobytes), - /* K4 */ be_nested_str(stop_iteration), - /* K5 */ be_nested_str(MD5), - /* K6 */ be_nested_str(update), - /* K7 */ be_nested_str(EBEBFFFFFFFFFFFFFFFFFFFFFFFFFFFF), - /* K8 */ be_nested_str(finish), + ( &(const bvalue[ 6]) { /* constants */ + /* K0 */ be_nested_str(flash), + /* K1 */ be_nested_str(tobytes), + /* K2 */ be_nested_str(erase), + /* K3 */ be_nested_str(write), + /* K4 */ be_nested_str(otadata), + /* K5 */ be_nested_str(save), }), - &be_const_str_tobytes, + &be_const_str_save, &be_const_str_solidified, - ( &(const binstruction[35]) { /* code */ - 0x6004000C, // 0000 GETGBL R1 G12 - 0x88080100, // 0001 GETMBR R2 R0 K0 - 0x7C040200, // 0002 CALL R1 1 - 0x540A005E, // 0003 LDINT R2 95 - 0x24040202, // 0004 GT R1 R1 R2 - 0x78060000, // 0005 JMPF R1 #0007 - 0xB0060302, // 0006 RAISE 1 K1 K2 - 0x60040015, // 0007 GETGBL R1 G21 - 0x7C040000, // 0008 CALL R1 0 - 0x60080010, // 0009 GETGBL R2 G16 - 0x880C0100, // 000A GETMBR R3 R0 K0 - 0x7C080200, // 000B CALL R2 1 - 0xA8020005, // 000C EXBLK 0 #0013 - 0x5C0C0400, // 000D MOVE R3 R2 - 0x7C0C0000, // 000E CALL R3 0 - 0x8C100703, // 000F GETMET R4 R3 K3 - 0x7C100200, // 0010 CALL R4 1 - 0x00040204, // 0011 ADD R1 R1 R4 - 0x7001FFF9, // 0012 JMP #000D - 0x58080004, // 0013 LDCONST R2 K4 - 0xAC080200, // 0014 CATCH R2 1 0 - 0xB0080000, // 0015 RAISE 2 R0 R0 - 0xB80A0A00, // 0016 GETNGBL R2 K5 - 0x7C080000, // 0017 CALL R2 0 - 0x8C0C0506, // 0018 GETMET R3 R2 K6 - 0x5C140200, // 0019 MOVE R5 R1 - 0x7C0C0400, // 001A CALL R3 2 - 0x600C0015, // 001B GETGBL R3 G21 - 0x58100007, // 001C LDCONST R4 K7 - 0x7C0C0200, // 001D CALL R3 1 - 0x00040203, // 001E ADD R1 R1 R3 - 0x8C0C0508, // 001F GETMET R3 R2 K8 - 0x7C0C0200, // 0020 CALL R3 1 - 0x00040203, // 0021 ADD R1 R1 R3 - 0x80040200, // 0022 RET 1 R1 + ( &(const binstruction[15]) { /* code */ + 0xA4060000, // 0000 IMPORT R1 K0 + 0x8C080101, // 0001 GETMET R2 R0 K1 + 0x7C080200, // 0002 CALL R2 1 + 0x8C0C0302, // 0003 GETMET R3 R1 K2 + 0x54167FFF, // 0004 LDINT R5 32768 + 0x541A0FFF, // 0005 LDINT R6 4096 + 0x7C0C0600, // 0006 CALL R3 3 + 0x8C0C0303, // 0007 GETMET R3 R1 K3 + 0x54167FFF, // 0008 LDINT R5 32768 + 0x5C180400, // 0009 MOVE R6 R2 + 0x7C0C0600, // 000A CALL R3 3 + 0x880C0104, // 000B GETMBR R3 R0 K4 + 0x8C0C0705, // 000C GETMET R3 R3 K5 + 0x7C0C0200, // 000D CALL R3 1 + 0x80000000, // 000E RET 0 }) ) ); @@ -567,9 +544,9 @@ be_local_closure(Partition_tobytes, /* name */ /******************************************************************** -** Solidified function: tostring +** Solidified function: load ********************************************************************/ -be_local_closure(Partition_tostring, /* name */ +be_local_closure(Partition_load, /* name */ be_nested_proto( 6, /* nstack */ 1, /* argc */ @@ -579,43 +556,50 @@ be_local_closure(Partition_tostring, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 9]) { /* constants */ - /* K0 */ be_nested_str(_X3Cinstance_X3A_X20Partition_X28_X5B_X0A), - /* K1 */ be_nested_str(slots), - /* K2 */ be_nested_str(_X20_X20), - /* K3 */ be_nested_str(tostring), - /* K4 */ be_nested_str(_X0A), - /* K5 */ be_nested_str(stop_iteration), - /* K6 */ be_nested_str(_X5D_X2C_X0A_X20_X20), - /* K7 */ be_nested_str(otadata), - /* K8 */ be_nested_str(_X0A_X29_X3E), + ( &(const bvalue[ 3]) { /* constants */ + /* K0 */ be_nested_str(flash), + /* K1 */ be_nested_str(raw), + /* K2 */ be_nested_str(read), }), - &be_const_str_tostring, + &be_const_str_load, &be_const_str_solidified, - ( &(const binstruction[23]) { /* code */ - 0x58040000, // 0000 LDCONST R1 K0 - 0x60080010, // 0001 GETGBL R2 G16 - 0x880C0101, // 0002 GETMBR R3 R0 K1 - 0x7C080200, // 0003 CALL R2 1 - 0xA8020007, // 0004 EXBLK 0 #000D - 0x5C0C0400, // 0005 MOVE R3 R2 - 0x7C0C0000, // 0006 CALL R3 0 - 0x00040302, // 0007 ADD R1 R1 K2 - 0x8C100703, // 0008 GETMET R4 R3 K3 - 0x7C100200, // 0009 CALL R4 1 - 0x00040204, // 000A ADD R1 R1 R4 - 0x00040304, // 000B ADD R1 R1 K4 - 0x7001FFF7, // 000C JMP #0005 - 0x58080005, // 000D LDCONST R2 K5 - 0xAC080200, // 000E CATCH R2 1 0 - 0xB0080000, // 000F RAISE 2 R0 R0 - 0x00040306, // 0010 ADD R1 R1 K6 - 0x88080107, // 0011 GETMBR R2 R0 K7 - 0x8C080503, // 0012 GETMET R2 R2 K3 - 0x7C080200, // 0013 CALL R2 1 - 0x00040202, // 0014 ADD R1 R1 R2 - 0x00040308, // 0015 ADD R1 R1 K8 - 0x80040200, // 0016 RET 1 R1 + ( &(const binstruction[ 7]) { /* code */ + 0xA4060000, // 0000 IMPORT R1 K0 + 0x8C080302, // 0001 GETMET R2 R1 K2 + 0x54127FFF, // 0002 LDINT R4 32768 + 0x54160FFF, // 0003 LDINT R5 4096 + 0x7C080600, // 0004 CALL R2 3 + 0x90020202, // 0005 SETMBR R0 K1 R2 + 0x80000000, // 0006 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: get_active +********************************************************************/ +be_local_closure(Partition_get_active, /* name */ + be_nested_proto( + 2, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 2]) { /* constants */ + /* K0 */ be_nested_str(otadata), + /* K1 */ be_nested_str(active_otadata), + }), + &be_const_str_get_active, + &be_const_str_solidified, + ( &(const binstruction[ 3]) { /* code */ + 0x88040100, // 0000 GETMBR R1 R0 K0 + 0x88040301, // 0001 GETMBR R1 R1 K1 + 0x80040200, // 0002 RET 1 R1 }) ) ); @@ -660,229 +644,6 @@ be_local_closure(Partition_init, /* name */ /*******************************************************************/ -/******************************************************************** -** Solidified function: get_active -********************************************************************/ -be_local_closure(Partition_get_active, /* name */ - be_nested_proto( - 2, /* nstack */ - 1, /* argc */ - 2, /* varg */ - 0, /* has upvals */ - NULL, /* no upvals */ - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 2]) { /* constants */ - /* K0 */ be_nested_str(otadata), - /* K1 */ be_nested_str(active_otadata), - }), - &be_const_str_get_active, - &be_const_str_solidified, - ( &(const binstruction[ 3]) { /* code */ - 0x88040100, // 0000 GETMBR R1 R0 K0 - 0x88040301, // 0001 GETMBR R1 R1 K1 - 0x80040200, // 0002 RET 1 R1 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: switch_factory -********************************************************************/ -be_local_closure(Partition_switch_factory, /* name */ - be_nested_proto( - 6, /* nstack */ - 2, /* argc */ - 2, /* varg */ - 0, /* has upvals */ - NULL, /* no upvals */ - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 2]) { /* constants */ - /* K0 */ be_nested_str(flash), - /* K1 */ be_nested_str(factory), - }), - &be_const_str_switch_factory, - &be_const_str_solidified, - ( &(const binstruction[ 5]) { /* code */ - 0xA40A0000, // 0000 IMPORT R2 K0 - 0x8C0C0501, // 0001 GETMET R3 R2 K1 - 0x5C140200, // 0002 MOVE R5 R1 - 0x7C0C0400, // 0003 CALL R3 2 - 0x80000000, // 0004 RET 0 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: invalidate_spiffs -********************************************************************/ -be_local_closure(Partition_invalidate_spiffs, /* name */ - be_nested_proto( - 8, /* nstack */ - 1, /* argc */ - 2, /* varg */ - 0, /* has upvals */ - NULL, /* no upvals */ - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 8]) { /* constants */ - /* K0 */ be_nested_str(flash), - /* K1 */ be_nested_str(slots), - /* K2 */ be_nested_str(is_spiffs), - /* K3 */ be_nested_str(value_error), - /* K4 */ be_nested_str(No_X20SPIFFS_X20partition_X20found), - /* K5 */ be_nested_str(00), - /* K6 */ be_nested_str(write), - /* K7 */ be_nested_str(start), - }), - &be_const_str_invalidate_spiffs, - &be_const_str_solidified, - ( &(const binstruction[22]) { /* code */ - 0xA4060000, // 0000 IMPORT R1 K0 - 0x5409FFFE, // 0001 LDINT R2 -1 - 0x880C0101, // 0002 GETMBR R3 R0 K1 - 0x94080602, // 0003 GETIDX R2 R3 R2 - 0x8C100502, // 0004 GETMET R4 R2 K2 - 0x7C100200, // 0005 CALL R4 1 - 0x74120000, // 0006 JMPT R4 #0008 - 0xB0060704, // 0007 RAISE 1 K3 K4 - 0x600C0015, // 0008 GETGBL R3 G21 - 0x58100005, // 0009 LDCONST R4 K5 - 0x7C0C0200, // 000A CALL R3 1 - 0x8C100306, // 000B GETMET R4 R1 K6 - 0x88180507, // 000C GETMBR R6 R2 K7 - 0x5C1C0600, // 000D MOVE R7 R3 - 0x7C100600, // 000E CALL R4 3 - 0x8C100306, // 000F GETMET R4 R1 K6 - 0x88180507, // 0010 GETMBR R6 R2 K7 - 0x541E0FFF, // 0011 LDINT R7 4096 - 0x00180C07, // 0012 ADD R6 R6 R7 - 0x5C1C0600, // 0013 MOVE R7 R3 - 0x7C100600, // 0014 CALL R4 3 - 0x80000000, // 0015 RET 0 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: set_active -********************************************************************/ -be_local_closure(Partition_set_active, /* name */ - be_nested_proto( - 6, /* nstack */ - 2, /* argc */ - 2, /* varg */ - 0, /* has upvals */ - NULL, /* no upvals */ - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 7]) { /* constants */ - /* K0 */ be_const_int(0), - /* K1 */ be_nested_str(ota_max), - /* K2 */ be_nested_str(value_error), - /* K3 */ be_nested_str(Invalid_X20ota_X20partition_X20number), - /* K4 */ be_nested_str(otadata), - /* K5 */ be_nested_str(set_ota_max), - /* K6 */ be_nested_str(set_active), - }), - &be_const_str_set_active, - &be_const_str_solidified, - ( &(const binstruction[17]) { /* code */ - 0x14080300, // 0000 LT R2 R1 K0 - 0x740A0003, // 0001 JMPT R2 #0006 - 0x8C080101, // 0002 GETMET R2 R0 K1 - 0x7C080200, // 0003 CALL R2 1 - 0x24080202, // 0004 GT R2 R1 R2 - 0x780A0000, // 0005 JMPF R2 #0007 - 0xB0060503, // 0006 RAISE 1 K2 K3 - 0x88080104, // 0007 GETMBR R2 R0 K4 - 0x8C080505, // 0008 GETMET R2 R2 K5 - 0x8C100101, // 0009 GETMET R4 R0 K1 - 0x7C100200, // 000A CALL R4 1 - 0x7C080400, // 000B CALL R2 2 - 0x88080104, // 000C GETMBR R2 R0 K4 - 0x8C080506, // 000D GETMET R2 R2 K6 - 0x5C100200, // 000E MOVE R4 R1 - 0x7C080400, // 000F CALL R2 2 - 0x80000000, // 0010 RET 0 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: ota_max -********************************************************************/ -be_local_closure(Partition_ota_max, /* name */ - be_nested_proto( - 6, /* nstack */ - 1, /* argc */ - 2, /* varg */ - 0, /* has upvals */ - NULL, /* no upvals */ - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 5]) { /* constants */ - /* K0 */ be_nested_str(slots), - /* K1 */ be_nested_str(type), - /* K2 */ be_const_int(0), - /* K3 */ be_nested_str(subtype), - /* K4 */ be_nested_str(stop_iteration), - }), - &be_const_str_ota_max, - &be_const_str_solidified, - ( &(const binstruction[32]) { /* code */ - 0x4C040000, // 0000 LDNIL R1 - 0x60080010, // 0001 GETGBL R2 G16 - 0x880C0100, // 0002 GETMBR R3 R0 K0 - 0x7C080200, // 0003 CALL R2 1 - 0xA8020016, // 0004 EXBLK 0 #001C - 0x5C0C0400, // 0005 MOVE R3 R2 - 0x7C0C0000, // 0006 CALL R3 0 - 0x88100701, // 0007 GETMBR R4 R3 K1 - 0x1C100902, // 0008 EQ R4 R4 K2 - 0x78120010, // 0009 JMPF R4 #001B - 0x88100703, // 000A GETMBR R4 R3 K3 - 0x5416000F, // 000B LDINT R5 16 - 0x28100805, // 000C GE R4 R4 R5 - 0x7812000C, // 000D JMPF R4 #001B - 0x88100703, // 000E GETMBR R4 R3 K3 - 0x5416001F, // 000F LDINT R5 32 - 0x14100805, // 0010 LT R4 R4 R5 - 0x78120008, // 0011 JMPF R4 #001B - 0x88100703, // 0012 GETMBR R4 R3 K3 - 0x5416000F, // 0013 LDINT R5 16 - 0x04100805, // 0014 SUB R4 R4 R5 - 0x4C140000, // 0015 LDNIL R5 - 0x1C140205, // 0016 EQ R5 R1 R5 - 0x74160001, // 0017 JMPT R5 #001A - 0x24140801, // 0018 GT R5 R4 R1 - 0x78160000, // 0019 JMPF R5 #001B - 0x5C040800, // 001A MOVE R1 R4 - 0x7001FFE8, // 001B JMP #0005 - 0x58080004, // 001C LDCONST R2 K4 - 0xAC080200, // 001D CATCH R2 1 0 - 0xB0080000, // 001E RAISE 2 R0 R0 - 0x80040200, // 001F RET 1 R1 - }) - ) -); -/*******************************************************************/ - - /******************************************************************** ** Solidified function: parse ********************************************************************/ @@ -976,11 +737,11 @@ be_local_closure(Partition_parse, /* name */ /******************************************************************** -** Solidified function: has_factory +** Solidified function: get_max_flash_size_k ********************************************************************/ -be_local_closure(Partition_has_factory, /* name */ +be_local_closure(Partition_get_max_flash_size_k, /* name */ be_nested_proto( - 3, /* nstack */ + 6, /* nstack */ 1, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -988,17 +749,37 @@ be_local_closure(Partition_has_factory, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 1]) { /* constants */ - /* K0 */ be_nested_str(get_factory_slot), + ( &(const bvalue[ 6]) { /* constants */ + /* K0 */ be_nested_str(tasmota), + /* K1 */ be_nested_str(memory), + /* K2 */ be_nested_str(flash), + /* K3 */ be_nested_str(find), + /* K4 */ be_nested_str(flash_real), + /* K5 */ be_nested_str(get_flash_definition_sector), }), - &be_const_str_has_factory, + &be_const_str_get_max_flash_size_k, &be_const_str_solidified, - ( &(const binstruction[ 5]) { /* code */ - 0x8C040100, // 0000 GETMET R1 R0 K0 - 0x7C040200, // 0001 CALL R1 1 - 0x4C080000, // 0002 LDNIL R2 - 0x20040202, // 0003 NE R1 R1 R2 - 0x80040200, // 0004 RET 1 R1 + ( &(const binstruction[20]) { /* code */ + 0xB8060000, // 0000 GETNGBL R1 K0 + 0x8C040301, // 0001 GETMET R1 R1 K1 + 0x7C040200, // 0002 CALL R1 1 + 0x94040302, // 0003 GETIDX R1 R1 K2 + 0xB80A0000, // 0004 GETNGBL R2 K0 + 0x8C080501, // 0005 GETMET R2 R2 K1 + 0x7C080200, // 0006 CALL R2 1 + 0x8C080503, // 0007 GETMET R2 R2 K3 + 0x58100004, // 0008 LDCONST R4 K4 + 0x5C140200, // 0009 MOVE R5 R1 + 0x7C080600, // 000A CALL R2 3 + 0x200C0202, // 000B NE R3 R1 R2 + 0x780E0005, // 000C JMPF R3 #0013 + 0x8C0C0105, // 000D GETMET R3 R0 K5 + 0x7C0C0200, // 000E CALL R3 1 + 0x4C100000, // 000F LDNIL R4 + 0x200C0604, // 0010 NE R3 R3 R4 + 0x780E0000, // 0011 JMPF R3 #0013 + 0x5C040400, // 0012 MOVE R1 R2 + 0x80040200, // 0013 RET 1 R1 }) ) ); @@ -1006,9 +787,282 @@ be_local_closure(Partition_has_factory, /* name */ /******************************************************************** -** Solidified function: get_ota_slot +** Solidified function: resize_max_flash_size_k ********************************************************************/ -be_local_closure(Partition_get_ota_slot, /* name */ +be_local_closure(Partition_resize_max_flash_size_k, /* name */ + be_nested_proto( + 18, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[18]) { /* constants */ + /* K0 */ be_nested_str(tasmota), + /* K1 */ be_nested_str(memory), + /* K2 */ be_nested_str(flash), + /* K3 */ be_nested_str(find), + /* K4 */ be_nested_str(flash_real), + /* K5 */ be_nested_str(get_flash_definition_sector), + /* K6 */ be_nested_str(string), + /* K7 */ be_nested_str(read), + /* K8 */ be_const_int(3), + /* K9 */ be_const_int(1), + /* K10 */ be_const_int(0), + /* K11 */ be_const_int(2), + /* K12 */ be_nested_str(write), + /* K13 */ be_nested_str(log), + /* K14 */ be_nested_str(format), + /* K15 */ be_nested_str(UPL_X3A_X20changing_X20flash_X20definition_X20from_X200x02X_X20to_X200x_X2502X), + /* K16 */ be_nested_str(wrong_X20flash_X20size_X20), + /* K17 */ be_nested_str(internal_error), + }), + &be_const_str_resize_max_flash_size_k, + &be_const_str_solidified, + ( &(const binstruction[80]) { /* code */ + 0xB8060000, // 0000 GETNGBL R1 K0 + 0x8C040301, // 0001 GETMET R1 R1 K1 + 0x7C040200, // 0002 CALL R1 1 + 0x94040302, // 0003 GETIDX R1 R1 K2 + 0xB80A0000, // 0004 GETNGBL R2 K0 + 0x8C080501, // 0005 GETMET R2 R2 K1 + 0x7C080200, // 0006 CALL R2 1 + 0x8C080503, // 0007 GETMET R2 R2 K3 + 0x58100004, // 0008 LDCONST R4 K4 + 0x5C140200, // 0009 MOVE R5 R1 + 0x7C080600, // 000A CALL R2 3 + 0x8C0C0105, // 000B GETMET R3 R0 K5 + 0x7C0C0200, // 000C CALL R3 1 + 0x20100202, // 000D NE R4 R1 R2 + 0x7812003F, // 000E JMPF R4 #004F + 0x4C100000, // 000F LDNIL R4 + 0x20100604, // 0010 NE R4 R3 R4 + 0x7812003C, // 0011 JMPF R4 #004F + 0xA4120400, // 0012 IMPORT R4 K2 + 0xA4160C00, // 0013 IMPORT R5 K6 + 0x5C040400, // 0014 MOVE R1 R2 + 0x8C180907, // 0015 GETMET R6 R4 K7 + 0x5C200600, // 0016 MOVE R8 R3 + 0x54260003, // 0017 LDINT R9 4 + 0x7C180600, // 0018 CALL R6 3 + 0x941C0D08, // 0019 GETIDX R7 R6 K8 + 0x4C200000, // 001A LDNIL R8 + 0x542603FF, // 001B LDINT R9 1024 + 0x0C240409, // 001C DIV R9 R2 R9 + 0x1C281309, // 001D EQ R10 R9 K9 + 0x782A0001, // 001E JMPF R10 #0021 + 0x5820000A, // 001F LDCONST R8 K10 + 0x70020011, // 0020 JMP #0033 + 0x1C28130B, // 0021 EQ R10 R9 K11 + 0x782A0001, // 0022 JMPF R10 #0025 + 0x5422000F, // 0023 LDINT R8 16 + 0x7002000D, // 0024 JMP #0033 + 0x542A0003, // 0025 LDINT R10 4 + 0x1C28120A, // 0026 EQ R10 R9 R10 + 0x782A0001, // 0027 JMPF R10 #002A + 0x5422001F, // 0028 LDINT R8 32 + 0x70020008, // 0029 JMP #0033 + 0x542A0007, // 002A LDINT R10 8 + 0x1C28120A, // 002B EQ R10 R9 R10 + 0x782A0001, // 002C JMPF R10 #002F + 0x5422002F, // 002D LDINT R8 48 + 0x70020003, // 002E JMP #0033 + 0x542A000F, // 002F LDINT R10 16 + 0x1C28120A, // 0030 EQ R10 R9 R10 + 0x782A0000, // 0031 JMPF R10 #0033 + 0x5422003F, // 0032 LDINT R8 64 + 0x4C280000, // 0033 LDNIL R10 + 0x2028100A, // 0034 NE R10 R8 R10 + 0x782A0013, // 0035 JMPF R10 #004A + 0x94280D08, // 0036 GETIDX R10 R6 K8 + 0x942C0D08, // 0037 GETIDX R11 R6 K8 + 0x5432000E, // 0038 LDINT R12 15 + 0x2C2C160C, // 0039 AND R11 R11 R12 + 0x302C1608, // 003A OR R11 R11 R8 + 0x981A100B, // 003B SETIDX R6 K8 R11 + 0x8C2C090C, // 003C GETMET R11 R4 K12 + 0x5C340600, // 003D MOVE R13 R3 + 0x5C380C00, // 003E MOVE R14 R6 + 0x7C2C0600, // 003F CALL R11 3 + 0xB82E0000, // 0040 GETNGBL R11 K0 + 0x8C2C170D, // 0041 GETMET R11 R11 K13 + 0x8C340B0E, // 0042 GETMET R13 R5 K14 + 0x583C000F, // 0043 LDCONST R15 K15 + 0x5C401400, // 0044 MOVE R16 R10 + 0x94440D08, // 0045 GETIDX R17 R6 K8 + 0x7C340800, // 0046 CALL R13 4 + 0x58380008, // 0047 LDCONST R14 K8 + 0x7C2C0600, // 0048 CALL R11 3 + 0x70020004, // 0049 JMP #004F + 0x60280008, // 004A GETGBL R10 G8 + 0x5C2C1200, // 004B MOVE R11 R9 + 0x7C280200, // 004C CALL R10 1 + 0x002A200A, // 004D ADD R10 K16 R10 + 0xB006220A, // 004E RAISE 1 K17 R10 + 0x80000000, // 004F RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: get_flash_definition_sector +********************************************************************/ +be_local_closure(Partition_get_flash_definition_sector, /* name */ + be_nested_proto( + 8, /* nstack */ + 0, /* argc */ + 0, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 6]) { /* constants */ + /* K0 */ be_nested_str(flash), + /* K1 */ be_const_int(0), + /* K2 */ be_const_int(1), + /* K3 */ be_nested_str(read), + /* K4 */ be_nested_str(E9), + /* K5 */ be_nested_str(stop_iteration), + }), + &be_const_str_get_flash_definition_sector, + &be_const_str_solidified, + ( &(const binstruction[25]) { /* code */ + 0xA4020000, // 0000 IMPORT R0 K0 + 0x60040010, // 0001 GETGBL R1 G16 + 0x400A0302, // 0002 CONNECT R2 K1 K2 + 0x7C040200, // 0003 CALL R1 1 + 0xA802000F, // 0004 EXBLK 0 #0015 + 0x5C080200, // 0005 MOVE R2 R1 + 0x7C080000, // 0006 CALL R2 0 + 0x540E0FFF, // 0007 LDINT R3 4096 + 0x080C0403, // 0008 MUL R3 R2 R3 + 0x8C100103, // 0009 GETMET R4 R0 K3 + 0x5C180600, // 000A MOVE R6 R3 + 0x581C0002, // 000B LDCONST R7 K2 + 0x7C100600, // 000C CALL R4 3 + 0x60140015, // 000D GETGBL R5 G21 + 0x58180004, // 000E LDCONST R6 K4 + 0x7C140200, // 000F CALL R5 1 + 0x1C100805, // 0010 EQ R4 R4 R5 + 0x78120001, // 0011 JMPF R4 #0014 + 0xA8040001, // 0012 EXBLK 1 1 + 0x80040600, // 0013 RET 1 R3 + 0x7001FFEF, // 0014 JMP #0005 + 0x58040005, // 0015 LDCONST R1 K5 + 0xAC040200, // 0016 CATCH R1 1 0 + 0xB0080000, // 0017 RAISE 2 R0 R0 + 0x80000000, // 0018 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: resize_fs_to_max +********************************************************************/ +be_local_closure(Partition_resize_fs_to_max, /* name */ + be_nested_proto( + 11, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[17]) { /* constants */ + /* K0 */ be_nested_str(string), + /* K1 */ be_nested_str(get_unallocated_k), + /* K2 */ be_const_int(0), + /* K3 */ be_nested_str(tasmota), + /* K4 */ be_nested_str(log), + /* K5 */ be_nested_str(format), + /* K6 */ be_nested_str(BRY_X3A_X20Trying_X20to_X20expand_X20FS_X20by_X20_X25i_X20kB), + /* K7 */ be_const_int(2), + /* K8 */ be_nested_str(resize_max_flash_size_k), + /* K9 */ be_nested_str(slots), + /* K10 */ be_nested_str(sz), + /* K11 */ be_nested_str(save), + /* K12 */ be_nested_str(invalidate_spiffs), + /* K13 */ be_nested_str(global), + /* K14 */ be_nested_str(restart_flag), + /* K15 */ be_nested_str(BRY_X3A_X20Successfully_X20resized_X20FS_X2C_X20restarting), + /* K16 */ be_nested_str(BRY_X3A_X20Exception_X3E_X20_X27_X25s_X27_X20_X2D_X20_X25s), + }), + &be_const_str_resize_fs_to_max, + &be_const_str_solidified, + ( &(const binstruction[55]) { /* code */ + 0xA4060000, // 0000 IMPORT R1 K0 + 0xA8020026, // 0001 EXBLK 0 #0029 + 0x8C080101, // 0002 GETMET R2 R0 K1 + 0x7C080200, // 0003 CALL R2 1 + 0x180C0502, // 0004 LE R3 R2 K2 + 0x780E0002, // 0005 JMPF R3 #0009 + 0x4C0C0000, // 0006 LDNIL R3 + 0xA8040001, // 0007 EXBLK 1 1 + 0x80040600, // 0008 RET 1 R3 + 0xB80E0600, // 0009 GETNGBL R3 K3 + 0x8C0C0704, // 000A GETMET R3 R3 K4 + 0x8C140305, // 000B GETMET R5 R1 K5 + 0x581C0006, // 000C LDCONST R7 K6 + 0x5C200400, // 000D MOVE R8 R2 + 0x7C140600, // 000E CALL R5 3 + 0x58180007, // 000F LDCONST R6 K7 + 0x7C0C0600, // 0010 CALL R3 3 + 0x8C0C0108, // 0011 GETMET R3 R0 K8 + 0x7C0C0200, // 0012 CALL R3 1 + 0x540DFFFE, // 0013 LDINT R3 -1 + 0x88100109, // 0014 GETMBR R4 R0 K9 + 0x940C0803, // 0015 GETIDX R3 R4 R3 + 0x541A03FF, // 0016 LDINT R6 1024 + 0x08180406, // 0017 MUL R6 R2 R6 + 0x8814070A, // 0018 GETMBR R5 R3 K10 + 0x00140A06, // 0019 ADD R5 R5 R6 + 0x900E1405, // 001A SETMBR R3 K10 R5 + 0x8C14010B, // 001B GETMET R5 R0 K11 + 0x7C140200, // 001C CALL R5 1 + 0x8C10010C, // 001D GETMET R4 R0 K12 + 0x7C100200, // 001E CALL R4 1 + 0xB8120600, // 001F GETNGBL R4 K3 + 0x8810090D, // 0020 GETMBR R4 R4 K13 + 0x90121D07, // 0021 SETMBR R4 K14 K7 + 0xB8120600, // 0022 GETNGBL R4 K3 + 0x8C100904, // 0023 GETMET R4 R4 K4 + 0x5818000F, // 0024 LDCONST R6 K15 + 0x581C0007, // 0025 LDCONST R7 K7 + 0x7C100600, // 0026 CALL R4 3 + 0xA8040001, // 0027 EXBLK 1 1 + 0x7002000C, // 0028 JMP #0036 + 0xAC080002, // 0029 CATCH R2 0 2 + 0x70020009, // 002A JMP #0035 + 0xB8120600, // 002B GETNGBL R4 K3 + 0x8C100904, // 002C GETMET R4 R4 K4 + 0x8C180305, // 002D GETMET R6 R1 K5 + 0x58200010, // 002E LDCONST R8 K16 + 0x5C240400, // 002F MOVE R9 R2 + 0x5C280600, // 0030 MOVE R10 R3 + 0x7C180800, // 0031 CALL R6 4 + 0x581C0007, // 0032 LDCONST R7 K7 + 0x7C100600, // 0033 CALL R4 3 + 0x70020000, // 0034 JMP #0036 + 0xB0080000, // 0035 RAISE 2 R0 R0 + 0x80000000, // 0036 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: switch_factory +********************************************************************/ +be_local_closure(Partition_switch_factory, /* name */ be_nested_proto( 6, /* nstack */ 2, /* argc */ @@ -1018,77 +1072,18 @@ be_local_closure(Partition_get_ota_slot, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 3]) { /* constants */ - /* K0 */ be_nested_str(slots), - /* K1 */ be_nested_str(is_ota), - /* K2 */ be_nested_str(stop_iteration), - }), - &be_const_str_get_ota_slot, - &be_const_str_solidified, - ( &(const binstruction[18]) { /* code */ - 0x60080010, // 0000 GETGBL R2 G16 - 0x880C0100, // 0001 GETMBR R3 R0 K0 - 0x7C080200, // 0002 CALL R2 1 - 0xA8020008, // 0003 EXBLK 0 #000D - 0x5C0C0400, // 0004 MOVE R3 R2 - 0x7C0C0000, // 0005 CALL R3 0 - 0x8C100701, // 0006 GETMET R4 R3 K1 - 0x7C100200, // 0007 CALL R4 1 - 0x1C100801, // 0008 EQ R4 R4 R1 - 0x78120001, // 0009 JMPF R4 #000C - 0xA8040001, // 000A EXBLK 1 1 - 0x80040600, // 000B RET 1 R3 - 0x7001FFF6, // 000C JMP #0004 - 0x58080002, // 000D LDCONST R2 K2 - 0xAC080200, // 000E CATCH R2 1 0 - 0xB0080000, // 000F RAISE 2 R0 R0 - 0x4C080000, // 0010 LDNIL R2 - 0x80040400, // 0011 RET 1 R2 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: save -********************************************************************/ -be_local_closure(Partition_save, /* name */ - be_nested_proto( - 7, /* nstack */ - 1, /* argc */ - 2, /* varg */ - 0, /* has upvals */ - NULL, /* no upvals */ - 0, /* has sup protos */ - NULL, /* no sub protos */ - 1, /* has constants */ - ( &(const bvalue[ 6]) { /* constants */ + ( &(const bvalue[ 2]) { /* constants */ /* K0 */ be_nested_str(flash), - /* K1 */ be_nested_str(tobytes), - /* K2 */ be_nested_str(erase), - /* K3 */ be_nested_str(write), - /* K4 */ be_nested_str(otadata), - /* K5 */ be_nested_str(save), + /* K1 */ be_nested_str(factory), }), - &be_const_str_save, + &be_const_str_switch_factory, &be_const_str_solidified, - ( &(const binstruction[15]) { /* code */ - 0xA4060000, // 0000 IMPORT R1 K0 - 0x8C080101, // 0001 GETMET R2 R0 K1 - 0x7C080200, // 0002 CALL R2 1 - 0x8C0C0302, // 0003 GETMET R3 R1 K2 - 0x54167FFF, // 0004 LDINT R5 32768 - 0x541A0FFF, // 0005 LDINT R6 4096 - 0x7C0C0600, // 0006 CALL R3 3 - 0x8C0C0303, // 0007 GETMET R3 R1 K3 - 0x54167FFF, // 0008 LDINT R5 32768 - 0x5C180400, // 0009 MOVE R6 R2 - 0x7C0C0600, // 000A CALL R3 3 - 0x880C0104, // 000B GETMBR R3 R0 K4 - 0x8C0C0705, // 000C GETMET R3 R3 K5 - 0x7C0C0200, // 000D CALL R3 1 - 0x80000000, // 000E RET 0 + ( &(const binstruction[ 5]) { /* code */ + 0xA40A0000, // 0000 IMPORT R2 K0 + 0x8C0C0501, // 0001 GETMET R3 R2 K1 + 0x5C140200, // 0002 MOVE R5 R1 + 0x7C0C0400, // 0003 CALL R3 2 + 0x80000000, // 0004 RET 0 }) ) ); @@ -1161,9 +1156,9 @@ be_local_closure(Partition_load_otadata, /* name */ /******************************************************************** -** Solidified function: load +** Solidified function: tostring ********************************************************************/ -be_local_closure(Partition_load, /* name */ +be_local_closure(Partition_tostring, /* name */ be_nested_proto( 6, /* nstack */ 1, /* argc */ @@ -1173,21 +1168,256 @@ be_local_closure(Partition_load, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 3]) { /* constants */ - /* K0 */ be_nested_str(flash), - /* K1 */ be_nested_str(raw), - /* K2 */ be_nested_str(read), + ( &(const bvalue[ 9]) { /* constants */ + /* K0 */ be_nested_str(_X3Cinstance_X3A_X20Partition_X28_X5B_X0A), + /* K1 */ be_nested_str(slots), + /* K2 */ be_nested_str(_X20_X20), + /* K3 */ be_nested_str(tostring), + /* K4 */ be_nested_str(_X0A), + /* K5 */ be_nested_str(stop_iteration), + /* K6 */ be_nested_str(_X5D_X2C_X0A_X20_X20), + /* K7 */ be_nested_str(otadata), + /* K8 */ be_nested_str(_X0A_X29_X3E), }), - &be_const_str_load, + &be_const_str_tostring, &be_const_str_solidified, - ( &(const binstruction[ 7]) { /* code */ + ( &(const binstruction[23]) { /* code */ + 0x58040000, // 0000 LDCONST R1 K0 + 0x60080010, // 0001 GETGBL R2 G16 + 0x880C0101, // 0002 GETMBR R3 R0 K1 + 0x7C080200, // 0003 CALL R2 1 + 0xA8020007, // 0004 EXBLK 0 #000D + 0x5C0C0400, // 0005 MOVE R3 R2 + 0x7C0C0000, // 0006 CALL R3 0 + 0x00040302, // 0007 ADD R1 R1 K2 + 0x8C100703, // 0008 GETMET R4 R3 K3 + 0x7C100200, // 0009 CALL R4 1 + 0x00040204, // 000A ADD R1 R1 R4 + 0x00040304, // 000B ADD R1 R1 K4 + 0x7001FFF7, // 000C JMP #0005 + 0x58080005, // 000D LDCONST R2 K5 + 0xAC080200, // 000E CATCH R2 1 0 + 0xB0080000, // 000F RAISE 2 R0 R0 + 0x00040306, // 0010 ADD R1 R1 K6 + 0x88080107, // 0011 GETMBR R2 R0 K7 + 0x8C080503, // 0012 GETMET R2 R2 K3 + 0x7C080200, // 0013 CALL R2 1 + 0x00040202, // 0014 ADD R1 R1 R2 + 0x00040308, // 0015 ADD R1 R1 K8 + 0x80040200, // 0016 RET 1 R1 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: has_factory +********************************************************************/ +be_local_closure(Partition_has_factory, /* name */ + be_nested_proto( + 3, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_nested_str(get_factory_slot), + }), + &be_const_str_has_factory, + &be_const_str_solidified, + ( &(const binstruction[ 5]) { /* code */ + 0x8C040100, // 0000 GETMET R1 R0 K0 + 0x7C040200, // 0001 CALL R1 1 + 0x4C080000, // 0002 LDNIL R2 + 0x20040202, // 0003 NE R1 R1 R2 + 0x80040200, // 0004 RET 1 R1 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: tobytes +********************************************************************/ +be_local_closure(Partition_tobytes, /* name */ + be_nested_proto( + 6, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 9]) { /* constants */ + /* K0 */ be_nested_str(slots), + /* K1 */ be_nested_str(value_error), + /* K2 */ be_nested_str(Too_X20many_X20partiition_X20slots), + /* K3 */ be_nested_str(tobytes), + /* K4 */ be_nested_str(stop_iteration), + /* K5 */ be_nested_str(MD5), + /* K6 */ be_nested_str(update), + /* K7 */ be_nested_str(EBEBFFFFFFFFFFFFFFFFFFFFFFFFFFFF), + /* K8 */ be_nested_str(finish), + }), + &be_const_str_tobytes, + &be_const_str_solidified, + ( &(const binstruction[35]) { /* code */ + 0x6004000C, // 0000 GETGBL R1 G12 + 0x88080100, // 0001 GETMBR R2 R0 K0 + 0x7C040200, // 0002 CALL R1 1 + 0x540A005E, // 0003 LDINT R2 95 + 0x24040202, // 0004 GT R1 R1 R2 + 0x78060000, // 0005 JMPF R1 #0007 + 0xB0060302, // 0006 RAISE 1 K1 K2 + 0x60040015, // 0007 GETGBL R1 G21 + 0x7C040000, // 0008 CALL R1 0 + 0x60080010, // 0009 GETGBL R2 G16 + 0x880C0100, // 000A GETMBR R3 R0 K0 + 0x7C080200, // 000B CALL R2 1 + 0xA8020005, // 000C EXBLK 0 #0013 + 0x5C0C0400, // 000D MOVE R3 R2 + 0x7C0C0000, // 000E CALL R3 0 + 0x8C100703, // 000F GETMET R4 R3 K3 + 0x7C100200, // 0010 CALL R4 1 + 0x00040204, // 0011 ADD R1 R1 R4 + 0x7001FFF9, // 0012 JMP #000D + 0x58080004, // 0013 LDCONST R2 K4 + 0xAC080200, // 0014 CATCH R2 1 0 + 0xB0080000, // 0015 RAISE 2 R0 R0 + 0xB80A0A00, // 0016 GETNGBL R2 K5 + 0x7C080000, // 0017 CALL R2 0 + 0x8C0C0506, // 0018 GETMET R3 R2 K6 + 0x5C140200, // 0019 MOVE R5 R1 + 0x7C0C0400, // 001A CALL R3 2 + 0x600C0015, // 001B GETGBL R3 G21 + 0x58100007, // 001C LDCONST R4 K7 + 0x7C0C0200, // 001D CALL R3 1 + 0x00040203, // 001E ADD R1 R1 R3 + 0x8C0C0508, // 001F GETMET R3 R2 K8 + 0x7C0C0200, // 0020 CALL R3 1 + 0x00040203, // 0021 ADD R1 R1 R3 + 0x80040200, // 0022 RET 1 R1 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: ota_max +********************************************************************/ +be_local_closure(Partition_ota_max, /* name */ + be_nested_proto( + 6, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 5]) { /* constants */ + /* K0 */ be_nested_str(slots), + /* K1 */ be_nested_str(type), + /* K2 */ be_const_int(0), + /* K3 */ be_nested_str(subtype), + /* K4 */ be_nested_str(stop_iteration), + }), + &be_const_str_ota_max, + &be_const_str_solidified, + ( &(const binstruction[32]) { /* code */ + 0x4C040000, // 0000 LDNIL R1 + 0x60080010, // 0001 GETGBL R2 G16 + 0x880C0100, // 0002 GETMBR R3 R0 K0 + 0x7C080200, // 0003 CALL R2 1 + 0xA8020016, // 0004 EXBLK 0 #001C + 0x5C0C0400, // 0005 MOVE R3 R2 + 0x7C0C0000, // 0006 CALL R3 0 + 0x88100701, // 0007 GETMBR R4 R3 K1 + 0x1C100902, // 0008 EQ R4 R4 K2 + 0x78120010, // 0009 JMPF R4 #001B + 0x88100703, // 000A GETMBR R4 R3 K3 + 0x5416000F, // 000B LDINT R5 16 + 0x28100805, // 000C GE R4 R4 R5 + 0x7812000C, // 000D JMPF R4 #001B + 0x88100703, // 000E GETMBR R4 R3 K3 + 0x5416001F, // 000F LDINT R5 32 + 0x14100805, // 0010 LT R4 R4 R5 + 0x78120008, // 0011 JMPF R4 #001B + 0x88100703, // 0012 GETMBR R4 R3 K3 + 0x5416000F, // 0013 LDINT R5 16 + 0x04100805, // 0014 SUB R4 R4 R5 + 0x4C140000, // 0015 LDNIL R5 + 0x1C140205, // 0016 EQ R5 R1 R5 + 0x74160001, // 0017 JMPT R5 #001A + 0x24140801, // 0018 GT R5 R4 R1 + 0x78160000, // 0019 JMPF R5 #001B + 0x5C040800, // 001A MOVE R1 R4 + 0x7001FFE8, // 001B JMP #0005 + 0x58080004, // 001C LDCONST R2 K4 + 0xAC080200, // 001D CATCH R2 1 0 + 0xB0080000, // 001E RAISE 2 R0 R0 + 0x80040200, // 001F RET 1 R1 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: invalidate_spiffs +********************************************************************/ +be_local_closure(Partition_invalidate_spiffs, /* name */ + be_nested_proto( + 8, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 8]) { /* constants */ + /* K0 */ be_nested_str(flash), + /* K1 */ be_nested_str(slots), + /* K2 */ be_nested_str(is_spiffs), + /* K3 */ be_nested_str(value_error), + /* K4 */ be_nested_str(No_X20SPIFFS_X20partition_X20found), + /* K5 */ be_nested_str(00), + /* K6 */ be_nested_str(write), + /* K7 */ be_nested_str(start), + }), + &be_const_str_invalidate_spiffs, + &be_const_str_solidified, + ( &(const binstruction[22]) { /* code */ 0xA4060000, // 0000 IMPORT R1 K0 - 0x8C080302, // 0001 GETMET R2 R1 K2 - 0x54127FFF, // 0002 LDINT R4 32768 - 0x54160FFF, // 0003 LDINT R5 4096 - 0x7C080600, // 0004 CALL R2 3 - 0x90020202, // 0005 SETMBR R0 K1 R2 - 0x80000000, // 0006 RET 0 + 0x5409FFFE, // 0001 LDINT R2 -1 + 0x880C0101, // 0002 GETMBR R3 R0 K1 + 0x94080602, // 0003 GETIDX R2 R3 R2 + 0x8C100502, // 0004 GETMET R4 R2 K2 + 0x7C100200, // 0005 CALL R4 1 + 0x74120000, // 0006 JMPT R4 #0008 + 0xB0060704, // 0007 RAISE 1 K3 K4 + 0x600C0015, // 0008 GETGBL R3 G21 + 0x58100005, // 0009 LDCONST R4 K5 + 0x7C0C0200, // 000A CALL R3 1 + 0x8C100306, // 000B GETMET R4 R1 K6 + 0x88180507, // 000C GETMBR R6 R2 K7 + 0x5C1C0600, // 000D MOVE R7 R3 + 0x7C100600, // 000E CALL R4 3 + 0x8C100306, // 000F GETMET R4 R1 K6 + 0x88180507, // 0010 GETMBR R6 R2 K7 + 0x541E0FFF, // 0011 LDINT R7 4096 + 0x00180C07, // 0012 ADD R6 R6 R7 + 0x5C1C0600, // 0013 MOVE R7 R3 + 0x7C100600, // 0014 CALL R4 3 + 0x80000000, // 0015 RET 0 }) ) ); @@ -1237,33 +1467,180 @@ be_local_closure(Partition_get_factory_slot, /* name */ /*******************************************************************/ +/******************************************************************** +** Solidified function: set_active +********************************************************************/ +be_local_closure(Partition_set_active, /* name */ + be_nested_proto( + 6, /* nstack */ + 2, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 7]) { /* constants */ + /* K0 */ be_const_int(0), + /* K1 */ be_nested_str(ota_max), + /* K2 */ be_nested_str(value_error), + /* K3 */ be_nested_str(Invalid_X20ota_X20partition_X20number), + /* K4 */ be_nested_str(otadata), + /* K5 */ be_nested_str(set_ota_max), + /* K6 */ be_nested_str(set_active), + }), + &be_const_str_set_active, + &be_const_str_solidified, + ( &(const binstruction[17]) { /* code */ + 0x14080300, // 0000 LT R2 R1 K0 + 0x740A0003, // 0001 JMPT R2 #0006 + 0x8C080101, // 0002 GETMET R2 R0 K1 + 0x7C080200, // 0003 CALL R2 1 + 0x24080202, // 0004 GT R2 R1 R2 + 0x780A0000, // 0005 JMPF R2 #0007 + 0xB0060503, // 0006 RAISE 1 K2 K3 + 0x88080104, // 0007 GETMBR R2 R0 K4 + 0x8C080505, // 0008 GETMET R2 R2 K5 + 0x8C100101, // 0009 GETMET R4 R0 K1 + 0x7C100200, // 000A CALL R4 1 + 0x7C080400, // 000B CALL R2 2 + 0x88080104, // 000C GETMBR R2 R0 K4 + 0x8C080506, // 000D GETMET R2 R2 K6 + 0x5C100200, // 000E MOVE R4 R1 + 0x7C080400, // 000F CALL R2 2 + 0x80000000, // 0010 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: get_unallocated_k +********************************************************************/ +be_local_closure(Partition_get_unallocated_k, /* name */ + be_nested_proto( + 5, /* nstack */ + 1, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 6]) { /* constants */ + /* K0 */ be_nested_str(slots), + /* K1 */ be_nested_str(is_spiffs), + /* K2 */ be_nested_str(get_max_flash_size_k), + /* K3 */ be_nested_str(start), + /* K4 */ be_nested_str(sz), + /* K5 */ be_const_int(0), + }), + &be_const_str_get_unallocated_k, + &be_const_str_solidified, + ( &(const binstruction[19]) { /* code */ + 0x5405FFFE, // 0000 LDINT R1 -1 + 0x88080100, // 0001 GETMBR R2 R0 K0 + 0x94040401, // 0002 GETIDX R1 R2 R1 + 0x8C0C0301, // 0003 GETMET R3 R1 K1 + 0x7C0C0200, // 0004 CALL R3 1 + 0x780E000B, // 0005 JMPF R3 #0012 + 0x8C0C0102, // 0006 GETMET R3 R0 K2 + 0x7C0C0200, // 0007 CALL R3 1 + 0x5C080600, // 0008 MOVE R2 R3 + 0x880C0303, // 0009 GETMBR R3 R1 K3 + 0x88100304, // 000A GETMBR R4 R1 K4 + 0x000C0604, // 000B ADD R3 R3 R4 + 0x541203FF, // 000C LDINT R4 1024 + 0x0C0C0604, // 000D DIV R3 R3 R4 + 0x14100602, // 000E LT R4 R3 R2 + 0x78120001, // 000F JMPF R4 #0012 + 0x04100403, // 0010 SUB R4 R2 R3 + 0x80040800, // 0011 RET 1 R4 + 0x80060A00, // 0012 RET 1 K5 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: get_ota_slot +********************************************************************/ +be_local_closure(Partition_get_ota_slot, /* name */ + be_nested_proto( + 6, /* nstack */ + 2, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 3]) { /* constants */ + /* K0 */ be_nested_str(slots), + /* K1 */ be_nested_str(is_ota), + /* K2 */ be_nested_str(stop_iteration), + }), + &be_const_str_get_ota_slot, + &be_const_str_solidified, + ( &(const binstruction[18]) { /* code */ + 0x60080010, // 0000 GETGBL R2 G16 + 0x880C0100, // 0001 GETMBR R3 R0 K0 + 0x7C080200, // 0002 CALL R2 1 + 0xA8020008, // 0003 EXBLK 0 #000D + 0x5C0C0400, // 0004 MOVE R3 R2 + 0x7C0C0000, // 0005 CALL R3 0 + 0x8C100701, // 0006 GETMET R4 R3 K1 + 0x7C100200, // 0007 CALL R4 1 + 0x1C100801, // 0008 EQ R4 R4 R1 + 0x78120001, // 0009 JMPF R4 #000C + 0xA8040001, // 000A EXBLK 1 1 + 0x80040600, // 000B RET 1 R3 + 0x7001FFF6, // 000C JMP #0004 + 0x58080002, // 000D LDCONST R2 K2 + 0xAC080200, // 000E CATCH R2 1 0 + 0xB0080000, // 000F RAISE 2 R0 R0 + 0x4C080000, // 0010 LDNIL R2 + 0x80040400, // 0011 RET 1 R2 + }) + ) +); +/*******************************************************************/ + + /******************************************************************** ** Solidified class: Partition ********************************************************************/ be_local_class(Partition, 4, NULL, - be_nested_map(19, + be_nested_map(24, ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key(raw, 3), be_const_var(0) }, - { be_const_key(get_factory_slot, -1), be_const_closure(Partition_get_factory_slot_closure) }, - { be_const_key(tostring, 17), be_const_closure(Partition_tostring_closure) }, - { be_const_key(load, -1), be_const_closure(Partition_load_closure) }, - { be_const_key(get_active, -1), be_const_closure(Partition_get_active_closure) }, - { be_const_key(switch_factory, -1), be_const_closure(Partition_switch_factory_closure) }, - { be_const_key(slots, 18), be_const_var(2) }, - { be_const_key(invalidate_spiffs, -1), be_const_closure(Partition_invalidate_spiffs_closure) }, - { be_const_key(set_active, 11), be_const_closure(Partition_set_active_closure) }, - { be_const_key(ota_max, 1), be_const_closure(Partition_ota_max_closure) }, - { be_const_key(parse, -1), be_const_closure(Partition_parse_closure) }, - { be_const_key(load_otadata, -1), be_const_closure(Partition_load_otadata_closure) }, { be_const_key(save, -1), be_const_closure(Partition_save_closure) }, - { be_const_key(init, 15), be_const_closure(Partition_init_closure) }, - { be_const_key(tobytes, 12), be_const_closure(Partition_tobytes_closure) }, - { be_const_key(get_ota_slot, 6), be_const_closure(Partition_get_ota_slot_closure) }, - { be_const_key(md5, -1), be_const_var(1) }, - { be_const_key(has_factory, -1), be_const_closure(Partition_has_factory_closure) }, + { be_const_key(load, 8), be_const_closure(Partition_load_closure) }, + { be_const_key(get_active, -1), be_const_closure(Partition_get_active_closure) }, + { be_const_key(init, -1), be_const_closure(Partition_init_closure) }, + { be_const_key(parse, 21), be_const_closure(Partition_parse_closure) }, { be_const_key(otadata, -1), be_const_var(3) }, + { be_const_key(slots, 11), be_const_var(2) }, + { be_const_key(get_ota_slot, -1), be_const_closure(Partition_get_ota_slot_closure) }, + { be_const_key(resize_max_flash_size_k, -1), be_const_closure(Partition_resize_max_flash_size_k_closure) }, + { be_const_key(get_flash_definition_sector, -1), be_const_static_closure(Partition_get_flash_definition_sector_closure) }, + { be_const_key(resize_fs_to_max, -1), be_const_closure(Partition_resize_fs_to_max_closure) }, + { be_const_key(set_active, -1), be_const_closure(Partition_set_active_closure) }, + { be_const_key(get_factory_slot, -1), be_const_closure(Partition_get_factory_slot_closure) }, + { be_const_key(tostring, -1), be_const_closure(Partition_tostring_closure) }, + { be_const_key(invalidate_spiffs, -1), be_const_closure(Partition_invalidate_spiffs_closure) }, + { be_const_key(tobytes, 12), be_const_closure(Partition_tobytes_closure) }, + { be_const_key(load_otadata, 20), be_const_closure(Partition_load_otadata_closure) }, + { be_const_key(raw, -1), be_const_var(0) }, + { be_const_key(has_factory, 14), be_const_closure(Partition_has_factory_closure) }, + { be_const_key(md5, -1), be_const_var(1) }, + { be_const_key(ota_max, -1), be_const_closure(Partition_ota_max_closure) }, + { be_const_key(switch_factory, -1), be_const_closure(Partition_switch_factory_closure) }, + { be_const_key(get_unallocated_k, -1), be_const_closure(Partition_get_unallocated_k_closure) }, + { be_const_key(get_max_flash_size_k, 7), be_const_closure(Partition_get_max_flash_size_k_closure) }, })), (bstring*) &be_const_str_Partition ); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_7_berry_embedded.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_7_berry_embedded.ino index 08fdb1e88..33c7692a6 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_7_berry_embedded.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_7_berry_embedded.ino @@ -43,6 +43,14 @@ const char berry_prog[] = "def log(m,l) tasmota.log(m,l) end " "def load(f) return tasmota.load(f) end " + // try to resize FS to max at first boot + // "tasmota.log('>>> bootcount=' + str(tasmota.settings.bootcount), 2) " + "if tasmota.settings.bootcount == 0 " + "import partition_core " + "var p = partition_core.Partition() " + "p.resize_fs_to_max() " + "end " + #ifdef USE_AUTOCONF // autoconf "import autoconf " From 39a05984ca208de880836ae4852be7f7e44ce83f Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 16 Oct 2022 12:19:08 +0200 Subject: [PATCH 11/13] Automatically resize FS to max flash size at initial boot (ESP32x) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05417e36a..523981f19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ## [12.1.1.6] ### Added - Command ``WcClock 10..200`` set webcam clock in MHz. Default is 20 +- Automatically resize FS to max flash size at initial boot (ESP32x) ### Changed From 480fae680467d1c6826ea9925ee8a38466eba350 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 16 Oct 2022 12:57:17 +0200 Subject: [PATCH 12/13] Add command ``SspmPowerOnState 0|1|2`` Add command ``SspmPowerOnState 0|1|2`` to set Sonoff SPM 4Relay module v1.2.0 power on state overruling tasmota global power on state. 0 = Off, 1 = On, 2 = Saved state (#13447) --- CHANGELOG.md | 3 +- RELEASENOTES.md | 2 + .../xdrv_86_esp32_sonoff_spm.ino | 192 +++++++++++++++--- 3 files changed, 164 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 523981f19..0ab77373a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file. ## [12.1.1.6] ### Added - Command ``WcClock 10..200`` set webcam clock in MHz. Default is 20 -- Automatically resize FS to max flash size at initial boot (ESP32x) +- ESP32 Automatically resize FS to max flash size at initial boot (#16838) +- Command ``SspmPowerOnState 0|1|2`` to set Sonoff SPM 4Relay module v1.2.0 power on state overruling tasmota global power on state. 0 = Off, 1 = On, 2 = Saved state (#13447) ### Changed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 00a250149..18ed93054 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -116,6 +116,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - Command ``UrlFetch `` to download a file to filesystem - Command ``DspSpeed 2..127`` to control message rotation speed on display of POWR3xxD and THR3xxD - Command ``DspLine<1|2> ,,,,...`` to select message(s) on display of POWR3xxD and THR3xxD +- Command ``SspmPowerOnState 0|1|2`` to set Sonoff SPM 4Relay module v1.2.0 power on state overruling tasmota global power on state. 0 = Off, 1 = On, 2 = Saved state [#13447](https://github.com/arendst/Tasmota/issues/13447) - Command ``Sunrise 0..3`` to select sunrise dawn angle between Normal, Civil, Nautical or Astronomical [#16795](https://github.com/arendst/Tasmota/issues/16795) - Command ``WcClock 10..200`` set webcam clock in MHz. Default is 20 - Support for Shelly Plus 2PM @@ -133,6 +134,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - Support for Ethernet in ESP32 safeboot firmware [#16388](https://github.com/arendst/Tasmota/issues/16388) - ESP32-S3 support for internal temperature sensor - ESP32-S2 and ESP32-S3 touch button support +- ESP32 Automatically resize FS to max flash size at initial boot [#16838](https://github.com/arendst/Tasmota/issues/16838) - Berry has persistent MQTT subscriptions: auto-subscribe at (re)connection - Berry automated solidification of code - LVGL/HASPmota add tiny "pixel perfect" fonts for small screens [#16758](https://github.com/arendst/Tasmota/issues/16758) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino b/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino index aa1e2e153..7cdc8011d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino @@ -146,7 +146,10 @@ #define SSPM_FUNC_RESET 28 // 0x1C - Remove device from eWelink and factory reset #define SSPM_FUNC_UPLOAD_DATA 31 // 0x1F - SPI Upload incremental data blocks of max 512 bytes to ARM #define SSPM_FUNC_UPLOAD_DONE 33 // 0x21 - SPI Finish upload -#define SSPM_FUNC_GET_NEW1 37 // 0x25 +#define SSPM_FUNC_34 34 // 0x22 - v1.2.0 +#define SSPM_FUNC_GET_OPS_DEFAULTS 35 // 0x23 - v1.2.0 - Get Overload protection defaults +#define SSPM_FUNC_SET_POS 36 // 0x24 - v1.2.0 - Save power on relay state +#define SSPM_FUNC_GET_POS 37 // 0x25 - v1.2.0 - Read power on relay state // From ARM to ESP #define SSPM_FUNC_ENERGY_RESULT 6 // 0x06 @@ -166,17 +169,14 @@ #define SSPM_FUNC_23 23 // 0x17 #define SSPM_FUNC_29 29 // 0x1D #define SSPM_FUNC_32 32 // 0x20 -#define SSPM_FUNC_34 34 // 0x22 -#define SSPM_FUNC_35 35 // 0x23 -#define SSPM_FUNC_36 36 // 0x24 #define SSPM_GPIO_ARM_RESET 15 #define SSPM_GPIO_LED_ERROR 33 #define SSPM_MODULE_NAME_SIZE 12 -#define SSPM_MAIN_V1_0_0 0x00010000 -#define SSPM_MAIN_V1_2_0 0x00010200 +#define SSPM_VERSION_1_0_0 0x00010000 +#define SSPM_VERSION_1_2_0 0x00010200 /*********************************************************************************************/ @@ -264,6 +264,7 @@ typedef struct { uint32_t timeout; uint32_t main_version; + uint32_t relay_version; power_t old_power; power_t power_on_state; uint16_t last_totals; @@ -271,11 +272,12 @@ typedef struct { uint16_t expected_bytes; uint8_t module[SSPM_MAX_MODULES][SSPM_MODULE_NAME_SIZE]; uint8_t history_day[SSPM_MAX_MODULES][4]; + uint8_t poweron_state[SSPM_MAX_MODULES][4]; #ifdef SSPM_SIMULATE uint8_t simulate; uint8_t simulated_module; -#endif +#endif // SSPM_SIMULATE uint8_t allow_updates; uint8_t get_energy_relay; int8_t get_energy_relay_focus; @@ -406,7 +408,7 @@ uint32_t SSPMGetMappedModuleId(uint32_t module) { module_nr = 0; // Emulate modules by 0 } } -#endif +#endif // SSPM_SIMULATE return (uint32_t)module_nr; // 0, 1, ... } @@ -912,7 +914,68 @@ void SSPMSendGetEnergyPeriod(uint32_t relay) { } -void SSPMSendGetNew1(uint32_t module) { +void SSPMSendFunc34(uint32_t module) { + /* + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 00 22 00 00 f2 6a 7f + Marker |Module id |Ac|Cm|Size |Ix|Chksm| + */ + if (module >= Sspm->module_max) { return; } + + SSPMInitSend(); + memcpy(SspmBuffer +3, Sspm->module[SSPMGetMappedModuleId(module)], SSPM_MODULE_NAME_SIZE); + SspmBuffer[16] = SSPM_FUNC_34; // 0x22 + Sspm->command_sequence++; + SspmBuffer[19] = Sspm->command_sequence; + + SSPMSend(22); +} + +void SSPMSendGetOPSDefaults(uint32_t module) { + /* + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 00 23 00 00 f4 94 fe + Marker |Module id |Ac|Cm|Size |Ix|Chksm| + */ + if (module >= Sspm->module_max) { return; } + + SSPMInitSend(); + memcpy(SspmBuffer +3, Sspm->module[SSPMGetMappedModuleId(module)], SSPM_MODULE_NAME_SIZE); + SspmBuffer[16] = SSPM_FUNC_GET_OPS_DEFAULTS; // 0x23 + Sspm->command_sequence++; + SspmBuffer[19] = Sspm->command_sequence; + + SSPMSend(22); +} + +void SSPMSendSetPowerOnState(uint32_t module) { + /* + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 00 24 00 05 0f 00 01 02 01 00 f3 c2 + Marker |Module id |Ac|Cm|Size |??|P1|P2|P3|P4|Ix|Chksm| + P1 - Relay1 power on state (0 = On, 1 = Off, 2 = Laststate) + P2 - Relay2 power on state (0 = On, 1 = Off, 2 = Laststate) + P3 - Relay3 power on state (0 = On, 1 = Off, 2 = Laststate) + P4 - Relay4 power on state (0 = On, 1 = Off, 2 = Laststate) + */ + if (module >= Sspm->module_max) { return; } + + SSPMInitSend(); + memcpy(SspmBuffer +3, Sspm->module[SSPMGetMappedModuleId(module)], SSPM_MODULE_NAME_SIZE); + SspmBuffer[16] = SSPM_FUNC_SET_POS; // 0x24 + SspmBuffer[18] = 0x05; + SspmBuffer[19] = 0x0F; + SspmBuffer[20] = Sspm->poweron_state[module][0]; + SspmBuffer[21] = Sspm->poweron_state[module][1]; + SspmBuffer[22] = Sspm->poweron_state[module][2]; + SspmBuffer[23] = Sspm->poweron_state[module][3]; + Sspm->command_sequence++; + SspmBuffer[24] = Sspm->command_sequence; + + SSPMSend(27); +} + +void SSPMSendGetPowerOnState(uint32_t module) { /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 aa 55 01 6b 7e 32 37 39 37 34 13 4b 35 36 37 00 25 00 00 08 c0 0a @@ -922,7 +985,7 @@ void SSPMSendGetNew1(uint32_t module) { SSPMInitSend(); memcpy(SspmBuffer +3, Sspm->module[SSPMGetMappedModuleId(module)], SSPM_MODULE_NAME_SIZE); - SspmBuffer[16] = SSPM_FUNC_GET_NEW1; // 0x25 + SspmBuffer[16] = SSPM_FUNC_GET_POS; // 0x25 Sspm->command_sequence++; SspmBuffer[19] = Sspm->command_sequence; @@ -955,6 +1018,11 @@ void SSPMAddModule(void) { } Sspm->map_change = true; } + + uint32_t relay_version = SspmBuffer[36] << 16 | SspmBuffer[37] << 8 | SspmBuffer[38]; // 0x00010000 or 0x00010200 + if (relay_version < Sspm->relay_version) { + Sspm->relay_version = relay_version; // Lowest version will be supported + } mapped++; AddLog(LOG_LEVEL_INFO, PSTR("SPM: 4Relay %d (mapped to %d) type %d version %d.%d.%d found with id %12_H"), Sspm->module_max +1, mapped, SspmBuffer[35], SspmBuffer[36], SspmBuffer[37], SspmBuffer[38], Sspm->module[Sspm->module_max]); @@ -1086,8 +1154,8 @@ void SSPMHandleReceivedData(void) { MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR("SSPMOverload")); Sspm->overload_relay = 255; } else { - if (Sspm->main_version > SSPM_MAIN_V1_0_0) { - SSPMSendGetNew1(Sspm->module_selected -1); + if (Sspm->main_version > SSPM_VERSION_1_0_0) { + SSPMSendGetPowerOnState(Sspm->module_selected -1); } else { Sspm->module_selected--; if (Sspm->module_selected > 0) { @@ -1109,7 +1177,7 @@ void SSPMHandleReceivedData(void) { uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[3] << 8 | SspmBuffer[4]); #ifdef SSPM_SIMULATE if (Sspm->Settings.simulate_count) { module = Sspm->simulated_module; } -#endif +#endif // SSPM_SIMULATE power_t current_state = (SspmBuffer[20] >> 4) << (module * 4); // Relays state power_t mask = 0x0000000F << (module * 4); TasmotaGlobal.power &= (POWER_MASK ^ mask); @@ -1206,7 +1274,7 @@ void SSPMHandleReceivedData(void) { uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[20] << 8 | SspmBuffer[21]); #ifdef SSPM_SIMULATE if (Sspm->Settings.simulate_count) { module = Sspm->simulated_module; } -#endif +#endif // SSPM_SIMULATE if (Sspm->history_relay < 255) { uint32_t history_module = Sspm->history_relay >> 2; uint32_t history_channel = Sspm->history_relay & 0x03; // Channel relays are NOT bit masked this time @@ -1359,16 +1427,53 @@ void SSPMHandleReceivedData(void) { case SSPM_FUNC_RESET: /* 0x1C AA 55 01 00 00 00 00 00 00 00 00 00 00 00 00 80 1c 00 01 00 0b f9 e3 + Marker |Module id |Ac|Cm|Size |St|Ix|Chksm| */ // TasmotaGlobal.restart_flag = 2; break; - case SSPM_FUNC_GET_NEW1: - /* 0x25 v1.2.0 - 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 - AA 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 80 25 00 01 01 06 98 06 + case SSPM_FUNC_34: + /* 0x22 v1.2.0 + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 80 22 00 02 00 00 f2 19 00 + Marker |Module id |Ac|Cm|Size |St| |Ix|Chksm| + */ + break; + case SSPM_FUNC_GET_OPS_DEFAULTS: + /* 0x23 v1.2.0 + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 80 23 00 11 00 14 00 00 0a 01 08 00 00 5a 00 12 c0 00 00 00 0a f4 7f 4d + Marker |Module id |Ac|Cm|Size |St|Max I|Min I|Max U |Min U |Max P |Min P |Ix|Chksm| + |OK|20.0A|0.10A| 240.00V| 0.10V|4400.00W| 0.10W| + */ + break; + case SSPM_FUNC_SET_POS: + /* 0x24 v1.2.0 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 80 24 00 01 00 00 80 a8 Marker |Module id |Ac|Cm|Size |St|Ix|Chksm| */ + break; + case SSPM_FUNC_GET_POS: + /* 0x25 v1.2.0 - Get Power On State + Response v1.0.0 + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + AA 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 80 25 00 01 01 06 98 06 + Marker |Module id |Ac|Cm|Size |St|Ix|Chksm| + + Response v1.2.0 + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 + aa 55 01 8b 34 32 37 39 37 34 13 4b 35 36 37 80 25 00 05 00 00 01 02 01 07 b6 89 + Marker |Module id |Ac|Cm|Size |St|P1|P2|P3|P4|Ix|Chksm| + P1 - Relay1 power on state (0 = On, 1 = Off, 2 = Laststate) + P2 - Relay2 power on state (0 = On, 1 = Off, 2 = Laststate) + P3 - Relay3 power on state (0 = On, 1 = Off, 2 = Laststate) + P4 - Relay4 power on state (0 = On, 1 = Off, 2 = Laststate) + */ Sspm->module_selected--; + if (!status && (0x05 == expected_bytes)) { + for (uint32_t i = 0; i < 4; i++) { + Sspm->poweron_state[Sspm->module_selected][i] = SspmBuffer[20 +i]; + } + } if (Sspm->module_selected > 0) { SSPMSendGetModuleState(Sspm->module_selected -1); } else { @@ -1402,7 +1507,7 @@ void SSPMHandleReceivedData(void) { uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[19] << 8 | SspmBuffer[20]); #ifdef SSPM_SIMULATE if (Sspm->Settings.simulate_count) { module = Sspm->simulated_module; } -#endif +#endif // SSPM_SIMULATE Sspm->current[module][channel] = SspmBuffer[32] + (float)SspmBuffer[33] / 100; // x.xxA Sspm->voltage[module][channel] = SSPMGetValue(&SspmBuffer[34]); // x.xxV Sspm->active_power[module][channel] = SSPMGetValue(&SspmBuffer[37]); // x.xxW @@ -1428,7 +1533,7 @@ void SSPMHandleReceivedData(void) { uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[19] << 8 | SspmBuffer[20]); #ifdef SSPM_SIMULATE // if (Sspm->Settings.simulate_count) { module = Sspm->simulated_module; } // Won't work as this is initiated from device -#endif +#endif // SSPM_SIMULATE power_t relay = (SspmBuffer[31] & 0x0F) << (module * 4); // Relays active power_t relay_state = (SspmBuffer[31] >> 4) << (module * 4); // Relays state for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) { @@ -1524,7 +1629,7 @@ void SSPMHandleReceivedData(void) { SspmBuffer[19] = current_idh; SspmBuffer[20] = current_idl; } -#endif +#endif // SSPM_SIMULATE } SSPMSendAck(command_sequence); break; @@ -1818,6 +1923,7 @@ void SSPMInit(void) { #endif #endif + Sspm->relay_version = 0xFFFFFFFF; // Find lowest supported relay version Sspm->overload_relay = 255; // Disable display overload settings Sspm->history_relay = 255; // Disable display energy history Sspm->log_relay = 255; // Disable display logging @@ -1916,15 +2022,18 @@ void SSPMEvery100ms(void) { // Scan sequence finished #ifdef SSPM_SIMULATE if (!Sspm->Settings.simulate_count) { -#endif - if (Sspm->power_on_state) { - TasmotaGlobal.power = Sspm->power_on_state; - Sspm->power_on_state = 0; // Reset power on state solving re-scan - SetPowerOnState(); // Set power on state now that all relays have been detected +#endif // SSPM_SIMULATE + if (Sspm->relay_version < SSPM_VERSION_1_2_0) { + // Set relay power on state based on Tasmota global setting + if (Sspm->power_on_state) { + TasmotaGlobal.power = Sspm->power_on_state; + Sspm->power_on_state = 0; // Reset power on state solving re-scan + SetPowerOnState(); // Set power on state now that all relays have been detected + } } #ifdef SSPM_SIMULATE } -#endif +#endif // SSPM_SIMULATE TasmotaGlobal.discovery_counter = 1; // Force TasDiscovery() Sspm->allow_updates = 1; // Enable requests from 100mSec loop Sspm->get_energy_relay = 0; @@ -2201,19 +2310,19 @@ const char kSSPMCommands[] PROGMEM = "SSPM|" // Prefix "Display|Dump|" // SetOptions #ifdef SSPM_SIMULATE "Simulate|" -#endif +#endif // SSPM_SIMULATE "Log|Energy|History|Scan|IamHere|" "Reset|Map|Overload|" - D_CMND_ENERGYTOTAL "|" D_CMND_ENERGYYESTERDAY "|Send"; + D_CMND_ENERGYTOTAL "|" D_CMND_ENERGYYESTERDAY "|Send|" D_CMND_POWERONSTATE; void (* const SSPMCommand[])(void) PROGMEM = { &CmndSSPMDisplay, &CmndSSPMDump, #ifdef SSPM_SIMULATE &CmndSSPMSimulate, -#endif +#endif // SSPM_SIMULATE &CmndSSPMLog, &CmndSSPMEnergy, &CmndSSPMHistory, &CmndSSPMScan, &CmndSSPMIamHere, &CmndSSPMReset, &CmndSSPMMap, &CmndSSPMOverload, - &CmndSpmEnergyTotal, &CmndSpmEnergyYesterday, &CmndSSPMSend }; + &CmndSpmEnergyTotal, &CmndSpmEnergyYesterday, &CmndSSPMSend, &CmndSSPMPowerOnState }; void CmndSSPMDisplay(void) { // Select either all relays, only powered on relays or user selected relay module @@ -2244,7 +2353,7 @@ void CmndSSPMSimulate(void) { } ResponseCmndNumber(Sspm->Settings.simulate_count); } -#endif +#endif // SSPM_SIMULATE void CmndSpmEnergyTotal(void) { // Reset Energy Total @@ -2471,6 +2580,25 @@ void CmndSSPMSend(void) { } } +void CmndSSPMPowerOnState(void) { + // SspmPowerOnState2 0|1|2 - Set relay2 power on state (0 = Off, 1 = On, 2 = Saved) + if (Sspm->relay_version > SSPM_VERSION_1_0_0) { + uint32_t max_index = (Sspm->module_max *4) +1; + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index < max_index)) { + uint32_t module = (XdrvMailbox.index -1) >>2; + uint32_t relay = (XdrvMailbox.index -1) &3; + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { + if (XdrvMailbox.payload < 2) { XdrvMailbox.payload = !XdrvMailbox.payload; } // Swap Tasmota power off (0) with Sonoff (1) + Sspm->poweron_state[module][relay] = XdrvMailbox.payload; + SSPMSendSetPowerOnState(module); + } + uint32_t poweron_state = Sspm->poweron_state[module][relay]; + if (poweron_state < 2) { poweron_state = !poweron_state; } // Swap Sonoff power off (1) with Tasmota (0) + ResponseCmndIdxNumber(poweron_state); + } + } +} + /*********************************************************************************************\ * Interface \*********************************************************************************************/ From 411a7f0788fe14c44cf4072e0cb445d2e928d5a9 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 16 Oct 2022 15:03:05 +0200 Subject: [PATCH 13/13] Update xdrv_86_esp32_sonoff_spm.ino --- .../xdrv_86_esp32_sonoff_spm.ino | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino b/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino index 7cdc8011d..4b568da3a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_86_esp32_sonoff_spm.ino @@ -1037,6 +1037,16 @@ void SSPMAddModule(void) { /*********************************************************************************************/ +void SSPMLogResult(uint32_t command, uint32_t status) { + if (1 == status) { + AddLog(LOG_LEVEL_DEBUG, PSTR("SPM: Command %d not supported"), command); + } else if (2 == status) { + AddLog(LOG_LEVEL_DEBUG, PSTR("SPM: Command %d timeout"), command); + } else { + AddLog(LOG_LEVEL_DEBUG, PSTR("SPM: Command %d result %d"), command, status); + } +} + void SSPMHandleReceivedData(void) { /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 @@ -1047,7 +1057,7 @@ void SSPMHandleReceivedData(void) { uint32_t command = SspmBuffer[16]; // Cm uint32_t expected_bytes = (SspmBuffer[17] << 8) + SspmBuffer[18]; // Size // 0 - OK - // 1 - + // 1 - Not supported // 2 - Timeout // 3 - Log empty // 4 - @@ -1061,7 +1071,7 @@ void SSPMHandleReceivedData(void) { if (ack) { // Responses from ARM (Acked) if (status > 0) { - AddLog(LOG_LEVEL_DEBUG, PSTR("SPM: Command %d result %d"), command, status); + SSPMLogResult(command, status); } switch(command) { case SSPM_FUNC_FIND: @@ -1469,10 +1479,8 @@ void SSPMHandleReceivedData(void) { P4 - Relay4 power on state (0 = On, 1 = Off, 2 = Laststate) */ Sspm->module_selected--; - if (!status && (0x05 == expected_bytes)) { - for (uint32_t i = 0; i < 4; i++) { - Sspm->poweron_state[Sspm->module_selected][i] = SspmBuffer[20 +i]; - } + for (uint32_t i = 0; i < 4; i++) { + Sspm->poweron_state[Sspm->module_selected][i] = (!status && (expected_bytes >= 0x05)) ? SspmBuffer[20 +i] : 1; } if (Sspm->module_selected > 0) { SSPMSendGetModuleState(Sspm->module_selected -1); @@ -1575,7 +1583,7 @@ void SSPMHandleReceivedData(void) { Ot - Overtemp */ if (status > 0) { - AddLog(LOG_LEVEL_DEBUG, PSTR("SPM: Command %d result %d"), command, status); + SSPMLogResult(command, status); } else if (0x14 == expected_bytes) { // Overload/Overtemp triggered uint32_t any_bit_set = 0; @@ -2582,20 +2590,26 @@ void CmndSSPMSend(void) { void CmndSSPMPowerOnState(void) { // SspmPowerOnState2 0|1|2 - Set relay2 power on state (0 = Off, 1 = On, 2 = Saved) - if (Sspm->relay_version > SSPM_VERSION_1_0_0) { - uint32_t max_index = (Sspm->module_max *4) +1; - if ((XdrvMailbox.index > 0) && (XdrvMailbox.index < max_index)) { - uint32_t module = (XdrvMailbox.index -1) >>2; - uint32_t relay = (XdrvMailbox.index -1) &3; - if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { - if (XdrvMailbox.payload < 2) { XdrvMailbox.payload = !XdrvMailbox.payload; } // Swap Tasmota power off (0) with Sonoff (1) - Sspm->poweron_state[module][relay] = XdrvMailbox.payload; - SSPMSendSetPowerOnState(module); - } - uint32_t poweron_state = Sspm->poweron_state[module][relay]; - if (poweron_state < 2) { poweron_state = !poweron_state; } // Swap Sonoff power off (1) with Tasmota (0) - ResponseCmndIdxNumber(poweron_state); + uint32_t max_index = Sspm->module_max *4; + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= max_index)) { + uint32_t module = (XdrvMailbox.index -1) >>2; + uint32_t relay = (XdrvMailbox.index -1) &3; + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { + if (XdrvMailbox.payload < 2) { XdrvMailbox.payload = !XdrvMailbox.payload; } // Swap Tasmota power off (0) with Sonoff (1) + Sspm->poweron_state[module][relay] = XdrvMailbox.payload; + SSPMSendSetPowerOnState(module); } + Response_P(PSTR("{\"%s\":["), XdrvMailbox.command); + bool more = false; + for (uint32_t module = 0; module < Sspm->module_max; module++) { + for (uint32_t relay = 0; relay < 4; relay++) { + uint32_t poweron_state = Sspm->poweron_state[module][relay]; + if (poweron_state < 2) { poweron_state = !poweron_state; } // Swap Sonoff power off (1) with Tasmota (0) + ResponseAppend_P(PSTR("%s%d"), (more)?",":"", poweron_state); + more = true; + } + } + ResponseAppend_P(PSTR("]}")); } }