Skip to content

Instantly share code, notes, and snippets.

@daurnimator
Created October 19, 2014 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daurnimator/e0a3215d93252645812b to your computer and use it in GitHub Desktop.
Save daurnimator/e0a3215d93252645812b to your computer and use it in GitHub Desktop.
For bsdfox from #lua
#!/usr/bin/lua
local evdev = require "evdev"
local pirsensor = evdev.Device "/dev/input/event0"
local cqueues = require "cqueues"
local sleeptime = 10
local pending = nil
-- ensure backlight is off to start
os.execute("/home/h36sa/Projects/fbtft/backlight_off.sh")
local cq = cqueues.new()
cq:wrap(function()
while true do
cqueues.poll(pirsensor)
local timestamp, eventType, eventCode, value = pirsensor:tryread()
if timestamp ~= nil and eventType == evdev.EV_KEY then
if value == 1 then
print("Motion detected! turn on lcd backlight (minimum 10 sec)")
os.execute("/home/h36sa/Projects/fbtft/backlight_on.sh")
pending = cq:wrap(function()
cqueues.sleep(sleeptime)
if pending == cqueues.running() then
print("All quiet right now. turn off lcd backlight")
os.execute("/home/h36sa/Projects/fbtft/backlight_off.sh")
end
end)
end
end
end
end)
assert(cq:loop())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment