mirror of https://github.com/arendst/Tasmota.git
Merge pull request #10701 from curzon01/development
Refactor TX2x sensor float outputs
This commit is contained in:
commit
11f9aa62ae
|
@ -80,16 +80,16 @@ extern "C" {
|
||||||
#define D_TX20_WIND_ANGLE "∠"
|
#define D_TX20_WIND_ANGLE "∠"
|
||||||
#define D_TX20_WIND_DEGREE "°"
|
#define D_TX20_WIND_DEGREE "°"
|
||||||
const char HTTP_SNS_TX2X[] PROGMEM =
|
const char HTTP_SNS_TX2X[] PROGMEM =
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED "{m}%s %s{e}"
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED "{m}%*_f %s{e}"
|
||||||
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED " " D_TX20_WIND_AVG "{m}%s %s{e}"
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED " " D_TX20_WIND_AVG "{m}%*_f %s{e}"
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_MIN "{m}%s %s{e}"
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_MIN "{m}%*_f %s{e}"
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_MAX "{m}%s %s{e}"
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_SPEED_MAX "{m}%*_f %s{e}"
|
||||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION "{m}%s %s" D_TX20_WIND_DEGREE "{e}"
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION "{m}%s %*_f" D_TX20_WIND_DEGREE "{e}"
|
||||||
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION " " D_TX20_WIND_AVG "{m}%s %s" D_TX20_WIND_DEGREE "{e}"
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION " " D_TX20_WIND_AVG "{m}%s %*_f" D_TX20_WIND_DEGREE "{e}"
|
||||||
"{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION " " D_TX20_WIND_ANGLE "{m}%s" D_TX20_WIND_DEGREE " (%s,%s)" D_TX20_WIND_DEGREE;
|
"{s}" D_TX2x_NAME " " D_TX20_WIND_DIRECTION " " D_TX20_WIND_ANGLE "{m}%*_f" D_TX20_WIND_DEGREE " (%*_f,%*_f)" D_TX20_WIND_DEGREE;
|
||||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
;
|
;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
@ -412,19 +412,13 @@ void Tx2xRead(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_TASMOTA_SENSOR
|
#ifdef DEBUG_TASMOTA_SENSOR
|
||||||
char diravg[FLOATSZ];
|
DEBUG_SENSOR_LOG(PSTR(D_TX2x_NAME ": dir stat - counter=%ld, actint=%ld, avgint=%ld, avg=%*_f (cosx=%*_f, siny=%*_f), min %d, max %d"),
|
||||||
dtostrfd(tx2x_wind_direction_avg, 1, diravg);
|
|
||||||
char cosx[FLOATSZ];
|
|
||||||
dtostrfd(tx2x_wind_direction_avg_x, 1, cosx);
|
|
||||||
char siny[FLOATSZ];
|
|
||||||
dtostrfd(tx2x_wind_direction_avg_y, 1, siny);
|
|
||||||
DEBUG_SENSOR_LOG(PSTR(D_TX2x_NAME ": dir stat - counter=%ld, actint=%ld, avgint=%ld, avg=%s (cosx=%s, siny=%s), min %d, max %d"),
|
|
||||||
(TasmotaGlobal.uptime-tx2x_last_uptime),
|
(TasmotaGlobal.uptime-tx2x_last_uptime),
|
||||||
tx2x_wind_direction,
|
tx2x_wind_direction,
|
||||||
tx2x_wind_direction_avg_int,
|
tx2x_wind_direction_avg_int,
|
||||||
diravg,
|
1, &tx2x_wind_direction_avg,
|
||||||
cosx,
|
1, &tx2x_wind_direction_avg_x,
|
||||||
siny,
|
1, &tx2x_wind_direction_avg_y,
|
||||||
tx2x_wind_direction_min,
|
tx2x_wind_direction_min,
|
||||||
tx2x_wind_direction_max
|
tx2x_wind_direction_max
|
||||||
);
|
);
|
||||||
|
@ -484,86 +478,77 @@ void Tx2xShow(bool json)
|
||||||
{
|
{
|
||||||
if (!Tx2xAvailable()) { return; }
|
if (!Tx2xAvailable()) { return; }
|
||||||
|
|
||||||
char wind_speed_string[FLOATSZ];
|
float wind_speed_float = ConvertSpeed(tx2x_wind_speed) / 10;
|
||||||
dtostrfd(ConvertSpeed(tx2x_wind_speed)/10, 1, wind_speed_string);
|
float wind_direction_float = tx2x_wind_direction * 22.5;
|
||||||
char wind_direction_string[FLOATSZ];
|
|
||||||
dtostrfd(tx2x_wind_direction*22.5, 1, wind_direction_string);
|
|
||||||
char wind_direction_cardinal_string[TX2X_DIRECTIONS_MAXSIZE+1];
|
char wind_direction_cardinal_string[TX2X_DIRECTIONS_MAXSIZE+1];
|
||||||
GetTextIndexed(wind_direction_cardinal_string, sizeof(wind_direction_cardinal_string), tx2x_wind_direction, kTx2xDirections);
|
GetTextIndexed(wind_direction_cardinal_string, sizeof(wind_direction_cardinal_string), tx2x_wind_direction, kTx2xDirections);
|
||||||
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
char wind_speed_min_string[FLOATSZ];
|
float wind_speed_min_float = ConvertSpeed(tx2x_wind_speed_min) / 10;
|
||||||
dtostrfd(ConvertSpeed(tx2x_wind_speed_min)/10, 1, wind_speed_min_string);
|
float wind_speed_max_float = ConvertSpeed(tx2x_wind_speed_max) / 10;
|
||||||
char wind_speed_max_string[FLOATSZ];
|
float wind_speed_avg_float = ConvertSpeed(tx2x_wind_speed_avg) / 10;
|
||||||
dtostrfd(ConvertSpeed(tx2x_wind_speed_max)/10, 1, wind_speed_max_string);
|
float wind_direction_avg_float = tx2x_wind_direction_avg;
|
||||||
char wind_speed_avg_string[FLOATSZ];
|
|
||||||
dtostrfd(ConvertSpeed(tx2x_wind_speed_avg)/10, 1, wind_speed_avg_string);
|
|
||||||
char wind_direction_avg_string[FLOATSZ];
|
|
||||||
dtostrfd(tx2x_wind_direction_avg, 1, wind_direction_avg_string);
|
|
||||||
char wind_direction_avg_cardinal_string[4];
|
char wind_direction_avg_cardinal_string[4];
|
||||||
GetTextIndexed(wind_direction_avg_cardinal_string, sizeof(wind_direction_avg_cardinal_string), int((tx2x_wind_direction_avg/22.5f)+0.5f) % 16, kTx2xDirections);
|
GetTextIndexed(wind_direction_avg_cardinal_string, sizeof(wind_direction_avg_cardinal_string), int((tx2x_wind_direction_avg/22.5f)+0.5f) % 16, kTx2xDirections);
|
||||||
char wind_direction_range_string[FLOATSZ];
|
float wind_direction_range_float = (tx2x_wind_direction_max-tx2x_wind_direction_min) * 22.5;
|
||||||
dtostrfd(Tx2xNormalize(tx2x_wind_direction_max-tx2x_wind_direction_min)*22.5, 1, wind_direction_range_string);
|
float wind_direction_min_float = Tx2xNormalize(tx2x_wind_direction_min) * 22.5;
|
||||||
char wind_direction_min_string[FLOATSZ];
|
float wind_direction_max_float = tx2x_wind_direction_max * 22.5;
|
||||||
dtostrfd(Tx2xNormalize(tx2x_wind_direction_min)*22.5, 1, wind_direction_min_string);
|
|
||||||
char wind_direction_max_string[FLOATSZ];
|
|
||||||
dtostrfd(Tx2xNormalize(tx2x_wind_direction_max)*22.5, 1, wind_direction_max_string);
|
|
||||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
#ifdef USE_TX2x_LEGACY_JSON
|
#ifdef USE_TX2x_LEGACY_JSON
|
||||||
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":%s,\"SpeedAvg\":%s,\"SpeedMax\":%s,\"Direction\":\"%s\",\"Degree\":%s}"),
|
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":%*_f,\"SpeedAvg\":%*_f,\"SpeedMax\":%*_f,\"Direction\":\"%s\",\"Degree\":%*_f}"),
|
||||||
wind_speed_string,
|
1, &wind_speed_float,
|
||||||
wind_speed_avg_string,
|
1, &wind_speed_avg_float,
|
||||||
wind_speed_max_string,
|
1, &wind_speed_max_float,
|
||||||
wind_direction_cardinal_string,
|
wind_direction_cardinal_string,
|
||||||
wind_direction_string
|
1, &wind_direction_float
|
||||||
);
|
);
|
||||||
#else // USE_TX2x_LEGACY_JSON
|
#else // USE_TX2x_LEGACY_JSON
|
||||||
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":{\"Act\":%s,\"Avg\":%s,\"Min\":%s,\"Max\":%s},\"Dir\":{\"Card\":\"%s\",\"Deg\":%s,\"Avg\":%s,\"AvgCard\":\"%s\",\"Min\":%s,\"Max\":%s,\"Range\":%s}}"),
|
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":{\"Act\":%*_f,\"Avg\":%*_f,\"Min\":%*_f,\"Max\":%*_f},\"Dir\":{\"Card\":\"%s\",\"Deg\":%*_f,\"Avg\":%*_f,\"AvgCard\":\"%s\",\"Min\":%*_f,\"Max\":%*_f,\"Range\":%*_f}}"),
|
||||||
wind_speed_string,
|
1, &wind_speed_float,
|
||||||
wind_speed_avg_string,
|
1, &wind_speed_avg_float,
|
||||||
wind_speed_min_string,
|
1, &wind_speed_min_float,
|
||||||
wind_speed_max_string,
|
1, &wind_speed_max_float,
|
||||||
wind_direction_cardinal_string,
|
wind_direction_cardinal_string,
|
||||||
wind_direction_string,
|
1, &wind_direction_float,
|
||||||
wind_direction_avg_string,
|
1, &wind_direction_avg_float,
|
||||||
wind_direction_avg_cardinal_string,
|
wind_direction_avg_cardinal_string,
|
||||||
wind_direction_min_string,
|
1, &wind_direction_min_float,
|
||||||
wind_direction_max_string,
|
1, &wind_direction_max_float,
|
||||||
wind_direction_range_string
|
1, &wind_direction_range_float
|
||||||
);
|
);
|
||||||
#endif // USE_TX2x_LEGACY_JSON
|
#endif // USE_TX2x_LEGACY_JSON
|
||||||
#else // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#else // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
#ifdef USE_TX2x_LEGACY_JSON
|
#ifdef USE_TX2x_LEGACY_JSON
|
||||||
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":%s,\"Direction\":\"%s\",\"Degree\":%s}"),
|
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":%*_f,\"Direction\":\"%s\",\"Degree\":%*_f}"),
|
||||||
wind_speed_string, wind_direction_cardinal_string, wind_direction_string);
|
1, &wind_speed_float, wind_direction_cardinal_string, 1, &wind_direction_float);
|
||||||
#else // USE_TX2x_LEGACY_JSON
|
#else // USE_TX2x_LEGACY_JSON
|
||||||
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":{\"Act\":%s},\"Dir\":{\"Card\":\"%s\",\"Deg\":%s}}"),
|
ResponseAppend_P(PSTR(",\"" D_TX2x_NAME "\":{\"" D_JSON_SPEED "\":{\"Act\":%*_f},\"Dir\":{\"Card\":\"%s\",\"Deg\":%*_f}}"),
|
||||||
wind_speed_string, wind_direction_cardinal_string, wind_direction_string);
|
1, &wind_speed_float, wind_direction_cardinal_string, 1, &wind_direction_float);
|
||||||
#endif // USE_TX2x_LEGACY_JSON
|
#endif // USE_TX2x_LEGACY_JSON
|
||||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_PD(HTTP_SNS_TX2X,
|
WSContentSend_PD(HTTP_SNS_TX2X,
|
||||||
wind_speed_string,
|
1, &wind_speed_float,
|
||||||
SpeedUnit().c_str(),
|
SpeedUnit().c_str(),
|
||||||
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
wind_speed_avg_string,
|
1, &wind_speed_avg_float,
|
||||||
SpeedUnit().c_str(),
|
SpeedUnit().c_str(),
|
||||||
wind_speed_min_string,
|
1, &wind_speed_min_float,
|
||||||
SpeedUnit().c_str(),
|
SpeedUnit().c_str(),
|
||||||
wind_speed_max_string,
|
1, &wind_speed_max_float,
|
||||||
SpeedUnit().c_str(),
|
SpeedUnit().c_str(),
|
||||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
wind_direction_cardinal_string,
|
wind_direction_cardinal_string,
|
||||||
wind_direction_string
|
1, &wind_direction_float
|
||||||
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
,wind_direction_avg_cardinal_string,
|
,wind_direction_avg_cardinal_string,
|
||||||
wind_direction_avg_string,
|
1, &wind_direction_avg_float,
|
||||||
wind_direction_range_string,
|
1, &wind_direction_range_float,
|
||||||
wind_direction_min_string,
|
1, &wind_direction_min_float,
|
||||||
wind_direction_max_string
|
1, &wind_direction_max_float
|
||||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||||
);
|
);
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
Loading…
Reference in New Issue