23
23
`adafruit_framebuf`
24
24
====================================================
25
25
26
- CircuitPython frambuf module, based on the Python frambuf module.
26
+ CircuitPython pure-python framebuf module, based on the micropython framebuf module.
27
27
28
28
* Author(s): Kattni Rembor, Tony DiCola, original file created by Damien P. George
29
29
50
50
MVLSB = 0 # Single bit displays (like SSD1306 OLED)
51
51
RGB565 = 1 # 16-bit color displays
52
52
GS4_HMSB = 2 # Unimplemented!
53
+ MHMSB = 3 # Single bit displays like the Sharp Memory
54
+
55
+ class MHMSBFormat :
56
+ """MHMSBFormat"""
57
+ @staticmethod
58
+ def set_pixel (framebuf , x , y , color ):
59
+ """Set a given pixel to a color."""
60
+ index = (y * framebuf .stride + x ) // 8
61
+ offset = 7 - x & 0x07
62
+ framebuf .buf [index ] = (framebuf .buf [index ] & ~ (0x01 << offset )) | ((color != 0 ) << offset )
63
+
64
+ @staticmethod
65
+ def get_pixel (framebuf , x , y ):
66
+ """Get the color of a given pixel"""
67
+ index = (y * framebuf .stride + x ) // 8
68
+ offset = 7 - x & 0x07
69
+ return (framebuf .buf [index ] >> offset ) & 0x01
70
+
71
+ @staticmethod
72
+ def fill_rect (framebuf , x , y , width , height , color ):
73
+ """Draw a rectangle at the given location, size and color. The ``fill_rect`` method draws
74
+ both the outline and interior."""
75
+ # pylint: disable=too-many-arguments
76
+ for _x in range (x , x + width ):
77
+ offset = 7 - _x & 0x07
78
+ for _y in range (y , y + height ):
79
+ index = (_y * framebuf .stride + _x ) // 8
80
+ framebuf .buf [index ] = (framebuf .buf [index ] & ~ (0x01 << offset )) \
81
+ | ((color != 0 ) << offset )
53
82
54
83
class MVLSBFormat :
55
84
"""MVLSBFormat"""
@@ -140,6 +169,8 @@ def __init__(self, buf, width, height, buf_format=MVLSB, stride=None):
140
169
self .stride = width
141
170
if buf_format == MVLSB :
142
171
self .format = MVLSBFormat ()
172
+ elif buf_format == MHMSB :
173
+ self .format = MHMSBFormat ()
143
174
elif buf_format == RGB565 :
144
175
self .format = RGB565Format ()
145
176
else :
@@ -209,13 +240,13 @@ def line(self, x_0, y_0, x_1, y_1, color):
209
240
else :
210
241
err = d_y / 2.0
211
242
while y != y_1 :
212
- self .pixel (x , y , 1 )
243
+ self .pixel (x , y , color )
213
244
err -= d_x
214
245
if err < 0 :
215
246
x += s_x
216
247
err += d_y
217
248
y += s_y
218
- self .pixel (x , y , 1 )
249
+ self .pixel (x , y , color )
219
250
220
251
def blit (self ):
221
252
"""blit is not yet implemented"""
@@ -227,11 +258,7 @@ def scroll(self):
227
258
228
259
def text (self , string , x , y , color , * ,
229
260
font_name = "font5x8.bin" ):
230
- """Write an ascii string to location (x, y) as the bottom left corner,
231
- in a given color, in left-to-right fashion.
232
- Does not handle text wrapping. You can also pass in a font_name, but
233
- this has to be generated as a special binary format and placed in the
234
- working directory of the main script (so, probably /)"""
261
+ """text is not yet implemented"""
235
262
if not self ._font or self ._font .font_name != font_name :
236
263
# load the font!
237
264
self ._font = BitmapFont ()
0 commit comments