peterhinch / micropython-font-to-py

A Python 3 utility to convert fonts to Python source capable of being frozen as bytecode
MIT License
368 stars 67 forks source link

sh1106 compatability #12

Closed pacmac closed 5 years ago

pacmac commented 5 years ago

Hi Peter;

https://github.com/robert-hh/SH1106

Am trying to use the writer with the sh1106 but I get:

ValueError: Device must be derived from FrameBuffer.

But it looks like this is derived from framebuffer ??

import sh1106
>>> ssd = sh1106.SH1106_I2C(128, 64, gpio.i2c)
>>> dir(ssd)
['__class__', '__dict__', '__init__', '__module__', '__qualname__', 'addr', 'blit', 'buffer', 'fill', 'fill_rect', 'framebuf', 'hline', 'invert', 'line', 'pixel', 'rect', 'reset', 'scroll', 'sleep', 'text', 'vline', 'res', 'init_display', 'poweroff', 'poweron', 'contrast', 'show', 'width', 'height', 'external_vcc', 'pages', 'write_cmd', 'write_data', 'i2c', 'temp', 'rotate', 'hw_write_data', 'sw_write_data']
peterhinch commented 5 years ago

If you look at the driver code you'll see that the framebuf results from composition rather than inheritance. I guess it was written before the facility to inherit from framebuf was developed.

pacmac commented 5 years ago

I managed to successfully convert the driver to inheritance:

https://github.com/pacmac/micropython-share/blob/master/sh1106_i2c.py

peterhinch commented 5 years ago

I suggest you submit a PR: I'm sure Robert will appreciate it. Subclassing framebuf offers the benefit of providing the framebuf graphics primitives at zero cost.