From ca52ce8b66ecdc321ce5dfc6db45316031631111 Mon Sep 17 00:00:00 2001 From: MaxineMuster <146550015+MaxineMuster@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:49:56 +0100 Subject: [PATCH 1/5] improve logging of hex values / fix calc of negative temperatures --- src/driver/drv_ds1820_simple.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index ea33465df..caa4df705 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -384,7 +384,7 @@ int DS1820_DiscoverFamily() if(crc != ROM[7]) { // This might mean bad signal integrity or multiple 1-wire devices on the bus - DS1820_LOG(DEBUG, "Discover CRC failed (CRC=%x != calculated:%x)", ROM[7], crc); + DS1820_LOG(DEBUG, "Discover CRC failed (CRC=0x%02X != calculated:0x%02X)", ROM[7], crc); return 0; } @@ -393,12 +393,12 @@ int DS1820_DiscoverFamily() if(family == 0x10 || family == 0x28) { ds18_family = family; - DS1820_LOG(INFO, "Discover Family - discovered %x", family); + DS1820_LOG(INFO, "Discover Family - discovered 0x%02X", family); return 1; } else { - DS1820_LOG(DEBUG, "Discover Family %x not supported", family); + DS1820_LOG(DEBUG, "Discover Family 0x%02X not supported", family); return 0; } } @@ -432,8 +432,8 @@ void DS1820_OnEverySecond() if(crc != scratchpad[8]) { errcount++; - DS1820_LOG(ERROR, "Read CRC=%x != calculated:%x (errcount=%i)", scratchpad[8], crc, errcount); - DS1820_LOG(ERROR, "Scratchpad Data Read: %x %x %x %x %x %x %x %x %x", + DS1820_LOG(ERROR, "Read CRC=0x%02X != calculated:0x%02X (errcount=%i)", scratchpad[8], crc, errcount); + DS1820_LOG(ERROR, "Scratchpad Data Read: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X", scratchpad[0], scratchpad[1], scratchpad[2], scratchpad[3], scratchpad[4], scratchpad[5], scratchpad[6], scratchpad[7], scratchpad[8]); @@ -449,7 +449,7 @@ void DS1820_OnEverySecond() int16_t dT = 128 * (scratchpad[7] - scratchpad[6]); dT /= scratchpad[7]; raw = 64 * (raw & 0xFFFE) - 32 + dT; - DS1820_LOG(DEBUG, "family=%x, raw=%i, count_remain=%i, count_per_c=%i, dT=%i", ds18_family, raw, scratchpad[6], scratchpad[7], dT); + DS1820_LOG(DEBUG, "family=0x%02X, raw=%i, count_remain=%i, count_per_c=%i, dT=%i", ds18_family, raw, scratchpad[6], scratchpad[7], dT); } else { // DS18B20 @@ -458,18 +458,19 @@ void DS1820_OnEverySecond() else if(cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms else if(cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms raw = raw << 3; // multiply by 8 - DS1820_LOG(DEBUG, "family=%x, raw=%i, cfg=%x (%i bit resolution)", ds18_family, raw, cfg, 9 + (cfg) / 32); + DS1820_LOG(DEBUG, "family=0x%02X, raw=%i, cfg=0x%02X (%i bit resolution)", ds18_family, raw, cfg, 9 + (cfg) / 32); } // Raw is t * 128 t = (raw / 128) * 100; // Whole degrees int frac = (raw % 128) * 100 / 128; // Fractional degrees - t += t > 0 ? frac : -frac; + t += frac; dsread = 0; lastconv = g_secondsElapsed; CHANNEL_Set(g_cfg.pins.channels[Pin], t, CHANNEL_SET_FLAG_SILENT); - DS1820_LOG(INFO, "Temp=%i.%02i", (int)t / 100, (int)t % 100); + DS1820_LOG(INFO, "Temp=%0.2f", (float)t / 100); + } } else if(dsread == 0 && (g_secondsElapsed % ds18_conversionPeriod == 0 || lastconv == 0)) From e071b73170fd5571af03a4061fe8d06cf0963a07 Mon Sep 17 00:00:00 2001 From: maxinemuster Date: Sat, 9 Nov 2024 16:47:13 +0100 Subject: [PATCH 2/5] invalidate temperature after some time (here 30 seconds for testing, later 5 minutes) --- src/driver/drv_ds1820_simple.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index caa4df705..6722672f5 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -9,11 +9,21 @@ #define interrupts() taskEXIT_CRITICAL() #endif +// temperature value meaning "undefined" +// -12700 ~ -127.00° +#define DSUNDEFTEMP -12700 +// timeout in seconds for unsudccessfull readings of sensor +// temperature will be set "undefined" after this time +// 300 seconds = 5 Minutes +#define DSTIMEOUT 30 + + + static uint8_t dsread = 0; static int Pin; -static int t = -127; +static int t = DSUNDEFTEMP; static int errcount = 0; -static int lastconv; // secondsElapsed on last successfull reading +static int lastconv=0; // secondsElapsed on last successfull reading static uint8_t ds18_family = 0; static int ds18_conversionPeriod = 0; @@ -360,7 +370,9 @@ void DS1820_driver_Init() void DS1820_AppendInformationToHTTPIndexPage(http_request_t* request) { - hprintf255(request, "
DS1820 Temperature: %.2f C (read %i secs ago)
", (float)t / 100, g_secondsElapsed - lastconv); + hprintf255(request, "
DS1820 Temperature: "); + if (t != DSUNDEFTEMP) hprintf255(request, "%.2f C (read %i secs ago)
", (float)t / 100, g_secondsElapsed - lastconv); + else hprintf255(request, "-"); } int DS1820_DiscoverFamily() @@ -408,6 +420,10 @@ void DS1820_OnEverySecond() // for now just find the pin used Pin = PIN_FindPinIndexForRole(IOR_DS1820_IO, 99); uint8_t scratchpad[9], crc; + if ( (t != DSUNDEFTEMP) && lastconv && (g_secondsElapsed - lastconv > DSTIMEOUT)) { + t = DSUNDEFTEMP; + CHANNEL_Set(g_cfg.pins.channels[Pin], t, CHANNEL_SET_FLAG_SILENT); + } if(Pin != 99) { // only if pin is set From 8a9d6d91adf1e74228b218911313d531629c5397 Mon Sep 17 00:00:00 2001 From: MaxineMuster <146550015+MaxineMuster@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:17:52 +0100 Subject: [PATCH 3/5] Show device found in GUI (DS18B20 or DS18(S)20) --- src/driver/drv_ds1820_simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index 6722672f5..ca1f77c07 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -370,7 +370,7 @@ void DS1820_driver_Init() void DS1820_AppendInformationToHTTPIndexPage(http_request_t* request) { - hprintf255(request, "
DS1820 Temperature: "); + hprintf255(request, "
DS18%s20 Temperature: ", family == 0x28 ? "B" : "20/DS18S20"); if (t != DSUNDEFTEMP) hprintf255(request, "%.2f C (read %i secs ago)
", (float)t / 100, g_secondsElapsed - lastconv); else hprintf255(request, "-"); } From e00150539b767e2baa68f826b329bc3e70fe7f1c Mon Sep 17 00:00:00 2001 From: MaxineMuster <146550015+MaxineMuster@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:58:29 +0100 Subject: [PATCH 4/5] fix typo --- src/driver/drv_ds1820_simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index ca1f77c07..ed6cceaf7 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -370,7 +370,7 @@ void DS1820_driver_Init() void DS1820_AppendInformationToHTTPIndexPage(http_request_t* request) { - hprintf255(request, "
DS18%s20 Temperature: ", family == 0x28 ? "B" : "20/DS18S20"); + hprintf255(request, "
DS18%s20 Temperature: ", ds18_family == 0x28 ? "B" : "20/DS18S20"); if (t != DSUNDEFTEMP) hprintf255(request, "%.2f C (read %i secs ago)
", (float)t / 100, g_secondsElapsed - lastconv); else hprintf255(request, "-"); } From 608557d0c5add83380dc7e7eb91e2307280699cf Mon Sep 17 00:00:00 2001 From: MaxineMuster <146550015+MaxineMuster@users.noreply.github.com> Date: Sat, 16 Nov 2024 15:34:22 +0100 Subject: [PATCH 5/5] =?UTF-8?q?After=20timeout,=20don't=20publish=20"DUNDE?= =?UTF-8?q?F"=20temperature=20(-127=C2=B0C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/driver/drv_ds1820_simple.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/driver/drv_ds1820_simple.c b/src/driver/drv_ds1820_simple.c index ed6cceaf7..5f4f26876 100644 --- a/src/driver/drv_ds1820_simple.c +++ b/src/driver/drv_ds1820_simple.c @@ -420,9 +420,11 @@ void DS1820_OnEverySecond() // for now just find the pin used Pin = PIN_FindPinIndexForRole(IOR_DS1820_IO, 99); uint8_t scratchpad[9], crc; + // handle reading timout - set local temp to "UNDEF" value ... if ( (t != DSUNDEFTEMP) && lastconv && (g_secondsElapsed - lastconv > DSTIMEOUT)) { t = DSUNDEFTEMP; - CHANNEL_Set(g_cfg.pins.channels[Pin], t, CHANNEL_SET_FLAG_SILENT); + // .. but don't publish this value - so value can "time out" + // CHANNEL_Set(g_cfg.pins.channels[Pin], t, CHANNEL_SET_FLAG_SILENT); } if(Pin != 99) {