Created
October 19, 2014 20:03
-
-
Save daurnimator/e0a3215d93252645812b to your computer and use it in GitHub Desktop.
For bsdfox from #lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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