-
Notifications
You must be signed in to change notification settings - Fork 105
/
drivers_partial.py
596 lines (513 loc) · 21.3 KB
/
drivers_partial.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# Copyright (c) 2018 Jouko Strömmer
# Copyright (c) 2017 Waveshare
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from papertty.drivers.drivers_base import WaveshareEPD
class WavesharePartial(WaveshareEPD):
"""Displays that support partial refresh (*monochrome*): 1.54", 2.13", 2.9".
The code is almost entirely identical with these, just small differences in the 2.13"."""
BOOSTER_SOFT_START_CONTROL = 0x0C
BORDER_WAVEFORM_CONTROL = 0x3C
DATA_ENTRY_MODE_SETTING = 0x11
DEEP_SLEEP_MODE = 0x10
DISPLAY_UPDATE_CONTROL_1 = 0x21
DISPLAY_UPDATE_CONTROL_2 = 0x22
DRIVER_OUTPUT_CONTROL = 0x01
GATE_SCAN_START_POSITION = 0x0F
MASTER_ACTIVATION = 0x20
SET_DUMMY_LINE_PERIOD = 0x3A
SET_GATE_TIME = 0x3B
SET_RAM_X_ADDRESS_COUNTER = 0x4E
SET_RAM_X_ADDRESS_START_END_POSITION = 0x44
SET_RAM_Y_ADDRESS_COUNTER = 0x4F
SET_RAM_Y_ADDRESS_START_END_POSITION = 0x45
SW_RESET = 0x12
TEMPERATURE_SENSOR_CONTROL = 0x1A
TERMINATE_FRAME_READ_WRITE = 0xFF
WRITE_LUT_REGISTER = 0x32
WRITE_RAM = 0x24
WRITE_VCOM_REGISTER = 0x2C
# these LUTs are used by 1.54" and 2.9" - 2.13" overrides them
lut_full_update = [
0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22,
0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88,
0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51,
0x35, 0x51, 0x51, 0x19, 0x01, 0x00
]
lut_partial_update = [
0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.supports_partial = True
self.colors = 2
self.lut = None
def init(self, partial=True):
self.partial_refresh = partial
if self.epd_init() != 0:
return -1
# EPD hardware init start
self.lut = self.lut_partial_update if partial else self.lut_full_update
self.reset()
self.send_command(self.DRIVER_OUTPUT_CONTROL)
self.send_data((self.height - 1) & 0xFF)
self.send_data(((self.height - 1) >> 8) & 0xFF)
self.send_data(0x00) # GD = 0 SM = 0 TB = 0
self.send_command(self.BOOSTER_SOFT_START_CONTROL)
self.send_data(0xD7)
self.send_data(0xD6)
self.send_data(0x9D)
self.send_command(self.WRITE_VCOM_REGISTER)
self.send_data(0xA8) # VCOM 7C
self.send_command(self.SET_DUMMY_LINE_PERIOD)
self.send_data(0x1A) # 4 dummy lines per gate
self.send_command(self.SET_GATE_TIME)
self.send_data(0x08) # 2us per line
self.send_command(self.DATA_ENTRY_MODE_SETTING)
self.send_data(0x03) # X increment Y increment
self.set_lut(self.lut)
# EPD hardware init end
return 0
def wait_until_idle(self):
while self.digital_read(self.BUSY_PIN) == 1: # 0: idle, 1: busy
self.delay_ms(100)
def set_lut(self, lut):
self.lut = lut
self.send_command(self.WRITE_LUT_REGISTER)
# the length of look-up table is 30 bytes
for i in range(0, len(lut)):
self.send_data(self.lut[i])
def get_frame_buffer(self, image):
buf = [0x00] * int(self.width * self.height / 8)
# Set buffer to value of Python Imaging Library image.
# Image must be in mode 1.
image_monocolor = image.convert('1')
imwidth, imheight = image_monocolor.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display \
({0}x{1}).'.format(self.width, self.height))
pixels = image_monocolor.load()
for y in range(self.height):
for x in range(self.width):
# Set the bits for the column of pixels at the current position.
if pixels[x, y] != 0:
buf[int((x + y * self.width) / 8)] |= 0x80 >> (x % 8)
return buf
# this differs with 2.13" but is the same for 1.54" and 2.9"
def set_frame_memory(self, image, x, y):
if image is None or x < 0 or y < 0:
return
image_monocolor = image.convert('1')
image_width, image_height = image_monocolor.size
# x point must be the multiple of 8 or the last 3 bits will be ignored
x = x & 0xF8
image_width = image_width & 0xF8
if x + image_width >= self.width:
x_end = self.width - 1
else:
x_end = x + image_width - 1
if y + image_height >= self.height:
y_end = self.height - 1
else:
y_end = y + image_height - 1
self.set_memory_area(x, y, x_end, y_end)
self.set_memory_pointer(x, y)
self.send_command(self.WRITE_RAM)
# send the image data
pixels = image_monocolor.load()
byte_to_send = 0x00
for j in range(0, y_end - y + 1):
# 1 byte = 8 pixels, steps of i = 8
for i in range(0, x_end - x + 1):
# Set the bits for the column of pixels at the current position.
if pixels[i, j] != 0:
byte_to_send |= 0x80 >> (i % 8)
if i % 8 == 7:
self.send_data(byte_to_send)
byte_to_send = 0x00
def clear_frame_memory(self, color):
self.set_memory_area(0, 0, self.width - 1, self.height - 1)
self.set_memory_pointer(0, 0)
self.send_command(self.WRITE_RAM)
# send the color data
for i in range(0, int(self.width / 8 * self.height)):
self.send_data(color)
def display_frame(self):
self.send_command(self.DISPLAY_UPDATE_CONTROL_2)
self.send_data(0xC4)
self.send_command(self.MASTER_ACTIVATION)
self.send_command(self.TERMINATE_FRAME_READ_WRITE)
self.wait_until_idle()
def set_memory_area(self, x_start, y_start, x_end, y_end):
self.send_command(self.SET_RAM_X_ADDRESS_START_END_POSITION)
# x point must be the multiple of 8 or the last 3 bits will be ignored
self.send_data((x_start >> 3) & 0xFF)
self.send_data((x_end >> 3) & 0xFF)
self.send_command(self.SET_RAM_Y_ADDRESS_START_END_POSITION)
self.send_data(y_start & 0xFF)
self.send_data((y_start >> 8) & 0xFF)
self.send_data(y_end & 0xFF)
self.send_data((y_end >> 8) & 0xFF)
def set_memory_pointer(self, x, y):
self.send_command(self.SET_RAM_X_ADDRESS_COUNTER)
# x point must be the multiple of 8 or the last 3 bits will be ignored
self.send_data((x >> 3) & 0xFF)
self.send_command(self.SET_RAM_Y_ADDRESS_COUNTER)
self.send_data(y & 0xFF)
self.send_data((y >> 8) & 0xFF)
self.wait_until_idle()
def sleep(self):
self.send_command(self.DEEP_SLEEP_MODE)
self.wait_until_idle()
def draw(self, x, y, image):
"""Replace a particular area on the display with an image"""
self.set_frame_memory(image, x, y)
self.display_frame()
if self.partial_refresh:
# set the memory again if partial refresh LUT is used
self.set_frame_memory(image, x, y)
self.display_frame()
class EPD1in54(WavesharePartial):
"""Waveshare 1.54" - monochrome"""
def __init__(self):
super().__init__(name='1.54" BW', width=200, height=200)
class EPD2in13(WavesharePartial):
"""Waveshare 2.13" - monochrome"""
lut_full_update = [
0x22, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x11,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00
]
lut_partial_update = [
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
def __init__(self):
# the actual pixel width is 122, but 128 is the 'logical' width
super().__init__(name='2.13" BW', width=128, height=250)
def set_frame_memory(self, image, x, y):
if image is None or x < 0 or y < 0:
return
image_monocolor = image.convert('1')
image_width, image_height = image_monocolor.size
# x point must be the multiple of 8 or the last 3 bits will be ignored
x = x & 0xF8
image_width = image_width & 0xF8
if x + image_width >= self.width:
x_end = self.width - 1
else:
x_end = x + image_width - 1
if y + image_height >= self.height:
y_end = self.height - 1
else:
y_end = y + image_height - 1
self.set_memory_area(x, y, x_end, y_end)
# send the image data
pixels = image_monocolor.load()
byte_to_send = 0x00
for j in range(y, y_end + 1):
self.set_memory_pointer(x, j)
self.send_command(self.WRITE_RAM)
# 1 byte = 8 pixels, steps of i = 8
for i in range(x, x_end + 1):
# Set the bits for the column of pixels at the current position.
if pixels[i - x, j - y] != 0:
byte_to_send |= 0x80 >> (i % 8)
if i % 8 == 7:
self.send_data(byte_to_send)
byte_to_send = 0x00
class EPD2in13v2(WavesharePartial):
"""Waveshare 2.13" V2 - monochrome"""
lut_full_update = [
0x80,0x60,0x40,0x00,0x00,0x00,0x00, #LUT0: BB: VS 0 ~7
0x10,0x60,0x20,0x00,0x00,0x00,0x00, #LUT1: BW: VS 0 ~7
0x80,0x60,0x40,0x00,0x00,0x00,0x00, #LUT2: WB: VS 0 ~7
0x10,0x60,0x20,0x00,0x00,0x00,0x00, #LUT3: WW: VS 0 ~7
0x00,0x00,0x00,0x00,0x00,0x00,0x00, #LUT4: VCOM: VS 0 ~7
0x03,0x03,0x00,0x00,0x02, # TP0 A~D RP0
0x09,0x09,0x00,0x00,0x02, # TP1 A~D RP1
0x03,0x03,0x00,0x00,0x02, # TP2 A~D RP2
0x00,0x00,0x00,0x00,0x00, # TP3 A~D RP3
0x00,0x00,0x00,0x00,0x00, # TP4 A~D RP4
0x00,0x00,0x00,0x00,0x00, # TP5 A~D RP5
0x00,0x00,0x00,0x00,0x00, # TP6 A~D RP6
0x15,0x41,0xA8,0x32,0x30,0x0A
]
lut_partial_update = [
0x00,0x00,0x00,0x00,0x00,0x00,0x00, #LUT0: BB: VS 0 ~7
0x80,0x00,0x00,0x00,0x00,0x00,0x00, #LUT1: BW: VS 0 ~7
0x40,0x00,0x00,0x00,0x00,0x00,0x00, #LUT2: WB: VS 0 ~7
0x00,0x00,0x00,0x00,0x00,0x00,0x00, #LUT3: WW: VS 0 ~7
0x00,0x00,0x00,0x00,0x00,0x00,0x00, #LUT4: VCOM: VS 0 ~7
0x0A,0x00,0x00,0x00,0x00, # TP0 A~D RP0
0x00,0x00,0x00,0x00,0x00, # TP1 A~D RP1
0x00,0x00,0x00,0x00,0x00, # TP2 A~D RP2
0x00,0x00,0x00,0x00,0x00, # TP3 A~D RP3
0x00,0x00,0x00,0x00,0x00, # TP4 A~D RP4
0x00,0x00,0x00,0x00,0x00, # TP5 A~D RP5
0x00,0x00,0x00,0x00,0x00, # TP6 A~D RP6
0x15,0x41,0xA8,0x32,0x30,0x0A,
]
def __init__(self):
# the actual pixel width is 122, but 128 is the 'logical' width
super().__init__(name='2.13" BW V2 (full refresh only)', width=128, height=250)
class EPD2in9(WavesharePartial):
"""Waveshare 2.9" - monochrome"""
def __init__(self):
super().__init__(name='2.9" BW', width=128, height=296)
class EPD2in13d(WavesharePartial):
"""Waveshare 2.13" D - monochrome (flexible)"""
# Note: the original code for this display was pretty broken and seemed
# to have been written by some other person than the rest of the drivers.
def __init__(self):
super().__init__(name='2.13" D', width=104, height=212)
lut_vcomDC = [
0x00, 0x08, 0x00, 0x00, 0x00, 0x02,
0x60, 0x28, 0x28, 0x00, 0x00, 0x01,
0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
0x00, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
]
lut_ww = [
0x40, 0x08, 0x00, 0x00, 0x00, 0x02,
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
0x40, 0x14, 0x00, 0x00, 0x00, 0x01,
0xA0, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_bw = [
0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
0x90, 0x0F, 0x0F, 0x00, 0x00, 0x03,
0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_wb = [
0x80, 0x08, 0x00, 0x00, 0x00, 0x02,
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
0x80, 0x14, 0x00, 0x00, 0x00, 0x01,
0x50, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_bb = [
0x80, 0x08, 0x00, 0x00, 0x00, 0x02,
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
0x80, 0x14, 0x00, 0x00, 0x00, 0x01,
0x50, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_vcom1 = [
0x00, 0x19, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
]
lut_ww1 = [
0x00, 0x19, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_bw1 = [
0x80, 0x19, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_wb1 = [
0x40, 0x19, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
lut_bb1 = [
0x00, 0x19, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]
def wait_until_idle(self):
"""This particular model's code sends the GET_STATUS command while waiting - dunno why."""
while self.digital_read(self.BUSY_PIN) == 0: # 0: idle, 1: busy
self.send_command(self.GET_STATUS)
self.delay_ms(100)
def init(self, **kwargs):
if self.epd_init() != 0:
return -1
self.reset()
self.send_command(0x01) # POWER SETTING
self.send_data(0x03)
self.send_data(0x00)
self.send_data(0x2b)
self.send_data(0x2b)
self.send_data(0x03)
self.send_command(0x06) # boost soft start
self.send_data(0x17) # A
self.send_data(0x17) # B
self.send_data(0x17) # C
self.send_command(0x04)
self.wait_until_idle()
self.send_command(0x00) # panel setting
self.send_data(0xbf) # LUT from OTP,128x296
self.send_data(0x0d) # VCOM to 0V fast
self.send_command(0x30) # PLL setting
self.send_data(0x3a) # 3a 100HZ 29 150Hz 39 200HZ 31 171HZ
self.send_command(0x61) # resolution setting
self.send_data(self.width)
self.send_data((self.height >> 8) & 0xff)
self.send_data(self.height & 0xff)
self.send_command(0x82) # vcom_DC setting
self.send_data(0x28)
# self.send_command(0X50) #VCOM AND DATA INTERVAL SETTING
# self.send_data(0xb7) #WBmode:VBDF 17|D7 VBDW 97 VBDB 57 WBRmode:VBDF F7 VBDW 77 VBDB 37 VBDR B7
return 0
def set_full_reg(self):
self.send_command(0x82)
self.send_data(0x00)
self.send_command(0X50)
self.send_data(0xb7)
self.send_command(0x20) # vcom
for count in range(0, 44):
self.send_data(self.lut_vcomDC[count])
self.send_command(0x21) # ww --
for count in range(0, 42):
self.send_data(self.lut_ww[count])
self.send_command(0x22) # bw r
for count in range(0, 42):
self.send_data(self.lut_bw[count])
self.send_command(0x23) # wb w
for count in range(0, 42):
self.send_data(self.lut_wb[count])
self.send_command(0x24) # bb b
for count in range(0, 42):
self.send_data(self.lut_bb[count])
def set_part_reg(self):
self.send_command(0x82)
self.send_data(0x03)
self.send_command(0X50)
self.send_data(0x47)
self.send_command(0x20) # vcom
for count in range(0, 44):
self.send_data(self.lut_vcom1[count])
self.send_command(0x21) # ww --
for count in range(0, 42):
self.send_data(self.lut_ww1[count])
self.send_command(0x22) # bw r
for count in range(0, 42):
self.send_data(self.lut_bw1[count])
self.send_command(0x23) # wb w
for count in range(0, 42):
self.send_data(self.lut_wb1[count])
self.send_command(0x24) # bb b
for count in range(0, 42):
self.send_data(self.lut_bb1[count])
def turn_on_display(self):
self.send_command(0x12)
self.delay_ms(10)
self.wait_until_idle()
def clear(self):
self.send_command(0x10)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(0x00)
self.delay_ms(10)
self.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(0xFF)
self.delay_ms(10)
self.set_full_reg()
self.turn_on_display()
def display_full(self, frame_buffer):
if not frame_buffer:
return
self.send_command(0x10)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(0x00)
self.delay_ms(10)
self.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)):
self.send_data(frame_buffer[i])
self.delay_ms(10)
self.set_full_reg()
self.turn_on_display()
def display_partial(self, frame_buffer, x_start, y_start, x_end, y_end):
if not frame_buffer:
return
self.set_part_reg()
self.send_command(0x91)
self.send_command(0x90)
self.send_data(x_start)
self.send_data(x_end - 1)
self.send_data(y_start / 256)
self.send_data(y_start % 256)
self.send_data(y_end / 256)
self.send_data(y_end % 256 - 1)
self.send_data(0x28)
self.send_command(0x10)
for i in range(0, int(self.width * self.height / 8)):
# print(frame_buffer[i],'%d','0x10')
self.send_data(frame_buffer[i])
self.delay_ms(10)
self.send_command(0x13)
for i in range(0, int(self.width * self.height / 8)):
# print(~frame_buffer[i],'%d','0x13')
self.send_data(~frame_buffer[i])
self.delay_ms(10)
# self.set_full_reg()
self.turn_on_display()
# after this, call epd.init() to awaken the module
def sleep(self):
self.send_command(0x50)
self.send_data(0xf7)
self.send_command(0x02) # power off
self.send_command(0x07) # deep sleep
self.send_data(0xA5)
def draw(self, x, y, image):
"""Replace a particular area on the display with an image"""
if self.partial_refresh:
self.display_partial(self.get_frame_buffer(image), x, y, x + image.width, x + image.height)
else:
self.display_full(self.get_frame_buffer(image))