Skip to content

Commit f0b4909

Browse files
committed
DM: add back in soft framebuf stuff
1 parent ece8303 commit f0b4909

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

adafruit_epd/epd.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,55 @@ def data(self, dat):
103103
self.spi_device.write(dat)
104104
self._cs.value = True
105105
self.spi_device.unlock()
106+
107+
def draw_pixel(self, x, y, color):
108+
"""This should be overridden in the subclass"""
109+
pass
110+
111+
#framebuf methods
112+
def fill(self, color):
113+
"""fill the screen with the passed color"""
114+
self.fill_rect(0, 0, self.width, self.height, color)
115+
116+
# pylint: disable=too-many-arguments
117+
def fill_rect(self, x, y, width, height, color):
118+
"""fill a rectangle with the passed color"""
119+
if width < 1 or height < 1 or (x+width) <= 0:
120+
return
121+
if (y+height) <= 0 or y >= self.height or x >= self.width:
122+
return
123+
xend = min(self.width, x+width)
124+
yend = min(self.height, y+height)
125+
x = max(x, 0)
126+
y = max(y, 0)
127+
for _x in range(xend - x):
128+
for _y in range(yend - y):
129+
self.draw_pixel(x + _x, y + _y, color)
130+
return
131+
132+
def pixel(self, x, y, color=None):
133+
"""draw a pixel"""
134+
if x < 0 or x >= self.width or y < 0 or y >= self.height:
135+
return None
136+
#TODO: figure this out when we know what framebuffer we
137+
# will actually use
138+
#if color is None:
139+
# return self.get_pixel(self, x, y)
140+
141+
self.draw_pixel(x, y, color)
142+
return None
143+
144+
def hline(self, x, y, width, color):
145+
"""draw a horizontal line"""
146+
self.fill_rect(x, y, width, 1, color)
147+
148+
def vline(self, x, y, height, color):
149+
"""draw a vertical line"""
150+
self.fill_rect(x, y, 1, height, color)
151+
152+
def rect(self, x, y, width, height, color):
153+
"""draw a rectangle"""
154+
self.fill_rect(x, y, width, 1, color)
155+
self.fill_rect(x, y+height, width, 1, color)
156+
self.fill_rect(x, y, 1, height, color)
157+
self.fill_rect(x+width, y, 1, height, color)

examples/epd_simpletest.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
# clear the buffer
1919
display.clear_buffer()
2020

21-
#draw some lines!!
22-
for i in range(152):
23-
display.draw_pixel(i, i, Adafruit_EPD.RED)
24-
display.draw_pixel(152-i, i, Adafruit_EPD.RED)
25-
display.draw_pixel(10, i, Adafruit_EPD.BLACK)
26-
display.draw_pixel(20, i, Adafruit_EPD.BLACK)
27-
display.draw_pixel(30, i, Adafruit_EPD.BLACK)
28-
display.draw_pixel(40, i, Adafruit_EPD.BLACK)
29-
display.draw_pixel(50, i, Adafruit_EPD.BLACK)
30-
display.draw_pixel(60, i, Adafruit_EPD.BLACK)
31-
display.draw_pixel(70, i, Adafruit_EPD.BLACK)
32-
display.draw_pixel(80, i, Adafruit_EPD.BLACK)
21+
r_width = 5
22+
r_pos = display.height
23+
24+
color = Adafruit_EPD.BLACK
25+
while r_pos > display.height/2:
26+
if r_pos < display.height - 50:
27+
color = Adafruit_EPD.RED
28+
display.rect(display.width - r_pos, display.height - r_pos,
29+
display.width - 2*(display.width - r_pos),
30+
display.height - 2*(display.height - r_pos), color)
31+
r_pos = r_pos - r_width
3332

3433
display.display()

0 commit comments

Comments
 (0)