diff --git a/CHANGELOG.md b/CHANGELOG.md index d24aea8b2..b34fad6bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,9 @@ All notable changes to this project will be documented in this file. - Matter support for password for remote Tasmota devices (#20296) - Display of active drivers using command ``status 4`` - ESP32 used UART information -- HASPmota added `haspmota.page_show()` to change page -- Berry added `introspect.set()` for class attributes +- HASPmota added `haspmota.page_show()` to change page (#20333) +- Berry added `introspect.set()` for class attributes (#20339) +- Support negative power on BL0942 using index 5..8 (#20322) ### Breaking Changed - Refactoring of Berry `animate` module for WS2812 Leds (#20236) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 9fe82cdde..a526e6cbe 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -122,7 +122,10 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm - Support for Sonoff Basic R4 Magic Switch [#20247](https://github.com/arendst/Tasmota/issues/20247) - Display of active drivers using command ``status 4`` - NeoPool hydrolysis FL1 and Redox flag [#20258](https://github.com/arendst/Tasmota/issues/20258) +- Support negative power on BL0942 using index 5..8 [#20322](https://github.com/arendst/Tasmota/issues/20322) - ESP32 used UART information +- Berry added `introspect.set()` for class attributes [#20339](https://github.com/arendst/Tasmota/issues/20339) +- HASPmota added `haspmota.page_show()` to change page [#20333](https://github.com/arendst/Tasmota/issues/20333) - Matter support for password for remote Tasmota devices [#20296](https://github.com/arendst/Tasmota/issues/20296) ### Breaking Changed diff --git a/tasmota/include/tasmota_template.h b/tasmota/include/tasmota_template.h index 63779e918..1d09cb47b 100644 --- a/tasmota/include/tasmota_template.h +++ b/tasmota/include/tasmota_template.h @@ -496,7 +496,7 @@ const char kSensorNamesFixed[] PROGMEM = #define MAX_BP1658CJ_DAT 16 #define MAX_DINGTIAN_SHIFT 4 #define MAX_MAGIC_SWITCH_MODES 2 -#define MAX_BL0942_RX 4 // Baudrates 1 (4800), 2 (9600), 3 (19200), 4 (38400) +#define MAX_BL0942_RX 8 // Baudrates 1/5 (4800), 2/6 (9600), 3/7 (19200), 4/8 (38400), Support Positive values only 1..4, Support also negative values 5..8 const uint16_t kGpioNiceList[] PROGMEM = { GPIO_NONE, // Not used diff --git a/tasmota/tasmota_xnrg_energy/xnrg_14_bl09xx.ino b/tasmota/tasmota_xnrg_energy/xnrg_14_bl09xx.ino index af1f0f6fc..da66a5cf4 100644 --- a/tasmota/tasmota_xnrg_energy/xnrg_14_bl09xx.ino +++ b/tasmota/tasmota_xnrg_energy/xnrg_14_bl09xx.ino @@ -102,6 +102,7 @@ struct BL09XX { uint8_t address = 0; uint8_t model = 0; uint8_t rx_pin; + bool support_negative = 0; bool received = false; } Bl09XX; @@ -187,11 +188,15 @@ bool Bl09XXDecode42(void) { Bl09XX.voltage = Bl09XX.rx_buffer[6] << 16 | Bl09XX.rx_buffer[5] << 8 | Bl09XX.rx_buffer[4]; // V_RMS unsigned Bl09XX.current[0] = Bl09XX.rx_buffer[3] << 16 | Bl09XX.rx_buffer[2] << 8 | Bl09XX.rx_buffer[1]; // IA_RMS unsigned -// Bl09XX.power[0] = Bl09XX.rx_buffer[12] << 16 | Bl09XX.rx_buffer[11] << 8 | Bl09XX.rx_buffer[10]; // WATT_A signed -// if (bitRead(Bl09XX.power[0], 23)) { Bl09XX.power[0] |= 0xFF000000; } // Extend sign bit - // Above reverted in favour of https://github.com/arendst/Tasmota/issues/15374#issuecomment-1105293179 - int32_t tmp = Bl09XX.rx_buffer[12] << 24 | Bl09XX.rx_buffer[11] << 16 | Bl09XX.rx_buffer[10] << 8; // WATT_A signed - Bl09XX.power[0] = abs(tmp >> 8); + + if (Bl09XX.support_negative) { + Bl09XX.power[0] = Bl09XX.rx_buffer[12] << 16 | Bl09XX.rx_buffer[11] << 8 | Bl09XX.rx_buffer[10]; // WATT_A signed + if (bitRead(Bl09XX.power[0], 23)) { Bl09XX.power[0] |= 0xFF000000; } // Extend sign bit + // Above reverted in favour of https://github.com/arendst/Tasmota/issues/15374#issuecomment-1105293179 + } else { + int32_t tmp = Bl09XX.rx_buffer[12] << 24 | Bl09XX.rx_buffer[11] << 16 | Bl09XX.rx_buffer[10] << 8; // WATT_A signed + Bl09XX.power[0] = abs(tmp >> 8); + } #ifdef DEBUG_BL09XX AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("BL9: U %d, I %d, P %d"), @@ -361,7 +366,9 @@ void Bl09XXPreInit(void) { else if (PinUsed(GPIO_BL0942_RX, GPIO_ANY)) { Bl09XX.model = BL0942_MODEL; Bl09XX.rx_pin = Pin(GPIO_BL0942_RX, GPIO_ANY); - uint32_t baudrate = GetPin(Bl09XX.rx_pin) - AGPIO(GPIO_BL0942_RX); // 0 .. 3 + uint32_t option = GetPin(Bl09XX.rx_pin) - AGPIO(GPIO_BL0942_RX); // 0 .. 7 + Bl09XX.support_negative = (option > 3); // 4 .. 7 + uint32_t baudrate = option & 0x3; // 0 .. 3 and 4 .. 7 Bl09XX.baudrate <<= baudrate; // Support 1 (4800), 2 (9600), 3 (19200), 4 (38400) } if (Bl09XX.model != BL09XX_MODEL) {