|
| 1 | +""" |
| 2 | +SSD1327 display wrapper — converts RGB colors to 4-bit grayscale. |
| 3 | +
|
| 4 | +Wraps the raw SSD1327 driver so that steami_screen can pass RGB tuples |
| 5 | +while the hardware receives grayscale values (0-15). |
| 6 | +
|
| 7 | +Usage on the STeaMi board: |
| 8 | + import ssd1327 |
| 9 | + from steami_ssd1327 import SSD1327Display |
| 10 | + raw = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs) |
| 11 | + display = SSD1327Display(raw) |
| 12 | +""" |
| 13 | + |
| 14 | +from steami_screen.colors import rgb_to_gray4 |
| 15 | + |
| 16 | + |
| 17 | +class SSD1327Display: |
| 18 | + """Thin wrapper around an SSD1327 driver that accepts RGB colors.""" |
| 19 | + |
| 20 | + def __init__(self, raw): |
| 21 | + self._raw = raw |
| 22 | + self.width = getattr(raw, 'width', 128) |
| 23 | + self.height = getattr(raw, 'height', 128) |
| 24 | + |
| 25 | + def fill(self, color): |
| 26 | + self._raw.fill(rgb_to_gray4(color)) |
| 27 | + |
| 28 | + def pixel(self, x, y, color): |
| 29 | + self._raw.pixel(x, y, rgb_to_gray4(color)) |
| 30 | + |
| 31 | + def text(self, string, x, y, color): |
| 32 | + self._raw.text(string, x, y, rgb_to_gray4(color)) |
| 33 | + |
| 34 | + def line(self, x1, y1, x2, y2, color): |
| 35 | + self._raw.line(x1, y1, x2, y2, rgb_to_gray4(color)) |
| 36 | + |
| 37 | + def fill_rect(self, x, y, w, h, color): |
| 38 | + self._raw.fill_rect(x, y, w, h, rgb_to_gray4(color)) |
| 39 | + |
| 40 | + def rect(self, x, y, w, h, color): |
| 41 | + self._raw.rect(x, y, w, h, rgb_to_gray4(color)) |
| 42 | + |
| 43 | + def show(self): |
| 44 | + self._raw.show() |
0 commit comments