mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 00:14:09 -04:00
g13gui: g13: Add a bitwidgets backend for displaying to the G13
This commit is contained in:
parent
186f64c33f
commit
493206d552
57
g13gui/g13gui/g13/displaydevice.py
Normal file
57
g13gui/g13gui/g13/displaydevice.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import PIL
|
||||||
|
import struct
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
from g13gui.bitwidgets.displaydevice import DisplayDevice
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayMetrics(object):
|
||||||
|
WIDTH_PIXELS = 160
|
||||||
|
HEIGHT_PIXELS = 48
|
||||||
|
|
||||||
|
|
||||||
|
def ImageToLPBM(image):
|
||||||
|
"""Simple function to convert a PIL Image into LPBM format."""
|
||||||
|
|
||||||
|
i = PIL.PyAccess.new(image, readonly=True)
|
||||||
|
bio = BytesIO()
|
||||||
|
|
||||||
|
maxBytes = (DisplayMetrics.WIDTH_PIXELS *
|
||||||
|
DisplayMetrics.HEIGHT_PIXELS // 8)
|
||||||
|
row = 0
|
||||||
|
col = 0
|
||||||
|
|
||||||
|
for byteNum in range(0, maxBytes):
|
||||||
|
b = int()
|
||||||
|
|
||||||
|
if row == 40:
|
||||||
|
maxSubrow = 3
|
||||||
|
else:
|
||||||
|
maxSubrow = 8
|
||||||
|
|
||||||
|
for subrow in range(0, maxSubrow):
|
||||||
|
b |= i[col, row + subrow] << subrow
|
||||||
|
|
||||||
|
bio.write(struct.pack('<B', b))
|
||||||
|
|
||||||
|
col += 1
|
||||||
|
if (col % 160) == 0:
|
||||||
|
col = 0
|
||||||
|
row += 8
|
||||||
|
|
||||||
|
return bio.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
class G13DisplayDevice(DisplayDevice):
|
||||||
|
"""A bitwidget display device for the G13 LCD"""
|
||||||
|
|
||||||
|
def __init__(self, manager):
|
||||||
|
self._manager = manager
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dimensions(self):
|
||||||
|
return (DisplayMetrics.WIDTH_PIXELS, DisplayMetrics.HEIGHT_PIXELS)
|
||||||
|
|
||||||
|
def update(self, image):
|
||||||
|
lpbm = ImageToLPBM(image)
|
||||||
|
self._manager.setLCDBuffer(lpbm)
|
34
g13gui/g13gui/g13/displaydevice_tests.py
Normal file
34
g13gui/g13gui/g13/displaydevice_tests.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import unittest
|
||||||
|
import time
|
||||||
|
|
||||||
|
from g13gui.model.prefs import Preferences
|
||||||
|
from g13gui.bitwidgets.display import Display
|
||||||
|
from g13gui.bitwidgets.screen import Screen
|
||||||
|
from g13gui.bitwidgets.label import Label
|
||||||
|
from g13gui.g13.displaydevice import G13DisplayDevice
|
||||||
|
from g13gui.g13.manager import Manager
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayDeviceTests(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.prefs = Preferences()
|
||||||
|
self.manager = Manager(self.prefs)
|
||||||
|
self.manager.start()
|
||||||
|
time.sleep(0.25)
|
||||||
|
self.dd = G13DisplayDevice(self.manager)
|
||||||
|
self.d = Display(self.dd)
|
||||||
|
self.s = Screen(self.d)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
time.sleep(1)
|
||||||
|
self.manager.shutdown()
|
||||||
|
|
||||||
|
def testDisplay(self):
|
||||||
|
label = Label(0, 0, 'Hello, world!')
|
||||||
|
label.show()
|
||||||
|
self.s.addChild(label)
|
||||||
|
self.s.nextFrame()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user