From ff8291f77dd30aa5724f5d4e9ea748a83f4fadd3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:00:43 +0100 Subject: [PATCH] Add support for filesystem calib.dat --- tasmota/tasmota_xnrg_energy/xnrg_07_ade7953.ino | 11 +++++++++-- tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xnrg_energy/xnrg_07_ade7953.ino b/tasmota/tasmota_xnrg_energy/xnrg_07_ade7953.ino index f30619274..c5f282bef 100644 --- a/tasmota/tasmota_xnrg_energy/xnrg_07_ade7953.ino +++ b/tasmota/tasmota_xnrg_energy/xnrg_07_ade7953.ino @@ -608,14 +608,21 @@ void Ade7953Defaults(void) { } } } + + String calib = ""; +#ifdef USE_UFILESYS + calib = TfsLoadString("/calib.dat"); +#endif // USE_UFILESYS #ifdef USE_RULES // rule3 on file#calib.dat do {"angles":{"angle0":180,"angle1":176}} endon - String calib = RuleLoadFile("CALIB.DAT"); + if (!calib.length()) { + calib = RuleLoadFile("CALIB.DAT"); + } +#endif // USE_RULES if (calib.length()) { // AddLog(LOG_LEVEL_DEBUG, PSTR("ADE: File '%s'"), calib.c_str()); Ade7953SetDefaults(calib.c_str()); } -#endif // USE_RULES } void Ade7953DrvInit(void) { diff --git a/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino b/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino index 37d157d16..a11ab38f0 100644 --- a/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino +++ b/tasmota/tasmota_xnrg_energy/xnrg_23_ade7880.ino @@ -633,14 +633,20 @@ void Ade7880Defaults(void) { Ade7880.calib_angle[1] = ADE7880_BPHCAL_INIT; Ade7880.calib_angle[2] = ADE7880_CPHCAL_INIT; + String calib = ""; +#ifdef USE_UFILESYS + calib = TfsLoadString("/calib.dat"); +#endif // USE_UFILESYS #ifdef USE_RULES // rule3 on file#calib.dat do {"rms":{"current_a":3166385,"current_b":3125691,"current_c":3131983,"current_s":1756557,"voltage_a":-767262,"voltage_b":-763439,"voltage_c":-749854},"angles":{"angle0":180,"angle1":176,"angle2":176},"powers":{"totactive": {"a":-1345820,"b":-1347328,"c":-1351979}},"freq":0} endon - String calib = RuleLoadFile("CALIB.DAT"); + if (!calib.length()) { + calib = RuleLoadFile("CALIB.DAT"); + } +#endif // USE_RULES if (calib.length()) { // AddLog(LOG_LEVEL_DEBUG, PSTR("A78: File '%s'"), calib.c_str()); Ade7880SetDefaults(calib.c_str()); } -#endif // USE_RULES } void Ade7880DrvInit(void) {