Skip to content

Commit 2247330

Browse files
committed
DM: add framebuf methods
1 parent 284c65b commit 2247330

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed

Adafruit_EPD/epd.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,51 @@ def data(self, d):
7474
self._dc.value = True
7575
self.spi_device.write(d)
7676
self._cs.value = True
77-
self.spi_device.unlock()
77+
self.spi_device.unlock()
78+
79+
#framebuf methods
80+
def fill(self, color):
81+
self.format.fill_rect(self, 0, 0, self.width, self.height, color)
82+
83+
def fill_rect(self, x, y, width, height, color):
84+
if width < 1 or height < 1 or (x+width) <= 0 or (y+height) <= 0 or y >= self.height or x >= self.width:
85+
return
86+
xend = min(self.width, x+width)
87+
yend = min(self.height, y+height)
88+
x = max(x, 0)
89+
y = max(y, 0)
90+
for _x in range(xend - x):
91+
for _y in range(yend - y):
92+
self.draw_pixel(x + _x, y + _y, color)
93+
94+
def pixel(self, x, y, color=None):
95+
if x < 0 or x >= self.width or y < 0 or y >= self.height:
96+
return
97+
if color is None:
98+
return self.get_pixel(self, x, y)
99+
else:
100+
self.draw_pixel(self, x, y, color)
101+
102+
def hline(self, x, y, width, color):
103+
self.fill_rect(x, y, width, 1, color)
104+
105+
def vline(self, x, y, height, color):
106+
self.fill_rect(x, y, 1, height, color)
107+
108+
def rect(self, x, y, width, height, color):
109+
self.fill_rect(x, y, width, 1, color)
110+
self.fill_rect(x, y+height, width, 1, color)
111+
self.fill_rect(self, x, y, 1, height, color)
112+
self.fill_rect(self, x+width, y, 1, height, color)
113+
114+
def line(self):
115+
raise NotImplementedError()
116+
117+
def blit(self):
118+
raise NotImplementedError()
119+
120+
def scroll(self):
121+
raise NotImplementedError()
122+
123+
def text(self):
124+
raise NotImplementedError()

Adafruit_EPD/il0373.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ def draw_pixel(self, x, y, color):
149149

150150
self.sram.write8(addr, c)
151151

152+
def get_pixel(self, x, y, color):
153+
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):
154+
return
155+
156+
if x == 0:
157+
x = 1
158+
159+
addr = int(((self.width - x) * self.height + y)/8)
160+
if color == Adafruit_EPD.RED:
161+
addr = addr + self.bw_bufsize
162+
c = self.sram.read8(addr)
163+
return c
164+
152165
def clear_buffer(self):
153166
self.sram.erase(0x00, self.bw_bufsize, 0xFF)
154167
self.sram.erase(self.bw_bufsize, self.red_bufsize, 0xFF)

examples/basic_154.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,9 @@
1919
#clear the buffer
2020
display.clear_buffer()
2121

22-
#draw some lines!!
23-
for i in range(152):
24-
display.draw_pixel(i, i, Adafruit_EPD.RED)
25-
display.draw_pixel(152-i, i, Adafruit_EPD.RED)
26-
display.draw_pixel(10, i, Adafruit_EPD.BLACK)
27-
display.draw_pixel(20, i, Adafruit_EPD.BLACK)
28-
display.draw_pixel(30, i, Adafruit_EPD.BLACK)
29-
display.draw_pixel(40, i, Adafruit_EPD.BLACK)
30-
display.draw_pixel(50, i, Adafruit_EPD.BLACK)
31-
display.draw_pixel(60, i, Adafruit_EPD.BLACK)
32-
display.draw_pixel(70, i, Adafruit_EPD.BLACK)
33-
display.draw_pixel(80, i, Adafruit_EPD.BLACK)
22+
#draw some arbitrary lines and shapes!!
23+
display.fill_rect(30, 20, 50, 60, Adafruit_EPD.RED)
24+
display.hline(120, 30, 60, Adafruit_EPD.BLACK)
25+
display.vline(120, 30, 60, Adafruit_EPD.BLACK)
3426

3527
display.display()

0 commit comments

Comments
 (0)