-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholed_menu.py
More file actions
86 lines (73 loc) · 2.55 KB
/
oled_menu.py
File metadata and controls
86 lines (73 loc) · 2.55 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
from PIL import ImageFont
from time import sleep
from RPi import GPIO
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306
import time
GPIO.setmode(GPIO.BCM)
global menuindex
global insubmenu
L1 = 17
L2 = 27
L3 = 22
L4 = 10
C1 = 9
C2 = 11
C3 = 26
GPIO.setwarnings(False)
GPIO.setup(L1, GPIO.OUT)
GPIO.setup(L2, GPIO.OUT)
GPIO.setup(L3, GPIO.OUT)
GPIO.setup(L4, GPIO.OUT)
GPIO.setup(C1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
serial = i2c(port=1, address=0x3C)
device = ssd1306(serial, rotate=0)
def invert(draw,x,y,text):
font = ImageFont.load_default()
draw.rectangle((x, y, x+120, y+10), outline=255, fill=255)
draw.text((x, y), text, font=font, outline=0,fill="black")
# Box and text rendered in portrait mode
def menu(device, draw, menustr,index):
global menuindex
font = ImageFont.load_default()
draw.rectangle(device.bounding_box, outline="white", fill="black")
for i in range(len(menustr)):
if(i == index):
menuindex = i
invert(draw, 2, i*10, menustr[i])
else:
draw.text((2, i*10), menustr[i], font=font, fill=255)
names = ['1.) Quantity', '2.) Freqeuncy', '3.) Information']
with canvas(device) as draw:
menu(device, draw, names, 1)
#
try:
while(1):
GPIO.output(GPIO.HIGH)
if (GPIO.input(C1)==1) :
with canvas(device) as draw:
draw.text((0, 0), "Select quantity of next meal: ", fill="white")
sleep(0.5)
continue
#draw.text((0, 26), sys_info.disk_usage('/'), fill="white")
elif (GPIO.input(C2)==1):
with canvas(device) as draw:
draw.text((0, 0), "Select time before next meal: ", fill="white")
sleep(0.5)
continue
#draw.text((0, 26), sys_info.mem_usage(), fill="white")
elif (GPIO.input(C3)==1):
with canvas(device) as draw:
draw.text((0, 0), "Amount of kibble left: ", fill="white")
draw.text((0, 0), "Time before next meal: ", fill="white")
sleep(0.5)
continue
#draw.text((0, 26), sys_info.network('wlan0'), fill="white")
names = ['1.) Quantity', '2.) Freqeuncy', '3.) Information']
with canvas(device) as draw:
menu(device, draw, names, 1)
except KeyboardInterrupt:
GPIO.cleanup()