Renamed briPercent to briPer

This commit is contained in:
Ollo 2021-02-10 20:04:22 +01:00
parent e4b22a9921
commit 712ddaafeb
3 changed files with 22 additions and 22 deletions

View File

@ -100,15 +100,15 @@ local generateLEDs = function(words, colorBg, colorFg, colorM1, colorM2, colorM3
data.aoC = 0 data.aoC = 0
end end
if ( (adc ~= nil) and (words.briPercent ~= nil) ) then if ( (adc ~= nil) and (words.briPer ~= nil) ) then
local per = math.floor(100*adc.read(0)/1000) local per = math.floor(100*adc.read(0)/1000)
words.briPercent = tonumber( ((words.briPercent * 4) + per) / 5) words.briPer = tonumber( ((words.briPer * 4) + per) / 5)
print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(words.briPercent) .. "% current: " .. tostring(per) .. "%") print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(words.briPer) .. "% current: " .. tostring(per) .. "%")
data.colorFg = string.char(string.byte(colorFg,1) * briPercent / 100, string.byte(colorFg,2) * briPercent / 100, string.byte(colorFg,3) * briPercent / 100) data.colorFg = string.char(string.byte(colorFg,1) * briPer / 100, string.byte(colorFg,2) * briPer / 100, string.byte(colorFg,3) * briPer / 100)
data.colorM1 = string.char(string.byte(colorM1,1) * briPercent / 100, string.byte(colorM1,2) * briPercent / 100, string.byte(colorM1,3) * briPercent / 100) data.colorM1 = string.char(string.byte(colorM1,1) * briPer / 100, string.byte(colorM1,2) * briPer / 100, string.byte(colorM1,3) * briPer / 100)
data.colorM2 = string.char(string.byte(colorM2,1) * briPercent / 100, string.byte(colorM2,2) * briPercent / 100, string.byte(colorM2,3) * briPercent / 100) data.colorM2 = string.char(string.byte(colorM2,1) * briPer / 100, string.byte(colorM2,2) * briPer / 100, string.byte(colorM2,3) * briPer / 100)
data.colorM3 = string.char(string.byte(colorM3,1) * briPercent / 100, string.byte(colorM3,2) * briPercent / 100, string.byte(colorM3,3) * briPercent / 100) data.colorM3 = string.char(string.byte(colorM3,1) * briPer / 100, string.byte(colorM3,2) * briPer / 100, string.byte(colorM3,3) * briPer / 100)
data.colorM4 = string.char(string.byte(colorM4,1) * briPercent / 100, string.byte(colorM4,2) * briPercent / 100, string.byte(colorM4,3) * briPercent / 100) data.colorM4 = string.char(string.byte(colorM4,1) * briPer / 100, string.byte(colorM4,2) * briPer / 100, string.byte(colorM4,3) * briPer / 100)
else else
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars) -- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
data.colorFg=colorFg data.colorFg=colorFg

View File

@ -20,7 +20,6 @@ function syncTimeFromInternet()
end end
end end
briPercent = 50
function displayTime() function displayTime()
collectgarbage() collectgarbage()
local sec, usec = rtctime.get() local sec, usec = rtctime.get()
@ -31,12 +30,12 @@ function displayTime()
local time = getTime(sec, timezoneoffset) local time = getTime(sec, timezoneoffset)
local words = display_timestat(time.hour, time.minute) local words = display_timestat(time.hour, time.minute)
if ((dim ~= nil) and (dim == "on")) then if ((dim ~= nil) and (dim == "on")) then
words.briPercent=briPercent words.briPer=briPer
if (words.briPercent ~= nil and words.briPercent < 3) then if (words.briPer ~= nil and words.briPer < 3) then
words.briPercent=3 words.briPer=3
end end
else else
words.briPercent=nil words.briPer=nil
end end
mydofile("displayword") mydofile("displayword")
if (displayword ~= nil) then if (displayword ~= nil) then
@ -59,7 +58,7 @@ function displayTime()
end end
-- cleanup -- cleanup
briPercent=words.briPercent briPer=words.briPer
words=nil words=nil
time=nil time=nil
collectgarbage() collectgarbage()
@ -169,6 +168,7 @@ function normalOperation()
end end
-------------------main program ----------------------------- -------------------main program -----------------------------
briPer = 50 -- Default brightness is set to 50%
ws2812.init() -- WS2812 LEDs initialized on GPIO2 ws2812.init() -- WS2812 LEDs initialized on GPIO2
----------- button --------- ----------- button ---------

View File

@ -6,10 +6,10 @@ local t=nil
function handleSingleCommand(client, topic, data) function handleSingleCommand(client, topic, data)
if (data == "ON") then if (data == "ON") then
briPercent=100 briPer=100
m:publish(mqttPrefix .. "/clock", "ON", 0, 0) m:publish(mqttPrefix .. "/clock", "ON", 0, 0)
elseif (data == "OFF") then elseif (data == "OFF") then
briPercent=0 briPer=0
m:publish(mqttPrefix .. "/clock", "OFF", 0, 0) m:publish(mqttPrefix .. "/clock", "OFF", 0, 0)
elseif ((data:sub(1,1) == "#" and data:len() == 7) or (string.match(data, "%d+,%d+,%d+"))) then elseif ((data:sub(1,1) == "#" and data:len() == 7) or (string.match(data, "%d+,%d+,%d+"))) then
local red=0 local red=0
@ -22,7 +22,7 @@ function handleSingleCommand(client, topic, data)
else else
red, green, blue = string.match(data, "(%d+),(%d+),(%d+)") red, green, blue = string.match(data, "(%d+),(%d+),(%d+)")
end end
colorBg=string.char(green * briPercent / 100, red * briPercent / 100, blue * briPercent / 100) colorBg=string.char(green * briPer / 100, red * briPer / 100, blue * briPer / 100)
print("Updated BG: " .. tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue) ) print("Updated BG: " .. tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue) )
m:publish(mqttPrefix .. "/background", tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0) m:publish(mqttPrefix .. "/background", tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0)
if (displayTime~= nil) then if (displayTime~= nil) then
@ -30,7 +30,7 @@ function handleSingleCommand(client, topic, data)
end end
else else
if (tonumber(data) >= 0 and tonumber(data) <= 100) then if (tonumber(data) >= 0 and tonumber(data) <= 100) then
briPercent=tonumber(data) briPer=tonumber(data)
m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0) m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0)
else else
print "Unknown MQTT command" print "Unknown MQTT command"
@ -55,7 +55,7 @@ function parseBgColor(data, row)
end end
if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then
m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0) m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0)
return string.char(green * briPercent / 100, red * briPercent / 100, blue * briPercent / 100) return string.char(green * briPer / 100, red * briPer / 100, blue * briPer / 100)
else else
return nil return nil
end end
@ -158,15 +158,15 @@ function startMqttClient()
if (t ~= nil) then if (t ~= nil) then
temp=readTemp() temp=readTemp()
end end
if (oldBrightness ~= briPercent) then if (oldBrightness ~= briPer) then
m:publish(mqttPrefix .. "/brightness", tostring(briPercent), 0, 0) m:publish(mqttPrefix .. "/brightness", tostring(briPer), 0, 0)
elseif (temp ~= nil and temp ~= oldTemp) then elseif (temp ~= nil and temp ~= oldTemp) then
oldTemp = temp oldTemp = temp
m:publish(mqttPrefix .. "/temp", tostring(temp/100).."."..tostring(temp%100), 0, 0) m:publish(mqttPrefix .. "/temp", tostring(temp/100).."."..tostring(temp%100), 0, 0)
else else
m:publish(mqttPrefix .. "/heap", tostring(node.heap()), 0, 0) m:publish(mqttPrefix .. "/heap", tostring(node.heap()), 0, 0)
end end
oldBrightness = briPercent oldBrightness = briPer
end end
end) end)
mqtttimer:start() mqtttimer:start()