locker = subprocess.Popen([ "mlock" ]) | locker = subprocess.Popen([ "mlock" ]) | ||||
print("locker "+str(locker.pid)+" spawned") | print("locker "+str(locker.pid)+" spawned") | ||||
matcher = subprocess.Popen([ "./facewaiter.sh" ]) | |||||
matcher = subprocess.Popen([ "./facewaiter.py" ]) | |||||
print("matcher "+str(matcher.pid)+" spawned") | print("matcher "+str(matcher.pid)+" spawned") | ||||
def waitfor(x, others): | def waitfor(x, others): |
"-s", "--show", default=False, action="store_true", | "-s", "--show", default=False, action="store_true", | ||||
help="show what the camera sees") | help="show what the camera sees") | ||||
sub_match.add_argument( | sub_match.add_argument( | ||||
"-w", "--wait", type=str, default=None, | |||||
"-w", "--wait", default=False, action="store_true", | |||||
help="wait for newline on stdin") | help="wait for newline on stdin") | ||||
sub_match.add_argument( | sub_match.add_argument( | ||||
"-t", "--delay", type=int, default=0, | "-t", "--delay", type=int, default=0, |
#!/usr/bin/env python | |||||
import subprocess | |||||
keyboard = "AT Translated Set 2 keyboard" | |||||
battery = "/sys/class/power_supply/BAT0" | |||||
device = "2" | |||||
faces = "faces" | |||||
key = "36" | |||||
bat = False | |||||
if battery is not None: | |||||
with open(f"{battery}/status", "r") as f: | |||||
s = f.read().strip() | |||||
if s == "Discharging" or s == "Unknown": | |||||
bat = True | |||||
proc = subprocess.Popen( | |||||
f"./facematcher.py match --wait --delay 500 --device {device} {faces}/$USER/*", | |||||
stdin=subprocess.PIPE, shell=True) | |||||
if bat: | |||||
print(f"On battery, so waiting for {key}") | |||||
subprocess.check_output( | |||||
f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | " + | |||||
f"while read -r line; do exit; done", | |||||
shell=True) | |||||
print(f"Got {key}.") | |||||
proc.stdin.write(b"hello\n") | |||||
proc.stdin.flush() | |||||
exit(proc.wait()) |
#!/bin/bash | |||||
keyboard="AT Translated Set 2 keyboard" | |||||
battery="/sys/class/power_supply/BAT0" | |||||
device=2 | |||||
faces="faces" | |||||
if [ -n "$battery" ]; then | |||||
st="$(cat "$battery/status")" | |||||
if [ "$st" != "Discharging" ] && [ "$st" != "Unknown" ]; then | |||||
./facematcher.py match --delay 500 --device "$device" $faces/$USER/* | |||||
exit $? | |||||
fi | |||||
fi | |||||
rm -f .testfifo | |||||
mkfifo .testfifo | |||||
xinput test "AT Translated Set 2 keyboard" \ | |||||
| grep --line-buffered "key press 36" > .testfifo & | |||||
xpid=$! | |||||
rm -f .matchfifo | |||||
mkfifo .matchfifo | |||||
matcher() { | |||||
cat .matchfifo | ./facematcher.py match --delay 500 --device 2 --wait $faces/$USER/* | |||||
} | |||||
matcher & | |||||
matchpid=$! | |||||
trap "kill $matchpid" SIGINT SIGTERM | |||||
read <.testfifo | |||||
echo > .matchfifo | |||||
kill $xpid | |||||
wait | |||||
rm -f .testfifo | |||||
rm -f .matchfifo |