Add support negative power on BL0942 using index 5..8 (#20322)

This commit is contained in:
Theo Arends 2023-12-29 22:54:32 +01:00
parent 6a8435b731
commit 4393327bb9
4 changed files with 20 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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