added color picker

This commit is contained in:
C3MA 2016-12-14 18:37:56 +01:00
parent 8de86b065d
commit 67c506571f
3 changed files with 13 additions and 9 deletions

View File

@ -1,4 +1,4 @@
print("Autostart in 10 seconds...") print("Autostart in 5 seconds...")
ws2812.init() -- WS2812 LEDs initialized on GPIO2 ws2812.init() -- WS2812 LEDs initialized on GPIO2
@ -34,7 +34,7 @@ function mydofile(mod)
end end
tmr.alarm(1, 10000, 0, function() tmr.alarm(1, 5000, 0, function()
tmr.stop(2) tmr.stop(2)
if (file.open("main.lua")) then if (file.open("main.lua")) then
recompileAll() recompileAll()

View File

@ -14,7 +14,7 @@ function sendWebPage(conn,answertype)
if (color == nil) then if (color == nil) then
color=string.char(0,0,250) color=string.char(0,0,250)
end end
local hexColor = "#" .. string.format("%02x",string.byte(color,1)) .. string.format("%02x",string.byte(color,2)) .. string.format("%02x",string.byte(color,3))
local buf="HTTP/1.1 200 OK\nServer: NodeMCU\nContent-Type: text/html\n\n" local buf="HTTP/1.1 200 OK\nServer: NodeMCU\nContent-Type: text/html\n\n"
if (node.heap() < 8000) then if (node.heap() < 8000) then
buf = buf .. "<h1>Busy, please come later again</h1>" buf = buf .. "<h1>Busy, please come later again</h1>"
@ -29,9 +29,7 @@ function sendWebPage(conn,answertype)
buf = buf .."<tr><th>WIFI-Password</th><td><input name=\"password\"></td><td /></tr>" buf = buf .."<tr><th>WIFI-Password</th><td><input name=\"password\"></td><td /></tr>"
buf = buf .."<tr><th>SNTP Server</th><td><input name=\"sntpserver\" value=\"" .. sntpserverhostname .. "\"></td><td>ntp server to sync the time</tr>" buf = buf .."<tr><th>SNTP Server</th><td><input name=\"sntpserver\" value=\"" .. sntpserverhostname .. "\"></td><td>ntp server to sync the time</tr>"
buf = buf .."<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>" buf = buf .."<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>"
buf = buf .."<tr><th>Red</th><td><input type=\"number\" name=\"red\" value=\"" .. string.byte(color,1) .. "\"></td><td /></tr>" buf = buf .."<tr><th>Color</th><td><input type=\"color\" name=\"fcolor\" value=\"" .. hexColor .. "\"></td><td /></tr>"
buf = buf .."<tr><th>Green</th><td><input type=\"number\" name=\"green\" value=\"" .. string.byte(color,2) .. "\"></td><td /></tr>"
buf = buf .."<tr><th>Blue</th><td><input type=\"number\" name=\"blue\" value=\"" .. string.byte(color,3) .. "\"></td><td>All Colors: 0 - 255</td></tr>"
buf = buf .."<tr><th>Three quater</th><td><input type=\"checkbox\" name=\"threequater\" ".. (threequater and "checked" or "") .. "></td><td>Dreiviertel Joa/nei</td></tr>" buf = buf .."<tr><th>Three quater</th><td><input type=\"checkbox\" name=\"threequater\" ".. (threequater and "checked" or "") .. "></td><td>Dreiviertel Joa/nei</td></tr>"
buf = buf .. "<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>" buf = buf .. "<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>"
buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>" buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>"

View File

@ -71,8 +71,14 @@ function startWebServer()
sec, _ = rtctime.get() sec, _ = rtctime.get()
file.open(configFile.. ".new", "w+") file.open(configFile.. ".new", "w+")
file.write("-- Config\n" .. "wifi.sta.config(\"" .. _POST.ssid .. "\",\"" .. _POST.password .. "\")\n" .. "sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n") file.write("-- Config\n" .. "wifi.sta.config(\"" .. _POST.ssid .. "\",\"" .. _POST.password .. "\")\n" .. "sntpserverhostname=\"" .. _POST.sntpserver .. "\"\n" .. "timezoneoffset=\"" .. _POST.timezoneoffset .. "\"\n")
if ( (_POST.red ~= nil) and (_POST.green ~= nil) and (_POST.blue ~= nil) ) then if ( _POST.fcolor ~= nil) then
color=string.char(_POST.green, _POST.red, _POST.blue) -- 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)
color=string.char(red, green, blue)
end end
file.write("color=string.char(" .. string.byte(color,1) .. "," .. string.byte(color, 2) .. "," .. string.byte(color, 3) .. ")\n print(\"Config from " .. sec .. "\")\n") file.write("color=string.char(" .. string.byte(color,1) .. "," .. string.byte(color, 2) .. "," .. string.byte(color, 3) .. ")\n print(\"Config from " .. sec .. "\")\n")
if (_POST.threequater ~= nil) then if (_POST.threequater ~= nil) then