From b44eb6f13eb81db5053036c9d3055c71cad957a4 Mon Sep 17 00:00:00 2001 From: Ollo Date: Thu, 14 Jan 2021 22:14:59 +0100 Subject: [PATCH] Background can be changed via MQTT --- displayword.lua | 7 ++++++- main.lua | 2 +- mqtt.lua | 16 +++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/displayword.lua b/displayword.lua index a87c43d..d725b84 100644 --- a/displayword.lua +++ b/displayword.lua @@ -54,7 +54,7 @@ end local data={} -- Module displaying of the words -local generateLEDs = function(words, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) +local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars) -- Set the local variables needed for the colored progress bar if (words == nil) then return nil @@ -103,9 +103,14 @@ local generateLEDs = function(words, colorFg, colorMin1, colorMin2, colorMin3, c end data.drawnCharacters=0 local charsPerLine=11 + -- Space / background has no color by default local space=string.char(0,0,0) + if (colorBg ~= nil) then + space = colorBg + end + -- Set the foreground color as the default color local buf=data.colorFg local line=space diff --git a/main.lua b/main.lua index cd85dc3..2497c2b 100644 --- a/main.lua +++ b/main.lua @@ -72,7 +72,7 @@ function displayTime() invertRows=true end local characters = displayword.countChars(words) - ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4, invertRows, characters) + ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters) end displayword = nil if (ledBuf ~= nil) then diff --git a/mqtt.lua b/mqtt.lua index 2959cdd..a1141ee 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -16,15 +16,21 @@ function registerMqtt() elseif (data == "OFF") then briPercent=0 m:publish(mqttPrefix .. "/clock", "OFF", 0, 0) - elseif (data:sub(1,1) == "#" and data:len() == 7) then - red = tonumber(data:sub(2,3), 16) - green = tonumber(data:sub(4,5), 16) - blue = tonumber(data:sub(6,7), 16) - colorBg=string.char(red, green, blue) + elseif (data:sub(1,1) == "#" and data:len() == 7) then + red = tonumber(data:sub(2,3), 16) + green = tonumber(data:sub(4,5), 16) + blue = tonumber(data:sub(6,7), 16) + colorBg=string.char(red, green, blue) + print("Updated BG: " .. tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue) ) + if (displayTime~= nil) then + displayTime() + end else if (tonumber(data) >= 0 and tonumber(data) <= 100) then briPercent=tonumber(data) m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0) + else + print "Unknown MQTT command" end end end