From c5e2cef17566e6c9f6dcc60c7203e9cd16d8e43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bub=C3=ADk?= Date: Sat, 6 Mar 2021 21:52:54 +0100 Subject: [PATCH 1/6] PROJECTOR_CTRL: make serial baudrate configurable --- tasmota/xdrv_53_projector_ctrl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasmota/xdrv_53_projector_ctrl.h b/tasmota/xdrv_53_projector_ctrl.h index 71683b8c9..347f7a576 100644 --- a/tasmota/xdrv_53_projector_ctrl.h +++ b/tasmota/xdrv_53_projector_ctrl.h @@ -7,7 +7,10 @@ #endif //PROJECTOR_CTRL_PWR_BY_RELAY #define PROJECTOR_CTRL_SERIAL_TIMEOUT 10 //up to 254 seconds + +#ifndef PROJECTOR_CTRL_SERIAL_BAUDRATE #define PROJECTOR_CTRL_SERIAL_BAUDRATE 9600 +#endif //PROJECTOR_CTRL_SERIAL_BAUDRATE #ifdef USE_PROJECTOR_CTRL_NEC /* see the serial codes in From cabd9bdffc8e17d7d49957c94f770de046a9c9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bub=C3=ADk?= Date: Sat, 6 Mar 2021 22:07:06 +0100 Subject: [PATCH 2/6] PROJECTOR_CTRL: Use at least one projector (fix) --- tasmota/xdrv_53_projector_ctrl.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdrv_53_projector_ctrl.ino b/tasmota/xdrv_53_projector_ctrl.ino index 7f0c28bf5..9030aff23 100644 --- a/tasmota/xdrv_53_projector_ctrl.ino +++ b/tasmota/xdrv_53_projector_ctrl.ino @@ -27,7 +27,7 @@ #define XDRV_53 53 -#ifndef USE_PROJECTOR_CTRL_NEC +#if !defined(USE_PROJECTOR_CTRL_NEC) && !defined(USE_PROJECTOR_CTRL_OPTOMA) #define USE_PROJECTOR_CTRL_NEC // Use at least one projector #endif From 2793402027f5206160be9e61e2db3aa0c87fe237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bub=C3=ADk?= Date: Sat, 6 Mar 2021 23:05:51 +0100 Subject: [PATCH 3/6] PROJECTOR_CTRL: Add WARMING states [NEC] NEC V300W returns undocumented states 0x01 and 0x02 during warming up Consider Projector already powered-up --- tasmota/xdrv_53_projector_ctrl.h | 4 ++++ tasmota/xdrv_53_projector_ctrl.ino | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_53_projector_ctrl.h b/tasmota/xdrv_53_projector_ctrl.h index 347f7a576..4aca0d12b 100644 --- a/tasmota/xdrv_53_projector_ctrl.h +++ b/tasmota/xdrv_53_projector_ctrl.h @@ -35,6 +35,8 @@ static const struct projector_ctrl_command_info_s projector_ctrl_commands[] = { }; #define PROJECTOR_CTRL_QRYPWR_ON 0x04 #define PROJECTOR_CTRL_QRYPWR_COOLING 0x05 +#define PROJECTOR_CTRL_QRYPWR_STARTING 0x01 //undocumented state, seen on V300W +#define PROJECTOR_CTRL_QRYPWR_WARMING 0x02 //undocumented state, seen on V300W #elif defined(USE_PROJECTOR_CTRL_OPTOMA) @@ -59,6 +61,8 @@ static const struct projector_ctrl_command_info_s projector_ctrl_commands[] = { }; #define PROJECTOR_CTRL_QRYPWR_ON 0x31 #define PROJECTOR_CTRL_QRYPWR_COOLING 0x31 //placebo +#define PROJECTOR_CTRL_QRYPWR_STARTING 0x31 //placebo +#define PROJECTOR_CTRL_QRYPWR_WARMING 0x31 //placebo #else diff --git a/tasmota/xdrv_53_projector_ctrl.ino b/tasmota/xdrv_53_projector_ctrl.ino index 9030aff23..433ecbba0 100644 --- a/tasmota/xdrv_53_projector_ctrl.ino +++ b/tasmota/xdrv_53_projector_ctrl.ino @@ -328,11 +328,19 @@ projector_ctrl_loop(struct projector_ctrl_softc_s *sc) break; case PROJECTOR_CTRL_S_IDLE: if ((oldstate==PROJECTOR_CTRL_S_QRY_PWR)&&(sc->sc_ser_result==PROJECTOR_CTRL_R_PASS)){ - if(((sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_ON)||(sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_COOLING))&&(sc->sc_dev_state!=PROJECTOR_CTRL_DEV_PWR_ON)){ + if(( (sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_ON) + ||(sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_COOLING) + ||(sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_STARTING) + ||(sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_WARMING) + )&&(sc->sc_dev_state!=PROJECTOR_CTRL_DEV_PWR_ON)){ sc->sc_dev_state=PROJECTOR_CTRL_DEV_PWR_ON; ExecuteCommandPower(sc->sc_device, POWER_ON, SRC_IGNORE); }; - if(((sc->sc_ser_value!=PROJECTOR_CTRL_QRYPWR_ON)&&(sc->sc_ser_value!=PROJECTOR_CTRL_QRYPWR_COOLING))&&(sc->sc_dev_state!=PROJECTOR_CTRL_DEV_PWR_OFF)){ + if(( (sc->sc_ser_value!=PROJECTOR_CTRL_QRYPWR_ON) + &&(sc->sc_ser_value!=PROJECTOR_CTRL_QRYPWR_COOLING) + &&(sc->sc_ser_value!=PROJECTOR_CTRL_QRYPWR_STARTING) + &&(sc->sc_ser_value!=PROJECTOR_CTRL_QRYPWR_WARMING) + )&&(sc->sc_dev_state!=PROJECTOR_CTRL_DEV_PWR_OFF)){ sc->sc_dev_state=PROJECTOR_CTRL_DEV_PWR_OFF; ExecuteCommandPower(sc->sc_device, POWER_OFF, SRC_IGNORE); }; From 93b9f14fc57a455be1b9f4af2a8d1bf021a29700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bub=C3=ADk?= Date: Sat, 6 Mar 2021 23:20:09 +0100 Subject: [PATCH 4/6] PROJECTOR_CTRL: consistent logging of [DIS]CONNECTs --- tasmota/xdrv_53_projector_ctrl.ino | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_53_projector_ctrl.ino b/tasmota/xdrv_53_projector_ctrl.ino index 433ecbba0..4c8142d7a 100644 --- a/tasmota/xdrv_53_projector_ctrl.ino +++ b/tasmota/xdrv_53_projector_ctrl.ino @@ -324,10 +324,16 @@ projector_ctrl_loop(struct projector_ctrl_softc_s *sc) oldstate = sc->sc_ser_state; switch (sc->sc_ser_state = (projector_ctrl_serial_state_e)projector_ctrl_parse(sc, serial->read())) { case PROJECTOR_CTRL_S_UNCONNECTED: - sc->sc_dev_state=PROJECTOR_CTRL_DEV_UNKNOWN; + if (sc->sc_dev_state!=PROJECTOR_CTRL_DEV_UNKNOWN){ + sc->sc_dev_state=PROJECTOR_CTRL_DEV_UNKNOWN; + AddLog_P(LOG_LEVEL_INFO,PSTR(PROJECTOR_CTRL_LOGNAME ": DISCONNECTED(unexpected input)")); + } break; case PROJECTOR_CTRL_S_IDLE: if ((oldstate==PROJECTOR_CTRL_S_QRY_PWR)&&(sc->sc_ser_result==PROJECTOR_CTRL_R_PASS)){ + if(sc->sc_dev_state==PROJECTOR_CTRL_DEV_UNKNOWN){ + AddLog_P(LOG_LEVEL_INFO,PSTR(PROJECTOR_CTRL_LOGNAME ": CONNECTED")); + }; if(( (sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_ON) ||(sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_COOLING) ||(sc->sc_ser_value==PROJECTOR_CTRL_QRYPWR_STARTING) @@ -383,7 +389,7 @@ projector_ctrl_tick(struct projector_ctrl_softc_s *sc) }; }else if(sc->sc_ticks > sc->sc_cmd_info->timeout_ticks){ //current CMD has ran out of time, drop connection - AddLog_P(LOG_LEVEL_INFO,PSTR(PROJECTOR_CTRL_LOGNAME ": DISCONNECTED")); + AddLog_P(LOG_LEVEL_INFO,PSTR(PROJECTOR_CTRL_LOGNAME ": DISCONNECTED(timeout)")); sc->sc_dev_state=PROJECTOR_CTRL_DEV_UNKNOWN; sc->sc_ser_state=PROJECTOR_CTRL_S_UNCONNECTED; }; From 86e2bc53beb429af057a09981fd567e62f56d243 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:34:32 +0100 Subject: [PATCH 5/6] Fix CSE7761 default calibration --- tasmota/xnrg_19_cse7761.ino | 64 ++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/tasmota/xnrg_19_cse7761.ino b/tasmota/xnrg_19_cse7761.ino index d731bef89..571f50fc4 100644 --- a/tasmota/xnrg_19_cse7761.ino +++ b/tasmota/xnrg_19_cse7761.ino @@ -31,9 +31,9 @@ //#define CSE7761_SIMULATE -#define CSE7761_UREF 10000 // Gain 1 * 10000 in V -#define CSE7761_IREF 160000 // Gain 16 * 10000 in A -#define CSE7761_PREF 50000 // in W +#define CSE7761_UREF 42563 // RmsUc +#define CSE7761_IREF 52241 // RmsIAC +#define CSE7761_PREF 44513 // PowerPAC #define CSE7761_REG_SYSCON 0x00 // System Control Register #define CSE7761_REG_EMUCON 0x01 // Metering control register @@ -80,6 +80,7 @@ struct { uint32_t current_rms[2] = { 0 }; uint32_t energy[2] = { 0 }; uint32_t active_power[2] = { 0 }; + uint16_t coefficient[8] = { 0 }; uint8_t energy_update = 0; uint8_t init = 4; uint8_t ready = 0; @@ -162,16 +163,36 @@ uint32_t Cse7761ReadFallback(uint32_t reg, uint32_t prev) { return value; } +uint32_t Cse7761Ref(uint32_t unit) { + switch (unit) { + case 1: return 0x400000 * 100 / CSE7761Data.coefficient[RmsUC]; + case 2: return (0x800000 * 100 / CSE7761Data.coefficient[RmsIAC]) * 10; // Stay within 32 bits + case 3: return 0x80000000 / CSE7761Data.coefficient[PowerPAC]; + } + return 0; +} + bool Cse7761ChipInit(void) { uint16_t calc_chksum = 0xFFFF; for (uint32_t i = 0; i < 8; i++) { - calc_chksum = Cse7761Read(CSE7761_REG_RMSIAC + i); + CSE7761Data.coefficient[i] = Cse7761Read(CSE7761_REG_RMSIAC + i); + calc_chksum += CSE7761Data.coefficient[i]; } calc_chksum = ~calc_chksum; // uint16_t dummy = Cse7761Read(CSE7761_REG_COEFFOFFSET); uint16_t coeff_chksum = Cse7761Read(CSE7761_REG_COEFFCHKSUM); - if (calc_chksum != coeff_chksum) { - AddLog(LOG_LEVEL_DEBUG, PSTR("C61: Not calibrated")); + if ((calc_chksum != coeff_chksum) || (!calc_chksum)) { + AddLog(LOG_LEVEL_DEBUG, PSTR("C61: Default calibration")); + CSE7761Data.coefficient[RmsIAC] = CSE7761_IREF; +// CSE7761Data.coefficient[RmsIBC] = 0xCC05; + CSE7761Data.coefficient[RmsUC] = CSE7761_UREF; + CSE7761Data.coefficient[PowerPAC] = CSE7761_PREF; +// CSE7761Data.coefficient[PowerPBC] = 0xADD7; + } + if (HLW_PREF_PULSE == Settings.energy_power_calibration) { + Settings.energy_voltage_calibration = Cse7761Ref(1); + Settings.energy_current_calibration = Cse7761Ref(2); + Settings.energy_power_calibration = Cse7761Ref(3); } Cse7761Write(CSE7761_SPECIAL_COMMAND, CSE7761_CMD_ENABLE_WRITE); @@ -317,8 +338,7 @@ void Cse7761GetData(void) { // The active power parameter PowerA/B is in two’s complement format, 32-bit data, the highest bit is Sign bit. uint32_t value = Cse7761ReadFallback(CSE7761_REG_RMSU, CSE7761Data.voltage_rms); #ifdef CSE7761_SIMULATE -// value = 2342160; // 234.2V - value = 2000000; // 200V + value = 2342160; // 237.7V #endif CSE7761Data.voltage_rms = (value >= 0x800000) ? 0 : value; @@ -335,14 +355,12 @@ void Cse7761GetData(void) { value = Cse7761ReadFallback(CSE7761_REG_RMSIB, CSE7761Data.current_rms[1]); #ifdef CSE7761_SIMULATE -// value = 29760; // 0.186A - value = 800000; // 5A + value = 29760; // 0.185A #endif CSE7761Data.current_rms[1] = ((value >= 0x800000) || (value < 1600)) ? 0 : value; // No load threshold of 10mA value = Cse7761ReadFallback(CSE7761_REG_POWERPB, CSE7761Data.active_power[1]); #ifdef CSE7761_SIMULATE -// value = 2126641; // 42.5W - value = 50000000; // 1000W + value = 2126641; // 44.05W #endif CSE7761Data.active_power[1] = (0 == CSE7761Data.current_rms[1]) ? 0 : (value & 0x80000000) ? (~value) + 1 : value; @@ -352,24 +370,25 @@ void Cse7761GetData(void) { CSE7761Data.active_power[0], CSE7761Data.active_power[1]); if (Energy.power_on) { // Powered on + // Voltage = RmsU * RmsUC * 10 / 0x400000 + // Energy.voltage[0] = (float)(((uint64_t)CSE7761Data.voltage_rms * CSE7761Data.coefficient[RmsUC] * 10) >> 22) / 1000; // V Energy.voltage[0] = ((float)CSE7761Data.voltage_rms / Settings.energy_voltage_calibration); // V for (uint32_t channel = 0; channel < 2; channel++) { Energy.data_valid[channel] = 0; + // Active power = PowerPA * PowerPAC * 1000 / 0x80000000 + // Energy.active_power[channel] = (float)(((uint64_t)CSE7761Data.active_power[channel] * CSE7761Data.coefficient[PowerPAC + channel] * 1000) >> 31) / 1000; // W Energy.active_power[channel] = (float)CSE7761Data.active_power[channel] / Settings.energy_power_calibration; // W if (0 == Energy.active_power[channel]) { Energy.current[channel] = 0; } else { + // Current = RmsIA * RmsIAC / 0x800000 + // Energy.current[channel] = (float)(((uint64_t)CSE7761Data.current_rms[channel] * CSE7761Data.coefficient[RmsIAC + channel]) >> 23) / 1000; // A Energy.current[channel] = (float)CSE7761Data.current_rms[channel] / Settings.energy_current_calibration; // A CSE7761Data.energy[channel] += Energy.active_power[channel]; CSE7761Data.energy_update++; } } -/* - } else { // Powered off - Energy.data_valid[0] = ENERGY_WATCHDOG; - Energy.data_valid[1] = ENERGY_WATCHDOG; -*/ } } @@ -428,11 +447,6 @@ void Cse7761SnsInit(void) { SetSerial(38400, TS_SERIAL_8E1); ClaimSerial(); } - if (HLW_PREF_PULSE == Settings.energy_power_calibration) { - Settings.energy_voltage_calibration = CSE7761_UREF; - Settings.energy_current_calibration = CSE7761_IREF; - Settings.energy_power_calibration = CSE7761_PREF; - } } else { TasmotaGlobal.energy_driver = ENERGY_NONE; } @@ -455,15 +469,15 @@ bool Cse7761Command(void) { uint32_t value = (uint32_t)(CharToFloat(XdrvMailbox.data) * 100); // 1.23 = 123 if (CMND_POWERCAL == Energy.command_code) { - if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = CSE7761_PREF; } + if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(3); } // Service in xdrv_03_energy.ino } else if (CMND_VOLTAGECAL == Energy.command_code) { - if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = CSE7761_UREF; } + if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(1); } // Service in xdrv_03_energy.ino } else if (CMND_CURRENTCAL == Energy.command_code) { - if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = CSE7761_IREF; } + if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(2); } // Service in xdrv_03_energy.ino } else if (CMND_POWERSET == Energy.command_code) { From d231bb47314dabcfd074784bf330552be376d47b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 8 Mar 2021 16:56:33 +0100 Subject: [PATCH 6/6] Prep CSE7761 for final --- tasmota/xnrg_19_cse7761.ino | 46 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tasmota/xnrg_19_cse7761.ino b/tasmota/xnrg_19_cse7761.ino index 571f50fc4..98ad863bb 100644 --- a/tasmota/xnrg_19_cse7761.ino +++ b/tasmota/xnrg_19_cse7761.ino @@ -114,7 +114,7 @@ void Cse7761Write(uint32_t reg, uint32_t data) { AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("C61: Tx %*_H"), len, buffer); } -uint32_t Cse7761Read(uint32_t reg) { +uint32_t Cse7761Read(uint32_t reg, uint32_t size) { while (Cse7761Serial->available()) { Cse7761Serial->read(); } Cse7761Write(reg, 0); @@ -122,6 +122,8 @@ uint32_t Cse7761Read(uint32_t reg) { uint8_t buffer[8] = { 0 }; uint32_t rcvd = 0; uint32_t timeout = millis() + 3; + +// while (!TimeReached(timeout) && (rcvd <= size)) { while (!TimeReached(timeout)) { int value = Cse7761Serial->read(); if ((value > -1) && (rcvd < sizeof(buffer) -1)) { @@ -155,8 +157,8 @@ uint32_t Cse7761Read(uint32_t reg) { return result; } -uint32_t Cse7761ReadFallback(uint32_t reg, uint32_t prev) { - uint32_t value = Cse7761Read(reg); +uint32_t Cse7761ReadFallback(uint32_t reg, uint32_t prev, uint32_t size) { + uint32_t value = Cse7761Read(reg, size); if (1 == value) { // CRC Error so use previous value read value = prev; } @@ -165,9 +167,9 @@ uint32_t Cse7761ReadFallback(uint32_t reg, uint32_t prev) { uint32_t Cse7761Ref(uint32_t unit) { switch (unit) { - case 1: return 0x400000 * 100 / CSE7761Data.coefficient[RmsUC]; - case 2: return (0x800000 * 100 / CSE7761Data.coefficient[RmsIAC]) * 10; // Stay within 32 bits - case 3: return 0x80000000 / CSE7761Data.coefficient[PowerPAC]; + case RmsUC: return 0x400000 * 100 / CSE7761Data.coefficient[RmsUC]; + case RmsIAC: return (0x800000 * 100 / CSE7761Data.coefficient[RmsIAC]) * 10; // Stay within 32 bits + case PowerPAC: return 0x80000000 / CSE7761Data.coefficient[PowerPAC]; } return 0; } @@ -175,12 +177,12 @@ uint32_t Cse7761Ref(uint32_t unit) { bool Cse7761ChipInit(void) { uint16_t calc_chksum = 0xFFFF; for (uint32_t i = 0; i < 8; i++) { - CSE7761Data.coefficient[i] = Cse7761Read(CSE7761_REG_RMSIAC + i); + CSE7761Data.coefficient[i] = Cse7761Read(CSE7761_REG_RMSIAC + i, 2); calc_chksum += CSE7761Data.coefficient[i]; } calc_chksum = ~calc_chksum; -// uint16_t dummy = Cse7761Read(CSE7761_REG_COEFFOFFSET); - uint16_t coeff_chksum = Cse7761Read(CSE7761_REG_COEFFCHKSUM); +// uint16_t dummy = Cse7761Read(CSE7761_REG_COEFFOFFSET, 2); + uint16_t coeff_chksum = Cse7761Read(CSE7761_REG_COEFFCHKSUM, 2); if ((calc_chksum != coeff_chksum) || (!calc_chksum)) { AddLog(LOG_LEVEL_DEBUG, PSTR("C61: Default calibration")); CSE7761Data.coefficient[RmsIAC] = CSE7761_IREF; @@ -190,9 +192,9 @@ bool Cse7761ChipInit(void) { // CSE7761Data.coefficient[PowerPBC] = 0xADD7; } if (HLW_PREF_PULSE == Settings.energy_power_calibration) { - Settings.energy_voltage_calibration = Cse7761Ref(1); - Settings.energy_current_calibration = Cse7761Ref(2); - Settings.energy_power_calibration = Cse7761Ref(3); + Settings.energy_voltage_calibration = Cse7761Ref(RmsUC); + Settings.energy_current_calibration = Cse7761Ref(RmsIAC); + Settings.energy_power_calibration = Cse7761Ref(PowerPAC); } Cse7761Write(CSE7761_SPECIAL_COMMAND, CSE7761_CMD_ENABLE_WRITE); @@ -201,7 +203,7 @@ bool Cse7761ChipInit(void) { uint32_t timeout = millis() + 8; while (!TimeReached(timeout)) { } - uint8_t sys_status = Cse7761Read(CSE7761_REG_SYSSTATUS); + uint8_t sys_status = Cse7761Read(CSE7761_REG_SYSSTATUS, 1); #ifdef CSE7761_SIMULATE sys_status = 0x11; #endif @@ -336,29 +338,29 @@ void Cse7761GetData(void) { // The effective value of current and voltage Rms is a 24-bit signed number, the highest bit is 0 for valid data, // and when the highest bit is 1, the reading will be processed as zero // The active power parameter PowerA/B is in two’s complement format, 32-bit data, the highest bit is Sign bit. - uint32_t value = Cse7761ReadFallback(CSE7761_REG_RMSU, CSE7761Data.voltage_rms); + uint32_t value = Cse7761ReadFallback(CSE7761_REG_RMSU, CSE7761Data.voltage_rms, 3); #ifdef CSE7761_SIMULATE value = 2342160; // 237.7V #endif CSE7761Data.voltage_rms = (value >= 0x800000) ? 0 : value; - value = Cse7761ReadFallback(CSE7761_REG_RMSIA, CSE7761Data.current_rms[0]); + value = Cse7761ReadFallback(CSE7761_REG_RMSIA, CSE7761Data.current_rms[0], 3); #ifdef CSE7761_SIMULATE value = 455; #endif CSE7761Data.current_rms[0] = ((value >= 0x800000) || (value < 1600)) ? 0 : value; // No load threshold of 10mA - value = Cse7761ReadFallback(CSE7761_REG_POWERPA, CSE7761Data.active_power[0]); + value = Cse7761ReadFallback(CSE7761_REG_POWERPA, CSE7761Data.active_power[0], 4); #ifdef CSE7761_SIMULATE value = 217; #endif CSE7761Data.active_power[0] = (0 == CSE7761Data.current_rms[0]) ? 0 : (value & 0x80000000) ? (~value) + 1 : value; - value = Cse7761ReadFallback(CSE7761_REG_RMSIB, CSE7761Data.current_rms[1]); + value = Cse7761ReadFallback(CSE7761_REG_RMSIB, CSE7761Data.current_rms[1], 3); #ifdef CSE7761_SIMULATE value = 29760; // 0.185A #endif CSE7761Data.current_rms[1] = ((value >= 0x800000) || (value < 1600)) ? 0 : value; // No load threshold of 10mA - value = Cse7761ReadFallback(CSE7761_REG_POWERPB, CSE7761Data.active_power[1]); + value = Cse7761ReadFallback(CSE7761_REG_POWERPB, CSE7761Data.active_power[1], 4); #ifdef CSE7761_SIMULATE value = 2126641; // 44.05W #endif @@ -406,7 +408,7 @@ void Cse7761EverySecond(void) { Cse7761Write(CSE7761_SPECIAL_COMMAND, CSE7761_CMD_RESET); } else if (2 == CSE7761Data.init) { - uint16_t syscon = Cse7761Read(0x00); // Default 0x0A04 + uint16_t syscon = Cse7761Read(0x00, 2); // Default 0x0A04 #ifdef CSE7761_SIMULATE syscon = 0x0A04; #endif @@ -469,15 +471,15 @@ bool Cse7761Command(void) { uint32_t value = (uint32_t)(CharToFloat(XdrvMailbox.data) * 100); // 1.23 = 123 if (CMND_POWERCAL == Energy.command_code) { - if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(3); } + if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(PowerPAC); } // Service in xdrv_03_energy.ino } else if (CMND_VOLTAGECAL == Energy.command_code) { - if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(1); } + if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(RmsUC); } // Service in xdrv_03_energy.ino } else if (CMND_CURRENTCAL == Energy.command_code) { - if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(2); } + if (1 == XdrvMailbox.payload) { XdrvMailbox.payload = Cse7761Ref(RmsIAC); } // Service in xdrv_03_energy.ino } else if (CMND_POWERSET == Energy.command_code) {