Wordclock/wordclock.lua

196 lines
4.9 KiB
Lua
Raw Permalink Normal View History

2016-04-12 18:21:56 +02:00
-- Revese engeeniered code of display_wc_ger.c by Vlad Tepesch
2021-02-10 19:45:08 +01:00
-- See https://www.mikrocontroller.net/articles/Word_cl_Variante_1#Download
2021-02-11 21:23:32 +01:00
local M
do
2021-02-11 21:23:32 +01:00
-- @fn wc_timestat
2017-02-28 18:24:38 +01:00
-- Return the leds to use the granuality is 5 minutes
-- @param hours the current hours (0-23)
-- @param minutes the current minute (0-59)
-- @param longmode (optional parameter) 0: no long mode, 1: long mode (itis will be set)
2021-02-11 21:23:32 +01:00
local timestat=function (hours, minutes, longmode)
if (longmode == nil) then
longmode=0
end
-- generate an empty return type
2021-02-10 19:45:08 +01:00
-- Values: it, is, 5 minutes, 10 minutes, afer, before, three hour, quarter, dreiviertel, half, s
-- hours: one, one Long, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve
-- Special ones: twenty, clock, minute 1 flag, minute 2 flag, minute 3 flag, minute 4 flag
local ret = { it=0, is=0, m5=0, m10=0, ha=0, hb=0, h3=0, hq=0, h3q=0, half=0, s=0,
h1=0, h1l=0, h2=0, h3=0, h4=0, h5=0, h6=0, h7=0, h8=0, h9=0, h10=0, h11=0, h12=0,
m20=0, cl=0, m1=0, m2=0, m3=0, m4=0 }
-- return black screen if there is no real time given
if (hours == nil or minutes == nil) then
return ret
end
-- transcode minutes
local minutesLeds = minutes%5
2016-06-19 00:08:21 +02:00
local minutes=math.floor(minutes/5)
-- "It is" only display each half hour and each hour
-- or if longmode is set
if ((longmode==1)
or (minutes==0)
or (minutes==6)) then
2018-01-28 15:08:08 +01:00
ret.it=1
ret.is=1
end
-- Handle minutes
if (minutes > 0) then
if (minutes==1) then
2021-02-10 19:45:08 +01:00
ret.m5=1
ret.ha=1
elseif (minutes==2) then
2021-02-10 19:45:08 +01:00
ret.m10=1
ret.ha=1
elseif (minutes==3) then
2021-02-10 19:45:08 +01:00
ret.hq=1
ret.ha=1
elseif (minutes==4) then
2021-02-10 19:45:08 +01:00
ret.m20=1
ret.ha=1
elseif (minutes==5) then
2021-02-10 19:45:08 +01:00
ret.m5=1
ret.half=1
2021-02-10 19:45:08 +01:00
ret.hb=1
elseif (minutes==6) then
ret.half=1
elseif (minutes==7) then
2021-02-10 19:45:08 +01:00
ret.m5=1
ret.half=1
2021-02-10 19:45:08 +01:00
ret.ha=1
elseif (minutes==8) then
2021-02-10 19:45:08 +01:00
ret.m20=1
ret.hb=1
2016-06-07 23:30:13 +02:00
elseif (minutes==9) then
-- Hande if three quater or quater before is displayed
2020-12-10 22:15:27 +01:00
if ((threequater ~= nil) and (threequater==true or threequater=="on")) then
2021-02-10 19:45:08 +01:00
ret.h3q=1
else
2021-02-10 19:45:08 +01:00
ret.hq = 1
ret.hb = 1
end
elseif (minutes==10) then
2021-02-10 19:45:08 +01:00
ret.m10=1
ret.hb=1
elseif (minutes==11) then
2021-02-10 19:45:08 +01:00
ret.m5=1
ret.hb=1
end
2017-01-04 21:54:54 +01:00
if (minutes > 4) then
hours=hours+1
end
else
2021-02-10 19:45:08 +01:00
ret.cl=1
end
2021-02-10 19:45:08 +01:00
-- Display the minutes as as extra gimmic on m1 to min 4 to display the cut number
if (minutesLeds==1) then
2021-02-10 19:45:08 +01:00
ret.m1=1
elseif (minutesLeds==2) then
2021-02-10 19:45:08 +01:00
ret.m2=1
elseif (minutesLeds==3) then
2021-02-10 19:45:08 +01:00
ret.m3=1
elseif (minutesLeds==4) then
2021-02-10 19:45:08 +01:00
ret.m4=1
end
-- handle hours
if (hours > 12) then
hours = hours - 12
end
if (hours==0) then
hours=12
end
if (hours == 1) then
2019-03-23 13:54:29 +01:00
if ((ret.it == 1) and (ret.half == 0) ) then
2021-02-10 19:45:08 +01:00
ret.h1=1
else
2021-02-10 19:45:08 +01:00
ret.h1l=1
end
elseif (hours == 2) then
2021-02-10 19:45:08 +01:00
ret.h2=1
elseif (hours == 3) then
2021-02-10 19:45:08 +01:00
ret.h3=1
elseif (hours == 4) then
2021-02-10 19:45:08 +01:00
ret.h4=1
elseif (hours == 5) then
2021-02-10 19:45:08 +01:00
ret.h5=1
elseif (hours == 6) then
2021-02-10 19:45:08 +01:00
ret.h6=1
elseif (hours == 7) then
2021-02-10 19:45:08 +01:00
ret.h7=1
elseif (hours == 8) then
2021-02-10 19:45:08 +01:00
ret.h8=1
elseif (hours == 9) then
2021-02-10 19:45:08 +01:00
ret.h9=1
elseif (hours == 10) then
2021-02-10 19:45:08 +01:00
ret.h10=1
elseif (hours == 11) then
2021-02-10 19:45:08 +01:00
ret.h11=1
elseif (hours == 12) then
2021-02-10 19:45:08 +01:00
ret.h12=1
end
collectgarbage()
return ret
end
-- Logic to display number from Mqtt as text
function showText(dw, rgbBuffer, invertRows, dispNumber)
if (dispNumber ~= nil) then
-- Values: it, is, 5 minutes, 10 minutes, afer, before, three hour, quarter, dreiviertel, half, s
-- hours: one, one Long, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve
-- Special ones: twenty, clock, minute 1 flag, minute 2 flag, minute 3 flag, minute 4 flag
local ret = { it=0, is=0, m5=0, m10=0, ha=0, hb=0, h3=0, hq=0, h3q=0, half=0, s=0,
h1=0, h1l=0, h2=0, h3=0, h4=0, h5=0, h6=0, h7=0, h8=0, h9=0, h10=0, h11=0, h12=0,
m20=0, cl=0, m1=0, m2=0, m3=0, m4=0 }
print("Mqtt Display of temperature: " .. tostring(dispNumber) )
if (dispNumber == 1) or (dispNumber == -1) then
ret.h1=1
elseif (dispNumber == 2) or (dispNumber == -2) then
ret.h2=1
elseif (dispNumber == 3) or (dispNumber == -3) then
ret.h3=1
elseif (dispNumber == 4) or (dispNumber == -4) then
ret.h4=1
elseif (dispNumber == 5) or (dispNumber == -5) then
ret.h5=1
elseif (dispNumber == 6) or (dispNumber == -6) then
ret.h6=1
elseif (dispNumber == 7) or (dispNumber == -7) then
ret.h7=1
elseif (dispNumber == 8) or (dispNumber == -8) then
ret.h8=1
elseif (dispNumber == 9) or (dispNumber == -9) then
ret.h9=1
elseif (dispNumber == 10) or (dispNumber == -10) then
ret.h10=1
elseif (dispNumber == 11) or (dispNumber == -11) then
ret.h11=1
elseif (dispNumber == 12) or (dispNumber == -12) then
ret.h12=1
else
-- over or under temperature
end
return ret
else
return nil
end
end
2021-02-11 21:23:32 +01:00
-- Pack everything into a module
M = {
timestat = timestat,
showText = showText
2021-02-11 21:23:32 +01:00
}
end
wc = M