#112 fixed bug with flasher

This commit is contained in:
Mikayla Fischler 2022-11-02 12:02:52 -04:00
parent 004c960e4d
commit d87dfb9ebd
2 changed files with 9 additions and 9 deletions

View File

@ -16,7 +16,7 @@ local config = require("coordinator.config")
local coordinator = require("coordinator.coordinator") local coordinator = require("coordinator.coordinator")
local renderer = require("coordinator.renderer") local renderer = require("coordinator.renderer")
local COORDINATOR_VERSION = "alpha-v0.5.11" local COORDINATOR_VERSION = "alpha-v0.5.12"
local print = util.print local print = util.print
local println = util.println local println = util.println

View File

@ -2,7 +2,7 @@
-- Indicator Light Flasher -- Indicator Light Flasher
-- --
local tcd = require("scada-common.tcallbackdsp") local tcd = require("scada-common.tcallbackdsp")
local flasher = {} local flasher = {}
@ -26,14 +26,14 @@ local callback_counter = 0
-- this assumes it is called every 250ms, it does no checking of time on its own -- this assumes it is called every 250ms, it does no checking of time on its own
local function callback_250ms() local function callback_250ms()
if active then if active then
for _, f in pairs(registry[PERIOD.BLINK_250_MS]) do f() end for _, f in ipairs(registry[PERIOD.BLINK_250_MS]) do f() end
if callback_counter % 2 == 0 then if callback_counter % 2 == 0 then
for _, f in pairs(registry[PERIOD.BLINK_500_MS]) do f() end for _, f in ipairs(registry[PERIOD.BLINK_500_MS]) do f() end
end end
if callback_counter % 4 == 0 then if callback_counter % 4 == 0 then
for _, f in pairs(registry[PERIOD.BLINK_1000_MS]) do f() end for _, f in ipairs(registry[PERIOD.BLINK_1000_MS]) do f() end
end end
callback_counter = callback_counter + 1 callback_counter = callback_counter + 1
@ -70,10 +70,10 @@ end
---@param f function function callback registered ---@param f function function callback registered
function flasher.stop(f) function flasher.stop(f)
for i = 1, #registry do for i = 1, #registry do
for j = 1, #registry[i] do for key, val in ipairs(registry[i]) do
if registry[i][j] == f then if val == f then
registry[i][j] = nil table.remove(registry[i], key)
break return
end end
end end
end end