Merge branch 'temparture' (where temperature was removed)
This commit is contained in:
commit
c5aae1c7e3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
wlancfg.lua
|
||||
config.lua
|
||||
*.swp
|
||||
unit/testTimesMarchOctoberWithAllSeconds.lua
|
||||
|
375
displayword.lua
375
displayword.lua
@ -1,63 +1,45 @@
|
||||
-- Module filling a buffer, sent to the LEDs
|
||||
|
||||
function updateColor(data, inverseRow, characters2draw)
|
||||
if (inverseRow == nil) then
|
||||
inverseRow=false
|
||||
end
|
||||
-- special case, and there are exactly 4 words to display (so each word for each minute)
|
||||
if (not inverseRow) then -- nomral row
|
||||
if (data.drawnCharacters < data.charsPerMinute) then
|
||||
return data.colorFg
|
||||
elseif (data.drawnCharacters < data.charsPerMinute*2) then
|
||||
return data.colorMin1
|
||||
elseif (data.drawnCharacters < data.charsPerMinute*3) then
|
||||
return data.colorMin2
|
||||
elseif (data.drawnCharacters > data.charsPerMinute*4) then
|
||||
return data.colorMin3
|
||||
elseif (data.drawnCharacters > data.charsPerMinute*5) then
|
||||
return data.colorMin4
|
||||
else
|
||||
return data.colorFg
|
||||
end
|
||||
else -- inverse row
|
||||
--FIXME magic missing to start on the left side
|
||||
if (data.drawnCharacters < data.charsPerMinute) then
|
||||
return data.colorMin1
|
||||
elseif (data.drawnCharacters < data.charsPerMinute*2) then
|
||||
return data.colorMin2
|
||||
elseif (data.drawnCharacters < data.charsPerMinute*3) then
|
||||
return data.colorMin3
|
||||
elseif (data.drawnCharacters > data.charsPerMinute*4) then
|
||||
return data.colorMin4
|
||||
else
|
||||
return data.colorFg
|
||||
end
|
||||
local M
|
||||
do
|
||||
local updateColor = function (data)
|
||||
if (data.amountOfChars > 0) then
|
||||
local div = tonumber(data.drawnCharacters/data.amountOfChars)
|
||||
if (div < 1) then
|
||||
return data.colorFg
|
||||
elseif (div < 2) then
|
||||
return data.colorMin1
|
||||
elseif (div < 3) then
|
||||
return data.colorMin2
|
||||
elseif (div < 4) then
|
||||
return data.colorMin3
|
||||
elseif (div < 5) then
|
||||
return data.colorMin4
|
||||
else
|
||||
return data.colorFg
|
||||
end
|
||||
else
|
||||
return data.colorFg
|
||||
end
|
||||
end
|
||||
|
||||
function drawLEDs(data, numberNewChars, inverseRow)
|
||||
if (inverseRow == nil) then
|
||||
inverseRow=false
|
||||
end
|
||||
local drawLEDs = function(data, numberNewChars)
|
||||
if (numberNewChars == nil) then
|
||||
numberNewChars=0
|
||||
end
|
||||
print(tostring(numberNewChars) .. " charactes " .. tostring(data.charsPerMinute) .. " per minute; " .. tonumber(data.drawnCharacters) .. " used characters")
|
||||
local tmpBuf=nil
|
||||
for i=1,numberNewChars do
|
||||
if (tmpBuf == nil) then
|
||||
tmpBuf = updateColor(data, inverseRow, numberNewChars)
|
||||
tmpBuf = updateColor(data)
|
||||
else
|
||||
tmpBuf=tmpBuf .. updateColor(data, inverseRow, numberNewChars)
|
||||
tmpBuf=tmpBuf .. updateColor(data)
|
||||
end
|
||||
data.drawnCharacters=data.drawnCharacters+1
|
||||
end
|
||||
data.drawnWords=data.drawnWords+1
|
||||
return tmpBuf
|
||||
end
|
||||
|
||||
-- Utility function for round
|
||||
function round(num)
|
||||
local round = function(num)
|
||||
under = math.floor(num)
|
||||
upper = math.floor(num) + 1
|
||||
underV = -(under - num)
|
||||
@ -69,11 +51,18 @@ function round(num)
|
||||
end
|
||||
end
|
||||
|
||||
local data={}
|
||||
|
||||
-- Module displaying of the words
|
||||
function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, characters)
|
||||
local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars)
|
||||
-- Set the local variables needed for the colored progress bar
|
||||
data={}
|
||||
|
||||
if (words == nil) then
|
||||
return nil
|
||||
end
|
||||
if (invertRows == nil) then
|
||||
invertRows=false
|
||||
end
|
||||
|
||||
local minutes=1
|
||||
if (words.min1 == 1) then
|
||||
minutes = minutes + 1
|
||||
@ -84,37 +73,47 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
|
||||
elseif (words.min4 == 1) then
|
||||
minutes = minutes + 4
|
||||
end
|
||||
data.charsPerMinute = round( (characters / minutes) )
|
||||
if (adc ~= nil) then
|
||||
briPercent=(100*adc.read(0)/900)
|
||||
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) .. " bright: " .. tostring(briPercent) .. "%")
|
||||
data.colorFg = colorForground
|
||||
data.colorMin1 = colorMin1
|
||||
data.colorMin2 = colorMin2
|
||||
data.colorMin3 = colorMin3
|
||||
data.colorMin4 = colorMin4
|
||||
-- always set a foreground value
|
||||
if (colorFg == nil) then
|
||||
colorFg = string.char(255,255,255)
|
||||
end
|
||||
|
||||
if (amountOfChars ~= nil) then
|
||||
data.amountOfChars = amountOfChars/minutes
|
||||
else
|
||||
data.amountOfChars = 0
|
||||
end
|
||||
|
||||
if ( (adc ~= nil) and (words.briPercent ~= 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.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)
|
||||
else
|
||||
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
|
||||
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) )
|
||||
data.colorFg=colorForground
|
||||
data.colorFg=colorFg
|
||||
data.colorMin1=colorMin1
|
||||
data.colorMin2=colorMin2
|
||||
data.colorMin3=colorMin3
|
||||
data.colorMin4=colorMin4
|
||||
end
|
||||
data.words=words
|
||||
data.drawnCharacters=0
|
||||
data.drawnWords=0
|
||||
data.amountWords=display_countwords_de(words)
|
||||
local charsPerLine=11
|
||||
|
||||
-- Space / background has no color by default
|
||||
local space=string.char(0,0,0)
|
||||
-- set FG to fix value:
|
||||
colorFg = string.char(255,255,255)
|
||||
|
||||
if (colorBg ~= nil) then
|
||||
space = colorBg
|
||||
end
|
||||
|
||||
-- Set the foreground color as the default color
|
||||
local buf=colorFg
|
||||
|
||||
local buf=data.colorFg
|
||||
local line=space
|
||||
-- line 1----------------------------------------------
|
||||
if (words.it==1) then
|
||||
buf=drawLEDs(data,2) -- ES
|
||||
@ -136,120 +135,158 @@ if (words.fiveMin== 1) then
|
||||
buf= buf .. space:rep(4)
|
||||
end
|
||||
-- line 2-- even row (so inverted) --------------------
|
||||
if (words.twenty == 1) then
|
||||
buf= buf .. drawLEDs(data,7,true) -- ZWANZIG
|
||||
else
|
||||
buf= buf .. space:rep(7)
|
||||
end
|
||||
if (words.tenMin == 1) then
|
||||
buf= buf .. drawLEDs(data,4,true) -- ZEHN
|
||||
line= drawLEDs(data,4) -- ZEHN
|
||||
else
|
||||
buf= buf .. space:rep(4)
|
||||
line= space:rep(4)
|
||||
end
|
||||
if (words.twenty == 1) then
|
||||
line= line .. drawLEDs(data,7) -- ZWANZIG
|
||||
else
|
||||
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)
|
||||
end
|
||||
|
||||
-- line3----------------------------------------------
|
||||
if (words.threequater == 1) then
|
||||
buf= buf .. drawLEDs(data,11) -- Dreiviertel
|
||||
line= drawLEDs(data,11) -- Dreiviertel
|
||||
elseif (words.quater == 1) then
|
||||
buf= buf .. space:rep(4)
|
||||
buf= buf .. drawLEDs(data,7) -- VIERTEL
|
||||
line= space:rep(4)
|
||||
line= line .. drawLEDs(data,7) -- VIERTEL
|
||||
else
|
||||
buf= buf .. space:rep(11)
|
||||
line= space:rep(11)
|
||||
end
|
||||
-- fill, the buffer
|
||||
buf = buf .. line
|
||||
--line 4-------- even row (so inverted) -------------
|
||||
if (words.before == 1) then
|
||||
buf=buf .. space:rep(2)
|
||||
buf= buf .. drawLEDs(data,3,true) -- VOR
|
||||
else
|
||||
buf= buf .. space:rep(5)
|
||||
end
|
||||
if (words.after == 1) then
|
||||
buf= buf .. drawLEDs(data,4,true) -- NACH
|
||||
buf= buf .. space:rep(2) -- TG
|
||||
line= space:rep(2) -- TG
|
||||
line= line .. drawLEDs(data,4) -- NACH
|
||||
else
|
||||
buf= buf .. space:rep(6)
|
||||
line= space:rep(6)
|
||||
end
|
||||
if (words.before == 1) then
|
||||
line= line .. drawLEDs(data,3) -- VOR
|
||||
line= line .. space:rep(2)
|
||||
else
|
||||
line= line .. space:rep(5)
|
||||
end
|
||||
if (invertRows == true) then
|
||||
buf = buf .. line
|
||||
else
|
||||
for i = 0,10 do
|
||||
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
||||
end
|
||||
end
|
||||
------------------------------------------------
|
||||
if (words.half == 1) then
|
||||
buf= buf .. drawLEDs(data,4) -- HALB
|
||||
buf= buf .. space:rep(1) -- X
|
||||
line= drawLEDs(data,4) -- HALB
|
||||
line= line .. space:rep(1) -- X
|
||||
else
|
||||
buf= buf .. space:rep(5)
|
||||
line= space:rep(5)
|
||||
end
|
||||
if (words.twelve == 1) then
|
||||
buf= buf .. drawLEDs(data,5) -- ZWOELF
|
||||
buf= buf .. space:rep(1) -- P
|
||||
line= line .. drawLEDs(data,5) -- ZWOELF
|
||||
line= line .. space:rep(1) -- P
|
||||
else
|
||||
buf= buf .. space:rep(6)
|
||||
line= line .. space:rep(6)
|
||||
end
|
||||
if (invertRows == true) then
|
||||
for i = 0,10 do
|
||||
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
||||
end
|
||||
else
|
||||
buf=buf .. line
|
||||
end
|
||||
------------even row (so inverted) ---------------------
|
||||
if (words.seven == 1) then
|
||||
buf= buf .. drawLEDs(data,6,true) -- SIEBEN
|
||||
buf= buf .. space:rep(5)
|
||||
line= space:rep(5)
|
||||
line= line .. drawLEDs(data,6) -- SIEBEN
|
||||
elseif (words.oneLong == 1) then
|
||||
buf= buf .. space:rep(5)
|
||||
buf= buf .. drawLEDs(data,4,true) -- EINS
|
||||
buf= buf .. space:rep(2)
|
||||
line= space:rep(2)
|
||||
line= line .. drawLEDs(data,4) -- EINS
|
||||
line= line .. space:rep(5)
|
||||
elseif (words.one == 1) then
|
||||
buf= buf .. space:rep(6)
|
||||
buf= buf .. drawLEDs(data,3,true) -- EIN
|
||||
buf= buf .. space:rep(2)
|
||||
line= space:rep(2)
|
||||
line= line .. drawLEDs(data,3) -- EIN
|
||||
line= line .. space:rep(6)
|
||||
elseif (words.two == 1) then
|
||||
buf= buf .. space:rep(7)
|
||||
buf= buf .. drawLEDs(data,4,true) -- ZWEI
|
||||
line= drawLEDs(data,4) -- ZWEI
|
||||
line= line .. space:rep(7)
|
||||
else
|
||||
buf= buf .. space:rep(11)
|
||||
line= space:rep(11)
|
||||
end
|
||||
if (invertRows == true) then
|
||||
buf = buf .. line
|
||||
else
|
||||
for i = 0,10 do
|
||||
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
||||
end
|
||||
end
|
||||
------------------------------------------------
|
||||
if (words.three == 1) then
|
||||
buf= buf .. space:rep(1)
|
||||
buf= buf .. drawLEDs(data,4) -- DREI
|
||||
buf= buf .. space:rep(6)
|
||||
elseif (words.five == 1) then
|
||||
buf= buf .. space:rep(7)
|
||||
buf= buf .. drawLEDs(data,4) -- FUENF
|
||||
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
|
||||
else
|
||||
buf= buf .. space:rep(11)
|
||||
line= space:rep(11)
|
||||
end
|
||||
buf = buf .. line
|
||||
------------even row (so inverted) ---------------------
|
||||
if (words.four == 1) then
|
||||
buf= buf .. drawLEDs(data,4,true) -- VIER
|
||||
buf= buf .. space:rep(7)
|
||||
line= space:rep(7)
|
||||
line= line .. drawLEDs(data,4) -- VIER
|
||||
elseif (words.nine == 1) then
|
||||
buf= buf .. space:rep(4)
|
||||
buf= buf .. drawLEDs(data,4,true) -- NEUN
|
||||
buf= buf .. space:rep(3)
|
||||
line= space:rep(3)
|
||||
line= line .. drawLEDs(data,4) -- NEUN
|
||||
line= line .. space:rep(4)
|
||||
elseif (words.eleven == 1) then
|
||||
buf= buf .. space:rep(8)
|
||||
buf= buf .. drawLEDs(data,3,true) -- ELEVEN
|
||||
line= drawLEDs(data,3) -- ELEVEN
|
||||
line= line .. space:rep(8)
|
||||
else
|
||||
buf= buf .. space:rep(11)
|
||||
line= space:rep(11)
|
||||
end
|
||||
|
||||
for i = 0,10 do
|
||||
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
||||
end
|
||||
------------------------------------------------
|
||||
if (words.eight == 1) then
|
||||
buf= buf .. space:rep(1)
|
||||
buf= buf .. drawLEDs(data,4) -- ACHT
|
||||
buf= buf .. space:rep(6)
|
||||
line= space:rep(1)
|
||||
line= line .. drawLEDs(data,4) -- ACHT
|
||||
line= line .. space:rep(6)
|
||||
elseif (words.ten == 1) then
|
||||
buf= buf .. space:rep(5)
|
||||
buf= buf .. drawLEDs(data,4) -- ZEHN
|
||||
buf= buf .. space:rep(2)
|
||||
line= space:rep(5)
|
||||
line= line .. drawLEDs(data,4) -- ZEHN
|
||||
line= line .. space:rep(2)
|
||||
else
|
||||
buf= buf .. space:rep(11)
|
||||
line= space:rep(11)
|
||||
end
|
||||
buf = buf .. line
|
||||
------------even row (so inverted) ---------------------
|
||||
if (words.clock == 1) then
|
||||
buf= buf .. drawLEDs(data,3,true) -- UHR
|
||||
else
|
||||
buf= buf .. space:rep(3)
|
||||
end
|
||||
if (words.six == 1) then
|
||||
buf= buf .. space:rep(2)
|
||||
buf= buf .. drawLEDs(data,5,true) -- SECHS
|
||||
buf= buf .. space:rep(1)
|
||||
line= space:rep(1)
|
||||
line= line .. drawLEDs(data,5) -- SECHS
|
||||
line= line .. space:rep(2)
|
||||
else
|
||||
buf= buf .. space:rep(8)
|
||||
line= space:rep(8)
|
||||
end
|
||||
|
||||
if (words.clock == 1) then
|
||||
line= line .. drawLEDs(data,3) -- UHR
|
||||
else
|
||||
line= line .. space:rep(3)
|
||||
end
|
||||
|
||||
for i = 0,10 do
|
||||
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
|
||||
end
|
||||
------ Minutes -----------
|
||||
if (words.min1 == 1) then
|
||||
buf= buf .. colorFg
|
||||
else
|
||||
@ -271,7 +308,79 @@ if (words.fiveMin== 1) then
|
||||
buf= buf .. space:rep(1)
|
||||
end
|
||||
collectgarbage()
|
||||
|
||||
return buf
|
||||
end
|
||||
|
||||
-- Count amount of characters to display
|
||||
local countChars = function(words)
|
||||
local characters = 0
|
||||
for key,value in pairs(words) do
|
||||
if (value > 0) then
|
||||
if (key == "it") then
|
||||
characters = characters + 2
|
||||
elseif (key == "is") then
|
||||
characters = characters + 3
|
||||
elseif (key == "fiveMin") then
|
||||
characters = characters + 4
|
||||
elseif (key == "tenMin") then
|
||||
characters = characters + 4
|
||||
elseif (key == "after") then
|
||||
characters = characters + 4
|
||||
elseif (key == "before") then
|
||||
characters = characters + 3
|
||||
elseif (key == "threeHour") then
|
||||
characters = characters + 4
|
||||
elseif (key == "quater") then
|
||||
characters = characters + 7
|
||||
elseif (key == "threequater") then
|
||||
characters = characters + 11
|
||||
elseif (key == "half") then
|
||||
characters = characters + 4
|
||||
elseif (key == "one") then
|
||||
characters = characters + 3
|
||||
elseif (key == "oneLong") then
|
||||
characters = characters + 4
|
||||
elseif (key == "two") then
|
||||
characters = characters + 4
|
||||
elseif (key == "three") then
|
||||
characters = characters + 4
|
||||
elseif (key == "four") then
|
||||
characters = characters + 4
|
||||
elseif (key == "five") then
|
||||
characters = characters + 4
|
||||
elseif (key == "six") then
|
||||
characters = characters + 4
|
||||
elseif (key == "seven") then
|
||||
characters = characters + 6
|
||||
elseif (key == "eight") then
|
||||
characters = characters + 4
|
||||
elseif (key == "nine") then
|
||||
characters = characters + 4
|
||||
elseif (key == "ten") then
|
||||
characters = characters + 4
|
||||
elseif (key == "eleven") then
|
||||
characters = characters + 3
|
||||
elseif (key == "twelve") then
|
||||
characters = characters + 5
|
||||
elseif (key == "twenty") then
|
||||
characters = characters + 7
|
||||
elseif (key == "clock") then
|
||||
characters = characters + 3
|
||||
elseif (key == "sr_nc") then
|
||||
characters = characters + 3
|
||||
end
|
||||
end
|
||||
end
|
||||
return characters
|
||||
end
|
||||
|
||||
M = {
|
||||
generateLEDs = generateLEDs,
|
||||
round = round,
|
||||
drawLEDs = drawLEDs,
|
||||
updateColor = updateColor,
|
||||
data = data,
|
||||
countChars = countChars
|
||||
}
|
||||
end
|
||||
displayword = M
|
||||
|
22
index.html
22
index.html
@ -1,22 +0,0 @@
|
||||
<html>
|
||||
<head><title>WordClock Setup Page</title>
|
||||
</head><body>
|
||||
<h1>Welcome to the WordClock</h1>
|
||||
<form action="" method="POST">
|
||||
<table>
|
||||
<tr><th>WIFI-SSID</b></th><td><input name="ssid" value="${SSID}"></td><td /></tr>
|
||||
<tr><th>WIFI-Password</th><td><input name="password"></td><td /></tr>
|
||||
<tr><th>SNTP Server</th><td><input name="sntpserver" value="${sntpserverhostname}" ></td><td>ntp server to sync the time</tr>
|
||||
<tr><th>Offset to UTC time</th><td><input type="number" name="timezoneoffset" value="${TIMEZONEOFFSET}"></td><td>Define the offset to UTC time in hours. E.g +1</tr>
|
||||
<tr><th>Color</th><td><input type="color" name="fcolor" value="${HEXCOLOR}"></td><td /></tr>
|
||||
<tr><th>1. Minute Color</th><td><input type=\"color\" name=\"colorMin1\" value=\"" .. hexColor1 .. "\"></td><td /></tr>"
|
||||
<tr><th>2. Minute Color</th><td><input type=\"color\" name=\"colorMin2\" value=\"" .. hexColor2 .. "\"></td><td /></tr>"
|
||||
<tr><th>3. Minute Color</th><td><input type=\"color\" name=\"colorMin3\" value=\"" .. hexColor3 .. "\"></td><td /></tr>"
|
||||
<tr><th>4. Minute Color</th><td><input type=\"color\" name=\"colorMin4\" value=\"" .. hexColor4 .. "\"></td><td /></tr>"
|
||||
<tr><th>Three quater</th><td><input type="checkbox" name="threequater" ${THREEQUARTERCHECKED}></td><td>Dreiviertel Joa/nei</td></tr>
|
||||
<tr><th>ColorMode</th><td><input type="checkbox" name="colorMode" ${COLORMODECHECKED}></td><td>If checked, words are dark, rest is colored</td></tr>
|
||||
<tr><td colspan="3"><div align="center"><input type="submit" value="Save Configuration" onclick="this.value='Submitting ..';this.disabled='disabled'; this.form.submit();"></div></td></tr>
|
||||
<tr><td colspan="3"><div align="center"><input type="submit" name="action" value="Reboot"></div></td></tr>
|
||||
</table></form>
|
||||
$ADDITIONAL_LINE
|
||||
</body></html>
|
6
init.lua
6
init.lua
@ -36,8 +36,10 @@ end
|
||||
function mydofile(mod)
|
||||
if (file.open(mod .. ".lua")) then
|
||||
dofile( mod .. ".lua")
|
||||
else
|
||||
elseif (file.open(mod .. ".lc")) then
|
||||
dofile(mod .. ".lc")
|
||||
else
|
||||
print("Error: " .. mod)
|
||||
end
|
||||
end
|
||||
|
||||
@ -49,7 +51,7 @@ tmr.alarm(1, 5000, 0, function()
|
||||
(file.open("timecore.lua")) or
|
||||
(file.open("wordclock.lua")) or
|
||||
(file.open("displayword.lua")) or
|
||||
(file.open("webserver.lua"))
|
||||
(file.open("telnet.lua"))
|
||||
) then
|
||||
c = string.char(0,128,0)
|
||||
w = string.char(0,0,0)
|
||||
|
173
main.lua
173
main.lua
@ -1,5 +1,7 @@
|
||||
-- Main Module
|
||||
|
||||
displayword = {}
|
||||
|
||||
function startSetupMode()
|
||||
tmr.stop(0)
|
||||
tmr.stop(1)
|
||||
@ -29,53 +31,62 @@ end
|
||||
|
||||
|
||||
function syncTimeFromInternet()
|
||||
--ptbtime1.ptb.de
|
||||
if (syncRunning == nil) then
|
||||
syncRunning=true
|
||||
sntp.sync(sntpserverhostname,
|
||||
function(sec,usec,server)
|
||||
print('sync', sec, usec, server)
|
||||
displayTime()
|
||||
syncRunning=nil
|
||||
end,
|
||||
function()
|
||||
print('failed!')
|
||||
syncRunning=nil
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
briPercent = 50
|
||||
function displayTime()
|
||||
sec, usec = rtctime.get()
|
||||
local sec, usec = rtctime.get()
|
||||
-- Handle lazy programmer:
|
||||
if (timezoneoffset == nil) then
|
||||
timezoneoffset=0
|
||||
end
|
||||
time = getTime(sec, timezoneoffset)
|
||||
words = display_timestat(time.hour, time.minute)
|
||||
|
||||
local charactersOfTime = display_countcharacters_de(words)
|
||||
local wordsOfTime = display_countwords_de(words)
|
||||
ledBuf = generateLEDs(words, color, color1, color2, color3, color4,
|
||||
charactersOfTime)
|
||||
|
||||
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " in " .. charactersOfTime .. " chars " .. wordsOfTime .. " words")
|
||||
|
||||
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
|
||||
if ((inv46 ~= nil) and (inv46 == "on")) then
|
||||
tempstring = ledBuf:sub(1,99) -- first 33 leds
|
||||
rowend = {44,55,66}
|
||||
for _, startled in ipairs(rowend) do
|
||||
for i = 0,10 do
|
||||
tempstring = tempstring .. ledBuf:sub((startled-i)*3-2,(startled-i)*3)
|
||||
end
|
||||
end
|
||||
tempstring = tempstring .. ledBuf:sub((67*3)-2,ledBuf:len())
|
||||
ws2812.write(tempstring)
|
||||
tempstring=nil
|
||||
else
|
||||
ws2812.write(ledBuf)
|
||||
ledBuf=nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
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
|
||||
end
|
||||
else
|
||||
words.briPercent=nil
|
||||
end
|
||||
dofile("displayword.lc")
|
||||
if (displayword ~= nil) then
|
||||
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
|
||||
local invertRows=false
|
||||
if ((inv46 ~= nil) and (inv46 == "on")) then
|
||||
invertRows=true
|
||||
end
|
||||
local characters = displayword.countChars(words)
|
||||
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters)
|
||||
end
|
||||
displayword = nil
|
||||
if (ledBuf ~= nil) then
|
||||
ws2812.write(ledBuf)
|
||||
else
|
||||
if ((colorBg ~= nil) and (color ~= nil)) then
|
||||
ws2812.write(colorBg:rep(107) .. color:rep(3))
|
||||
else
|
||||
local space=string.char(0,0,0)
|
||||
-- set FG to fix value:
|
||||
colorFg = string.char(255,0,0)
|
||||
ws2812.write(space:rep(107) .. colorFg:rep(3))
|
||||
end
|
||||
end
|
||||
-- Used for debugging
|
||||
if (clockdebug ~= nil) then
|
||||
for key,value in pairs(words) do
|
||||
@ -85,7 +96,7 @@ function displayTime()
|
||||
end
|
||||
end
|
||||
-- cleanup
|
||||
|
||||
briPercent=words.briPercent
|
||||
words=nil
|
||||
time=nil
|
||||
collectgarbage()
|
||||
@ -97,18 +108,41 @@ function normalOperation()
|
||||
-- Color is defined as GREEN, RED, BLUE
|
||||
color=string.char(0,0,250)
|
||||
end
|
||||
print("Fg Color: " .. tostring(string.byte(color,1)) .. "x" .. tostring(string.byte(color,2)) .. "x" .. tostring(string.byte(color,3)) )
|
||||
|
||||
connect_counter=0
|
||||
-- Wait to be connect to the WiFi access point.
|
||||
tmr.alarm(0, 1000, 1, function()
|
||||
tmr.alarm(0, 500, 1, function()
|
||||
connect_counter=connect_counter+1
|
||||
if wifi.sta.status() ~= 5 then
|
||||
print(connect_counter .. "/60 Connecting to AP...")
|
||||
if (connect_counter % 2 == 0) then
|
||||
if (connect_counter % 5 ~= 4) then
|
||||
local wlanColor=string.char((connect_counter % 6)*20,(connect_counter % 5)*20,(connect_counter % 3)*20)
|
||||
local space=string.char(0,0,0)
|
||||
local buf=space:rep(6) .. wlanColor .. space:rep(4)
|
||||
buf= buf .. space:rep(3) .. wlanColor:rep(3)
|
||||
local buf=space:rep(6)
|
||||
if ((connect_counter % 5) >= 1) then
|
||||
buf = buf .. wlanColor
|
||||
else
|
||||
buf = buf .. space
|
||||
end
|
||||
buf = buf .. space:rep(4)
|
||||
buf= buf .. space:rep(3)
|
||||
if ((connect_counter % 5) >= 3) then
|
||||
buf = buf .. wlanColor
|
||||
else
|
||||
buf = buf .. space
|
||||
end
|
||||
if ((connect_counter % 5) >= 2) then
|
||||
buf = buf .. wlanColor
|
||||
else
|
||||
buf = buf .. space
|
||||
end
|
||||
if ((connect_counter % 5) >= 0) then
|
||||
buf = buf .. wlanColor
|
||||
else
|
||||
buf = buf .. space
|
||||
end
|
||||
buf = buf .. space:rep(100)
|
||||
ws2812.write(buf)
|
||||
else
|
||||
ws2812.write(string.char(0,0,0):rep(114))
|
||||
@ -118,25 +152,42 @@ function normalOperation()
|
||||
print('IP: ',wifi.sta.getip())
|
||||
-- Here the WLAN is found, and something is done
|
||||
print("Solving dependencies")
|
||||
local dependModules = { "timecore" , "wordclock", "displayword" }
|
||||
local dependModules = { "timecore" , "wordclock", "telnet", "mqtt" }
|
||||
for _,mod in pairs(dependModules) do
|
||||
print("Loading " .. mod)
|
||||
mydofile(mod)
|
||||
end
|
||||
|
||||
tmr.alarm(2, 500, 0 ,function()
|
||||
|
||||
setupCounter=5
|
||||
tmr.alarm(1, 5000, 1 ,function()
|
||||
if (setupCounter > 4) then
|
||||
syncTimeFromInternet()
|
||||
setupCounter=setupCounter-1
|
||||
elseif (setupCounter > 3) then
|
||||
if (startTelnetServer ~= nil) then
|
||||
startTelnetServer()
|
||||
else
|
||||
print("NO Telent found")
|
||||
end
|
||||
setupCounter=setupCounter-1
|
||||
elseif (setupCounter > 2) then
|
||||
if (startMqttClient ~= nil) then
|
||||
startMqttClient()
|
||||
else
|
||||
print("NO Mqtt found")
|
||||
end
|
||||
setupCounter=setupCounter-1
|
||||
else
|
||||
displayTime()
|
||||
end
|
||||
collectgarbage()
|
||||
end)
|
||||
|
||||
-- sync the time every 5 minutes
|
||||
tmr.alarm(2, 300003, 1 ,function()
|
||||
syncTimeFromInternet()
|
||||
displayTime()
|
||||
end)
|
||||
tmr.alarm(3, 2000, 0 ,function()
|
||||
print("Start webserver...")
|
||||
mydofile("webserver")
|
||||
startWebServer()
|
||||
end)
|
||||
displayTime()
|
||||
-- Start the time Thread
|
||||
tmr.alarm(1, 20000, 1 ,function()
|
||||
displayTime()
|
||||
end)
|
||||
|
||||
end
|
||||
-- when no wifi available, open an accesspoint and ask the user
|
||||
@ -148,15 +199,37 @@ function normalOperation()
|
||||
|
||||
end
|
||||
|
||||
function stopWordclock()
|
||||
for i=0,5,1 do tmr.stop(i) end
|
||||
end
|
||||
|
||||
-------------------main program -----------------------------
|
||||
ws2812.init() -- WS2812 LEDs initialized on GPIO2
|
||||
|
||||
if ( file.open("config.lua") ) then
|
||||
--- Normal operation
|
||||
wifi.setmode(wifi.STATION)
|
||||
dofile("config.lua")
|
||||
mydofile("config")
|
||||
normalOperation()
|
||||
else
|
||||
-- Logic for inital setup
|
||||
startSetupMode()
|
||||
end
|
||||
----------- button ---------
|
||||
gpio.mode(3, gpio.INPUT)
|
||||
btnCounter=0
|
||||
-- Start the time Thread
|
||||
tmr.alarm(4, 500, 1 ,function()
|
||||
if (gpio.read(3) == 0) then
|
||||
tmr.stop(1) -- stop the LED thread
|
||||
print("Button pressed " .. tostring(btnCounter))
|
||||
btnCounter = btnCounter + 5
|
||||
local ledBuf= string.char(128,0,0):rep(btnCounter) .. string.char(0,0,0):rep(110 - btnCounter)
|
||||
ws2812.write(ledBuf)
|
||||
if (btnCounter >= 110) then
|
||||
file.remove("config.lua")
|
||||
file.remove("config.lc")
|
||||
node.restart()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
76
mqtt.lua
Normal file
76
mqtt.lua
Normal file
@ -0,0 +1,76 @@
|
||||
-- Global variable
|
||||
m=nil
|
||||
mqttConnected = false
|
||||
|
||||
-- MQTT extension
|
||||
function registerMqtt()
|
||||
m = mqtt.Client("wordclock", 120)
|
||||
-- on publish message receive event
|
||||
m:on("message", function(client, topic, data)
|
||||
print(topic .. ":" )
|
||||
if data ~= nil then
|
||||
print(data)
|
||||
if (data == "ON") then
|
||||
briPercent=100
|
||||
m:publish(mqttPrefix .. "/clock", "ON", 0, 0)
|
||||
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)
|
||||
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
|
||||
end)
|
||||
|
||||
m:connect(mqttServer, 1883, 0, function(client)
|
||||
print("MQTT is connected")
|
||||
mqttConnected = true
|
||||
-- subscribe topic with qos = 0
|
||||
client:subscribe(mqttPrefix .. "/command", 0)
|
||||
tmr.alarm(3, 500, 0, function()
|
||||
-- publish a message with data = hello, QoS = 0, retain = 0
|
||||
client:publish(mqttPrefix .. "/ip", tostring(wifi.sta.getip()), 0, 0)
|
||||
end)
|
||||
end,
|
||||
function(client, reason)
|
||||
print("failed reason: " .. reason)
|
||||
mqttConnected = false
|
||||
end)
|
||||
end
|
||||
|
||||
function startMqttClient()
|
||||
if (mqttServer ~= nil and mqttPrefix ~= nil) then
|
||||
registerMqtt()
|
||||
print "Started MQTT client"
|
||||
oldBrightness=0
|
||||
oldTemp=0
|
||||
tmr.alarm(5, 5001, 1 ,function()
|
||||
if (mqttConnected) then
|
||||
local temp = nil
|
||||
if (t ~= nil) then
|
||||
temp=readTemp()
|
||||
end
|
||||
if (oldBrightness ~= briPercent) then
|
||||
m:publish(mqttPrefix .. "/brightness", tostring(briPercent), 0, 0)
|
||||
else
|
||||
m:publish(mqttPrefix .. "/heap", tostring(node.heap()), 0, 0)
|
||||
end
|
||||
oldBrightness = briPercent
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
4166
os/esptool.py
4166
os/esptool.py
File diff suppressed because it is too large
Load Diff
13
os/flash.sh
13
os/flash.sh
@ -4,7 +4,7 @@ if [ $# -ne 1 ]; then
|
||||
echo "One parameter required: the device of the serial interface"
|
||||
echo "$0 <device>"
|
||||
echo "e.g.:"
|
||||
echo "$0 ttyUSB0"
|
||||
echo "$0 /dev/ttyUSB0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -14,8 +14,8 @@ DEVICE=$1
|
||||
|
||||
# check the serial connection
|
||||
|
||||
if [ ! -c /dev/$DEVICE ]; then
|
||||
echo "/dev/$DEVICE does not exist"
|
||||
if [ ! -c $DEVICE ]; then
|
||||
echo "$DEVICE does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -24,13 +24,12 @@ if [ ! -f esptool.py ]; then
|
||||
echo "esptool.py"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
./esptool.py --port /dev/$DEVICE $BAUD read_mac
|
||||
python3 esptool.py --port $DEVICE $BAUD read_mac
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error reading the MAC -> set the device into the bootloader!"
|
||||
exit 1
|
||||
fi
|
||||
echo "Flashing the new"
|
||||
#./esptool.py --port /dev/$DEVICE $BAUD write_flash -fm dio 0x00000 nodemcu2.bin
|
||||
./esptool.py --port /dev/$DEVICE $BAUD write_flash -fm dio 0x00000 0x00000.bin 0x10000 0x10000.bin 0x3fc000 esp_init_data_default.bin 0x07e000 blank.bin 0x3fe000 blank.bin
|
||||
#python3 esptool.py --port $DEVICE $BAUD write_flash -fm dio 0x00000 nodemcu2.bin
|
||||
python3 esptool.py --port $DEVICE write_flash -fm dio 0x00000 0x00000.bin 0x10000 0x10000.bin 0x3fc000 esp_init_data_default.bin
|
||||
|
@ -1,15 +1,13 @@
|
||||
green=0
|
||||
green2=128
|
||||
green2=200
|
||||
red=128
|
||||
blue=0
|
||||
blue=200
|
||||
|
||||
color=string.char(0, 0, 128)
|
||||
color1=string.char(128, 0, 0)
|
||||
color2=string.char(tonumber(green2*0.8), 0, 0)
|
||||
color3=string.char(tonumber(green2*0.4), 0, 0)
|
||||
color4=string.char(tonumber(green2*0.2), 0, 0)
|
||||
color=string.char(0, 0, blue)
|
||||
color1=string.char(red, 0, 0)
|
||||
color2=string.char(tonumber(red*0.8), 0, 0)
|
||||
color3=string.char(0, tonumber(green2*0.4), 0)
|
||||
color4=string.char(0,0 ,tonumber(blue*0.2))
|
||||
|
||||
colorBg=string.char(0,0,0) -- black is the default background color
|
||||
sntpserverhostname="ptbtime1.ptb.de"
|
||||
timezoneoffset=1
|
||||
|
||||
|
@ -11,5 +11,7 @@ public interface LuaSimulation {
|
||||
|
||||
public void rebootTriggered();
|
||||
|
||||
public void setSimulationTime(long timeInMillis);
|
||||
public void setSimulationTime(long timeInMillis);
|
||||
|
||||
public void setADC(int value);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
import de.c3ma.ollo.mockup.DoFileFunction;
|
||||
import de.c3ma.ollo.mockup.ESP8266Adc;
|
||||
import de.c3ma.ollo.mockup.ESP8266File;
|
||||
import de.c3ma.ollo.mockup.ESP8266Net;
|
||||
import de.c3ma.ollo.mockup.ESP8266Node;
|
||||
@ -36,6 +37,7 @@ public class WS2812Simulation implements LuaSimulation {
|
||||
private ESP8266Node espNode = new ESP8266Node(this);
|
||||
private DoFileFunction doFile = new DoFileFunction(globals);
|
||||
private ESP8266Ws2812 ws2812 = new ESP8266Ws2812();
|
||||
private ESP8266Adc adc = new ESP8266Adc();
|
||||
private String scriptName;
|
||||
|
||||
public WS2812Simulation(File sourceFolder) {
|
||||
@ -44,6 +46,7 @@ public class WS2812Simulation implements LuaSimulation {
|
||||
globals.load(espTmr);
|
||||
globals.load(espFile);
|
||||
globals.load(espNode);
|
||||
globals.load(adc);
|
||||
globals.load(new ESP8266Wifi());
|
||||
globals.load(new ESP8266Net());
|
||||
globals.load(new ESP8266Time());
|
||||
@ -93,9 +96,16 @@ public class WS2812Simulation implements LuaSimulation {
|
||||
if (args.length >= 3) {
|
||||
File additionalFile = new File(args[2]);
|
||||
if (additionalFile.exists() && (simu.doFile != null)) {
|
||||
|
||||
Files.copy(additionalFile.toPath(), new File(simu.doFile.getWorkingDirectory()
|
||||
+ File.separator + additionalFile.getName()).toPath());
|
||||
File targetFile = new File(simu.doFile.getWorkingDirectory()
|
||||
+ File.separator + additionalFile.getName());
|
||||
if (targetFile.exists()) {
|
||||
if (targetFile.delete()) {
|
||||
System.out.println("Removed original " + targetFile.getName() + "");
|
||||
} else {
|
||||
System.err.println("Cannot removed original " + targetFile.getName() + "");
|
||||
}
|
||||
}
|
||||
Files.copy(additionalFile.toPath(), targetFile.toPath());
|
||||
System.out.println("Integrate " + additionalFile.getName() + " into simulation");
|
||||
} else {
|
||||
System.err.println("Script " + args[2] + " cannot be found");
|
||||
@ -150,9 +160,8 @@ public class WS2812Simulation implements LuaSimulation {
|
||||
callScript(this.scriptName);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void callScript(String filename) {
|
||||
@ -170,4 +179,9 @@ public class WS2812Simulation implements LuaSimulation {
|
||||
public void setSimulationTime(long timeInMillis) {
|
||||
ESP8266Time.setOverwrittenTime(timeInMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setADC(int value) {
|
||||
adc.setADC(value);
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,6 @@ public class DoFileFunction extends OneArgFunction {
|
||||
public LuaValue call(LuaValue luaFilename) {
|
||||
String filename = luaFilename.checkjstring();
|
||||
|
||||
System.out.println("[Nodemcu] dofile " + filename);
|
||||
|
||||
File f = new File(workingDir.getAbsolutePath() + File.separator + filename);
|
||||
|
||||
if (f.exists()) {
|
||||
|
47
simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java
Normal file
47
simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java
Normal file
@ -0,0 +1,47 @@
|
||||
package de.c3ma.ollo.mockup;
|
||||
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.lib.TwoArgFunction;
|
||||
import org.luaj.vm2.lib.VarArgFunction;
|
||||
|
||||
/**
|
||||
* created at 24.04.2019 - 21:12:03<br />
|
||||
* creator: ollo<br />
|
||||
* project: WS2812Emulation<br />
|
||||
* $Id: $<br />
|
||||
* @author ollo<br />
|
||||
*/
|
||||
public class ESP8266Adc extends TwoArgFunction {
|
||||
|
||||
private int mAdc = 0;
|
||||
|
||||
@Override
|
||||
public LuaValue call(LuaValue modname, LuaValue env) {
|
||||
env.checkglobals();
|
||||
final LuaTable adc = new LuaTable();
|
||||
adc.set("read", new Read(this));
|
||||
env.set("adc", adc);
|
||||
env.get("package").get("loaded").set("adc", adc);
|
||||
return adc;
|
||||
}
|
||||
|
||||
private class Read extends VarArgFunction {
|
||||
|
||||
private ESP8266Adc adc;
|
||||
|
||||
public Read(ESP8266Adc a) {
|
||||
this.adc = a;
|
||||
}
|
||||
|
||||
public Varargs invoke(Varargs varargs) {
|
||||
return LuaValue.valueOf(this.adc.mAdc);
|
||||
}
|
||||
}
|
||||
|
||||
public void setADC(int newValue) {
|
||||
this.mAdc = newValue;
|
||||
System.out.println("[ADC] updated to " + this.mAdc);
|
||||
}
|
||||
}
|
@ -21,7 +21,10 @@ import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
@ -42,6 +45,13 @@ public class WS2812Layout extends JFrame {
|
||||
*/
|
||||
private static final long serialVersionUID = -6815557232118826140L;
|
||||
|
||||
/**
|
||||
* Parameter for the ADC brightness control
|
||||
*/
|
||||
private static final int ADC_INIT = 512;
|
||||
private static final int ADC_MIN = 0;
|
||||
private static final int ADC_MAX = 1024;
|
||||
|
||||
private ArrayList<String> mLines = new ArrayList<String>();
|
||||
private int mColumn = 0;
|
||||
private int mRow = 0;
|
||||
@ -106,6 +116,18 @@ public class WS2812Layout extends JFrame {
|
||||
}
|
||||
contentPane.add(ledPanel, BorderLayout.CENTER);
|
||||
|
||||
JSlider adc = new JSlider(JSlider.VERTICAL,
|
||||
ADC_MIN, ADC_MAX, ADC_INIT);
|
||||
adc.addChangeListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
nodemcuSimu.setADC(adc.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
contentPane.add(adc, BorderLayout.EAST);
|
||||
|
||||
JPanel bottomPanel = new JPanel();
|
||||
|
||||
final JTextField dateTime = new JTextField("yyyy-mm-dd HH:MM:SS");
|
||||
|
222
telnet.lua
Normal file
222
telnet.lua
Normal file
@ -0,0 +1,222 @@
|
||||
-- Telnet Server
|
||||
function startTelnetServer()
|
||||
s=net.createServer(net.TCP, 180)
|
||||
s:listen(23,function(c)
|
||||
global_c=c
|
||||
printlines = {}
|
||||
function s_output(str)
|
||||
if(global_c~=nil) then
|
||||
if #printlines > 0 then
|
||||
printlines[ #printlines + 1] = str
|
||||
else
|
||||
printlines[ #printlines + 1] = str
|
||||
global_c:send("\r") -- Send something, so the queue is read after sending
|
||||
end
|
||||
end
|
||||
end
|
||||
node.output(s_output, 0)
|
||||
c:on("receive",function(c,l)
|
||||
node.input(l)
|
||||
end)
|
||||
c:on("disconnection",function(c)
|
||||
node.output(nil)
|
||||
global_c=nil
|
||||
end)
|
||||
c:on("sent", function()
|
||||
if #printlines > 0 then
|
||||
global_c:send(table.remove(printlines, 1))
|
||||
end
|
||||
end)
|
||||
print("Welcome to the Wordclock.")
|
||||
print("- storeConfig()")
|
||||
print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands")
|
||||
end)
|
||||
print("Telnetserver is up")
|
||||
end
|
||||
|
||||
function storeConfig(_ssid, _password, _timezoneoffset, _sntpserver, _inv46, _dim, _fcolor, _colorMin1, _colorMin2, _colorMin3, _colorMin4, _bcolor, _threequater)
|
||||
|
||||
if ( (_ssid == nil) and
|
||||
(_password == nil) and
|
||||
(_timezoneoffset == nil) and
|
||||
(_sntpserver == nil) and
|
||||
(_inv46 == nil) and
|
||||
(_dim == nil) and
|
||||
(_fcolor == nil) and
|
||||
(_colorMin1 == nil) and
|
||||
(_colorMin2 == nil) and
|
||||
(_colorMin3 == nil) and
|
||||
(_colorMin4 == nil) and
|
||||
(_bcolor == nil) and
|
||||
(_threequater == nil) ) then
|
||||
print("one parameter is mandatory:")
|
||||
print("storeConfig(ssid, ")
|
||||
print(" password,")
|
||||
print(" timezoneoffset,")
|
||||
print(" sntpserver,")
|
||||
print(" inv46,")
|
||||
print(" dim,")
|
||||
print(" fcolor,")
|
||||
print(" colorMin1,")
|
||||
print(" colorMin2,")
|
||||
print(" colorMin3,")
|
||||
print(" colorMin4,")
|
||||
print(" bcolor,")
|
||||
print(" threequater)")
|
||||
print(" ")
|
||||
print("e.g.:")
|
||||
print('storeConfig(nil, nil, 1, nil, "on", true, "00FF00", "00FF88", "008888", "00FF44", "004488", "000000", true)')
|
||||
return
|
||||
end
|
||||
|
||||
if (_password==nil) then
|
||||
_, password, _, _ = wifi.sta.getconfig()
|
||||
print("Restore password")
|
||||
else
|
||||
password = _password
|
||||
end
|
||||
if (_ssid==nil) then
|
||||
ssid, _, _, _ = wifi.sta.getconfig()
|
||||
else
|
||||
ssid = _ssid
|
||||
end
|
||||
|
||||
if (_sntpserver == nil) then
|
||||
sntpserver = sntpserverhostname
|
||||
print("Restore SNTP: " .. tostring(sntpserver))
|
||||
else
|
||||
sntpserver = _sntpserver
|
||||
end
|
||||
|
||||
if (_timezoneoffset ~= nil) then
|
||||
timezoneoffset = _timezoneoffset
|
||||
end
|
||||
if (_inv46 ~= nil) then
|
||||
if ((_inv46 == true) or (_inv == "on")) then
|
||||
inv46 = "on"
|
||||
elseif ((_inv46 == false) or (_inv == "off")) then
|
||||
inv46 = "off"
|
||||
else
|
||||
inv46 = "off"
|
||||
end
|
||||
end
|
||||
if ( _dim ~= nil) then
|
||||
dim = _dim
|
||||
end
|
||||
if (_fcolor ~= nil) then
|
||||
fcolor = _fcolor
|
||||
end
|
||||
if (_bcolor ~= nil) then
|
||||
bcolor = _bcolor
|
||||
end
|
||||
if (_colorMin1 ~= nil) then
|
||||
colorMin1 = _colorMin1
|
||||
end
|
||||
if (_colorMin2 ~= nil) then
|
||||
colorMin2 = _colorMin2
|
||||
end
|
||||
if (_colorMin3 ~= nil) then
|
||||
colorMin3 = _colorMin3
|
||||
end
|
||||
if (_colorMin4 ~= nil) then
|
||||
colorMin4 = _colorMin4
|
||||
end
|
||||
if (_threequater ~= nil) then
|
||||
threequater = _threequater
|
||||
end
|
||||
|
||||
print("SSID = " .. tostring(ssid))
|
||||
print("TZNE = " .. tostring(timezoneoffset))
|
||||
print("NTP = " .. tostring(sntpserver))
|
||||
print("INVT = " .. tostring(inv46))
|
||||
print("DIM = " .. tostring(dim))
|
||||
print("FCOL = " .. tostring(fcolor))
|
||||
print("BCOL = " .. tostring(bcolor))
|
||||
print("MIN1 = " .. tostring(colorMin1))
|
||||
print("MIN2 = " .. tostring(colorMin2))
|
||||
print("MIN3 = " .. tostring(colorMin3))
|
||||
print("MIN4 = " .. tostring(colorMin4))
|
||||
print("3QRT = " .. tostring(threequater))
|
||||
|
||||
local configFile="config.lua"
|
||||
-- Safe configuration:
|
||||
file.remove(configFile .. ".new")
|
||||
sec, _ = rtctime.get()
|
||||
file.open(configFile.. ".new", "w+")
|
||||
file.write("-- Config\n" .. "station_cfg={}\nstation_cfg.ssid=\"" .. ssid .. "\"\nstation_cfg.pwd=\"" .. password .. "\"\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
|
||||
file.write("sntpserverhostname=\"" .. sntpserver .. "\"\n" .. "timezoneoffset=\"" .. timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(inv46) .. "\"\n" .. "dim=\"" .. tostring(dim) .. "\"\n")
|
||||
|
||||
if (fcolor ~= nil) then
|
||||
local hexColor=string.sub(fcolor, 1)
|
||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||
file.write("color=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
-- fill the current values
|
||||
color=string.char(green, red, blue)
|
||||
end
|
||||
if (colorMin1 ~= nil) then
|
||||
local hexColor=string.sub(colorMin1, 1)
|
||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||
file.write("color1=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
color1=string.char(green, red, blue)
|
||||
end
|
||||
if ( colorMin2 ~= nil) then
|
||||
local hexColor=string.sub(colorMin2, 1)
|
||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||
file.write("color2=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
color2=string.char(green, red, blue)
|
||||
end
|
||||
if ( colorMin3 ~= nil) then
|
||||
local hexColor=string.sub(colorMin3, 1)
|
||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||
file.write("color3=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
color3=string.char(green, red, blue)
|
||||
end
|
||||
if ( colorMin4 ~= nil) then
|
||||
local hexColor=string.sub(colorMin4, 1)
|
||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||
file.write("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
color4=string.char(green, red, blue)
|
||||
end
|
||||
if ( bcolor ~= nil) then
|
||||
local hexColor=string.sub(bcolor, 1)
|
||||
local red = tonumber(string.sub(hexColor, 1, 2), 16)
|
||||
local green = tonumber(string.sub(hexColor, 3, 4), 16)
|
||||
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
|
||||
file.write("colorBg=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
-- fill the current values
|
||||
colorBg=string.char(green, red, blue)
|
||||
end
|
||||
if (getTime ~= nil) then
|
||||
time = getTime(sec, timezoneoffset)
|
||||
file.write("print(\"Config from " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. "\")\n")
|
||||
end
|
||||
if ( threequater ~= nil) then
|
||||
file.write("threequater=true\n")
|
||||
-- fill the current values
|
||||
threequater=true
|
||||
else
|
||||
file.write("threequater=nil\n") -- unset threequater
|
||||
-- fill the current values
|
||||
threequater=nil
|
||||
end
|
||||
file.close()
|
||||
collectgarbage()
|
||||
sec=nil
|
||||
file.remove(configFile)
|
||||
if (file.rename(configFile .. ".new", configFile)) then
|
||||
print("Rename Successfully")
|
||||
else
|
||||
print("Cannot rename " .. configFile .. ".new")
|
||||
end
|
||||
|
||||
end
|
@ -3,6 +3,7 @@
|
||||
LUATOOL=./tools/luatool.py
|
||||
|
||||
DEVICE=$1
|
||||
BAUD=115200
|
||||
|
||||
# check the serial connection
|
||||
|
||||
@ -12,23 +13,38 @@ if [ ! -c $DEVICE ]; then
|
||||
fi
|
||||
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
if [ $# -eq 0 ]; then
|
||||
echo ""
|
||||
echo "e.g. usage $0 <device>"
|
||||
echo "e.g. usage $0 <device> [<files to upoad>]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FILES="displayword.lua main.lua timecore.lua webpage.html webserver.lua wordclock.lua init.lua"
|
||||
if [ $# -eq 1 ]; then
|
||||
FILES="displayword.lua main.lua timecore.lua webpage.html webserver.lua telnet.lua wordclock.lua init.lua"
|
||||
else
|
||||
FILES=$2
|
||||
fi
|
||||
|
||||
|
||||
# Format filesystem first
|
||||
echo "Format the complete ESP"
|
||||
$LUATOOL -p $DEVICE -w -b 115200
|
||||
$LUATOOL -p $DEVICE -w -b $BAUD
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "STOOOOP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo
|
||||
#stty -F $DEVICE $BAUD
|
||||
#echo "Reboot the ESP"
|
||||
#echo "node.restart()" >> $DEVICE
|
||||
#sleep 1
|
||||
#for i in $(seq 0 5); do
|
||||
# echo "Stop TMR $i"
|
||||
# echo "tmr.stop($i)" >> $DEVICE
|
||||
# sleep 1
|
||||
#done
|
||||
|
||||
#echo
|
||||
echo "Start Flasing ..."
|
||||
for f in $FILES; do
|
||||
if [ ! -f $f ]; then
|
||||
@ -37,7 +53,7 @@ for f in $FILES; do
|
||||
exit 1
|
||||
fi
|
||||
echo "------------- $f ------------"
|
||||
$LUATOOL -p $DEVICE -f $f -b 115200 -t $f
|
||||
$LUATOOL -p $DEVICE -f $f -b $BAUD -t $f
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "STOOOOP"
|
||||
exit 1
|
||||
@ -45,6 +61,6 @@ for f in $FILES; do
|
||||
done
|
||||
|
||||
echo "Reboot the ESP"
|
||||
$LUATOOL -p $DEVICE -r -b 115200
|
||||
echo "node.restart()" >> $DEVICE
|
||||
|
||||
exit 0
|
||||
|
@ -49,7 +49,7 @@ def main(nodeip, luafile, volatile=None):
|
||||
else:
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((nodeip, 80))
|
||||
s.connect((nodeip, 23))
|
||||
time.sleep(0.050)
|
||||
s.sendall("\n")
|
||||
# Receive the hello Message of answer of the ESP
|
||||
@ -94,7 +94,7 @@ def main(nodeip, luafile, volatile=None):
|
||||
print "add a space at the end"
|
||||
|
||||
if (volatile is None):
|
||||
if (not sendCmd(s, "w([[" + l + "]]);")):
|
||||
if (not sendCmd(s, "w([==[" + l + "]==]);")):
|
||||
print "Cannot write line " + str(i)
|
||||
s.close()
|
||||
sys.exit(4)
|
||||
|
@ -56,7 +56,6 @@ expected.itis=1
|
||||
expected.one=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 1, 0)
|
||||
checkCharacter(display_countwords_de(leds), 11)
|
||||
|
||||
leds=display_timestat(2,5)
|
||||
expected={}
|
||||
@ -64,7 +63,6 @@ expected.two=1
|
||||
expected.fiveMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 2 , 5)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(3,10)
|
||||
expected={}
|
||||
@ -72,7 +70,6 @@ expected.three=1
|
||||
expected.tenMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 3 , 10)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(4,15)
|
||||
expected={}
|
||||
@ -80,7 +77,6 @@ expected.four=1
|
||||
expected.after=1
|
||||
expected.quater=1
|
||||
checkWords(leds, expected, 4 , 15)
|
||||
checkCharacter(display_countwords_de(leds), 15)
|
||||
|
||||
leds=display_timestat(5,20)
|
||||
expected={}
|
||||
@ -88,7 +84,6 @@ expected.five=1
|
||||
expected.twenty=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 5 , 20)
|
||||
checkCharacter(display_countwords_de(leds), 15)
|
||||
|
||||
leds=display_timestat(6,25)
|
||||
expected={}
|
||||
@ -97,7 +92,6 @@ expected.fiveMin=1
|
||||
expected.before=1
|
||||
expected.half=1
|
||||
checkWords(leds, expected, 6 , 25)
|
||||
checkCharacter(display_countwords_de(leds), 17)
|
||||
|
||||
leds=display_timestat(7,30)
|
||||
expected={}
|
||||
@ -105,7 +99,6 @@ expected.itis=1
|
||||
expected.eight=1
|
||||
expected.half=1
|
||||
checkWords(leds, expected, 7 , 30)
|
||||
checkCharacter(display_countwords_de(leds), 13)
|
||||
|
||||
leds=display_timestat(8,35)
|
||||
expected={}
|
||||
@ -114,7 +107,6 @@ expected.half=1
|
||||
expected.fiveMin=1
|
||||
expected.after=1
|
||||
checkWords(leds, expected, 8 , 35)
|
||||
checkCharacter(display_countwords_de(leds), 16)
|
||||
|
||||
leds=display_timestat(9,40)
|
||||
expected={}
|
||||
@ -122,7 +114,6 @@ expected.ten=1
|
||||
expected.twenty=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 9 , 40)
|
||||
checkCharacter(display_countwords_de(leds), 14)
|
||||
|
||||
leds=display_timestat(10,45)
|
||||
expected={}
|
||||
@ -130,7 +121,6 @@ expected.eleven=1
|
||||
expected.quater=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 10 , 45)
|
||||
checkCharacter(display_countwords_de(leds), 13)
|
||||
|
||||
leds=display_timestat(11,50)
|
||||
expected={}
|
||||
@ -138,7 +128,6 @@ expected.twelve=1
|
||||
expected.tenMin=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 11 , 50)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(12,55)
|
||||
expected={}
|
||||
@ -146,7 +135,6 @@ expected.oneLong=1
|
||||
expected.fiveMin=1
|
||||
expected.before=1
|
||||
checkWords(leds, expected, 12 , 55)
|
||||
checkCharacter(display_countwords_de(leds), 11)
|
||||
|
||||
leds=display_timestat(13,00)
|
||||
expected={}
|
||||
@ -154,7 +142,6 @@ expected.itis=1
|
||||
expected.one=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 13 , 00)
|
||||
checkCharacter(display_countwords_de(leds), 11)
|
||||
|
||||
-- test the minutes inbetween
|
||||
leds=display_timestat(14,01)
|
||||
@ -164,7 +151,6 @@ expected.two=1
|
||||
expected.min1=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 14 , 01)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(15,02)
|
||||
expected={}
|
||||
@ -173,7 +159,6 @@ expected.three=1
|
||||
expected.min2=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 15 , 02)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(16,03)
|
||||
expected={}
|
||||
@ -182,7 +167,6 @@ expected.four=1
|
||||
expected.min3=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 16 , 03)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(17,04)
|
||||
expected={}
|
||||
@ -191,7 +175,6 @@ expected.five=1
|
||||
expected.min4=1
|
||||
expected.clock=1
|
||||
checkWords(leds, expected, 17 , 04)
|
||||
checkCharacter(display_countwords_de(leds), 12)
|
||||
|
||||
leds=display_timestat(18,06)
|
||||
expected={}
|
||||
@ -200,7 +183,6 @@ expected.after=1
|
||||
expected.min1=1
|
||||
expected.six=1
|
||||
checkWords(leds, expected, 18 , 06)
|
||||
checkCharacter(display_countwords_de(leds), 13)
|
||||
|
||||
leds=display_timestat(19,09)
|
||||
expected={}
|
||||
@ -209,7 +191,6 @@ expected.after=1
|
||||
expected.min4=1
|
||||
expected.seven=1
|
||||
checkWords(leds, expected, 19 , 09)
|
||||
checkCharacter(display_countwords_de(leds), 14)
|
||||
|
||||
leds=display_timestat(20,17)
|
||||
expected={}
|
||||
@ -218,7 +199,6 @@ expected.after=1
|
||||
expected.min2=1
|
||||
expected.eight=1
|
||||
checkWords(leds, expected, 20 , 17)
|
||||
checkCharacter(display_countwords_de(leds), 15)
|
||||
|
||||
|
||||
|
||||
|
11
webpage.html
11
webpage.html
@ -45,18 +45,9 @@ Please note that all settings are mandatory<br /><br />
|
||||
<table id="table-6">
|
||||
<tr><th><b>WIFI-SSID</b></th><td><input id="ssid" name="ssid" value="$SSID"></td><td>SSID of the wireless network</td></tr>
|
||||
<tr><th>WIFI-Password</th><td><input id="password" name="password"></td><td>Password of the wireless network</td></tr>
|
||||
<tr><th>SNTP Server</th><td><input id="sntpserver" name="sntpserver" value="$SNTPSERVER"></td><td>Server to sync the time with. Only one ntp server is allowed.</td></tr>
|
||||
<tr><th>SNTP Server</th><td><input id="sntpserver" name="sntpserver" value="$SNTPSERVER"></td><td>Server to sync the time with. Only one ntp server is allowed.</td></tr>
|
||||
<tr><th>Offset to UTC time</th><td><input id="timezoneoffset" name="timezoneoffset" value="$TIMEOFFSET"></td><td>Define the offset to UTC time in hours. For example +1 hour for Germany</td></tr>
|
||||
<tr><th>Foreground Color</th><td><input type="color" name="fcolor" value="$HEXCOLORFG"></td><td>LED Color for all minutes, divisible by five</td></tr>
|
||||
<tr><th>Background Color</th><td><input type="color" name="bcolor" value="$HEXCOLORBG"></td><td>Background LED Color</td></tr>
|
||||
<tr><th>1. Minute Color</th><td><input type="color" name="colorMin1" value="$HEXCOLOR1"></td><td>First minute after</td></tr>
|
||||
<tr><th>2. Minute Color</th><td><input type="color" name="colorMin2" value="$HEXCOLOR2"></td><td>Second minute after</td></tr>
|
||||
<tr><th>3. Minute Color</th><td><input type="color" name="colorMin3" value="$HEXCOLOR3"></td><td>Third minute after</td></tr>
|
||||
<tr><th>4. Minute Color</th><td><input type="color" name="colorMin4" value="$HEXCOLOR4"></td><td>Fourth minute after</td></tr>
|
||||
|
||||
<tr><th>Three quater</th><td><input type="checkbox" name="threequater" $THREEQUATER></td><td>Dreiviertel Joa/nei</td></tr>
|
||||
<tr><th>Invert lines 4-6</th><td><input type="checkbox" name="inv46" $THREEQUATER></td><td>invert</td></tr>
|
||||
|
||||
<tr><td colspan="3"><div align="center"><input type="submit" value="Save Configuration" onclick="this.value='Submitting ..';this.disabled='disabled'; this.form.submit();"></div></td></tr>
|
||||
<tr><td colspan="3"><div align="center"><input type="submit" name="action" value="Reboot"></div></td></tr>
|
||||
</table>
|
||||
|
@ -122,6 +122,8 @@ function fillDynamicMap()
|
||||
replaceMap["$HEXCOLOR3"]=hexColor3
|
||||
replaceMap["$HEXCOLOR4"]=hexColor4
|
||||
replaceMap["$HEXCOLORBG"]=hexColorBg
|
||||
replaceMap["$INV46"]=((inv46 ~= nil and inv46 == "on") and "checked" or "")
|
||||
replaceMap["$AUTODIM"]=((dim ~= nil and dim == "on") and "checked" or "")
|
||||
return replaceMap
|
||||
end
|
||||
|
||||
@ -139,8 +141,6 @@ function stopWordclock()
|
||||
getUTCtime = nil
|
||||
getTime = nil
|
||||
display_timestat = nil
|
||||
display_countcharacters_de = nil
|
||||
display_countwords_de = nil
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
@ -207,7 +207,7 @@ function startWebServer()
|
||||
sec, _ = rtctime.get()
|
||||
file.open(configFile.. ".new", "w+")
|
||||
file.write("-- Config\n" .. "station_cfg={}\nstation_cfg.ssid=\"" .. _POST.ssid .. "\"\nstation_cfg.pwd=\"" .. _POST.password .. "\"\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
|
||||
file.write("sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(_POST.inv46) .. "\"\n")
|
||||
file.write("sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(_POST.inv46) .. "\"\n" .. "dim=\"" .. tostring(_POST.dim) .. "\"\n")
|
||||
|
||||
if ( _POST.fcolor ~= nil) then
|
||||
-- color=string.char(_POST.green, _POST.red, _POST.blue)
|
||||
|
101
wordclock.lua
101
wordclock.lua
@ -64,7 +64,7 @@ function display_timestat(hours, minutes, longmode)
|
||||
ret.before=1
|
||||
elseif (minutes==9) then
|
||||
-- Hande if three quater or quater before is displayed
|
||||
if (threequater ~= nil) then
|
||||
if ((threequater ~= nil) and (threequater==true or threequater=="on")) then
|
||||
ret.threequater=1
|
||||
else
|
||||
ret.quater = 1
|
||||
@ -136,102 +136,3 @@ function display_timestat(hours, minutes, longmode)
|
||||
collectgarbage()
|
||||
return ret
|
||||
end
|
||||
|
||||
-- @fn display_countcharacters_de
|
||||
-- Count the amount of characters, used to describe the current time in words
|
||||
-- @param words the same structure, as generated with the function @see display_timestat
|
||||
-- @return the amount of characters, used to describe the time or <code>0</code> on errors
|
||||
function display_countcharacters_de(words)
|
||||
local amount=0
|
||||
if (words.it == 1) then
|
||||
amount = amount + 2
|
||||
end
|
||||
if (words.is == 1) then
|
||||
amount = amount + 3
|
||||
end
|
||||
if (words.fiveMin == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.tenMin == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.twenty == 1) then
|
||||
amount = amount + 7
|
||||
end
|
||||
if (words.threequater == 1) then
|
||||
amount = amount + 11
|
||||
end
|
||||
if (words.quater == 1) then
|
||||
amount = amount + 7
|
||||
end
|
||||
if (words.before == 1) then
|
||||
amount = amount + 3
|
||||
end
|
||||
if (words.after == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.half == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.twelve == 1) then
|
||||
amount = amount + 5
|
||||
end
|
||||
if (words.seven == 1) then
|
||||
amount = amount + 6
|
||||
end
|
||||
if (words.one == 1) then
|
||||
amount = amount + 3
|
||||
end
|
||||
if (words.oneLong == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.two == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.three == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.five == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.four == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.nine == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.eleven == 1) then
|
||||
amount = amount + 3
|
||||
end
|
||||
if (words.eight == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.ten == 1) then
|
||||
amount = amount + 4
|
||||
end
|
||||
if (words.clock == 1) then
|
||||
amount = amount + 3
|
||||
end
|
||||
if (words.six == 1) then
|
||||
amount = amount + 5
|
||||
end
|
||||
|
||||
return amount
|
||||
end
|
||||
|
||||
-- @fn display_countcharacters_de
|
||||
-- Count the amount of words, used to describe the current time in words!
|
||||
-- (min1 to min4 are ignored)
|
||||
-- @param words the same structure, as generated with the function @see display_timestat
|
||||
-- @return the amount of words, used to describe the time or <code>0</code> on errors
|
||||
function display_countwords_de(words)
|
||||
local amount = 0
|
||||
for k,v in pairs(words) do
|
||||
if (v ~= nil and v == 1) then
|
||||
if (k ~= "min1" and k ~= "min2" and k ~= "min3" and k ~= "min4") then
|
||||
amount = amount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user