Commit 9d899f25 authored by Antoine's avatar Antoine

Merge branch 'extract_clock_in_a_module' into 'stable'

Move clock logic in a module

See merge request !4
parents 3bb4144a 87df4926
local M = {}
local tmr = tmr
setfenv(1, M)
local display
local time
local refresh_rate = 100
local function update_time()
now = time.get_zoned_time(1)
display.display(now["hour"], now["min"], now["sec"])
end
local function auto_update_time()
tmr.create():alarm(refresh_rate, tmr.ALARM_AUTO, update_time)
end
function M.init(time_module, time_display)
time = time_module
time.autosync()
display = time_display
end
function M.start()
time.autosync()
time.sync_ntp(function ()
update_time()
auto_update_time()
end)
end
return M
\ No newline at end of file
......@@ -2,28 +2,14 @@ local data=1
local clock=2
local time = require("time")
time.autosync()
local display = require("rainbow_binary_display")
display.init(clock,data)
local function update_time()
now = time.get_zoned_time(1)
display.display(now["hour"], now["min"], now["sec"])
end
local rainbow_clock = require("clock")
rainbow_clock.init(time, display)
local timer = tmr.create()
timer:register(100, tmr.ALARM_AUTO, update_time)
rainbow_clock.start()
local function auto_update_time()
timer:start()
end
function stop()
timer:stop()
end
time.sync_ntp(function ()
update_time()
auto_update_time()
end)
rainbow_clock = nil
package.loaded["clock"] = nil
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment