|
32 | 32 | bottom = height - padding
|
33 | 33 | x = 0
|
34 | 34 |
|
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") |
39 | 36 |
|
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) |
42 | 42 |
|
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) |
45 | 45 |
|
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) |
48 | 48 |
|
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) |
51 | 51 |
|
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) |
56 | 54 |
|
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() |
60 | 63 |
|
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