-
Notifications
You must be signed in to change notification settings - Fork 0
/
button_listener.py
35 lines (30 loc) · 962 Bytes
/
button_listener.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
from hardware import Hardware
import check_internet_conn
from configconn import *
import time, subprocess
dnsmasq = "/etc/dnsmasq.conf"
dhcpcd = "/etc/dhcpcd.conf"
wpa_supplicant = "/etc/wpa_supplicant/wpa_supplicant.conf"
buzzer_pin = 23
red_pin = 22
green_pin = 17
blue_pin = 27
button_pin = 24
hardware = Hardware(
redpin = red_pin,
greenpin = green_pin,
bluepin = blue_pin,
buttonpin = button_pin,
buzzerpin = buzzer_pin
)
def switchToAP():
print("Resetting network configuration")
hardware.playBuzzer(5, 0.2, 0.2, useLED=True, ledColor=(False, True, False))
APConfig.copyfile("configurations/dnsmasq.conf", dnsmasq)
APConfig.copyfile("configurations/dhcpcd.conf", dhcpcd)
APServices.start()
# hardware.setColorRGB(False, True, False)
hardware.buttonListen(target_time=3, callback_func=switchToAP)
hardware.close()
print("Executing system shutdown")
subprocess.run(["sudo", "shutdown", "-h", "now"], shell=False)