-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.py
More file actions
59 lines (44 loc) · 1.59 KB
/
display.py
File metadata and controls
59 lines (44 loc) · 1.59 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
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
from luma.core.virtual import viewport, snapshot
from datetime import datetime
import time
import ip
import bluetooth
import last_line
serial = i2c(port=1, address=0x3c)
device = ssd1306(serial, rotate=0)
def bt_is_connected(draw, pos=(1, 0)):
is_conn = bluetooth.is_connected()
out = "B+" if is_conn else "b-"
draw.text(pos, out, fill="white")
def wifi_is_connected(connected, draw, pos=(16, 0)):
out = "W+" if connected else "w-"
draw.text(pos, out, fill="white")
def ip_address(address, draw, pos=(1, 40)):
out = address if address else "Not Connected"
draw.text(pos, out, fill="white")
def last_result(out, draw, pos=(1, 15)):
draw.text(pos, out, fill="white")
def last_result_render():
row = last_line.last()[0]
format = '%H:%M'
dt = datetime.strftime(row['date'], format) if row else datetime.now().strftime(format)
out = "{color}: {gravity} @ {datetime}".format(color=row['color'], gravity=row['gravity'],
datetime=dt) if row else "No results @ {}".format(dt)
return out
def run():
while 1:
with canvas(device) as draw:
bt_is_connected(draw)
addr = ip.get_ip_address('wlan0')
wifi_is_connected(addr, draw)
last_result(last_result_render(), draw)
ip_address(addr, draw)
time.sleep(20)
if __name__ == "__main__":
try:
run()
except KeyboardInterrupt:
pass