mirror of https://github.com/arendst/Tasmota.git
Merge pull request #15017 from gemu2015/sml_offsets
optional calibration offset
This commit is contained in:
commit
725458013b
|
@ -1665,6 +1665,23 @@ uint32_t vbus_get_septet(uint8_t *cp) {
|
|||
}
|
||||
|
||||
|
||||
char *skip_double(char *cp) {
|
||||
if (*cp == '+' || *cp == '-') {
|
||||
cp++;
|
||||
}
|
||||
while (*cp) {
|
||||
if (*cp == '.') {
|
||||
cp++;
|
||||
}
|
||||
if (!isdigit(*cp)) {
|
||||
return cp;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void SML_Decode(uint8_t index) {
|
||||
const char *mp=(const char*)meter_p;
|
||||
int8_t mindex;
|
||||
|
@ -2168,6 +2185,12 @@ void SML_Decode(uint8_t index) {
|
|||
//AddLog(LOG_LEVEL_INFO, PSTR(">> %s"),mp);
|
||||
// get scaling factor
|
||||
double fac = CharToDouble((char*)mp);
|
||||
// get optional offset to calibrate meter
|
||||
char *cp = skip_double((char*)mp);
|
||||
if (cp && (*cp == '+' || *cp == '-')) {
|
||||
double offset = CharToDouble(cp);
|
||||
meter_vars[vindex] += offset;
|
||||
}
|
||||
meter_vars[vindex] /= fac;
|
||||
SML_Immediate_MQTT((const char*)mp, vindex, mindex);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue