Merge branch 'development' into prerelease-13.2

This commit is contained in:
Theo Arends 2023-10-19 10:57:47 +02:00
commit 81c4e518a0
7 changed files with 106 additions and 90 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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
})
)
);

View File

@ -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}

View File

@ -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,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 {
@ -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:
@ -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);
@ -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) {
@ -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];
}
@ -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();
}
@ -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
@ -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)
@ -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
@ -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);

View File

@ -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,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];
@ -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

View File

@ -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
}
/********************************************************************************************/
@ -347,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);
}
@ -382,20 +386,22 @@ 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 - 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);
@ -416,14 +422,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(","));
ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"), DS18X20Data.name, address);
if (i < DS18X20Data.sensors-1) { ResponseAppend_P(PSTR(",")); }
}
ResponseAppend_P(PSTR("}"));
}
#endif // DS18x20_USE_ID_ALIAS
#endif // DS18x20_USE_ID_ALIAS
/*********************************************************************************************\
* Interface