Browse Source

more reliable shutdown

master
mortie 6 years ago
parent
commit
e879761cdc
1 changed files with 4 additions and 5 deletions
  1. 4
    5
      scripts/esc-button.py

+ 4
- 5
scripts/esc-button.py View File



pressed = False pressed = False


shutdown = 3 * 10
iterations = 0
shutdown = 2.5
press_start = time.time()


while True: while True:
current = not GPIO.input(3) current = not GPIO.input(3)
if current and not pressed: if current and not pressed:
call(["xdotool", "keydown", "Escape"]) call(["xdotool", "keydown", "Escape"])
pressed = True pressed = True
press_start = time.time()
elif not current and pressed: elif not current and pressed:
call(["xdotool", "keyup", "Escape"]) call(["xdotool", "keyup", "Escape"])
pressed = False pressed = False
iterations = 0


if current: if current:
iterations += 1
if iterations > shutdown:
if time.time() - shutdown >= press_start:
call(["sudo", "shutdown", "-h", "now"]) call(["sudo", "shutdown", "-h", "now"])


time.sleep(0.1) time.sleep(0.1)

Loading…
Cancel
Save