2017-03-01 21:39:05 +01:00
|
|
|
-- Module filling a buffer, sent to the LEDs
|
2019-05-03 20:19:12 +02:00
|
|
|
local M
|
|
|
|
do
|
2019-05-10 23:42:20 +02:00
|
|
|
local updateColor = function (data)
|
2019-04-20 21:39:50 +02:00
|
|
|
--FIXME magic missing to start on the left side
|
|
|
|
return data.colorFg
|
2017-03-01 21:39:05 +01:00
|
|
|
end
|
|
|
|
|
2019-05-10 22:58:42 +02:00
|
|
|
local drawLEDs = function(data, numberNewChars)
|
2018-12-27 14:25:51 +01:00
|
|
|
if (numberNewChars == nil) then
|
|
|
|
numberNewChars=0
|
|
|
|
end
|
2017-03-01 21:39:05 +01:00
|
|
|
local tmpBuf=nil
|
|
|
|
for i=1,numberNewChars do
|
|
|
|
if (tmpBuf == nil) then
|
2019-05-10 23:42:20 +02:00
|
|
|
tmpBuf = updateColor(data)
|
2017-03-01 21:39:05 +01:00
|
|
|
else
|
2019-05-10 23:42:20 +02:00
|
|
|
tmpBuf=tmpBuf .. updateColor(data)
|
2017-03-01 21:39:05 +01:00
|
|
|
end
|
2018-01-28 15:08:08 +01:00
|
|
|
data.drawnCharacters=data.drawnCharacters+1
|
2017-03-01 21:39:05 +01:00
|
|
|
end
|
|
|
|
return tmpBuf
|
|
|
|
end
|
|
|
|
|
2018-12-27 23:30:39 +01:00
|
|
|
-- Utility function for round
|
2019-05-03 20:19:12 +02:00
|
|
|
local round = function(num)
|
2018-12-27 23:30:39 +01:00
|
|
|
under = math.floor(num)
|
|
|
|
upper = math.floor(num) + 1
|
|
|
|
underV = -(under - num)
|
|
|
|
upperV = upper - num
|
|
|
|
if (upperV > underV) then
|
|
|
|
return under
|
|
|
|
else
|
|
|
|
return upper
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-27 18:34:57 +02:00
|
|
|
local data={}
|
2019-04-19 23:38:46 +02:00
|
|
|
|
2016-06-15 21:24:40 +02:00
|
|
|
-- Module displaying of the words
|
2019-05-03 20:19:12 +02:00
|
|
|
local generateLEDs = function(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4)
|
2017-03-01 21:39:05 +01:00
|
|
|
-- Set the local variables needed for the colored progress bar
|
2019-05-03 20:45:16 +02:00
|
|
|
if (words == nil) then
|
|
|
|
return nil
|
|
|
|
end
|
2019-05-03 21:26:10 +02:00
|
|
|
|
2018-12-26 21:41:13 +01:00
|
|
|
local minutes=1
|
|
|
|
if (words.min1 == 1) then
|
|
|
|
minutes = minutes + 1
|
|
|
|
elseif (words.min2 == 1) then
|
|
|
|
minutes = minutes + 2
|
|
|
|
elseif (words.min3 == 1) then
|
|
|
|
minutes = minutes + 3
|
|
|
|
elseif (words.min4 == 1) then
|
|
|
|
minutes = minutes + 4
|
|
|
|
end
|
2019-05-03 22:11:44 +02:00
|
|
|
if ( (adc ~= nil) and (words.briPercent ~= nil) ) then
|
2019-04-27 00:22:29 +02:00
|
|
|
local per = math.floor(100*adc.read(0)/1000)
|
2019-05-03 21:26:10 +02:00
|
|
|
words.briPercent = tonumber( ((words.briPercent * 4) + per) / 5)
|
|
|
|
print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(words.briPercent) .. "% current: " .. tostring(per) .. "%")
|
2019-04-19 23:38:46 +02:00
|
|
|
data.colorFg = string.char(string.byte(colorForground,1) * briPercent / 100, string.byte(colorForground,2) * briPercent / 100, string.byte(colorForground,3) * briPercent / 100)
|
|
|
|
data.colorMin1 = string.char(string.byte(colorMin1,1) * briPercent / 100, string.byte(colorMin1,2) * briPercent / 100, string.byte(colorMin1,3) * briPercent / 100)
|
|
|
|
data.colorMin2 = string.char(string.byte(colorMin2,1) * briPercent / 100, string.byte(colorMin2,2) * briPercent / 100, string.byte(colorMin2,3) * briPercent / 100)
|
|
|
|
data.colorMin3 = string.char(string.byte(colorMin3,1) * briPercent / 100, string.byte(colorMin3,2) * briPercent / 100, string.byte(colorMin3,3) * briPercent / 100)
|
|
|
|
data.colorMin4 = string.char(string.byte(colorMin4,1) * briPercent / 100, string.byte(colorMin4,2) * briPercent / 100, string.byte(colorMin4,3) * briPercent / 100)
|
2019-03-22 23:52:25 +01:00
|
|
|
else
|
|
|
|
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
|
|
|
|
data.colorFg=colorForground
|
|
|
|
data.colorMin1=colorMin1
|
|
|
|
data.colorMin2=colorMin2
|
|
|
|
data.colorMin3=colorMin3
|
|
|
|
data.colorMin4=colorMin4
|
|
|
|
end
|
2018-01-28 15:08:08 +01:00
|
|
|
data.drawnCharacters=0
|
2018-05-02 20:40:20 +02:00
|
|
|
local charsPerLine=11
|
2018-05-02 19:52:08 +02:00
|
|
|
-- Space / background has no color by default
|
2017-01-03 14:46:09 +01:00
|
|
|
local space=string.char(0,0,0)
|
2018-05-02 19:52:08 +02:00
|
|
|
-- set FG to fix value:
|
2018-05-02 20:40:20 +02:00
|
|
|
colorFg = string.char(255,255,255)
|
2017-01-03 14:46:09 +01:00
|
|
|
|
2017-03-01 21:39:05 +01:00
|
|
|
-- Set the foreground color as the default color
|
|
|
|
local buf=colorFg
|
2019-05-10 22:58:42 +02:00
|
|
|
local line=space
|
2016-06-15 21:24:40 +02:00
|
|
|
-- line 1----------------------------------------------
|
2018-01-30 20:52:40 +01:00
|
|
|
if (words.it==1) then
|
2018-12-27 14:25:51 +01:00
|
|
|
buf=drawLEDs(data,2) -- ES
|
2018-01-30 20:52:40 +01:00
|
|
|
else
|
|
|
|
buf=space:rep(2)
|
|
|
|
end
|
|
|
|
-- K fill character
|
|
|
|
buf=buf .. space:rep(1)
|
|
|
|
if (words.is == 1) then
|
2018-12-27 14:25:51 +01:00
|
|
|
buf=buf .. drawLEDs(data,3) -- IST
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2018-01-30 20:52:40 +01:00
|
|
|
buf=buf .. space:rep(3)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2018-01-30 20:52:40 +01:00
|
|
|
-- L fill character
|
|
|
|
buf=buf .. space:rep(1)
|
|
|
|
if (words.fiveMin== 1) then
|
2018-12-27 14:25:51 +01:00
|
|
|
buf= buf .. drawLEDs(data,4) -- FUENF
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2017-01-03 14:46:09 +01:00
|
|
|
buf= buf .. space:rep(4)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
-- line 2-- even row (so inverted) --------------------
|
2019-05-10 22:58:42 +02:00
|
|
|
if (words.tenMin == 1) then
|
|
|
|
line= drawLEDs(data,4) -- ZEHN
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(4)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
if (words.twenty == 1) then
|
|
|
|
line= line .. drawLEDs(data,7) -- ZWANZIG
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= line .. space:rep(7)
|
|
|
|
end
|
|
|
|
-- fill, the buffer
|
|
|
|
for i = 0,10 do
|
|
|
|
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
|
2016-06-15 21:24:40 +02:00
|
|
|
-- line3----------------------------------------------
|
|
|
|
if (words.threequater == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= drawLEDs(data,11) -- Dreiviertel
|
2016-06-15 21:24:40 +02:00
|
|
|
elseif (words.quater == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(4)
|
|
|
|
line= line .. drawLEDs(data,7) -- VIERTEL
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(11)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
-- fill, the buffer
|
|
|
|
buf = buf .. line
|
2016-06-15 21:24:40 +02:00
|
|
|
--line 4-------- even row (so inverted) -------------
|
2019-05-10 22:58:42 +02:00
|
|
|
if (words.after == 1) then
|
2019-05-10 23:42:20 +02:00
|
|
|
line= space:rep(2) -- TG
|
|
|
|
line= line .. drawLEDs(data,4) -- NACH
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(6)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
if (words.before == 1) then
|
|
|
|
line= line .. drawLEDs(data,3) -- VOR
|
|
|
|
line= line .. space:rep(2)
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= line .. space:rep(5)
|
|
|
|
end
|
|
|
|
for i = 0,10 do
|
|
|
|
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
if (words.half == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= drawLEDs(data,4) -- HALB
|
|
|
|
line= line .. space:rep(1) -- X
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(5)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
if (words.twelve == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= line .. drawLEDs(data,5) -- ZWOELF
|
|
|
|
line= line .. space:rep(1) -- P
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= line .. space:rep(6)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
buf=buf .. line
|
2016-06-15 21:24:40 +02:00
|
|
|
------------even row (so inverted) ---------------------
|
|
|
|
if (words.seven == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(5)
|
|
|
|
line= line .. drawLEDs(data,6) -- SIEBEN
|
2017-03-01 18:32:40 +01:00
|
|
|
elseif (words.oneLong == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(2)
|
|
|
|
line= line .. drawLEDs(data,4) -- EINS
|
|
|
|
line= line .. space:rep(5)
|
2017-03-01 18:32:40 +01:00
|
|
|
elseif (words.one == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(2)
|
|
|
|
line= line .. drawLEDs(data,3) -- EIN
|
|
|
|
line= line .. space:rep(6)
|
2016-06-15 21:24:40 +02:00
|
|
|
elseif (words.two == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= drawLEDs(data,4) -- ZWEI
|
|
|
|
line= line .. space:rep(7)
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(11)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 0,10 do
|
|
|
|
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
if (words.three == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(1)
|
|
|
|
line= line .. drawLEDs(data,4) -- DREI
|
|
|
|
line= line .. space:rep(6)
|
|
|
|
elseif (words.five == 1) then
|
|
|
|
line= space:rep(7)
|
|
|
|
line= line .. drawLEDs(data,4) -- FUENF
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(11)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
buf = buf .. line
|
2016-06-15 21:24:40 +02:00
|
|
|
------------even row (so inverted) ---------------------
|
|
|
|
if (words.four == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(7)
|
|
|
|
line= line .. drawLEDs(data,4) -- VIER
|
2016-06-15 21:24:40 +02:00
|
|
|
elseif (words.nine == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(3)
|
|
|
|
line= line .. drawLEDs(data,4) -- NEUN
|
|
|
|
line= line .. space:rep(4)
|
2016-06-15 21:24:40 +02:00
|
|
|
elseif (words.eleven == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= drawLEDs(data,3) -- ELEVEN
|
|
|
|
line= line .. space:rep(8)
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(11)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 0,10 do
|
|
|
|
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
if (words.eight == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(1)
|
|
|
|
line= line .. drawLEDs(data,4) -- ACHT
|
|
|
|
line= line .. space:rep(6)
|
2016-06-15 21:24:40 +02:00
|
|
|
elseif (words.ten == 1) then
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(5)
|
|
|
|
line= line .. drawLEDs(data,4) -- ZEHN
|
|
|
|
line= line .. space:rep(2)
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(11)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
buf = buf .. line
|
2016-06-15 21:24:40 +02:00
|
|
|
------------even row (so inverted) ---------------------
|
2019-05-10 22:58:42 +02:00
|
|
|
if (words.six == 1) then
|
|
|
|
line= space:rep(1)
|
|
|
|
line= line .. drawLEDs(data,5) -- SECHS
|
|
|
|
line= line .. space:rep(2)
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= space:rep(8)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
if (words.clock == 1) then
|
|
|
|
line= line .. drawLEDs(data,3) -- UHR
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2019-05-10 22:58:42 +02:00
|
|
|
line= line .. space:rep(3)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 0,10 do
|
|
|
|
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2019-05-10 22:58:42 +02:00
|
|
|
------ Minutes -----------
|
2016-06-15 21:24:40 +02:00
|
|
|
if (words.min1 == 1) then
|
2017-03-01 21:39:05 +01:00
|
|
|
buf= buf .. colorFg
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2017-01-03 14:46:09 +01:00
|
|
|
buf= buf .. space:rep(1)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
if (words.min2 == 1) then
|
2017-03-01 21:39:05 +01:00
|
|
|
buf= buf .. colorFg
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2017-01-03 14:46:09 +01:00
|
|
|
buf= buf .. space:rep(1)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
if (words.min3 == 1) then
|
2017-03-01 21:39:05 +01:00
|
|
|
buf= buf .. colorFg
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2017-01-03 14:46:09 +01:00
|
|
|
buf= buf .. space:rep(1)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
|
|
|
if (words.min4 == 1) then
|
2017-03-01 21:39:05 +01:00
|
|
|
buf= buf .. colorFg
|
2016-06-15 21:24:40 +02:00
|
|
|
else
|
2017-01-03 14:46:09 +01:00
|
|
|
buf= buf .. space:rep(1)
|
2016-06-15 21:24:40 +02:00
|
|
|
end
|
2016-06-19 00:50:18 +02:00
|
|
|
collectgarbage()
|
2018-12-27 14:25:51 +01:00
|
|
|
return buf
|
2016-06-18 17:07:49 +02:00
|
|
|
end
|
2019-05-03 20:19:12 +02:00
|
|
|
M = {
|
|
|
|
generateLEDs = generateLEDs,
|
|
|
|
round = round,
|
|
|
|
drawLEDs = drawLEDs,
|
|
|
|
updateColor = updateColor,
|
2019-05-03 20:45:16 +02:00
|
|
|
data = data,
|
2019-05-03 20:19:12 +02:00
|
|
|
}
|
|
|
|
end
|
2019-05-08 21:12:02 +02:00
|
|
|
displayword = M
|