Пример #1
0
    def __init__(self, serial_interface=None, width=16, height=2, undefined='_',
                 selected_font=0, exec_time=0.000001,
                 framebuffer="diff_to_previous", **kwargs):
        super(hd44780, self).__init__(luma.lcd.const.hd44780, serial_interface,
        exec_time=exec_time, **kwargs)

        # Inherited from parallel_device class but multi-inheritence with
        # backlit_device requires it to be initialized here
        self._exec_time = exec_time

        self.capabilities(width * 5, height * 8, 0)
        self.framebuffer = getattr(luma.core.framebuffer, framebuffer)(self)

        # Currently only support 5x8 fonts for the hd44780
        self.font = embedded_fonts(self._const.FONTDATA,
            selected_font=selected_font)
        self.glyph_index = self.font.current.glyph_index
        self.device = self
        self._undefined = undefined
        self._custom = {}

        # Supported modes
        supported = (width, height) in [(16, 2), (16, 4), (20, 2), (20, 4)]
        if not supported:
            raise luma.core.error.DeviceDisplayModeError(
                "Unsupported display mode: {0} x {1}".format(width, height))

        self._initialize_device()
        self.text = ''
        self.command(self._const.CLEAR, exec_time=1e-3 * 1.5)
Пример #2
0
def test_embedded_font(load_all_embedded):
    """
    Tests the embedded_fonts class.  Loads FONTDATA.  Changes current font
    by name and number.  Combines two fonts and verifies that combined
    characters get rendered correctly.
    """
    bmfs = load_all_embedded
    ebf = embedded_fonts(FONTDATA)

    assert ebf.current == ebf.font_by_number[0]
    ebf.current = 'A02'
    assert ebf.current == ebf.font_by_number[1]
    a02fnt = ebf.current
    ebf.current = 0
    assert ebf.current == ebf.font_by_number[0]

    ebf.combine(a02fnt)

    img1 = Image.new('1', (10, 8), 0)
    drw = ImageDraw.Draw(img1)
    drw.text(((0, 0)), '\u00a5\u25c0', font=ebf, fill='white', spacing=0)

    img2 = Image.new('1', (10, 8), 0)
    drw = ImageDraw.Draw(img2)
    drw.text(((0, 0)), '\u00a5', font=bmfs[0], fill='white', spacing=0)
    drw.text(((5, 0)), '\u25c0', font=bmfs[1], fill='white', spacing=0)

    assert img1 == img2
Пример #3
0
def test_embedded_font_exceptions():
    """
    Tests exceptions when attempting to select a font that does not exist
    within the ``embedded_fonts`` object
    """
    ebf = embedded_fonts(FONTDATA)

    with pytest.raises(ValueError) as ex:
        ebf.current = 2
    assert str(ex.value) == 'No font with index 2'

    with pytest.raises(ValueError) as ex:
        ebf.current = 'BAD'
    assert str(ex.value) == 'No font with name BAD'

    with pytest.raises(TypeError) as ex:
        ebf.current = []
    assert str(ex.value) == f'Expected int or str.  Received {type([])}'
Пример #4
0
    def __init__(self, serial_interface=None, width=100, height=16, undefined='_', font=None, selected_font=0, exec_time=1e-6 * 50, rotate=0, framebuffer="diff_to_previous", const=luma.oled.const.ws0010, **kwargs):
        super(ws0010, self).__init__(const, serial_interface, exec_time=exec_time, **kwargs)
        self.capabilities(width, height, rotate)
        self.framebuffer = getattr(luma.core.framebuffer, framebuffer)(self)
        self.font = font if font is not None else embedded_fonts(self._const.FONTDATA, selected_font=selected_font)
        self._undefined = undefined
        self.device = self

        # Supported modes
        supported = (width, height) in [(40, 8), (40, 16), (60, 8), (60, 16), (80, 8), (80, 16), (100, 8), (100, 16)]
        if not supported:
            raise luma.core.error.DeviceDisplayModeError(
                "Unsupported display mode: {0} x {1}".format(width, height))

        # In case display just powered up, sleep to be sure it has finished
        # its internal initialization
        sleep(0.5)
        self._reset()
        self.text = ""