From 1cea6b377e763e6fb5d337a3bf0caa74c4db6c5d Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 23 Jan 2021 09:44:15 +0100 Subject: [PATCH 1/4] Background of first row changeable --- displayword.lua | 13 ++++++++++++- main.lua | 3 ++- mqtt.lua | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/displayword.lua b/displayword.lua index d725b84..395ac6c 100644 --- a/displayword.lua +++ b/displayword.lua @@ -54,7 +54,7 @@ end local data={} -- Module displaying of the words -local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) +local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars, row1bgColor) -- Set the local variables needed for the colored progress bar if (words == nil) then return nil @@ -107,14 +107,20 @@ local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, col -- Space / background has no color by default local space=string.char(0,0,0) + -- Background color must always be set if (colorBg ~= nil) then space = colorBg + else + colorBg = space end -- Set the foreground color as the default color local buf=data.colorFg local line=space -- line 1---------------------------------------------- + if (row1bgColor ~= nil) then + space = row1bgColor + end if (words.it==1) then buf=drawLEDs(data,2) -- ES else @@ -135,6 +141,11 @@ if (words.fiveMin== 1) then buf= buf .. space:rep(4) end -- line 2-- even row (so inverted) -------------------- + if (row2bgColor ~= nil) then + space = row2bgColor + else + space = colorBg + end if (words.tenMin == 1) then line= drawLEDs(data,4) -- ZEHN else diff --git a/main.lua b/main.lua index 18abe65..014bf44 100644 --- a/main.lua +++ b/main.lua @@ -72,7 +72,8 @@ function displayTime() invertRows=true end local characters = displayword.countChars(words) - ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters) + ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters, + row1bgColor) end displayword = nil if (ledBuf ~= nil) then diff --git a/mqtt.lua b/mqtt.lua index 3b8e5f6..32b6ae4 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -37,6 +37,24 @@ function handleSingleCommand(client, topic, data) end +function parseBgColor(data) + local red=nil + local green=nil + local blue=nil + if (data:sub(1,1) == "#") then + red = tonumber(data:sub(2,3), 16) + green = tonumber(data:sub(4,5), 16) + blue = tonumber(data:sub(6,7), 16) + else + red, green, blue = string.match(data, "(%d+),(%d+),(%d+)") + end + if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then + return string.char(green * briPercent / 100, red * briPercent / 100, blue * briPercent / 100) + else + return nil + end +end + -- MQTT extension function registerMqtt() m = mqtt.Client("wordclock", 120) @@ -58,6 +76,8 @@ function registerMqtt() collectgarbage() mydofile("telnet") startTelnetServer() + elseif (string.match(topic, "row1$")) then + row1bgColor = parseBgColor(data) end end end From f1baf8b916232c0b296dfbbc247455f75d7f2c99 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 23 Jan 2021 09:55:13 +0100 Subject: [PATCH 2/4] Formating corrected --- Readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index c84c38f..b286f1f 100644 --- a/Readme.md +++ b/Readme.md @@ -36,13 +36,13 @@ Determine the IP address of your clock and execute the following script: ## MQTT Interface * **basetopic**/cmd/single -** ON Set brightness to 100% -** OFF Set brightness to 0% -** 0-100 Set brightness to given value -** #rrggbb Bacground color is set to hex representation of red, green and blue -** 0-255,0-255,0-255 Background color is set to decimal representation of red, green an blue + * ON **Set brightness to 100%** + * OFF **Set brightness to 0%** + * 0-100 **Set brightness to given value** + * #rrggbb **Background color is set to hex representation of red, green and blue** + * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** * **basetopic**/cmd/telnet -** ignored Stop MQTT server and start telnetserver at port 23 + * ignored **Stop MQTT server and start telnetserver at port 23** ## OpenHAB2 Tested MQTT with binding-mqtt 2.5.x From 5b96bcc7bbe8780fe5f1ffec8486076c9bd299ac Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 23 Jan 2021 10:00:15 +0100 Subject: [PATCH 3/4] Documentation improved --- Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Readme.md b/Readme.md index b286f1f..e06bd90 100644 --- a/Readme.md +++ b/Readme.md @@ -30,11 +30,19 @@ Determine the IP address of your clock and execute the following script: ## Hardware Setup +Mandatory: * GPIO2 LEDs * GPIO0 Bootloader (at start) * GPIO0 factory reset (long during operation) +Optinal: +* ADC VT93N2, 48k light resistor ## MQTT Interface +### Status +* **basetopic**/brightness **Current brightness in percent** +* **basetopic**/background **Current background color** + +### Commands * **basetopic**/cmd/single * ON **Set brightness to 100%** * OFF **Set brightness to 0%** From f79195e9a575fc97bd2c892ae9f8b707254d4641 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 23 Jan 2021 10:05:18 +0100 Subject: [PATCH 4/4] Status of first row color added to MQTT --- Readme.md | 3 +++ mqtt.lua | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index e06bd90..4bce2b1 100644 --- a/Readme.md +++ b/Readme.md @@ -41,6 +41,7 @@ Optinal: ### Status * **basetopic**/brightness **Current brightness in percent** * **basetopic**/background **Current background color** +* **basetopic**/row1 **Current background color** ### Commands * **basetopic**/cmd/single @@ -51,6 +52,8 @@ Optinal: * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** * **basetopic**/cmd/telnet * ignored **Stop MQTT server and start telnetserver at port 23** +* **basetopic**/cmd/row1 + * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** ## OpenHAB2 Tested MQTT with binding-mqtt 2.5.x diff --git a/mqtt.lua b/mqtt.lua index 32b6ae4..ad82d94 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -37,7 +37,10 @@ function handleSingleCommand(client, topic, data) end -function parseBgColor(data) +-- Parse MQTT data and extract color +-- @param data MQTT information +-- @param row string of the row e.g. "row1" used to publish current state +function parseBgColor(data, row) local red=nil local green=nil local blue=nil @@ -49,6 +52,7 @@ function parseBgColor(data) red, green, blue = string.match(data, "(%d+),(%d+),(%d+)") end if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then + m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0) return string.char(green * briPercent / 100, red * briPercent / 100, blue * briPercent / 100) else return nil @@ -77,7 +81,7 @@ function registerMqtt() mydofile("telnet") startTelnetServer() elseif (string.match(topic, "row1$")) then - row1bgColor = parseBgColor(data) + row1bgColor = parseBgColor(data, "row1") end end end