-
Notifications
You must be signed in to change notification settings - Fork 0
/
gagnerLaCoupe.py
67 lines (50 loc) · 1.54 KB
/
gagnerLaCoupe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import signal
import RPi.GPIO as GPIO
import time
def terminate(signalNumber, frame):
GPIO.cleanup()
restoreMotd()
exit(0)
def wait():
try:
time.sleep(0.2)
except (InterruptedError, KeyboardInterrupt):
GPIO.cleanup()
restoreMotd()
def restoreMotd():
os.system('cp -f /etc/motd_save /etc/motd')
def writeMotd(message):
os.system('sudo echo -e "\n\e[34m[HL] ' + message + '\n\e[0m" >>/etc/motd')
os.system('sudo wall -n "[HL] ' + message + '"')
# catch 'killall -10 python3'
signal.signal(signal.SIGUSR1, terminate)
signal.signal(signal.SIGTERM, terminate)
# save motd
# os.system('sudo cp -f /etc/motd /etc/motd_save')
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_UP)
if GPIO.input(8) == GPIO.LOW:
writeMotd("Positionner l\'interrupteur sur 0 pour commencer")
while GPIO.input(8) == GPIO.LOW:
wait()
while True:
restoreMotd()
writeMotd("Positionner l\'interrupteur sur 1 pour lancer le HL")
while GPIO.input(8) == GPIO.HIGH:
wait()
os.system("sudo /home/pi/TechTheTachyon-HighLevel/run_master_from_python.sh &")
restoreMotd()
writeMotd("HL lancé!")
restoreMotd()
writeMotd("Positionner l\'interrupteur sur 0 pour stopeer le HL")
while GPIO.input(8) == GPIO.LOW:
wait()
os.system("sudo killall -9 java")
PID = open("/home/pi/panneauRaspi/LED/PID", "r")
killPID = PID.readline()
PID.close()
os.system("sudo kill -10 " + killPID)
restoreMotd()
writeMotd("HL stoppé")
GPIO.cleanup()