Skip to content

Commit

Permalink
Merge branch 'development' into prerelease-13.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Oct 19, 2023
2 parents 2efefeb + d5f506b commit 81c4e51
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 90 deletions.
13 changes: 12 additions & 1 deletion lib/libesp32/berry/src/be_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lib/libesp32/berry/tests/bool.be
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 10 additions & 11 deletions lib/libesp32/berry_tasmota/src/solidify/solidified_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
})
)
);
Expand Down
2 changes: 1 addition & 1 deletion platformio_tasmota32.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
58 changes: 23 additions & 35 deletions tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -179,7 +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
} Shutter[MAX_SHUTTERS_ESP32];

struct SHUTTERGLOBAL {
Expand Down Expand Up @@ -471,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:
Expand All @@ -491,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);
Expand All @@ -502,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) {
Expand Down Expand Up @@ -532,20 +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);
}
if (nextFreeChannel >= SOC_LEDC_CHANNEL_NUM) {
AddLog(LOG_LEVEL_ERROR, PSTR("SHT: All PWM channel busy. Open issue-ticket."));
} else {
AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Use channel %d"), nextFreeChannel+1);
}
return nextFreeChannel++;
}

uint8_t ShutterGetOptions(uint8_t index) {
return ShutterSettings.shutter_options[index];
}
Expand Down Expand Up @@ -822,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();
}

Expand Down Expand Up @@ -971,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
Expand All @@ -991,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)
Expand Down Expand Up @@ -1166,11 +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();
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
Expand All @@ -1195,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);

Expand Down
38 changes: 23 additions & 15 deletions tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/********************************************************************************************/
Expand Down Expand Up @@ -582,6 +588,8 @@ void (* const DSCommand[])(void) PROGMEM = {
&CmndDSAlias };

void CmndDSAlias(void) {
// 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];
Expand All @@ -607,14 +615,14 @@ 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("}"));
}
#endif // DS18x20_USE_ID_ALIAS
#endif // DS18x20_USE_ID_ALIAS

/*********************************************************************************************\
* Interface
Expand Down
Loading

0 comments on commit 81c4e51

Please sign in to comment.