-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdigibuttons.py
executable file
·108 lines (96 loc) · 3.6 KB
/
digibuttons.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python3
import select
import gpiod
import time
import threading
import subprocess
from signal import pause
from os import getenv
#from os import system
from dotenv import load_dotenv
from pathlib import Path
from os import path
def button_callback_24(number):
print("Button ", number, " pressed.")
if number == 24: # start digipeater
try:
cmd = "sudo systemctl is-active digipeater"
status = "active"
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
except:
status = "inactive"
if status == "inactive":
cmd = "sudo systemctl start digipeater"
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
else:
cmd = "hostname -I | cut -d' ' -f1"
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
if ( len(IP) < 5 ):
IP = "0.0.0.0"
cmd = "sudo systemctl stop digipeater"
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
subprocess.call(['/home/pi/digibanner.py', '-b', 'Standby', '-s', IP, '-d', getenv('NEWDISPLAYTYPE')])
return(0)
def button_callback_23(number):
print("Button ", number, " pressed.")
if number == 23: # start TNC/igate
try:
cmd = "sudo systemctl is-active tnc"
status = "active"
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
except:
status = "inactive"
if status == "inactive":
cmd = "sudo systemctl start tnc"
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
else:
cmd = "hostname -I | cut -d' ' -f1"
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
if ( len(IP) < 5 ):
IP = "0.0.0.0"
cmd = "sudo systemctl stop tnc"
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
subprocess.call(['/home/pi/digibanner.py', '-b', 'Standby', '-s', IP, '-d', getenv('NEWDISPLAYTYPE')])
cmd_output = subprocess.check_output(cmd, shell=True).decode("utf-8")
return(0)
def thread23():
lastcalltime = 0
if path.exists('/dev/gpiochip4'):
gpiochip = 'gpiochip4'
else:
gpiochip = 'gpiochip0'
chip = gpiod.Chip(gpiochip)
line23 = chip.get_line(23)
line23.request(consumer="GPIN", type=gpiod.LINE_REQ_EV_FALLING_EDGE, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
fd23 = line23.event_get_fd()
poll = select.poll()
poll.register(fd23)
while True:
event = line23.event_read()
if ((time.time() - lastcalltime) >= 1): # one second debounce
lastcalltime = time.time()
button_callback_23(23)
def thread24():
lastcalltime = 0
if path.exists('/dev/gpiochip4'):
gpiochip = 'gpiochip4'
else:
gpiochip = 'gpiochip0'
chip = gpiod.Chip(gpiochip)
line24 = chip.get_line(24)
line24.request(consumer="GPIN", type=gpiod.LINE_REQ_EV_FALLING_EDGE, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)
fd24 = line24.event_get_fd()
poll = select.poll()
poll.register(fd24)
while True:
event = line24.event_read()
if ((time.time() - lastcalltime) >= 1): # one second debounce
lastcalltime = time.time()
button_callback_24(24)
dotenv_path = Path('/home/pi/localize.env')
load_dotenv(dotenv_path=dotenv_path)
t23 = threading.Thread(target=thread23)
t23.start()
t24 = threading.Thread(target=thread24)
t24.start()
pause()