diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index cae66ee8..f8349258 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -598,6 +598,9 @@ PROGMEM const char* const custom_reset_string[] = { #ifndef ECH1560_MISO_PIN #define ECH1560_MISO_PIN 5 #endif + #ifndef ECH1560_INVERTED + #define ECH1560_INVERTED 0 + #endif #define ECH1560_SYNC_INTERVAL 600 #define ECH1560_BAUDRATE 4800 diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index e1e9ff2a..b14a7e7a 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -879,6 +879,7 @@ #define POWER_PROVIDER POWER_PROVIDER_ECH1560 #define ECH1560_CLK_PIN 4 #define ECH1560_MISO_PIN 5 + #define ECH1560_INVERTED 0 // ----------------------------------------------------------------------------- // Unknown hardware diff --git a/code/espurna/power_ech1560.ino b/code/espurna/power_ech1560.ino index ad422a27..2cb9bdc2 100644 --- a/code/espurna/power_ech1560.ino +++ b/code/espurna/power_ech1560.ino @@ -97,6 +97,12 @@ void _ech1560_sync() { } } + #if ECH1560_INVERTED + byte1 = 255 - byte1; + byte2 = 255 - byte2; + byte3 = 255 - byte3; + #endif + // power = (Ba*255+Bb+Bc/255)/2 _ech1560_apparent = ( (float) byte1 * 255 + (float) byte2 + (float) byte3 / 255.0) / 2; _ech1560_current = _ech1560_apparent / _ech1560_voltage;