From b4fee78ad86dfd8395a9de94907f97bc41be7a68 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 29 Oct 2025 23:47:15 +0100 Subject: [PATCH] aqhome-cgi: fixed a bug with RGBW values on pages. --- apps/aqhome-cgi/modules/devices/mdevices.c | 43 +++++++++++++++---- apps/aqhome-cgi/modules/devices/mdevices.h | 1 + .../modules/devices/mdevices_page.c | 10 ++++- .../modules/devices/mdevices_setdevice.c | 2 +- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/apps/aqhome-cgi/modules/devices/mdevices.c b/apps/aqhome-cgi/modules/devices/mdevices.c index aef7878..12939d6 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices.c +++ b/apps/aqhome-cgi/modules/devices/mdevices.c @@ -260,36 +260,36 @@ uint32_t AQH_ModDevices_RgbwFromComponents(int r, int g, int b, int w) { uint32_t colorOut; - colorOut=((r & 0xff)<<16) | ((g & 0xff)<<24) | (b &0xff) | ((w & 0xff)<<8); + colorOut=((r & 0xff)<<16) | ((g & 0xff)<<24) | (b & 0xff) | ((w & 0xff)<<8); return colorOut; } int AQH_ModDevices_RgbwGetR(uint32_t color) -{ - return (color & 0xff0000)>>16; +{ /* GGRRWWBB */ + return (color & 0x00ff0000)>>16; } int AQH_ModDevices_RgbwGetG(uint32_t color) -{ +{ /* GGRRWWBB */ return (color & 0xff000000)>>24; } int AQH_ModDevices_RgbwGetB(uint32_t color) -{ - return (color & 0xff); +{ /* GGRRWWBB */ + return (color & 0x000000ff); } int AQH_ModDevices_RgbwGetW(uint32_t color) -{ - return (color & 0xff00)>>8; +{ /* GGRRWWBB */ + return (color & 0x0000ff00)>>8; } @@ -485,6 +485,33 @@ int AQH_ModDevices_ValueGetLastDataAsInt(AQH_DATACLIENT *dc, const AQH_VALUE *va +uint32_t AQH_ModDevices_ValueGetLastDataAsUint32(AQH_DATACLIENT *dc, const AQH_VALUE *value, uint32_t defaultValue) +{ + const char *sValueSystemName; + uint64_t dataPoints[2]; + uint64_t recvdNum; + // uint64_t timestamp; + union {double f; uint64_t i;} u; + uint32_t uintVal; + + sValueSystemName=AQH_Value_GetNameForSystem(value); + recvdNum=AQH_DataClient_GetLastData(dc, sValueSystemName, &dataPoints[0], 1); + if (recvdNum>0) { + // timestamp=dataPoints[0]; + u.i=dataPoints[1]; + uintVal=(uint32_t) u.f; + DBG_ERROR(NULL, "Transformed value %.2f -> %08x", u.f, uintVal); + } + else { + DBG_INFO(NULL, "No last value for \"%s\"", sValueSystemName); + uintVal=defaultValue; + } + + return uintVal; +} + + + AQDG_GRAPH_DATAPAIR_LIST *AQH_ModDevices_RequestDataPairList(AQH_DATACLIENT *dc, const char *systemValueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num) diff --git a/apps/aqhome-cgi/modules/devices/mdevices.h b/apps/aqhome-cgi/modules/devices/mdevices.h index fadfe80..047155d 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices.h +++ b/apps/aqhome-cgi/modules/devices/mdevices.h @@ -59,6 +59,7 @@ int AQH_ModDevices_RgbwGetW(uint32_t color); AQH_VALUE *AQH_ModDevices_GetValueForDevice(AQH_DATACLIENT *dc, const char *sDeviceName, const char *sValueName); AQH_DEVICE *AQH_ModDevices_GetDevice(AQH_DATACLIENT *dc, const char *sDeviceName); int AQH_ModDevices_ValueGetLastDataAsInt(AQH_DATACLIENT *dc, const AQH_VALUE *value, int defaultValue); +uint32_t AQH_ModDevices_ValueGetLastDataAsUint32(AQH_DATACLIENT *dc, const AQH_VALUE *value, uint32_t defaultValue); AQDG_GRAPH_DATAPAIR_LIST *AQH_ModDevices_RequestDataPairList(AQH_DATACLIENT *dc, const char *systemValueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num); diff --git a/apps/aqhome-cgi/modules/devices/mdevices_page.c b/apps/aqhome-cgi/modules/devices/mdevices_page.c index 60eac5c..f6def1d 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices_page.c +++ b/apps/aqhome-cgi/modules/devices/mdevices_page.c @@ -570,11 +570,11 @@ void _writeActor(AQH_DATACLIENT *dc, const char *sPageId, GWEN_XMLNODE *n, int l value=AQH_ModDevices_GetValueForDevice(dc, sDeviceName, sValueName); if (value) { - int lastData; + uint32_t lastData; if (layout!=MY_LAYOUT_NONE) GBAS(dbuf, "\n"); - lastData=AQH_ModDevices_ValueGetLastDataAsInt(dc, value, 0); + lastData=AQH_ModDevices_ValueGetLastDataAsUint32(dc, value, 0); GBAS(dbuf,"
\n"); GBAA(dbuf, "\n", sPageId); GBAA(dbuf, "\n", sActorId); @@ -645,6 +645,12 @@ void _addGraphLink(const char *sPageId, const char *sGraphId, int w, int h, GWEN void _writeRgbwToForm(const char *sValueName, uint32_t color, GWEN_BUFFER *dbuf) { #if 1 + DBG_ERROR(NULL, "Color=%08x (%d, %d, %d, %d)", + color, + AQH_ModDevices_RgbwGetR(color), + AQH_ModDevices_RgbwGetG(color), + AQH_ModDevices_RgbwGetB(color), + AQH_ModDevices_RgbwGetW(color)); GBAA(dbuf, "", sValueName); GBAA(dbuf, "", sValueName, sValueName, AQH_ModDevices_RgbwGetR(color)); diff --git a/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c b/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c index 6edfd72..9c0879a 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c +++ b/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c @@ -80,7 +80,7 @@ void AQH_ModDevices_RunSetDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION * GWEN_BUFFER *pbuf; pbuf=GWEN_Buffer_new(0, 256, 0, 1); - GBAS(pbuf, "Location: /aqbt/devices/device.html?device="); + GBAS(pbuf, "Location: device.html?device="); GWEN_Text_EscapeToBuffer(sDeviceName, pbuf); AQCGI_Request_AddResponseHeaderData(rq, GWEN_Buffer_GetStart(pbuf)); GWEN_Buffer_free(pbuf);