-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhal.py
More file actions
114 lines (83 loc) · 1.93 KB
/
hal.py
File metadata and controls
114 lines (83 loc) · 1.93 KB
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
108
109
110
111
112
113
114
#!/usr/bin/env python
# Hal.py
#
#
#setup venv
# python3 -m venv hal_env
# source hal_env/bin/activate
# run program
# ./runhal.sh#
#
#
import RPi.GPIO as GPIO
from gpiozero import LED
from signal import signal,SIGTERM,SIGHUP,pause
import json
import os
import os.path
import yaml
import argparse
import sys
from time import sleep
from pathlib import Path
from threading import Thread
#definitions
BUTTON = 17
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(BUTTON, GPIO.IN)
redled= LED(13)
blink_on=False
reading=True
statusString="unknown"
#main loop. runs on schedule
def main_daemon():
while reading:
#print('Wakeup')
state = GPIO.input(BUTTON)
if state:
print("button off")
else:
print("button on")
sleep(2)
def get_settings():
full_file_path = Path(__file__).parent.joinpath('settings.yaml')
with open(full_file_path) as settings:
settings_data = yaml.load(settings, Loader=yaml.Loader)
return settings_data
#ctrl C to exit program, and reset gpio pins
def safe_exit(signum,frame):
print("Goodbye, Safe exit signal")
sleep(2)
exit(1)
def startup():
showAudioDevice()
#play_wav(INTROWAV ) # DOES NOT WORK. Match Device’s Native Sample Rate
play_wav(TESTWAV)
print("Strip blue ")
set_strip_color(0, 0, 255, 5)
sleep(4)
print("Strip Green ")
set_strip_color(0, 255, 0, 10)
sleep(4)
clear_strip()
print("red on")
redled.on()
sleep(4)
print("red blink")
redled.blink(0.5,0.5)
sleep(4)
redled.off()
try:
signal(SIGTERM, safe_exit)
signal(SIGHUP, safe_exit)
settingsDict =get_settings()
SS_SUBSCRIPTION_KEY=settingsDict["ss_key"]
print("sub key"+ SS_SUBSCRIPTION_KEY)
#BUTTON.when_pressed=button_handler
startup()
reader=Thread(target=main_daemon,daemon=True)
reader.start()
pause()
finally:
reading=False
pass