From 7a767f104cd2a9e1626bbcd1ee079f541086367f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 22 Sep 2018 15:09:53 +0200 Subject: [PATCH] 6.2.1.6 Remove some commands 6.2.1.6 20180922 * Removed commands PowerCal, VoltageCal and CurrentCal as more functionality is provided by commands PowerSet, VoltageSet and CurrentSet * Allow decimals as input to commands PowerSet, VoltageSet and CurrentSet * Add support for PCA9685 12bit 16pin hardware PWM driver (#3866) --- sonoff/_changelog.ino | 7 ++++++- sonoff/i18n.h | 3 --- sonoff/sonoff_version.h | 2 +- sonoff/xdrv_03_energy.ino | 35 ++++++++--------------------------- sonoff/xnrg_01_hlw8012.ino | 17 +++++++---------- sonoff/xnrg_02_cse7766.ino | 17 +++++++---------- sonoff/xnrg_04_mcp39f501.ino | 11 +---------- 7 files changed, 30 insertions(+), 62 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 908fd262a..2b954e151 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,9 @@ -/* 6.2.1.5 20180921 +/* 6.2.1.6 20180922 + * Removed commands PowerCal, VoltageCal and CurrentCal as more functionality is provided by commands PowerSet, VoltageSet and CurrentSet + * Allow decimals as input to commands PowerSet, VoltageSet and CurrentSet + * Add support for PCA9685 12bit 16pin hardware PWM driver (#3866) + * + * 6.2.1.5 20180921 * Add authentication to HTTP web pages * Add energy monitoring to Shelly2 (#2789) * Rewrite TSL2561 driver to fix some issues (#3681) diff --git a/sonoff/i18n.h b/sonoff/i18n.h index a45d7687d..80f757447 100644 --- a/sonoff/i18n.h +++ b/sonoff/i18n.h @@ -287,11 +287,8 @@ #define D_CMND_CURRENTLOW "CurrentLow" #define D_CMND_CURRENTHIGH "CurrentHigh" #define D_CMND_ENERGYRESET "EnergyReset" -#define D_CMND_POWERCAL "PowerCal" #define D_CMND_POWERSET "PowerSet" -#define D_CMND_VOLTAGECAL "VoltageCal" #define D_CMND_VOLTAGESET "VoltageSet" -#define D_CMND_CURRENTCAL "CurrentCal" #define D_CMND_CURRENTSET "CurrentSet" #define D_CMND_FREQUENCYSET "FrequencySet" #define D_CMND_MAXPOWER "MaxPower" diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 43253e40f..228a48d92 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06020105 +#define VERSION 0x06020106 #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 860183f49..3ccad7df4 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -29,14 +29,14 @@ enum EnergyCommands { CMND_POWERDELTA, CMND_POWERLOW, CMND_POWERHIGH, CMND_VOLTAGELOW, CMND_VOLTAGEHIGH, CMND_CURRENTLOW, CMND_CURRENTHIGH, - CMND_POWERCAL, CMND_POWERSET, CMND_VOLTAGECAL, CMND_VOLTAGESET, CMND_CURRENTCAL, CMND_CURRENTSET, CMND_FREQUENCYSET, + CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET, CMND_ENERGYRESET, CMND_MAXENERGY, CMND_MAXENERGYSTART, CMND_MAXPOWER, CMND_MAXPOWERHOLD, CMND_MAXPOWERWINDOW, CMND_SAFEPOWER, CMND_SAFEPOWERHOLD, CMND_SAFEPOWERWINDOW }; const char kEnergyCommands[] PROGMEM = D_CMND_POWERDELTA "|" D_CMND_POWERLOW "|" D_CMND_POWERHIGH "|" D_CMND_VOLTAGELOW "|" D_CMND_VOLTAGEHIGH "|" D_CMND_CURRENTLOW "|" D_CMND_CURRENTHIGH "|" - D_CMND_POWERCAL "|" D_CMND_POWERSET "|" D_CMND_VOLTAGECAL "|" D_CMND_VOLTAGESET "|" D_CMND_CURRENTCAL "|" D_CMND_CURRENTSET "|" D_CMND_FREQUENCYSET "|" + D_CMND_POWERSET "|" D_CMND_VOLTAGESET "|" D_CMND_CURRENTSET "|" D_CMND_FREQUENCYSET "|" D_CMND_ENERGYRESET "|" D_CMND_MAXENERGY "|" D_CMND_MAXENERGYSTART "|" D_CMND_MAXPOWER "|" D_CMND_MAXPOWERHOLD "|" D_CMND_MAXPOWERWINDOW "|" D_CMND_SAFEPOWER "|" D_CMND_SAFEPOWERHOLD "|" D_CMND_SAFEPOWERWINDOW ; @@ -415,45 +415,21 @@ boolean EnergyCommand() command, energy_total_chr, energy_yesterday_chr, energy_daily_chr); status_flag = 1; } - else if ((CMND_POWERCAL == command_code) && XnrgCall(FUNC_COMMAND)) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 32001)) { - Settings.energy_power_calibration = (XdrvMailbox.payload > 4000) ? XdrvMailbox.payload : HLW_PREF_PULSE; // HLW = 12530, CSE = 5364 - } - nvalue = Settings.energy_power_calibration; - unit = UNIT_MICROSECOND; - } - else if ((CMND_VOLTAGECAL == command_code) && XnrgCall(FUNC_COMMAND)) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 32001)) { - Settings.energy_voltage_calibration = (XdrvMailbox.payload > 999) ? XdrvMailbox.payload : HLW_UREF_PULSE; // HLW = 1950, CSE = 1912 - } - nvalue = Settings.energy_voltage_calibration; - unit = UNIT_MICROSECOND; - } - else if ((CMND_CURRENTCAL == command_code) && XnrgCall(FUNC_COMMAND)) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 32001)) { - Settings.energy_current_calibration = (XdrvMailbox.payload > 1100) ? XdrvMailbox.payload : HLW_IREF_PULSE; // HLW = 3500, CSE = 16140 - } - nvalue = Settings.energy_current_calibration; - unit = UNIT_MICROSECOND; - } else if ((CMND_POWERSET == command_code) && XnrgCall(FUNC_COMMAND)) { // Watt - snprintf_P(command, sizeof(command), PSTR(D_CMND_POWERCAL)); nvalue = Settings.energy_power_calibration; unit = UNIT_MICROSECOND; } else if ((CMND_VOLTAGESET == command_code) && XnrgCall(FUNC_COMMAND)) { // Volt - snprintf_P(command, sizeof(command), PSTR(D_CMND_VOLTAGECAL)); nvalue = Settings.energy_voltage_calibration; unit = UNIT_MICROSECOND; } else if ((CMND_CURRENTSET == command_code) && XnrgCall(FUNC_COMMAND)) { // milliAmpere - snprintf_P(command, sizeof(command), PSTR(D_CMND_CURRENTCAL)); nvalue = Settings.energy_current_calibration; unit = UNIT_MICROSECOND; } else if ((CMND_FREQUENCYSET == command_code) && XnrgCall(FUNC_COMMAND)) { // Hz nvalue = Settings.energy_frequency_calibration; - unit = UNIT_HERTZ; + unit = UNIT_MICROSECOND; } #if FEATURE_POWER_LIMIT @@ -518,6 +494,11 @@ boolean EnergyCommand() else serviced = false; // Unknown command if (serviced && !status_flag) { + + if (UNIT_MICROSECOND == unit) { + snprintf_P(command, sizeof(command), PSTR("%sCal"), command); + } + if (Settings.flag.value_units) { snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_LVALUE_SPACE_UNIT, command, nvalue, GetTextIndexed(sunit, sizeof(sunit), unit, kUnitNames)); } else { diff --git a/sonoff/xnrg_01_hlw8012.ino b/sonoff/xnrg_01_hlw8012.ino index 6ef196fb1..5140d6596 100644 --- a/sonoff/xnrg_01_hlw8012.ino +++ b/sonoff/xnrg_01_hlw8012.ino @@ -227,22 +227,19 @@ boolean HlwCommand() { boolean serviced = true; - if ((CMND_POWERCAL == energy_command_code) || (CMND_VOLTAGECAL == energy_command_code) || (CMND_CURRENTCAL == energy_command_code)) { - - } - else if (CMND_POWERSET == energy_command_code) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 3601) && hlw_cf_pulse_length) { - Settings.energy_power_calibration = (XdrvMailbox.payload * 10 * hlw_cf_pulse_length) / hlw_power_ratio; + if (CMND_POWERSET == energy_command_code) { + if (XdrvMailbox.data_len && hlw_cf_pulse_length) { + Settings.energy_power_calibration = ((unsigned long)(CharToDouble(XdrvMailbox.data) * 10) * hlw_cf_pulse_length) / hlw_power_ratio; } } else if (CMND_VOLTAGESET == energy_command_code) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 501) && hlw_cf1_voltage_pulse_length) { - Settings.energy_voltage_calibration = (XdrvMailbox.payload * 10 * hlw_cf1_voltage_pulse_length) / hlw_voltage_ratio; + if (XdrvMailbox.data_len && hlw_cf1_voltage_pulse_length) { + Settings.energy_voltage_calibration = ((unsigned long)(CharToDouble(XdrvMailbox.data) * 10) * hlw_cf1_voltage_pulse_length) / hlw_voltage_ratio; } } else if (CMND_CURRENTSET == energy_command_code) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 16001) && hlw_cf1_current_pulse_length) { - Settings.energy_current_calibration = (XdrvMailbox.payload * hlw_cf1_current_pulse_length) / hlw_current_ratio; + if (XdrvMailbox.data_len && hlw_cf1_current_pulse_length) { + Settings.energy_current_calibration = ((unsigned long)(CharToDouble(XdrvMailbox.data)) * hlw_cf1_current_pulse_length) / hlw_current_ratio; } } else serviced = false; // Unknown command diff --git a/sonoff/xnrg_02_cse7766.ino b/sonoff/xnrg_02_cse7766.ino index 84535cf96..a433bc4a4 100644 --- a/sonoff/xnrg_02_cse7766.ino +++ b/sonoff/xnrg_02_cse7766.ino @@ -195,22 +195,19 @@ boolean CseCommand() { boolean serviced = true; - if ((CMND_POWERCAL == energy_command_code) || (CMND_VOLTAGECAL == energy_command_code) || (CMND_CURRENTCAL == energy_command_code)) { - - } - else if (CMND_POWERSET == energy_command_code) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 3601) && power_cycle) { - Settings.energy_power_calibration = (XdrvMailbox.payload * power_cycle) / CSE_PREF; + if (CMND_POWERSET == energy_command_code) { + if (XdrvMailbox.data_len && power_cycle) { + Settings.energy_power_calibration = ((unsigned long)CharToDouble(XdrvMailbox.data) * power_cycle) / CSE_PREF; } } else if (CMND_VOLTAGESET == energy_command_code) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 501) && voltage_cycle) { - Settings.energy_voltage_calibration = (XdrvMailbox.payload * voltage_cycle) / CSE_UREF; + if (XdrvMailbox.data_len && voltage_cycle) { + Settings.energy_voltage_calibration = ((unsigned long)CharToDouble(XdrvMailbox.data) * voltage_cycle) / CSE_UREF; } } else if (CMND_CURRENTSET == energy_command_code) { - if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 16001) && current_cycle) { - Settings.energy_current_calibration = (XdrvMailbox.payload * current_cycle) / 1000; + if (XdrvMailbox.data_len && current_cycle) { + Settings.energy_current_calibration = ((unsigned long)CharToDouble(XdrvMailbox.data) * current_cycle) / 1000; } } else serviced = false; // Unknown command diff --git a/sonoff/xnrg_04_mcp39f501.ino b/sonoff/xnrg_04_mcp39f501.ino index c34846edf..05d55a425 100644 --- a/sonoff/xnrg_04_mcp39f501.ino +++ b/sonoff/xnrg_04_mcp39f501.ino @@ -637,16 +637,7 @@ boolean McpCommand() { boolean serviced = true; - if ((CMND_POWERCAL == energy_command_code) || (CMND_VOLTAGECAL == energy_command_code) || (CMND_CURRENTCAL == energy_command_code)) { - - // MCP Debug commands - PowerCal -// if (1 == XdrvMailbox.payload) { McpSingleWireStart(); } -// if (2 == XdrvMailbox.payload) { McpSingleWireStop(0); } -// if (3 == XdrvMailbox.payload) { McpGetAddress(); } - - serviced = false; - } - else if (CMND_POWERSET == energy_command_code) { + if (CMND_POWERSET == energy_command_code) { if (XdrvMailbox.data_len && mcp_output_registers.active_power) { Settings.energy_power_calibration = (unsigned long)(CharToDouble(XdrvMailbox.data) * 100); mcp_calibration_setpoint.calibration_active_power = Settings.energy_power_calibration;