Magnetic card door controller

master
D4VID 11 months ago
commit 693d598833

@ -0,0 +1,49 @@
local component = require("component")
local event = require("event")
local os = require("os")
local doorControllers = {}
local cardReader = component.os_magreader
for address, name in component.list("os_doorcontroller", true) do
table.insert(doorControllers, component.proxy(address))
end
GREEN_LED = 4
YELLOW_LED = 2
RED_LED = 1
local function magCardCallback(eventName, address, playerName, cardData, cardUniqueId, isCardLocked, side)
-- bits for green, yellow and red leds
cardReader.setLightState(YELLOW_LED)
if cardData == "supertajneheslo" then
cardReader.setLightState(GREEN_LED)
-- open the doors
for _, doorController in ipairs(doorControllers) do
doorController.open()
end
os.sleep(3)
-- close the doors
for _, doorController in ipairs(doorControllers) do
doorController.close()
end
else
cardReader.setLightState(RED_LED)
os.sleep(2)
end
-- turn light indicators off
cardReader.setLightState(0)
end
-- control led indicators manually
cardReader.swipeIndicator(false)
-- subscribe to the event "magData" with
event.listen("magData", magCardCallback)
-- wait for an interrupt before closing the script (CTRL + C)
event.pull("interrupted")
-- unsubscribe from the event bus
event.ignore("magData", magCardCallback)
Loading…
Cancel
Save