-
Notifications
You must be signed in to change notification settings - Fork 3
/
screen.py
executable file
·56 lines (42 loc) · 1.75 KB
/
screen.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
#!/usr/bin/env python3
import serial, math
import time
# COMMANDS
# from lcd_comm_rev_c.py
HELLO = bytearray((0x01, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc5, 0xd3))
OPTIONS = bytearray((0x7d, 0xef, 0x69, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2d))
RESTART = bytearray((0x84, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
TURNOFF = bytearray((0x83, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
TURNON = bytearray((0x83, 0xef, 0x69, 0x00, 0x00, 0x00, 0x00))
SET_BRIGHTNESS = bytearray((0x7b, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00))
# STOP COMMANDS
STOP_VIDEO = bytearray((0x79, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
STOP_MEDIA = bytearray((0x96, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
# IMAGE QUERY STATUS
QUERY_STATUS = bytearray((0xcf, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
# STATIC IMAGE
START_DISPLAY_BITMAP = bytearray((0x2c,))
PRE_UPDATE_BITMAP = bytearray((0x86, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
UPDATE_BITMAP = bytearray((0xcc, 0xef, 0x69, 0x00))
RESTARTSCREEN = bytearray((0x84, 0xef, 0x69, 0x00, 0x00, 0x00, 0x01))
DISPLAY_BITMAP = bytearray((0xc8, 0xef, 0x69, 0x00, 0x17, 0x70))
STARTMODE_DEFAULT = bytearray((0x00,))
STARTMODE_IMAGE = bytearray((0x01,))
STARTMODE_VIDEO = bytearray((0x02,))
FLIP_180 = bytearray((0x01,))
NO_FLIP = bytearray((0x00,))
SEND_PAYLOAD = bytearray((0xFF,))
def pad(message):
msg_size = len(message)
if not (msg_size / 250).is_integer():
pad_size = (250 * math.ceil(msg_size / 250) - msg_size)
message += b"\x00" * pad_size
return message
if __name__ == "__main__":
ser = serial.Serial("/dev/ttyACM0", 115200, timeout=1, rtscts=1)
ser.write(pad(HELLO))
resp = ser.read(22)
print(resp.decode())
ser.write(pad(SET_BRIGHTNESS + b"\x40"))
time.sleep(1)
ser.write(pad(SET_BRIGHTNESS + b"\x00"))