mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-22 10:16:30 +00:00
Make distance floats with one decimal (#17021)
This commit is contained in:
parent
05b43fb143
commit
64ed79debc
@ -901,6 +901,7 @@ const char HTTP_SNS_RANGE_CHR[] PROGMEM = "{s}%s " D_RANGE "{
|
||||
const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d" "{e}";
|
||||
const char HTTP_SNS_DISTANCE[] PROGMEM = "{s}%s " D_DISTANCE "{m}%d " D_UNIT_MILLIMETER "{e}";
|
||||
const char HTTP_SNS_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%s " D_UNIT_CENTIMETER "{e}";
|
||||
const char HTTP_SNS_F_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%1_f " D_UNIT_CENTIMETER "{e}";
|
||||
const char HTTP_SNS_HALL_EFFECT[] PROGMEM = "{s}%s " D_HALL_EFFECT "{m}%d" "{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}";
|
||||
|
@ -190,19 +190,16 @@ void Sr04TReading(void) {
|
||||
|
||||
void Sr04Show(bool json) {
|
||||
if (SR04.valid) { // Check if read failed
|
||||
char distance_chr[33];
|
||||
dtostrfd(SR04.distance, 3, distance_chr);
|
||||
|
||||
if(json) {
|
||||
ResponseAppend_P(PSTR(",\"SR04\":{\"" D_JSON_DISTANCE "\":%s}"), distance_chr);
|
||||
ResponseAppend_P(PSTR(",\"SR04\":{\"" D_JSON_DISTANCE "\":%1_f}"), &SR04.distance);
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (0 == TasmotaGlobal.tele_period) {
|
||||
DomoticzSensor(DZ_COUNT, distance_chr); // Send distance as Domoticz Counter value
|
||||
DomoticzFloatSensor(DZ_COUNT, SR04.distance); // Send distance as Domoticz Counter value
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
WSContentSend_PD(HTTP_SNS_DISTANCE_CM, "SR04", distance_chr);
|
||||
WSContentSend_PD(HTTP_SNS_F_DISTANCE_CM, "SR04", &SR04.distance);
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include <TasmotaSerial.h>
|
||||
TasmotaSerial *HRXLSerial = nullptr;
|
||||
|
||||
uint32_t hrxl_distance_cm = 0; // distance, cm
|
||||
uint32_t hrxl_distance_mm = 0; // distance, mm
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
@ -62,17 +62,18 @@ void HRXLEverySecond(void) {
|
||||
}
|
||||
}
|
||||
if (num_read > 1) {
|
||||
hrxl_distance_cm = int(sum / num_read) / 10; // cm
|
||||
hrxl_distance_mm = int(sum / num_read); // mm
|
||||
}
|
||||
}
|
||||
|
||||
void HRXLShow(bool json) {
|
||||
char types[5] = "HRXL";
|
||||
float distance = (float)hrxl_distance_mm / 10; // cm
|
||||
if (json) {
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%d}"), types, hrxl_distance_cm);
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%1_f}"), types, &distance);
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
WSContentSend_PD(HTTP_SNS_DISTANCE_CM, types, hrxl_distance_cm);
|
||||
WSContentSend_PD(HTTP_SNS_F_DISTANCE_CM, types, &distance);
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ TasmotaSerial *DYPSerial = nullptr;
|
||||
#define DYP_ABOVEMAX 4999
|
||||
#define DYP_NOSENSOR 5999
|
||||
|
||||
uint16_t DYPDistance = 0; // distance in centimeters
|
||||
uint16_t DYPDistance = 0; // distance in millimeters
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
@ -87,7 +87,7 @@ void DYPEverySecond(void) {
|
||||
if (data > DYP_MAX) {
|
||||
data = DYP_ABOVEMAX;
|
||||
}
|
||||
DYPDistance = data / 10; // cm
|
||||
DYPDistance = data; // mm
|
||||
} else {
|
||||
DYPDistance = DYP_CRCERROR;
|
||||
}
|
||||
@ -97,11 +97,12 @@ void DYPEverySecond(void) {
|
||||
|
||||
void DYPShow(bool json) {
|
||||
char types[4] = "DYP";
|
||||
float distance = (float)DYPDistance / 10; // cm
|
||||
if (json) {
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%d}"), types, DYPDistance);
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%1_f}"), types, &distance);
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
WSContentSend_PD(HTTP_SNS_DISTANCE_CM, types, DYPDistance);
|
||||
WSContentSend_PD(HTTP_SNS_F_DISTANCE_CM, types, &distance);
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
|
@ -185,24 +185,22 @@ const char HTTP_SNS_SIGNALSTRENGTH[] PROGMEM = "{s}%s " D_SIGNALSTRENGTH "{m}%d{
|
||||
const char HTTP_SNS_CHIPTEMPERATURE[] PROGMEM = "{s}%s " D_CHIPTEMPERATURE "{m}%d " D_UNIT_DEGREE "%c{e}";
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
void TfmpShow(bool json)
|
||||
{
|
||||
void TfmpShow(bool json) {
|
||||
char sensor_name[12];
|
||||
strcpy_P(sensor_name, "TFminiPlus");
|
||||
char distance_chr[FLOATSZ];
|
||||
dtostrfd(tfminiplus_sensor.distance, 3, distance_chr);
|
||||
float distance = (float)tfminiplus_sensor.distance; // cm
|
||||
|
||||
if (json) {
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":\"%s\",\"" D_JSON_SIGNALSTRENGTH "\":\"%d\",\"" D_JSON_CHIPTEMPERATURE "\":%d}"),
|
||||
sensor_name, distance_chr, tfminiplus_sensor.sigstrength, tfminiplus_sensor.chiptemp);
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":\"%1_f\",\"" D_JSON_SIGNALSTRENGTH "\":\"%d\",\"" D_JSON_CHIPTEMPERATURE "\":%d}"),
|
||||
sensor_name, &distance, tfminiplus_sensor.sigstrength, tfminiplus_sensor.chiptemp);
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (0 == TasmotaGlobal.tele_period) {
|
||||
DomoticzSensor(DZ_COUNT, distance_chr);
|
||||
DomoticzFloatSensor(DZ_COUNT, distance);
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
WSContentSend_P(HTTP_SNS_DISTANCE_CM, sensor_name, distance_chr);
|
||||
WSContentSend_P(HTTP_SNS_F_DISTANCE_CM, sensor_name, &distance);
|
||||
WSContentSend_P(HTTP_SNS_SIGNALSTRENGTH, sensor_name, tfminiplus_sensor.sigstrength);
|
||||
WSContentSend_P(HTTP_SNS_CHIPTEMPERATURE, sensor_name, tfminiplus_sensor.chiptemp, TempUnit());
|
||||
#endif // USE_WEBSERVER
|
||||
|
Loading…
x
Reference in New Issue
Block a user