6.4.1.6 Re-introduce Cal commands

6.4.1.6 20190105
 * Add commands PowerCal, VoltageCal and CurrentCal for HLW8012, HJL01 and BL0937 based energy sensors
This commit is contained in:
Theo Arends 2019-01-05 15:39:56 +01:00
parent f8ab1a8207
commit 41351001f5
4 changed files with 36 additions and 8 deletions

View File

@ -1,4 +1,7 @@
/* 6.4.1.5 20190103
/* 6.4.1.6 20190105
* Add commands PowerCal, VoltageCal and CurrentCal for HLW8012, HJL01 and BL0937 based energy sensors
*
* 6.4.1.5 20190103
* Remove command SetOption35 0-255 for mDNS start-up delay (#4793)
* Add command SetOption55 0/1 to disable/enable mDNS (#4793)
*

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06040105
#define VERSION 0x06040106
#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"

View File

@ -31,9 +31,14 @@
#include <Ticker.h>
#define D_CMND_POWERCAL "PowerCal"
#define D_CMND_VOLTAGECAL "VoltageCal"
#define D_CMND_CURRENTCAL "CurrentCal"
enum EnergyCommands {
CMND_POWERDELTA,
CMND_POWERLOW, CMND_POWERHIGH, CMND_VOLTAGELOW, CMND_VOLTAGEHIGH, CMND_CURRENTLOW, CMND_CURRENTHIGH,
CMND_POWERCAL, CMND_VOLTAGECAL, CMND_CURRENTCAL,
CMND_POWERSET, CMND_VOLTAGESET, CMND_CURRENTSET, CMND_FREQUENCYSET,
CMND_ENERGYRESET, CMND_MAXENERGY, CMND_MAXENERGYSTART,
CMND_MAXPOWER, CMND_MAXPOWERHOLD, CMND_MAXPOWERWINDOW,
@ -41,6 +46,7 @@ enum EnergyCommands {
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_VOLTAGECAL "|" D_CMND_CURRENTCAL "|"
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 "|"
@ -413,21 +419,36 @@ boolean EnergyCommand(void)
command, energy_total_chr, energy_yesterday_chr, energy_daily_chr);
status_flag = 1;
}
else if ((CMND_POWERSET == command_code) && XnrgCall(FUNC_COMMAND)) { // Watt
else if ((CMND_POWERCAL == command_code) && XnrgCall(FUNC_COMMAND)) { // microseconds
if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_power_calibration = XdrvMailbox.payload; }
nvalue = Settings.energy_power_calibration;
unit = UNIT_MICROSECOND;
}
else if ((CMND_VOLTAGESET == command_code) && XnrgCall(FUNC_COMMAND)) { // Volt
else if ((CMND_VOLTAGECAL == command_code) && XnrgCall(FUNC_COMMAND)) { // microseconds
if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_voltage_calibration = XdrvMailbox.payload; }
nvalue = Settings.energy_voltage_calibration;
unit = UNIT_MICROSECOND;
}
else if ((CMND_CURRENTSET == command_code) && XnrgCall(FUNC_COMMAND)) { // milliAmpere
else if ((CMND_CURRENTCAL == command_code) && XnrgCall(FUNC_COMMAND)) { // microseconds
if ((XdrvMailbox.payload > 999) && (XdrvMailbox.payload < 32001)) { Settings.energy_current_calibration = XdrvMailbox.payload; }
nvalue = Settings.energy_current_calibration;
unit = UNIT_MICROSECOND;
}
else if ((CMND_POWERSET == command_code) && XnrgCall(FUNC_COMMAND)) { // Watt
nvalue = Settings.energy_power_calibration;
unit = UNIT_MILLISECOND;
}
else if ((CMND_VOLTAGESET == command_code) && XnrgCall(FUNC_COMMAND)) { // Volt
nvalue = Settings.energy_voltage_calibration;
unit = UNIT_MILLISECOND;
}
else if ((CMND_CURRENTSET == command_code) && XnrgCall(FUNC_COMMAND)) { // milliAmpere
nvalue = Settings.energy_current_calibration;
unit = UNIT_MILLISECOND;
}
else if ((CMND_FREQUENCYSET == command_code) && XnrgCall(FUNC_COMMAND)) { // Hz
nvalue = Settings.energy_frequency_calibration;
unit = UNIT_MICROSECOND;
unit = UNIT_MILLISECOND;
}
#if FEATURE_POWER_LIMIT
@ -493,8 +514,9 @@ boolean EnergyCommand(void)
if (serviced && !status_flag) {
if (UNIT_MICROSECOND == unit) {
if (UNIT_MILLISECOND == unit) {
snprintf_P(command, sizeof(command), PSTR("%sCal"), command);
unit = UNIT_MICROSECOND;
}
if (Settings.flag.value_units) {

View File

@ -237,7 +237,10 @@ boolean HlwCommand(void)
{
boolean serviced = true;
if (CMND_POWERSET == energy_command_code) {
if ((CMND_POWERCAL == energy_command_code) || (CMND_VOLTAGECAL == energy_command_code) || (CMND_CURRENTCAL == energy_command_code)) {
// Service in xdrv_03_energy.ino
}
else 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;
}