Skip to content

Commit 563f062

Browse files
Made Python exit cleanly
1 parent 4fa6249 commit 563f062

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

LEDs/LEDsV2.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
for l in leds:
1212
GPIO.setup(l, GPIO.OUT)
13-
pwms.append(GPIO.PWM(l, 50))
13+
pwms.append(GPIO.PWM(l, 50)) # Setting frequency to 50Hz
14+
15+
print("Starting EP-0152 PWM LED Pulse")
1416

1517
for p in pwms:
1618
p.start(0)
@@ -25,11 +27,8 @@
2527
for p in pwms:
2628
p.ChangeDutyCycle(dc)
2729
time.sleep(0.1)
28-
except KeyboardInterrupt:
29-
pass
30-
31-
for p in pwms:
32-
p.stop()
33-
GPIO.cleanup()
34-
print("BYE")
35-
30+
finally:
31+
for p in pwms:
32+
p.stop()
33+
GPIO.cleanup()
34+
print("Ended EP-0152 PWM LED Pulse")

OLED/oledV2.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,38 @@
3232
bottom = height - padding
3333
x = 0
3434

35-
while True:
36-
draw.rectangle((0,0,width,height), outline=0, fill=0)
37-
cmd = "hostname -I | cut -d\' \' -f1"
38-
ip = subprocess.check_output(cmd, shell=True)
35+
print("Starting EP-0152 OLED Monitor")
3936

40-
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %s%%\", $(NF-2)*100}'"
41-
cpu = subprocess.check_output(cmd, shell=True)
37+
try:
38+
while True:
39+
draw.rectangle((0,0,width,height), outline=0, fill=0)
40+
cmd = "hostname -I | cut -d\' \' -f1"
41+
ip = subprocess.check_output(cmd, shell=True)
4242

43-
cmd = "free -m | awk 'NR==2{printf \"Mem: %.2f/%.2fGB %.2f%%\", $3/1024, $2/1024, $3*100/$2 }'"
44-
mem = subprocess.check_output(cmd, shell=True)
43+
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %s%%\", $(NF-2)*100}'"
44+
cpu = subprocess.check_output(cmd, shell=True)
4545

46-
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3, $2, $5}'"
47-
disk = subprocess.check_output(cmd, shell=True)
46+
cmd = "free -m | awk 'NR==2{printf \"Mem: %.2f/%.2fGB %.2f%%\", $3/1024, $2/1024, $3*100/$2 }'"
47+
mem = subprocess.check_output(cmd, shell=True)
4848

49-
cmd = "vcgencmd measure_temp"
50-
temp = subprocess.check_output(cmd, shell=True)
49+
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3, $2, $5}'"
50+
disk = subprocess.check_output(cmd, shell=True)
5151

52-
draw.text((x, top), "IP: {}".format(ip.decode('utf-8')), font=font, fill=255)
53-
draw.text((x, top+8), "{}".format(cpu.decode('utf-8')), font=font, fill=255)
54-
draw.text((x, top+16), "{}".format(mem.decode('utf-8')), font=font, fill=255)
55-
draw.text((x, top+24), "{}".format(temp.decode('utf-8')), font=font, fill=255)
52+
cmd = "vcgencmd measure_temp"
53+
temp = subprocess.check_output(cmd, shell=True)
5654

57-
# Display image
58-
oled.image(image)
59-
oled.show()
55+
draw.text((x, top), "IP: {}".format(ip.decode('utf-8')), font=font, fill=255)
56+
draw.text((x, top+8), "{}".format(cpu.decode('utf-8')), font=font, fill=255)
57+
draw.text((x, top+16), "{}".format(mem.decode('utf-8')), font=font, fill=255)
58+
draw.text((x, top+24), "{}".format(temp.decode('utf-8')), font=font, fill=255)
59+
60+
# Display image
61+
oled.image(image)
62+
oled.show()
6063

61-
time.sleep(3)
64+
time.sleep(3)
65+
finally:
66+
# Clear display
67+
oled.fill(0)
68+
oled.show()
69+
print("Ended EP-0152 OLED Monitor")

0 commit comments

Comments
 (0)