-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed.py
125 lines (105 loc) · 2.26 KB
/
oled.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import smbus
import oled_image2
import time
BUS_ID = 1
BUS_ADDR = 0x27
imgSent=False
def dayName(dow):
days = {
0: "Sunday",
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday"
}
return(days[dow])
def init():
bus=smbus.SMBus(BUS_ID)
clear(bus)
sendWord(bus,"CS0") # Disable Cursor
return(bus)
def sendWord(bus, val):
for character in str(val):
bus.write_byte(BUS_ADDR , ord(character))
def sendValue(bus,val):
bus.write_byte(BUS_ADDR, val)
def clear(bus):
global imgSent
imgSent=False
sendWord(bus,"CL")
def writeText(bus, text):
sendWord(bus,"TT"+text+"\n")
def drawRect(bus,x1,y1,x2,y2):
sendWord(bus,"DR")
sendValue(bus,x1)
sendValue(bus,y1)
sendValue(bus,x2)
sendValue(bus,y2)
def setFont(bus,font):
sendWord(bus,"SF")
sendValue(bus,font)
def setColor(bus,r,g,b):
sendWord(bus,"ESC")
sendValue(bus,r)
sendValue(bus,g)
sendValue(bus,b)
def grey(bus,bright):
setColor(bus,(bright*100+15),(bright*100+15),(bright*100+15))
def blue(bus,bright):
setColor(bus,0,0,(bright*120+15))
def green(bus,bright):
setColor(bus,0,(bright*118+19),0)
def red(bus,bright):
setColor(bus,(bright*120+15),0,0)
def black(bus):
setColor(bus,0,0,0)
def setPos(bus,x,y):
sendWord(bus,"TP")
sendValue(bus,x)
sendValue(bus,y)
def screenTimes(bus,next):
if (9 <= int(time.strftime("%H",time.localtime())) < 22):
bright=2
else:
bright=0
if(next):
clear(bus)
row=1
for timer in next:
setFont(bus,0)
if(timer[3]):
green(bus,bright)
else:
red(bus,bright)
setPos(bus,0,row)
writeText(bus,"%09s, %02u:%02u" % (dayName(timer[2]), timer[0], timer[1]))
row=(row+1)
setFont(bus,120)
blue(bus,bright)
setPos(bus,13,3)
writeText(bus,time.strftime("%H:%M", time.localtime()))
def screenRunning(bus):
global imgSent
sendWord(bus,"DM^")
setFont(bus,120)
black(bus)
if(imgSent):
setPos(bus,13,3)
#writeText(bus,time.strftime("%H:%M", (int(time.localtime())-60)))
else:
imgSent=True
drawImage(bus,0,0,160,128,oled_image2.sun())
setPos(bus,13,3)
def drawImage(bus,x,y,w,h,data):
#sendWord(bus,"SSS")
#print((len(data)+9))
#sendValue(bus,(len(data)+9))
sendWord(bus,"EDIM1")
sendValue(bus,x)
sendValue(bus,y)
sendValue(bus,w)
sendValue(bus,h)
for b in data:
sendValue(bus,b)