refactor: replace the TICK_MS global with app.setTickInterval()
A magic global that the runtime reads once at startup could not be changed later, gave no feedback when misspelled, and was a second spelling of a mechanism the sibling firmware already had. app.setTickInterval(ms) clamps to 33..3600000, takes 0 to stop, and errors when on_tick() is not defined -- by the time init() runs the chunk body has finished, so a missing callback is a typo rather than a race. Also drops the code comments pointing at the other repo. Where the two APIs agree or differ belongs in docs/lua-api-parity.md; a comment beside a constant explaining that another firmware picked the same number is noise a reader here cannot act on.
This commit is contained in:
@@ -13,6 +13,7 @@ local device = {
|
||||
rotation = 0,
|
||||
theme = "light",
|
||||
clockSynced = false,
|
||||
tickInterval = 0,
|
||||
timezone = "UTC0",
|
||||
raw = nil, -- pending raw touch reading, {x, y} or nil
|
||||
networks = {}, -- what wifi.scan() returns
|
||||
@@ -99,7 +100,14 @@ function device.install()
|
||||
forget = function() device.connected = nil return saved() end,
|
||||
}
|
||||
|
||||
log = {info = function() end}
|
||||
app = {
|
||||
setTickInterval = function(ms)
|
||||
assert(ms == 0 or on_tick, "setTickInterval without on_tick")
|
||||
device.tickInterval = ms
|
||||
end,
|
||||
}
|
||||
|
||||
log = {debug = function() end, info = function() end, error = function() end}
|
||||
|
||||
return device
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user