Browse Source

python > sh

master
Martin Dørum 2 years ago
parent
commit
7049565749
4 changed files with 34 additions and 41 deletions
  1. 1
    1
      facelock.py
  2. 1
    1
      facematcher.py
  3. 32
    0
      facewaiter.py
  4. 0
    39
      facewaiter.sh

+ 1
- 1
facelock.py View File

@@ -7,7 +7,7 @@ import threading

locker = subprocess.Popen([ "mlock" ])
print("locker "+str(locker.pid)+" spawned")
matcher = subprocess.Popen([ "./facewaiter.sh" ])
matcher = subprocess.Popen([ "./facewaiter.py" ])
print("matcher "+str(matcher.pid)+" spawned")

def waitfor(x, others):

+ 1
- 1
facematcher.py View File

@@ -136,7 +136,7 @@ sub_match.add_argument(
"-s", "--show", default=False, action="store_true",
help="show what the camera sees")
sub_match.add_argument(
"-w", "--wait", type=str, default=None,
"-w", "--wait", default=False, action="store_true",
help="wait for newline on stdin")
sub_match.add_argument(
"-t", "--delay", type=int, default=0,

+ 32
- 0
facewaiter.py View File

@@ -0,0 +1,32 @@
#!/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())

+ 0
- 39
facewaiter.sh View File

@@ -1,39 +0,0 @@
#!/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

Loading…
Cancel
Save