Skip to content

fix line typo for non-1 lines, added new displaytype for SHARP memory displays #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions adafruit_framebuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
`adafruit_framebuf`
====================================================

CircuitPython frambuf module, based on the Python frambuf module.
CircuitPython pure-python framebuf module, based on the micropython framebuf module.

* Author(s): Kattni Rembor, Tony DiCola, original file created by Damien P. George

Expand All @@ -50,6 +50,35 @@
MVLSB = 0 # Single bit displays (like SSD1306 OLED)
RGB565 = 1 # 16-bit color displays
GS4_HMSB = 2 # Unimplemented!
MHMSB = 3 # Single bit displays like the Sharp Memory

class MHMSBFormat:
"""MHMSBFormat"""
@staticmethod
def set_pixel(framebuf, x, y, color):
"""Set a given pixel to a color."""
index = (y * framebuf.stride + x) // 8
offset = 7 - x & 0x07
framebuf.buf[index] = (framebuf.buf[index] & ~(0x01 << offset)) | ((color != 0) << offset)

@staticmethod
def get_pixel(framebuf, x, y):
"""Get the color of a given pixel"""
index = (y * framebuf.stride + x) // 8
offset = 7 - x & 0x07
return (framebuf.buf[index] >> offset) & 0x01

@staticmethod
def fill_rect(framebuf, x, y, width, height, color):
"""Draw a rectangle at the given location, size and color. The ``fill_rect`` method draws
both the outline and interior."""
# pylint: disable=too-many-arguments
for _x in range(x, x+width):
offset = 7 - _x & 0x07
for _y in range(y, y+height):
index = (_y * framebuf.stride + _x) // 8
framebuf.buf[index] = (framebuf.buf[index] & ~(0x01 << offset)) \
| ((color != 0) << offset)

class MVLSBFormat:
"""MVLSBFormat"""
Expand Down Expand Up @@ -140,6 +169,8 @@ def __init__(self, buf, width, height, buf_format=MVLSB, stride=None):
self.stride = width
if buf_format == MVLSB:
self.format = MVLSBFormat()
elif buf_format == MHMSB:
self.format = MHMSBFormat()
elif buf_format == RGB565:
self.format = RGB565Format()
else:
Expand Down Expand Up @@ -209,13 +240,13 @@ def line(self, x_0, y_0, x_1, y_1, color):
else:
err = d_y / 2.0
while y != y_1:
self.pixel(x, y, 1)
self.pixel(x, y, color)
err -= d_x
if err < 0:
x += s_x
err += d_y
y += s_y
self.pixel(x, y, 1)
self.pixel(x, y, color)

def blit(self):
"""blit is not yet implemented"""
Expand All @@ -227,11 +258,7 @@ def scroll(self):

def text(self, string, x, y, color, *,
font_name="font5x8.bin"):
"""Write an ascii string to location (x, y) as the bottom left corner,
in a given color, in left-to-right fashion.
Does not handle text wrapping. You can also pass in a font_name, but
this has to be generated as a special binary format and placed in the
working directory of the main script (so, probably /)"""
"""text is not yet implemented"""
if not self._font or self._font.font_name != font_name:
# load the font!
self._font = BitmapFont()
Expand Down