-
Notifications
You must be signed in to change notification settings - Fork 1
/
piglow.py
executable file
·78 lines (67 loc) · 2.39 KB
/
piglow.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
#!/usr/bin/env python3
#
# Copyright 2023 Thomas Ackermann
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Displaying pihome diagnostic data with PiGlow
# (see http://shop.pimoroni.com/products/piglow
# and https://github.com/benleb/PyGlow)
#
import glob, string, time, os, PyGlow
path = "/tmp/pihome/*"
pyglow = PyGlow.PyGlow()
intensity = 1
try:
while True:
files = sorted(glob.glob(path))
arm = 1
pyglow.all(0)
leds = []
for file in files:
if arm <= 3:
fd = open(file)
for line in fd:
tok = line.strip().split()
if tok[0] == "ACTEX":
off = 1 # red led
if tok[1] == "0":
off = 6 # white led
leds = leds + [(arm - 1) * 6 + off]
if tok[0] == "DATA":
bits = bin(string.atoi(tok[1], 16))
bits = bits[2:]
led = (arm - 1) * 6 + 2 # the four leds between white and red
# are used to show lower nibble of DATA
numbits = 4
while len(bits) > 0 and numbits > 0:
bit = bits[-1:]
bits = bits[:-1]
if bit == "1":
leds = leds + [led]
led = led + 1
numbits = numbits - 1
fd.close()
arm = arm + 1
if len(leds) == 0:
leds = [5, 11, 17]
for i in range(0, 15):
pyglow.set_leds(leds, intensity)
pyglow.update_leds()
time.sleep(0.1)
pyglow.set_leds(leds, 0)
pyglow.update_leds()
time.sleep(1)
except KeyboardInterrupt:
pyglow.all(0)