DM: add framebuf methods
This commit is contained in:
parent
284c65bfbe
commit
2247330c6d
3 changed files with 65 additions and 13 deletions
|
|
@ -74,4 +74,51 @@ class Adafruit_EPD(object):
|
||||||
self._dc.value = True
|
self._dc.value = True
|
||||||
self.spi_device.write(d)
|
self.spi_device.write(d)
|
||||||
self._cs.value = True
|
self._cs.value = True
|
||||||
self.spi_device.unlock()
|
self.spi_device.unlock()
|
||||||
|
|
||||||
|
#framebuf methods
|
||||||
|
def fill(self, color):
|
||||||
|
self.format.fill_rect(self, 0, 0, self.width, self.height, color)
|
||||||
|
|
||||||
|
def fill_rect(self, x, y, width, height, color):
|
||||||
|
if width < 1 or height < 1 or (x+width) <= 0 or (y+height) <= 0 or y >= self.height or x >= self.width:
|
||||||
|
return
|
||||||
|
xend = min(self.width, x+width)
|
||||||
|
yend = min(self.height, y+height)
|
||||||
|
x = max(x, 0)
|
||||||
|
y = max(y, 0)
|
||||||
|
for _x in range(xend - x):
|
||||||
|
for _y in range(yend - y):
|
||||||
|
self.draw_pixel(x + _x, y + _y, color)
|
||||||
|
|
||||||
|
def pixel(self, x, y, color=None):
|
||||||
|
if x < 0 or x >= self.width or y < 0 or y >= self.height:
|
||||||
|
return
|
||||||
|
if color is None:
|
||||||
|
return self.get_pixel(self, x, y)
|
||||||
|
else:
|
||||||
|
self.draw_pixel(self, x, y, color)
|
||||||
|
|
||||||
|
def hline(self, x, y, width, color):
|
||||||
|
self.fill_rect(x, y, width, 1, color)
|
||||||
|
|
||||||
|
def vline(self, x, y, height, color):
|
||||||
|
self.fill_rect(x, y, 1, height, color)
|
||||||
|
|
||||||
|
def rect(self, x, y, width, height, color):
|
||||||
|
self.fill_rect(x, y, width, 1, color)
|
||||||
|
self.fill_rect(x, y+height, width, 1, color)
|
||||||
|
self.fill_rect(self, x, y, 1, height, color)
|
||||||
|
self.fill_rect(self, x+width, y, 1, height, color)
|
||||||
|
|
||||||
|
def line(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def blit(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def scroll(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def text(self):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
@ -149,6 +149,19 @@ class Adafruit_IL0373(Adafruit_EPD):
|
||||||
|
|
||||||
self.sram.write8(addr, c)
|
self.sram.write8(addr, c)
|
||||||
|
|
||||||
|
def get_pixel(self, x, y, color):
|
||||||
|
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):
|
||||||
|
return
|
||||||
|
|
||||||
|
if x == 0:
|
||||||
|
x = 1
|
||||||
|
|
||||||
|
addr = int(((self.width - x) * self.height + y)/8)
|
||||||
|
if color == Adafruit_EPD.RED:
|
||||||
|
addr = addr + self.bw_bufsize
|
||||||
|
c = self.sram.read8(addr)
|
||||||
|
return c
|
||||||
|
|
||||||
def clear_buffer(self):
|
def clear_buffer(self):
|
||||||
self.sram.erase(0x00, self.bw_bufsize, 0xFF)
|
self.sram.erase(0x00, self.bw_bufsize, 0xFF)
|
||||||
self.sram.erase(self.bw_bufsize, self.red_bufsize, 0xFF)
|
self.sram.erase(self.bw_bufsize, self.red_bufsize, 0xFF)
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,9 @@ display = Adafruit_IL0373(152, 152, rst, dc, busy, srcs, ecs, spi)
|
||||||
#clear the buffer
|
#clear the buffer
|
||||||
display.clear_buffer()
|
display.clear_buffer()
|
||||||
|
|
||||||
#draw some lines!!
|
#draw some arbitrary lines and shapes!!
|
||||||
for i in range(152):
|
display.fill_rect(30, 20, 50, 60, Adafruit_EPD.RED)
|
||||||
display.draw_pixel(i, i, Adafruit_EPD.RED)
|
display.hline(120, 30, 60, Adafruit_EPD.BLACK)
|
||||||
display.draw_pixel(152-i, i, Adafruit_EPD.RED)
|
display.vline(120, 30, 60, Adafruit_EPD.BLACK)
|
||||||
display.draw_pixel(10, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(20, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(30, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(40, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(50, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(60, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(70, i, Adafruit_EPD.BLACK)
|
|
||||||
display.draw_pixel(80, i, Adafruit_EPD.BLACK)
|
|
||||||
|
|
||||||
display.display()
|
display.display()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue