mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-29 05:36:39 +00:00
New ADC Range
This commit is contained in:
parent
6757d9731a
commit
26755202c7
@ -114,6 +114,7 @@
|
|||||||
#define D_JSON_ACTIVE_POWERUSAGE "ActivePower"
|
#define D_JSON_ACTIVE_POWERUSAGE "ActivePower"
|
||||||
#define D_JSON_APPARENT_POWERUSAGE "ApparentPower"
|
#define D_JSON_APPARENT_POWERUSAGE "ApparentPower"
|
||||||
#define D_JSON_REACTIVE_POWERUSAGE "ReactivePower"
|
#define D_JSON_REACTIVE_POWERUSAGE "ReactivePower"
|
||||||
|
#define D_JSON_RANGE "Range"
|
||||||
#define D_JSON_PRESSURE "Pressure"
|
#define D_JSON_PRESSURE "Pressure"
|
||||||
#define D_JSON_PRESSUREATSEALEVEL "SeaPressure"
|
#define D_JSON_PRESSUREATSEALEVEL "SeaPressure"
|
||||||
#define D_JSON_PRESSURE_UNIT "PressureUnit"
|
#define D_JSON_PRESSURE_UNIT "PressureUnit"
|
||||||
@ -605,6 +606,7 @@ const char JSON_SNS_TEMPHUM[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,
|
|||||||
|
|
||||||
const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}";
|
const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}";
|
||||||
const char JSON_SNS_MOISTURE[] PROGMEM = ",\"%s\":{\"" D_JSON_MOISTURE "\":%d}";
|
const char JSON_SNS_MOISTURE[] PROGMEM = ",\"%s\":{\"" D_JSON_MOISTURE "\":%d}";
|
||||||
|
const char JSON_SNS_RANGE[] PROGMEM = ",\"%s\":{\"" D_JSON_RANGE "\":%d}";
|
||||||
|
|
||||||
const char JSON_SNS_GNGPM[] PROGMEM = ",\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}";
|
const char JSON_SNS_GNGPM[] PROGMEM = ",\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}";
|
||||||
|
|
||||||
@ -636,6 +638,8 @@ const char HTTP_SNS_CO2EAVG[] PROGMEM = "{s}%s " D_ECO2 "{m}%d " D_UNIT_PARTS_PE
|
|||||||
const char HTTP_SNS_GALLONS[] PROGMEM = "{s}%s " D_TOTAL_USAGE "{m}%s " D_UNIT_GALLONS " {e}";
|
const char HTTP_SNS_GALLONS[] PROGMEM = "{s}%s " D_TOTAL_USAGE "{m}%s " D_UNIT_GALLONS " {e}";
|
||||||
const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{m}%s " D_UNIT_GALLONS_PER_MIN" {e}";
|
const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{m}%s " D_UNIT_GALLONS_PER_MIN" {e}";
|
||||||
const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d %%{e}";
|
const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d %%{e}";
|
||||||
|
const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d %%{e}";
|
||||||
|
|
||||||
|
|
||||||
const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}";
|
const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}";
|
||||||
const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}";
|
const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}";
|
||||||
|
@ -311,7 +311,7 @@ enum UserSelectableAdc0 {
|
|||||||
ADC0_LIGHT, // Light sensor
|
ADC0_LIGHT, // Light sensor
|
||||||
ADC0_BUTTON, // Button
|
ADC0_BUTTON, // Button
|
||||||
ADC0_BUTTON_INV,
|
ADC0_BUTTON_INV,
|
||||||
ADC0_MOIST, // Moisture
|
ADC0_RANGE, // Range
|
||||||
ADC0_CT_POWER, // Current
|
ADC0_CT_POWER, // Current
|
||||||
// ADC0_SWITCH, // Switch
|
// ADC0_SWITCH, // Switch
|
||||||
// ADC0_SWITCH_INV,
|
// ADC0_SWITCH_INV,
|
||||||
@ -328,7 +328,7 @@ const char kAdc0Names[] PROGMEM =
|
|||||||
D_SENSOR_NONE "|" D_ANALOG_INPUT "|"
|
D_SENSOR_NONE "|" D_ANALOG_INPUT "|"
|
||||||
D_TEMPERATURE "|" D_LIGHT "|"
|
D_TEMPERATURE "|" D_LIGHT "|"
|
||||||
D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|"
|
D_SENSOR_BUTTON "|" D_SENSOR_BUTTON "i|"
|
||||||
D_MOISTURE "|"
|
D_RANGE "|"
|
||||||
D_CT_POWER "|"
|
D_CT_POWER "|"
|
||||||
// D_SENSOR_SWITCH "|" D_SENSOR_SWITCH "i|"
|
// D_SENSOR_SWITCH "|" D_SENSOR_SWITCH "i|"
|
||||||
;
|
;
|
||||||
|
@ -85,8 +85,8 @@ void AdcInit(void)
|
|||||||
Settings.adc_param2 = ANALOG_LDR_LUX_CALC_SCALAR;
|
Settings.adc_param2 = ANALOG_LDR_LUX_CALC_SCALAR;
|
||||||
Settings.adc_param3 = ANALOG_LDR_LUX_CALC_EXPONENT * 10000;
|
Settings.adc_param3 = ANALOG_LDR_LUX_CALC_EXPONENT * 10000;
|
||||||
}
|
}
|
||||||
else if (ADC0_MOIST == my_adc0) {
|
else if (ADC0_RANGE == my_adc0) {
|
||||||
Settings.adc_param_type = ADC0_MOIST;
|
Settings.adc_param_type = ADC0_RANGE;
|
||||||
Settings.adc_param1 = 0;
|
Settings.adc_param1 = 0;
|
||||||
Settings.adc_param2 = 1023;
|
Settings.adc_param2 = 1023;
|
||||||
Settings.adc_param3 = 0;
|
Settings.adc_param3 = 0;
|
||||||
@ -145,14 +145,14 @@ uint16_t AdcGetLux(void)
|
|||||||
return (uint16_t)ldrLux;
|
return (uint16_t)ldrLux;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t AdcGetMoist(void)
|
uint16_t AdcGetRange(void)
|
||||||
{
|
{
|
||||||
// formula for calibration: value, fromLow, fromHigh, toHigh, toLow
|
// formula for calibration: value, fromLow, fromHigh, toLow, toHigh
|
||||||
// Example: 632, 0, 1023, 0, 100
|
// Example: 514, 632, 236, 0, 100
|
||||||
// int( ( ( (<param2> - <analogue-value>) / ( <param2> - <param1> ) ) * ( <param3> - <param4> ) ) + <param4> )
|
// int( ((<param2> - <analog-value>) / (<param2> - <param1>) ) * (<param3> - <param4>) ) + <param4> )
|
||||||
int adc = AdcRead(2);
|
int adc = AdcRead(2);
|
||||||
double amoist = ( ((double)Settings.adc_param2 - (double)adc) / ( ((double)Settings.adc_param2 - (double)Settings.adc_param1)) * ((double)Settings.adc_param3 - (double)Settings.adc_param4) + (double)Settings.adc_param4 );
|
double adcrange = ( ((double)Settings.adc_param2 - (double)adc) / ( ((double)Settings.adc_param2 - (double)Settings.adc_param1)) * ((double)Settings.adc_param3 - (double)Settings.adc_param4) + (double)Settings.adc_param4 );
|
||||||
return (uint16_t)amoist;
|
return (uint16_t)adcrange;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdcGetCurrentPower(uint8_t factor)
|
void AdcGetCurrentPower(uint8_t factor)
|
||||||
@ -253,14 +253,14 @@ void AdcShow(bool json)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ADC0_MOIST == my_adc0) {
|
else if (ADC0_RANGE == my_adc0) {
|
||||||
uint16_t adc_moist = AdcGetMoist();
|
uint16_t adc_range = AdcGetRange();
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
ResponseAppend_P(JSON_SNS_MOISTURE, "ANALOG", adc_moist);
|
ResponseAppend_P(JSON_SNS_RANGE, "ANALOG", adc_range);
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_PD(HTTP_SNS_MOISTURE, "", adc_moist);
|
WSContentSend_PD(HTTP_SNS_RANGE, "", adc_range);
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ void CmndAdcParam(void)
|
|||||||
if (XdrvMailbox.data_len) {
|
if (XdrvMailbox.data_len) {
|
||||||
if ((ADC0_TEMP == XdrvMailbox.payload) ||
|
if ((ADC0_TEMP == XdrvMailbox.payload) ||
|
||||||
(ADC0_LIGHT == XdrvMailbox.payload) ||
|
(ADC0_LIGHT == XdrvMailbox.payload) ||
|
||||||
(ADC0_MOIST == XdrvMailbox.payload) ||
|
(ADC0_RANGE == XdrvMailbox.payload) ||
|
||||||
(ADC0_CT_POWER == XdrvMailbox.payload)) {
|
(ADC0_CT_POWER == XdrvMailbox.payload)) {
|
||||||
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry
|
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry
|
||||||
char sub_string[XdrvMailbox.data_len +1];
|
char sub_string[XdrvMailbox.data_len +1];
|
||||||
@ -350,7 +350,7 @@ void CmndAdcParam(void)
|
|||||||
Settings.adc_param_type = XdrvMailbox.payload;
|
Settings.adc_param_type = XdrvMailbox.payload;
|
||||||
Settings.adc_param1 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
|
Settings.adc_param1 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
|
||||||
Settings.adc_param2 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 3), nullptr, 10);
|
Settings.adc_param2 = strtol(subStr(sub_string, XdrvMailbox.data, ",", 3), nullptr, 10);
|
||||||
if (ADC0_MOIST == XdrvMailbox.payload) {
|
if (ADC0_RANGE == XdrvMailbox.payload) {
|
||||||
Settings.adc_param3 = abs(strtol(subStr(sub_string, XdrvMailbox.data, ",", 4), nullptr, 10));
|
Settings.adc_param3 = abs(strtol(subStr(sub_string, XdrvMailbox.data, ",", 4), nullptr, 10));
|
||||||
Settings.adc_param4 = abs(strtol(subStr(sub_string, XdrvMailbox.data, ",", 5), nullptr, 10));
|
Settings.adc_param4 = abs(strtol(subStr(sub_string, XdrvMailbox.data, ",", 5), nullptr, 10));
|
||||||
} else {
|
} else {
|
||||||
@ -375,7 +375,7 @@ void CmndAdcParam(void)
|
|||||||
|
|
||||||
// AdcParam
|
// AdcParam
|
||||||
Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d"), Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2);
|
Response_P(PSTR("{\"" D_CMND_ADCPARAM "\":[%d,%d,%d"), Settings.adc_param_type, Settings.adc_param1, Settings.adc_param2);
|
||||||
if (ADC0_MOIST == my_adc0) {
|
if (ADC0_RANGE == my_adc0) {
|
||||||
ResponseAppend_P(PSTR(",%d,%d"), Settings.adc_param3, Settings.adc_param4);
|
ResponseAppend_P(PSTR(",%d,%d"), Settings.adc_param3, Settings.adc_param4);
|
||||||
} else {
|
} else {
|
||||||
int value = Settings.adc_param3;
|
int value = Settings.adc_param3;
|
||||||
@ -407,7 +407,7 @@ bool Xsns02(uint8_t function)
|
|||||||
if ((ADC0_INPUT == my_adc0) ||
|
if ((ADC0_INPUT == my_adc0) ||
|
||||||
(ADC0_TEMP == my_adc0) ||
|
(ADC0_TEMP == my_adc0) ||
|
||||||
(ADC0_LIGHT == my_adc0) ||
|
(ADC0_LIGHT == my_adc0) ||
|
||||||
(ADC0_MOIST == my_adc0) ||
|
(ADC0_RANGE == my_adc0) ||
|
||||||
(ADC0_CT_POWER == my_adc0)) {
|
(ADC0_CT_POWER == my_adc0)) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
#ifdef USE_RULES
|
#ifdef USE_RULES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user