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
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)
words.briPercent = tonumber( ((words.briPercent * 4) + per) / 5)
print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(words.briPercent) .. "% 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.colorM1 = string.char(string.byte(colorM1,1) * briPercent / 100, string.byte(colorM1,2) * briPercent / 100, string.byte(colorM1,3) * briPercent / 100)
data.colorM2 = string.char(string.byte(colorM2,1) * briPercent / 100, string.byte(colorM2,2) * briPercent / 100, string.byte(colorM2,3) * briPercent / 100)
data.colorM3 = string.char(string.byte(colorM3,1) * briPercent / 100, string.byte(colorM3,2) * briPercent / 100, string.byte(colorM3,3) * briPercent / 100)
data.colorM4 = string.char(string.byte(colorM4,1) * briPercent / 100, string.byte(colorM4,2) * briPercent / 100, string.byte(colorM4,3) * briPercent / 100)
words.briPer = tonumber( ((words.briPer * 4) + per) / 5)
print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(words.briPer) .. "% current: " .. tostring(per) .. "%")
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) * briPer / 100, string.byte(colorM1,2) * briPer / 100, string.byte(colorM1,3) * briPer / 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) * briPer / 100, string.byte(colorM3,2) * briPer / 100, string.byte(colorM3,3) * briPer / 100)
data.colorM4 = string.char(string.byte(colorM4,1) * briPer / 100, string.byte(colorM4,2) * briPer / 100, string.byte(colorM4,3) * briPer / 100)
else
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
data.colorFg=colorFg

View File

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

View File

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