From 2daaa367ff1f1139db676d5a0909a36f827c6920 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 18 Oct 2023 11:29:35 +0200 Subject: [PATCH 1/7] stepper shutter channel fix (#19784) --- .../xdrv_27_esp32_shutter.ino | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index a0b447e396c2..889fd9e05957 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -180,6 +180,7 @@ struct SHUTTER { uint32_t last_stop_time = 0; // record the last time the relay was switched off uint8_t button_simu_pressed = 0; // record if both button where pressed simultanously uint8_t ledc_channel = 0; // current used channel for PWM + uint32_t current_stop_way = 0; } Shutter[MAX_SHUTTERS_ESP32]; struct SHUTTERGLOBAL { @@ -410,6 +411,7 @@ void ShutterCalculateAccelerator(uint8_t i) min_runtime_ms = current_pwm_velocity * 1000 / STEPS_PER_SECOND / velocity_change_per_step_max; // decellaration way from current velocity current_stop_way = min_runtime_ms * STEPS_PER_SECOND * (current_pwm_velocity + velocity_change_per_step_max) * Shutter[i].direction / 2 / ShutterGlobal.open_velocity_max - (Shutter[i].accelerator<0?Shutter[i].direction*1000*current_pwm_velocity/ShutterGlobal.open_velocity_max:0); + Shutter[i].current_stop_way = current_stop_way; next_possible_stop_position = current_real_position + current_stop_way ; // ensure that the accelerotor kicks in at the first overrun of the target position if ( Shutter[i].accelerator < 0 || next_possible_stop_position * Shutter[i].direction > Shutter[i].target_position * Shutter[i].direction ) { @@ -537,13 +539,16 @@ uint8_t ShutterGetFreeChannel() { for (uint8_t i = 0; i < MAX_SHUTTERS_ESP32; i++) { //SOC_LEDC_CHANNEL_NUM nextFreeChannel = tmax(nextFreeChannel, Shutter[i].ledc_channel); + //AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: %d -> channel %d"), i, Shutter[i].ledc_channel); } if (nextFreeChannel >= SOC_LEDC_CHANNEL_NUM) { AddLog(LOG_LEVEL_ERROR, PSTR("SHT: All PWM channel busy. Open issue-ticket.")); + return 0; } else { - AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Use channel %d"), nextFreeChannel+1); + nextFreeChannel++; + AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Use channel %d"), nextFreeChannel); } - return nextFreeChannel++; + return nextFreeChannel; } uint8_t ShutterGetOptions(uint8_t index) { @@ -1167,6 +1172,7 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) #ifdef SHUTTER_STEPPER case SHT_COUNTER: Shutter[i].ledc_channel = ShutterGetFreeChannel(); + //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Channel %d assigned to SHT %d"),Shutter[i].ledc_channel, i); ledcSetup(Shutter[i].ledc_channel, Shutter[i].pwm_velocity, 8); ledcAttachPin(Pin(GPIO_PWM1, i), Shutter[i].ledc_channel); ledcWriteTone(Shutter[i].ledc_channel, Shutter[i].pwm_velocity); @@ -1276,9 +1282,9 @@ void ShutterUpdatePosition(void) // Update time information int32_t deltatime = Shutter[i].time - Shutter[i].last_reported_time; Shutter[i].last_reported_time = Shutter[i].time + 1; - AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d Time %d(%d), cStop %d, cVelo %d, mVelo %d, aVelo %d, mRun %d, aPos %d, aPos2 %d, nStop %d, Trgt %d, mVelo %d, Dir %d, Tilt %d, TrgtTilt: %d, Tiltmove: %d"), - i+1, Shutter[i].time, deltatime, current_stop_way, current_pwm_velocity, velocity_max, Shutter[i].accelerator, min_runtime_ms, current_real_position,Shutter[i].real_position, - next_possible_stop_position, Shutter[i].target_position, velocity_change_per_step_max, Shutter[i].direction,Shutter[i].tilt_real_pos, Shutter[i].tilt_target_pos, + AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d Time %d(%d), cStop %d, cVelo %d, mVelo %d, aVelo %d, mRun %d, aPos %d, nStop %d, Trgt %d, mVelo %d, Dir %d, Tilt %d, TrgtTilt: %d, Tiltmove: %d"), + i+1, Shutter[i].time, deltatime, Shutter[i].current_stop_way, Shutter[i].pwm_velocity, velocity_max, Shutter[i].accelerator, min_runtime_ms, Shutter[i].real_position, + Shutter[i].current_stop_way + Shutter[i].real_position, Shutter[i].target_position, velocity_change_per_step_max, Shutter[i].direction,Shutter[i].tilt_real_pos, Shutter[i].tilt_target_pos, Shutter[i].tiltmoving); // Check calibration mode and energy information From 13c6bc91cced21ef2ef9626acd5ea4138243c7c1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:15:49 +0200 Subject: [PATCH 2/7] Fix empty name if no DSAlias defined (#19763) --- .../tasmota_xsns_sensor/xsns_05_ds18x20.ino | 33 +++++++++++-------- .../xsns_05_esp32_ds18x20.ino | 33 +++++++++++-------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino index 9302381d6900..646c911ccef4 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino @@ -468,36 +468,42 @@ bool Ds18x20Read(uint8_t sensor) { } void Ds18x20Name(uint8_t sensor) { - uint8_t index = sizeof(ds18x20_chipids); + uint32_t sensor_index = ds18x20_sensor[sensor].index; + + uint32_t index = sizeof(ds18x20_chipids); while (--index) { - if (ds18x20_sensor[ds18x20_sensor[sensor].index].address[0] == ds18x20_chipids[index]) { + if (ds18x20_sensor[sensor_index].address[0] == ds18x20_chipids[index]) { break; } } + // DS18B20 GetTextIndexed(DS18X20Data.name, sizeof(DS18X20Data.name), index, kDs18x20Types); #ifdef DS18x20_USE_ID_AS_NAME char address[17]; for (uint32_t j = 0; j < 3; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[sensor].index].address[3-j]); // Only last 3 bytes + sprintf(address+2*j, "%02X", ds18x20_sensor[sensor_index].address[3-j]); // Only last 3 bytes } + // DS18B20-8EC44C snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%s"), DS18X20Data.name, IndexSeparator(), address); + return; #elif defined(DS18x20_USE_ID_ALIAS) - sensor = ds18x20_sensor[sensor].index; - if (ds18x20_sensor[sensor].alias[0] != '0') { - if (isdigit(ds18x20_sensor[sensor].alias[0])) { - snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("DS18Sens%c%d"), IndexSeparator(), atoi(ds18x20_sensor[sensor].alias)); + if (ds18x20_sensor[sensor_index].alias[0] && (ds18x20_sensor[sensor_index].alias[0] != '0')) { + if (isdigit(ds18x20_sensor[sensor_index].alias[0])) { + // DS18Sens-1 + snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("DS18Sens%c%d"), IndexSeparator(), atoi(ds18x20_sensor[sensor_index].alias)); } else { - snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s"), ds18x20_sensor[sensor].alias); + // UserText + snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s"), ds18x20_sensor[sensor_index].alias); } - } else { - snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%d"), DS18X20Data.name, IndexSeparator(), sensor + 1); + return; } -#else // no #defines set +#endif // DS18x20_USE_ID_AS_NAME or DS18x20_USE_ID_ALIAS + if (DS18X20Data.sensors > 1) { + // DS18B20-1 snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%d"), DS18X20Data.name, IndexSeparator(), sensor + 1); } -#endif } /********************************************************************************************/ @@ -582,6 +588,7 @@ void (* const DSCommand[])(void) PROGMEM = { &CmndDSAlias }; void CmndDSAlias(void) { + // Ds18Alias 430516707FA6FF28,Sensorname char Argument1[XdrvMailbox.data_len]; char Argument2[XdrvMailbox.data_len]; char address[17]; @@ -614,7 +621,7 @@ void CmndDSAlias(void) { } ResponseAppend_P(PSTR("}")); } -#endif // DS18x20_USE_ID_ALIAS +#endif // DS18x20_USE_ID_ALIAS /*********************************************************************************************\ * Interface diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino index d4b226ccdd77..094910c76217 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino @@ -212,36 +212,42 @@ bool Ds18x20Read(uint8_t sensor, float &t) { } void Ds18x20Name(uint8_t sensor) { - uint8_t index = sizeof(ds18x20_chipids); + uint32_t sensor_index = ds18x20_sensor[sensor].index; + + uint32_t index = sizeof(ds18x20_chipids); while (--index) { - if (ds18x20_sensor[ds18x20_sensor[sensor].index].address[0] == ds18x20_chipids[index]) { + if (ds18x20_sensor[sensor_index].address[0] == ds18x20_chipids[index]) { break; } } + // DS18B20 GetTextIndexed(DS18X20Data.name, sizeof(DS18X20Data.name), index, kDs18x20Types); #ifdef DS18x20_USE_ID_AS_NAME char address[17]; for (uint32_t j = 0; j < 3; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[sensor].index].address[3-j]); // Only last 3 bytes + sprintf(address+2*j, "%02X", ds18x20_sensor[sensor_index].address[3-j]); // Only last 3 bytes } + // DS18B20-8EC44C snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%s"), DS18X20Data.name, IndexSeparator(), address); + return; #elif defined(DS18x20_USE_ID_ALIAS) - sensor = ds18x20_sensor[sensor].index; - if (ds18x20_sensor[sensor].alias[0] != '0') { - if (isdigit(ds18x20_sensor[sensor].alias[0])) { - snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("DS18Sens%c%d"), IndexSeparator(), atoi(ds18x20_sensor[sensor].alias)); + if (ds18x20_sensor[sensor_index].alias[0] && (ds18x20_sensor[sensor_index].alias[0] != '0')) { + if (isdigit(ds18x20_sensor[sensor_index].alias[0])) { + // DS18Sens-1 + snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("DS18Sens%c%d"), IndexSeparator(), atoi(ds18x20_sensor[sensor_index].alias)); } else { - snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s"), ds18x20_sensor[sensor].alias); + // UserText + snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s"), ds18x20_sensor[sensor_index].alias); } - } else { - snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%d"), DS18X20Data.name, IndexSeparator(), sensor + 1); + return; } -#else // no #defines set +#endif // DS18x20_USE_ID_AS_NAME or DS18x20_USE_ID_ALIAS + if (DS18X20Data.sensors > 1) { + // DS18B20-1 snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%d"), DS18X20Data.name, IndexSeparator(), sensor + 1); } -#endif } /********************************************************************************************/ @@ -391,6 +397,7 @@ void CmndDSRescan(void) { } void CmndDSAlias(void) { + // Ds18Alias 430516707FA6FF28,Sensorname char Argument1[XdrvMailbox.data_len]; char Argument2[XdrvMailbox.data_len]; char address[17]; @@ -423,7 +430,7 @@ void CmndDSAlias(void) { } ResponseAppend_P(PSTR("}")); } -#endif // DS18x20_USE_ID_ALIAS +#endif // DS18x20_USE_ID_ALIAS /*********************************************************************************************\ * Interface From 1fa036f17687a14c52df8ff231039dd79700cb79 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:12:02 +0200 Subject: [PATCH 3/7] Fix unsorted DS18Alias (#19763) --- .../tasmota_xsns_sensor/xsns_05_ds18x20.ino | 9 +++--- .../xsns_05_esp32_ds18x20.ino | 31 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino index 646c911ccef4..1aeeb558462f 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino @@ -588,7 +588,8 @@ void (* const DSCommand[])(void) PROGMEM = { &CmndDSAlias }; void CmndDSAlias(void) { - // Ds18Alias 430516707FA6FF28,Sensorname + // Ds18Alias 430516707FA6FF28,SensorName - Use SensorName instead of DS18B20 + // Ds18Alias 430516707FA6FF28,0 - Disable alias (default) char Argument1[XdrvMailbox.data_len]; char Argument2[XdrvMailbox.data_len]; char address[17]; @@ -600,7 +601,7 @@ void CmndDSAlias(void) { for (uint32_t i = 0; i < DS18X20Data.sensors; i++) { for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); + sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); } if (!strncmp(Argument1, address, 12) && Argument2[0]) { snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2); @@ -614,10 +615,10 @@ void CmndDSAlias(void) { Ds18x20Name(i); char address[17]; for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); // Skip sensor type and crc + sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); // Skip sensor type and crc } ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"),DS18X20Data.name, address); - if (i < DS18X20Data.sensors-1) ResponseAppend_P(PSTR(",")); + if (i < DS18X20Data.sensors-1) { ResponseAppend_P(PSTR(",")); } } ResponseAppend_P(PSTR("}")); } diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino index 094910c76217..210d843d7409 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino @@ -353,32 +353,30 @@ const char kds18Commands[] PROGMEM = "DS18|" // prefix void (* const DSCommand[])(void) PROGMEM = { &CmndDSAlias, &CmndDSRescan ,&CmndDSRetryRead }; - void CmndDSRetryRead(void) { char argument[XdrvMailbox.data_len]; - if (ArgC()==1) { + if (ArgC() == 1) { DS18X20Data.retryRead = atoi(ArgV(argument, 1)); } - Response_P(PSTR("{\"DS18" D_CMND_DS_RETRYREAD "\": %d}"),DS18X20Data.retryRead); + Response_P(PSTR("{\"DS18" D_CMND_DS_RETRYREAD "\": %d}"), DS18X20Data.retryRead); } - void CmndDSRescan(void) { char argument[XdrvMailbox.data_len]; uint8_t retries = 1; uint8_t sensorsToFind = 1; - if (ArgC()>0 && ArgC()<3) { + if ((ArgC() > 0) && (ArgC() < 3)) { sensorsToFind = atoi(ArgV(argument, 1)); } - if (ArgC()==2) { + if (ArgC() == 2) { retries = atoi(ArgV(argument, 2)); } DS18X20Data.sensors = 0; memset(&ds18x20_sensor, 0, sizeof(ds18x20_sensor)); - while (DS18X20Data.sensors < sensorsToFind && retries-- > 0) { + while ((DS18X20Data.sensors < sensorsToFind) && (retries-- > 0)) { Ds18x20Search(); AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_DSB D_SENSORS_FOUND " %d"), DS18X20Data.sensors); } @@ -388,28 +386,29 @@ void CmndDSRescan(void) { Ds18x20Name(i); char address[17]; for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); // Skip sensor type and crc + sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); // Skip sensor type and crc } - ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"),DS18X20Data.name, address); - if (i < DS18X20Data.sensors-1) {ResponseAppend_P(PSTR(","));} + ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"), DS18X20Data.name, address); + if (i < DS18X20Data.sensors-1) { ResponseAppend_P(PSTR(",")); } } ResponseAppend_P(PSTR("}")); } void CmndDSAlias(void) { - // Ds18Alias 430516707FA6FF28,Sensorname + // Ds18Alias 430516707FA6FF28,SensorName - Use SensorName instead of DS18B20 + // Ds18Alias 430516707FA6FF28,0 - Disable alias (default) char Argument1[XdrvMailbox.data_len]; char Argument2[XdrvMailbox.data_len]; char address[17]; - if (ArgC()==2) { + if (ArgC() == 2) { ArgV(Argument1, 1); ArgV(Argument2, 2); TrimSpace(Argument2); for (uint32_t i = 0; i < DS18X20Data.sensors; i++) { for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); + sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); } if (!strncmp(Argument1, address, 12) && Argument2[0]) { snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2); @@ -423,10 +422,10 @@ void CmndDSAlias(void) { Ds18x20Name(i); char address[17]; for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); // Skip sensor type and crc + sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); // Skip sensor type and crc } - ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"),DS18X20Data.name, address); - if (i < DS18X20Data.sensors-1) ResponseAppend_P(PSTR(",")); + ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"), DS18X20Data.name, address); + if (i < DS18X20Data.sensors-1) { ResponseAppend_P(PSTR(",")); } } ResponseAppend_P(PSTR("}")); } From 58324da242487c04f7e8f75bd34d05e48a587e57 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:19:13 +0200 Subject: [PATCH 4/7] Final fix ;-) (#19763) --- tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino | 2 +- tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino index 1aeeb558462f..ccc489a62e99 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino @@ -601,7 +601,7 @@ void CmndDSAlias(void) { for (uint32_t i = 0; i < DS18X20Data.sensors; i++) { for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); + sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); } if (!strncmp(Argument1, address, 12) && Argument2[0]) { snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2); diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino index 210d843d7409..95b5776df164 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino @@ -408,7 +408,7 @@ void CmndDSAlias(void) { for (uint32_t i = 0; i < DS18X20Data.sensors; i++) { for (uint32_t j = 0; j < 8; j++) { - sprintf(address+2*j, "%02X", ds18x20_sensor[ds18x20_sensor[i].index].address[7-j]); + sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); } if (!strncmp(Argument1, address, 12) && Argument2[0]) { snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2); From 26e9d7e49c7606628c1373aadb5ade751ede410b Mon Sep 17 00:00:00 2001 From: Christian Baars Date: Wed, 18 Oct 2023 17:52:51 +0200 Subject: [PATCH 5/7] deactivate automatic flashsize detection (#19788) --- platformio_tasmota32.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio_tasmota32.ini b/platformio_tasmota32.ini index b430d6150be8..2a640c215eff 100644 --- a/platformio_tasmota32.ini +++ b/platformio_tasmota32.ini @@ -47,7 +47,7 @@ lib_ignore = ArduinoOTA ESP32-HomeKit extra_scripts = pre:pio-tools/add_c_flags.py - pre:pio-tools/get_flash_size.py + ; pre:pio-tools/get_flash_size.py pre:pio-tools/gen-berry-structures.py post:pio-tools/post_esp32.py ${esp_defaults.extra_scripts} From 385408dcfd1347dc8298991fa70c54f71625a584 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:02:47 +0200 Subject: [PATCH 6/7] Berry fix bool side effect (#19790) --- lib/libesp32/berry/src/be_code.c | 13 +++++++++++- lib/libesp32/berry/tests/bool.be | 4 ++++ .../src/solidify/solidified_mqtt.h | 21 +++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/libesp32/berry/src/be_code.c b/lib/libesp32/berry/src/be_code.c index 147036948847..c6aa6e815db1 100644 --- a/lib/libesp32/berry/src/be_code.c +++ b/lib/libesp32/berry/src/be_code.c @@ -472,7 +472,18 @@ static int exp2reg(bfuncinfo *finfo, bexpdesc *e, int dst) int pcf = NO_JUMP; /* position of an eventual LOAD false */ int pct = NO_JUMP; /* position of an eventual LOAD true */ int jpt = appendjump(finfo, jumpboolop(e, 1), e); - reg = e->v.idx; + /* below is a simplified version of `codedestreg` for a single bexpdesc */ + if (e->type == ETREG) { + /* if e is already ETREG from local calculation, we reuse the register */ + reg = e->v.idx; + } else { + /* otherwise, we allocate a new register or use the target provided */ + if (dst < 0) { + reg = be_code_allocregs(finfo, 1); + } else { + reg = dst; + } + } be_code_conjump(finfo, &e->t, jpt); pcf = code_bool(finfo, reg, 0, 1); pct = code_bool(finfo, reg, 1, 0); diff --git a/lib/libesp32/berry/tests/bool.be b/lib/libesp32/berry/tests/bool.be index b0323c3df197..2b6bf74746cd 100644 --- a/lib/libesp32/berry/tests/bool.be +++ b/lib/libesp32/berry/tests/bool.be @@ -47,3 +47,7 @@ assert(bool({nil:nil}) == false)# changed behavior - `nil` key is ignored so the import introspect assert(bool(introspect.toptr(0x1000)) == true) assert(bool(introspect.toptr(0)) == false) + +# reproduce bug https://github.com/berry-lang/berry/issues/372 +def f() var a = false var b = true || a return a end +assert(f() == false) diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_mqtt.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_mqtt.h index 33744dd36f50..14e08786cc70 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_mqtt.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_mqtt.h @@ -27,7 +27,7 @@ be_local_closure(MQTT_mqtt_data, /* name */ }), &be_const_str_mqtt_data, &be_const_str_solidified, - ( &(const binstruction[32]) { /* code */ + ( &(const binstruction[31]) { /* code */ 0x88140100, // 0000 GETMBR R5 R0 K0 0x4C180000, // 0001 LDNIL R6 0x1C140A06, // 0002 EQ R5 R5 R6 @@ -37,13 +37,13 @@ be_local_closure(MQTT_mqtt_data, /* name */ 0x60180010, // 0006 GETGBL R6 G16 0x881C0100, // 0007 GETMBR R7 R0 K0 0x7C180200, // 0008 CALL R6 1 - 0xA8020011, // 0009 EXBLK 0 #001C + 0xA8020010, // 0009 EXBLK 0 #001B 0x5C1C0C00, // 000A MOVE R7 R6 0x7C1C0000, // 000B CALL R7 0 0x88200F01, // 000C GETMBR R8 R7 K1 0x4C240000, // 000D LDNIL R9 0x20201009, // 000E NE R8 R8 R9 - 0x7822000A, // 000F JMPF R8 #001B + 0x78220009, // 000F JMPF R8 #001A 0x8C200F02, // 0010 GETMET R8 R7 K2 0x5C280200, // 0011 MOVE R10 R1 0x5C2C0400, // 0012 MOVE R11 R2 @@ -52,14 +52,13 @@ be_local_closure(MQTT_mqtt_data, /* name */ 0x7C200A00, // 0015 CALL R8 5 0x74160001, // 0016 JMPT R5 #0019 0x74220000, // 0017 JMPT R8 #0019 - 0x50200001, // 0018 LDBOOL R8 0 1 - 0x50200200, // 0019 LDBOOL R8 1 0 - 0x5C141000, // 001A MOVE R5 R8 - 0x7001FFED, // 001B JMP #000A - 0x58180003, // 001C LDCONST R6 K3 - 0xAC180200, // 001D CATCH R6 1 0 - 0xB0080000, // 001E RAISE 2 R0 R0 - 0x80040A00, // 001F RET 1 R5 + 0x50140001, // 0018 LDBOOL R5 0 1 + 0x50140200, // 0019 LDBOOL R5 1 0 + 0x7001FFEE, // 001A JMP #000A + 0x58180003, // 001B LDCONST R6 K3 + 0xAC180200, // 001C CATCH R6 1 0 + 0xB0080000, // 001D RAISE 2 R0 R0 + 0x80040A00, // 001E RET 1 R5 }) ) ); From d5f506b1e3df9396253c6754900e2f18367699cb Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 18 Oct 2023 23:41:52 +0200 Subject: [PATCH 7/7] reverted back some function and fix frequency storage (#19791) * optimize disc write delay during shutter movement changed to dynamic write delay to ensure no disc write on multiple shutter movement with stepper shutters. * optimize disc write delay ensure disc write will be postponed until all shutters stopped * reverted back to simple version * removed duplicate obsolete compiler options --- .../xdrv_27_esp32_shutter.ino | 70 +++++++------------ 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index 889fd9e05957..3e32ef566546 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -23,7 +23,6 @@ * Shutter or Blind support using two consecutive relays * Shutters for ESP32 with max eight shutters using more RAM and Settings from filesystem \*********************************************************************************************/ -#include "soc/soc_caps.h" #define XDRV_27 27 #ifndef SHUTTER_STEPPER @@ -179,8 +178,6 @@ struct SHUTTER { uint16_t last_reported_time = 0; // get information on skipped 50ms loop() slots uint32_t last_stop_time = 0; // record the last time the relay was switched off uint8_t button_simu_pressed = 0; // record if both button where pressed simultanously - uint8_t ledc_channel = 0; // current used channel for PWM - uint32_t current_stop_way = 0; } Shutter[MAX_SHUTTERS_ESP32]; struct SHUTTERGLOBAL { @@ -411,7 +408,6 @@ void ShutterCalculateAccelerator(uint8_t i) min_runtime_ms = current_pwm_velocity * 1000 / STEPS_PER_SECOND / velocity_change_per_step_max; // decellaration way from current velocity current_stop_way = min_runtime_ms * STEPS_PER_SECOND * (current_pwm_velocity + velocity_change_per_step_max) * Shutter[i].direction / 2 / ShutterGlobal.open_velocity_max - (Shutter[i].accelerator<0?Shutter[i].direction*1000*current_pwm_velocity/ShutterGlobal.open_velocity_max:0); - Shutter[i].current_stop_way = current_stop_way; next_possible_stop_position = current_real_position + current_stop_way ; // ensure that the accelerotor kicks in at the first overrun of the target position if ( Shutter[i].accelerator < 0 || next_possible_stop_position * Shutter[i].direction > Shutter[i].target_position * Shutter[i].direction ) { @@ -473,6 +469,7 @@ int32_t ShutterCalculatePosition(uint32_t i) void ShutterDecellerateForStop(uint8_t i) { + bool pwm_apply = false; // ESP32 only, do we need to apply PWM changes switch (ShutterGlobal.position_mode) { case SHT_PWM_VALUE: case SHT_COUNTER: @@ -493,9 +490,7 @@ void ShutterDecellerateForStop(uint8_t i) while (RtcSettings.pulse_counter[i] < (uint32_t)(Shutter[i].target_position-Shutter[i].start_position)*Shutter[i].direction*ShutterGlobal.open_velocity_max/RESOLUTION/STEPS_PER_SECOND && missing_steps > 0) { } TasmotaGlobal.pwm_value[i] = 0; - ledcWrite(Shutter[i].ledc_channel, 0); - ledcAttachPin(Pin(GPIO_PWM1, i), SOC_LEDC_CHANNEL_NUM); - Shutter[i].ledc_channel = 0; + pwm_apply = true; Shutter[i].real_position = ShutterCalculatePosition(i); //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Remain steps %d"), missing_steps); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Real %d, Pulsecount %d, tobe %d, Start %d"), Shutter[i].real_position,RtcSettings.pulse_counter[i], (uint32_t)(Shutter[i].target_position-Shutter[i].start_position)*Shutter[i].direction*ShutterGlobal.open_velocity_max/RESOLUTION/STEPS_PER_SECOND, Shutter[i].start_position); @@ -504,6 +499,7 @@ void ShutterDecellerateForStop(uint8_t i) Shutter[i].pwm_velocity = 0; break; } + if (pwm_apply) { PwmApplyGPIO(false); } } uint16_t ShutterGetCycleTime(uint8_t i, uint8_t max_runtime) { @@ -534,23 +530,6 @@ uint16_t ShutterGetCycleTime(uint8_t i, uint8_t max_runtime) { return cycle_time; } -uint8_t ShutterGetFreeChannel() { - uint8_t nextFreeChannel = 0; - for (uint8_t i = 0; i < MAX_SHUTTERS_ESP32; i++) { - //SOC_LEDC_CHANNEL_NUM - nextFreeChannel = tmax(nextFreeChannel, Shutter[i].ledc_channel); - //AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: %d -> channel %d"), i, Shutter[i].ledc_channel); - } - if (nextFreeChannel >= SOC_LEDC_CHANNEL_NUM) { - AddLog(LOG_LEVEL_ERROR, PSTR("SHT: All PWM channel busy. Open issue-ticket.")); - return 0; - } else { - nextFreeChannel++; - AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Use channel %d"), nextFreeChannel); - } - return nextFreeChannel; -} - uint8_t ShutterGetOptions(uint8_t index) { return ShutterSettings.shutter_options[index]; } @@ -827,9 +806,16 @@ void ShutterPowerOff(uint8_t i) #endif break; } - if (Settings->save_data) { - TasmotaGlobal.save_data_counter = Settings->save_data; + + // restore save_data behavior if all shutters are in stopped state + bool shutter_all_stopped = true; + for (uint8_t j = 0 ; j < TasmotaGlobal.shutters_present ; j++) { + if (Shutter[j].direction != 0) + shutter_all_stopped = false; } + if (shutter_all_stopped) + TasmotaGlobal.save_data_counter = Settings->save_data; + Shutter[i].last_stop_time = millis(); } @@ -976,7 +962,8 @@ void ShutterReportPosition(bool always, uint32_t index) void ShutterRtc50mS(void) { - // No Logging allowed. RTC Timer + bool pwm_apply = false; // ESP32 only, do we need to apply PWM changes + // No Logging allowed. RTC Timer for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) { if (Shutter[i].direction) { // update position data before increasing counter @@ -996,15 +983,15 @@ void ShutterRtc50mS(void) //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Accelerator i=%d -> %d"),i, Shutter[i].accelerator); ShutterUpdateVelocity(i); digitalWrite(Pin(GPIO_PWM1, i), LOW); - - ledcWriteTone(Shutter[i].ledc_channel, Shutter[i].pwm_velocity); // - //ledcWrite(i, 512); // Setzt den PWM-Wert auf 0 + analogWriteFreq(Shutter[i].pwm_velocity,Pin(GPIO_PWM1, i)); TasmotaGlobal.pwm_value[i] = 512; + pwm_apply = true; } break; } } // if (Shutter[i].direction) } + if (pwm_apply) { PwmApplyGPIO(false); } } void ShutterSetPosition(uint32_t device, uint32_t position) @@ -1171,12 +1158,9 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) switch (ShutterGlobal.position_mode) { #ifdef SHUTTER_STEPPER case SHT_COUNTER: - Shutter[i].ledc_channel = ShutterGetFreeChannel(); - //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Channel %d assigned to SHT %d"),Shutter[i].ledc_channel, i); - ledcSetup(Shutter[i].ledc_channel, Shutter[i].pwm_velocity, 8); - ledcAttachPin(Pin(GPIO_PWM1, i), Shutter[i].ledc_channel); - ledcWriteTone(Shutter[i].ledc_channel, Shutter[i].pwm_velocity); - ledcWrite(Shutter[i].ledc_channel, 0); // Setzt den PWM-Wert auf 0 + analogWriteFreq(PWM_MIN,Pin(GPIO_PWM1, i)); + TasmotaGlobal.pwm_value[i] = 0; + PwmApplyGPIO(false); RtcSettings.pulse_counter[i] = 0; break; #endif @@ -1201,11 +1185,9 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) Shutter[i].venetian_delay, Shutter[i].tilt_real_pos,direction,(Shutter[i].tilt_config[1]-Shutter[i].tilt_config[0]), Shutter[i].tilt_config[2],Shutter[i].tilt_start_pos,Shutter[i].tilt_target_pos); } - // avoid file system writes during move to minimize missing steps - if (Settings->save_data) { - uint32_t move_duration = (direction > 0) ? Shutter[i].open_time : Shutter[i].close_time; - TasmotaGlobal.save_data_counter = Settings->save_data + (move_duration / 10) +1; - } + // avoid file system writes during move to minimize missing steps. 15min diabled. Will re renabled on full stop + TasmotaGlobal.save_data_counter = 900; + } //AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Start shtr%d from %d to %d in dir: %d"), i, Shutter[i].start_position, Shutter[i].target_position, direction); @@ -1282,9 +1264,9 @@ void ShutterUpdatePosition(void) // Update time information int32_t deltatime = Shutter[i].time - Shutter[i].last_reported_time; Shutter[i].last_reported_time = Shutter[i].time + 1; - AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d Time %d(%d), cStop %d, cVelo %d, mVelo %d, aVelo %d, mRun %d, aPos %d, nStop %d, Trgt %d, mVelo %d, Dir %d, Tilt %d, TrgtTilt: %d, Tiltmove: %d"), - i+1, Shutter[i].time, deltatime, Shutter[i].current_stop_way, Shutter[i].pwm_velocity, velocity_max, Shutter[i].accelerator, min_runtime_ms, Shutter[i].real_position, - Shutter[i].current_stop_way + Shutter[i].real_position, Shutter[i].target_position, velocity_change_per_step_max, Shutter[i].direction,Shutter[i].tilt_real_pos, Shutter[i].tilt_target_pos, + AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Shtr%d Time %d(%d), cStop %d, cVelo %d, mVelo %d, aVelo %d, mRun %d, aPos %d, aPos2 %d, nStop %d, Trgt %d, mVelo %d, Dir %d, Tilt %d, TrgtTilt: %d, Tiltmove: %d"), + i+1, Shutter[i].time, deltatime, current_stop_way, current_pwm_velocity, velocity_max, Shutter[i].accelerator, min_runtime_ms, current_real_position,Shutter[i].real_position, + next_possible_stop_position, Shutter[i].target_position, velocity_change_per_step_max, Shutter[i].direction,Shutter[i].tilt_real_pos, Shutter[i].tilt_target_pos, Shutter[i].tiltmoving); // Check calibration mode and energy information