From 6cabc45b6710f84a47bb734efe91efaa0ce601e1 Mon Sep 17 00:00:00 2001 From: Tester23 Date: Sun, 17 Dec 2023 21:12:27 +0100 Subject: [PATCH] add Temperature_div100 for BMP280 --- src/driver/drv_bmp280.c | 2 +- src/driver/drv_max72xx_clock.c | 2 ++ src/httpserver/http_fns.c | 29 +++++++++++++++++++++++++++++ src/new_pins.c | 3 ++- src/new_pins.h | 7 +++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/driver/drv_bmp280.c b/src/driver/drv_bmp280.c index 0b0a4d80c..9ee611892 100644 --- a/src/driver/drv_bmp280.c +++ b/src/driver/drv_bmp280.c @@ -79,6 +79,6 @@ void BMP280_OnEverySecond() { void BMP280_AppendInformationToHTTPIndexPage(http_request_t* request) { - hprintf255(request, "

BMP280 Temperature=%f C, Pressure=%f hPa

", g_temperature*0.01f, g_pressure*0.01f); + hprintf255(request, "

BMP280 Temperature=%.2f C, Pressure=%.2f hPa

", g_temperature*0.01f, g_pressure*0.01f); } diff --git a/src/driver/drv_max72xx_clock.c b/src/driver/drv_max72xx_clock.c index 8aaaec455..5a5a37693 100644 --- a/src/driver/drv_max72xx_clock.c +++ b/src/driver/drv_max72xx_clock.c @@ -41,6 +41,8 @@ bool CHANNEL_IsTemperature(int type) { return true; if (type == ChType_Temperature_div10) return true; + if (type == ChType_Temperature_div100) + return true; return false; } bool CHANNEL_GetGenericOfType(float *out, bool (*checker)(int type)) { diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 41c280f96..06c73f9cd 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -418,6 +418,26 @@ int http_fn_index(http_request_t* request) { hprintf255(request, "Temperature Channel %s value %.2f C
", CHANNEL_GetLabel(i), fValue); poststr(request, ""); + } + else if (channelType == ChType_Pressure_div100) { + + iValue = CHANNEL_Get(i); + fValue = iValue * 0.01f; + + poststr(request, ""); + hprintf255(request, "Pressure Channel %s value %.2f hPa
", CHANNEL_GetLabel(i), fValue); + poststr(request, ""); + + } + else if (channelType == ChType_Temperature_div100) { + + iValue = CHANNEL_Get(i); + fValue = iValue * 0.01f; + + poststr(request, ""); + hprintf255(request, "Temperature Channel %s value %.2f C
", CHANNEL_GetLabel(i), fValue); + poststr(request, ""); + } else if (channelType == ChType_Humidity) { @@ -2038,6 +2058,15 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { discoveryQueued = true; } break; + case ChType_Temperature_div100: + { + dev_info = hass_init_sensor_device_info(TEMPERATURE_SENSOR, i, 2, 2, 1); + MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN); + hass_free_device_info(dev_info); + + discoveryQueued = true; + } + break; case ChType_Humidity: { dev_info = hass_init_sensor_device_info(HUMIDITY_SENSOR, i, -1, -1, 1); diff --git a/src/new_pins.c b/src/new_pins.c index 1eff2f6e9..5321e6432 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -1058,6 +1058,7 @@ float CHANNEL_GetFinalValue(int channel) { case ChType_Voltage_div100: case ChType_PowerFactor_div100: case ChType_Pressure_div100: + case ChType_Temperature_div100: dVal = (float)iVal / 100; break; case ChType_PowerFactor_div1000: @@ -1878,7 +1879,7 @@ const char* g_channelTypeNames[] = { "Frequency_div10", "PowerFactor_div100", "Pressure_div100", - "error", + "Temperature_div100", "error", "error", "error", diff --git a/src/new_pins.h b/src/new_pins.h index d7868215d..362404498 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -894,6 +894,13 @@ typedef enum channelType_e { //chandetail:"file":"new_pins.h", //chandetail:"driver":""} ChType_Pressure_div100, + //chandetail:{"name":"Temperature_div100", + //chandetail:"title":"TODO", + //chandetail:"descr":"Just like humidity_div100, but for temperature.", + //chandetail:"enum":"ChType_Temperature_div100", + //chandetail:"file":"new_pins.h", + //chandetail:"driver":""} + ChType_Temperature_div100, //chandetail:{"name":"Max", //chandetail:"title":"TODO", //chandetail:"descr":"This is the current total number of available channel types.",