All colors can be set via webpage
This commit is contained in:
parent
35a802009b
commit
db3a1e5e20
3
init.lua
3
init.lua
@ -17,6 +17,7 @@ end)
|
||||
bootledtimer:start()
|
||||
|
||||
function mydofile(mod)
|
||||
print("load:" .. mod)
|
||||
if (file.open(mod .. ".lua")) then
|
||||
dofile( mod .. ".lua")
|
||||
elseif (file.open(mod .. "_diet.lua")) then
|
||||
@ -36,7 +37,7 @@ initTimer:register(5000, tmr.ALARM_SINGLE, function (t)
|
||||
initTimer:unregister()
|
||||
initTimer=nil
|
||||
bootledtimer=nil
|
||||
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main" }
|
||||
local modlist = { "timecore" , "displayword", "ds18b20", "mqtt", "main", "webserver" }
|
||||
for i,mod in pairs(modlist) do
|
||||
if (file.open(mod .. "_diet.lua")) then
|
||||
file.remove(mod .. "_diet.lc")
|
||||
|
@ -47,7 +47,13 @@ Please note that all settings are mandatory<br /><br />
|
||||
<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>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>General 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>Foreground Color Minute1</th><td><input type="color" name="mcolor1" value="$HEXCOLORFG"></td><td>LED Color for first single minute</td></tr>
|
||||
<tr><th>Foreground Color Minute2</th><td><input type="color" name="mcolor2" value="$HEXCOLORFG"></td><td>LED Color for first single minute</td></tr>
|
||||
<tr><th>Foreground Color Minute3</th><td><input type="color" name="mcolor3" value="$HEXCOLORFG"></td><td>LED Color for first single minute</td></tr>
|
||||
<tr><th>Foreground Color Minute4</th><td><input type="color" name="mcolor4" value="$HEXCOLORFG"></td><td>LED Color for first single minute</td></tr>
|
||||
<tr><th>Threequarter</th><td><input type="checkbox" name="threequarter"></td><td>3/4 instead of 1/4 before</td></tr>
|
||||
<tr><th>Webserver</th><td><input type="checkbox" name="web"></td><td>Activate Webserver</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>
|
||||
|
@ -107,6 +107,14 @@ function fillDynamicMap()
|
||||
return replaceMap
|
||||
end
|
||||
|
||||
function readHex(source, variable)
|
||||
local hexColor=string.sub(source, 4)
|
||||
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(variable.."=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
|
||||
end
|
||||
|
||||
function startWebServer()
|
||||
srv=net.createServer(net.TCP)
|
||||
srv:listen(80,function(conn)
|
||||
@ -162,63 +170,37 @@ function startWebServer()
|
||||
if ( _POST.fcolor ~= nil) then
|
||||
-- color=string.char(_POST.green, _POST.red, _POST.blue)
|
||||
print ("Got fcolor: " .. _POST.fcolor)
|
||||
local hexColor=string.sub(_POST.fcolor, 4)
|
||||
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)
|
||||
readHex(_POST.fcolor, "color")
|
||||
end
|
||||
if ( _POST.colorMin1 ~= nil) then
|
||||
local hexColor=string.sub(_POST.colorMin1, 4)
|
||||
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")
|
||||
-- fill the current values
|
||||
color1=string.char(green, red, blue)
|
||||
if ( _POST.mcolor1 ~= nil) then
|
||||
readHex(_POST.mcolor1, "color1")
|
||||
end
|
||||
if ( _POST.colorMin2 ~= nil) then
|
||||
local hexColor=string.sub(_POST.colorMin2, 4)
|
||||
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")
|
||||
-- fill the current values
|
||||
color2=string.char(green, red, blue)
|
||||
if ( _POST.mcolor2 ~= nil) then
|
||||
readHex(_POST.mcolor2, "color2")
|
||||
end
|
||||
if ( _POST.colorMin3 ~= nil) then
|
||||
local hexColor=string.sub(_POST.colorMin3, 4)
|
||||
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")
|
||||
-- fill the current values
|
||||
color3=string.char(green, red, blue)
|
||||
if ( _POST.mcolor3 ~= nil) then
|
||||
readHex(_POST.mcolor3, "color3")
|
||||
end
|
||||
if ( _POST.colorMin4 ~= nil) then
|
||||
local hexColor=string.sub(_POST.colorMin4, 4)
|
||||
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")
|
||||
-- fill the current values
|
||||
color4=string.char(green, red, blue)
|
||||
if ( _POST.mcolor4 ~= nil) then
|
||||
readHex(_POST.mcolor4, "color4")
|
||||
end
|
||||
if ( _POST.bcolor ~= nil) then
|
||||
local hexColor=string.sub(_POST.bcolor, 4)
|
||||
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)
|
||||
readHex(_POST.bcolor, "colorBg")
|
||||
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 (_POST.web ~= nil) then
|
||||
file.write("web=true\n")
|
||||
-- fill the current values
|
||||
web=true
|
||||
else
|
||||
file.write("web=nil\n") -- use webserver instead of mqtt or telnet
|
||||
-- fill the current values
|
||||
web=nil
|
||||
end
|
||||
if (_POST.threequater ~= nil) then
|
||||
file.write("threequater=true\n")
|
||||
-- fill the current values
|
||||
@ -312,4 +294,4 @@ ledBuf=nil
|
||||
print("Waiting in access point >wordclock< for Clients")
|
||||
print("Please visit 192.168.4.1")
|
||||
startWebServer()
|
||||
collectgarbage()
|
||||
collectgarbage()
|
||||
|
Loading…
Reference in New Issue
Block a user