Skip to content

lcd_sdk

Classes:

Name Description
LcdSdkManager

Lcd SDK manager.

LcdSdkManager

LcdSdkManager(name: str, lcd_type: LcdType)

Lcd SDK manager.

Create Lcd SDK manager.

Parameters:

Name Type Description Default

name

str

A name of the LCD

required

lcd_type

LcdType

An integer representing the type of the LCD

required

Methods:

Name Description
clear_display

Clear display.

logi_lcd_color_set_background

Set an array of pixels as a rectangular area, 320 bytes wide and 240 bytes high.

logi_lcd_color_set_text

Set the specified text in the requested line on the color lcd device connected.

logi_lcd_color_set_title

Set the specified text in the first line on the color lcd device connected.

logi_lcd_init

Make the necessary initializations.

logi_lcd_is_button_pressed

Check if the button specified by the parameter is being pressed.

logi_lcd_is_connected

Check if a device of the type specified by the parameter is connected.

logi_lcd_mono_set_background

Set pixels as a rectangular area, 160 bytes wide and 43 bytes high.

logi_lcd_mono_set_text

Set the specified text in the requested line on the monochrome lcd device connected.

logi_lcd_shutdown

Kill the applet and frees memory used by the SDK.

logi_lcd_update

Update the LCD.

update_display

Update display LCD with image.

update_text

Update display LCD with a list of a text.

Source code in src/dcspy/sdk/lcd_sdk.py
18
19
20
21
22
23
24
25
26
27
28
29
def __init__(self, name: str, lcd_type: LcdType) -> None:
    """
    Create Lcd SDK manager.

    :param name: A name of the LCD
    :param lcd_type: An integer representing the type of the LCD
    """
    result = None
    if lcd_type != LcdType.NONE:
        self.lcd_dll: Lib = load_dll(LcdDll)  # type: ignore[assignment]
        result = self.logi_lcd_init(name=name, lcd_type=lcd_type)
    LOG.debug(f'LCD is connected: {result}')

clear_display

clear_display(true_clear: bool = False) -> None

Clear display.

Parameters:

Name Type Description Default

true_clear

bool
False
Source code in src/dcspy/sdk/lcd_sdk.py
187
188
189
190
191
192
193
194
195
196
197
def clear_display(self, true_clear: bool = False) -> None:
    """
    Clear display.

    :param true_clear:
    """
    if self.logi_lcd_is_connected(LcdType.MONO):
        self._clear_mono(true_clear)
    elif self.logi_lcd_is_connected(LcdType.COLOR):
        self._clear_color(true_clear)
    self.logi_lcd_update()

logi_lcd_color_set_background

logi_lcd_color_set_background(
    pixels: list[tuple[int, int, int, int]],
) -> bool

Set an array of pixels as a rectangular area, 320 bytes wide and 240 bytes high.

Since the color lcd can display the full RGB gamma, 32 bits per pixel (4-bytes) are used. The size of the colorBitmap array has to be 320x240x4 = 307,200 therefore. Note: In order to use this function, the image size must be 320x240

Parameters:

Name Type Description Default

pixels

list[tuple[int, int, int, int]]

List of 320x240x4 pixels as integers

required

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def logi_lcd_color_set_background(self, pixels: list[tuple[int, int, int, int]]) -> bool:
    """
    Set an array of pixels as a rectangular area, 320 bytes wide and 240 bytes high.

    Since the color lcd can display the full RGB gamma, 32 bits per pixel (4-bytes) are used.
    The size of the colorBitmap array has to be 320x240x4 = 307,200 therefore.
    Note: In order to use this function, the image size must be 320x240
    :param pixels: List of 320x240x4 pixels as integers
    :return: A result of execution
    """
    img_bytes = [byte for pixel in pixels for byte in pixel]
    with suppress(AttributeError, CDefError):  # we need catch error since BYTE[] is a Windows specific
        return self.lcd_dll.LogiLcdColorSetBackground(FFI().new('BYTE[]', img_bytes))  # type: ignore[attr-defined]
    return False

logi_lcd_color_set_text

logi_lcd_color_set_text(
    line_no: int,
    text: str,
    rgb: tuple[int, int, int] = (255, 255, 255),
) -> bool

Set the specified text in the requested line on the color lcd device connected.

If you don't specify any color, your title will be white.

Parameters:

Name Type Description Default

line_no

int

The color LCD has eight (8) lines for standard text

required

text

str

defines the text you want to display

required

rgb

tuple[int, int, int]

tuple with integer values between 0 and 255 (interpreted as red, green or blue)

(255, 255, 255)

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
135
136
137
138
139
140
141
142
143
144
145
146
147
def logi_lcd_color_set_text(self, line_no: int, text: str, rgb: tuple[int, int, int] = (255, 255, 255)) -> bool:
    """
    Set the specified text in the requested line on the color lcd device connected.

    If you don't specify any color, your title will be white.
    :param line_no: The color LCD has eight (8) lines for standard text
    :param text: defines the text you want to display
    :param rgb: tuple with integer values between 0 and 255 (interpreted as red, green or blue)
    :return: A result of execution
    """
    with suppress(AttributeError):
        return self.lcd_dll.LogiLcdColorSetText(line_no, FFI().new('wchar_t[]', text), *rgb)  # type: ignore[attr-defined]
    return False

logi_lcd_color_set_title

logi_lcd_color_set_title(
    text: str, rgb: tuple[int, int, int] = (255, 255, 255)
) -> bool

Set the specified text in the first line on the color lcd device connected.

The font size that will be displayed is bigger than the one used in the other lines, so you can use this function to set the title of your applet/page. If you don't specify any color, your title will be white.

Parameters:

Name Type Description Default

text

str

The text to display as a title

required

rgb

tuple[int, int, int]

a tuple with integer values between 0 and 255 as red, green, blue

(255, 255, 255)

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def logi_lcd_color_set_title(self, text: str, rgb: tuple[int, int, int] = (255, 255, 255)) -> bool:
    """
    Set the specified text in the first line on the color lcd device connected.

    The font size that will be displayed is bigger than the one used in the other lines,
    so you can use this function to set the title of your applet/page.
    If you don't specify any color, your title will be white.
    :param text: The text to display as a title
    :param rgb: a tuple with integer values between 0 and 255 as red, green, blue
    :return: A result of execution
    """
    with suppress(AttributeError):
        return self.lcd_dll.LogiLcdColorSetTitle(FFI().new('wchar_t[]', text), *rgb)  # type: ignore[attr-defined]
    return False

logi_lcd_init

logi_lcd_init(name: str, lcd_type: LcdType) -> bool

Make the necessary initializations.

You must call this function prior to any other function in the library.

Parameters:

Name Type Description Default

name

str

The name of your applet, you can't change it after initialization

required

lcd_type

LcdType

LCD type

required

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
31
32
33
34
35
36
37
38
39
40
41
42
def logi_lcd_init(self, name: str, lcd_type: LcdType) -> bool:
    """
    Make the necessary initializations.

    You must call this function prior to any other function in the library.
    :param name: The name of your applet, you can't change it after initialization
    :param lcd_type: LCD type
    :return: A result of execution
    """
    with suppress(AttributeError):
        return self.lcd_dll.LogiLcdInit(FFI().new('wchar_t[]', name), lcd_type.value)  # type: ignore[attr-defined]
    return False

logi_lcd_is_button_pressed

logi_lcd_is_button_pressed(button: LcdButton) -> bool

Check if the button specified by the parameter is being pressed.

Parameters:

Name Type Description Default

button

LcdButton

Defines the button to check on

required

Returns:

Type Description
bool

True if a button is being pressed, False otherwise

Source code in src/dcspy/sdk/lcd_sdk.py
55
56
57
58
59
60
61
62
63
64
def logi_lcd_is_button_pressed(self, button: LcdButton) -> bool:
    """
    Check if the button specified by the parameter is being pressed.

    :param button: Defines the button to check on
    :return: True if a button is being pressed, False otherwise
    """
    with suppress(AttributeError):
        return self.lcd_dll.LogiLcdIsButtonPressed(button.value)  # type: ignore[attr-defined]
    return False

logi_lcd_is_connected

logi_lcd_is_connected(lcd_type: LcdType) -> bool

Check if a device of the type specified by the parameter is connected.

Parameters:

Name Type Description Default

lcd_type

LcdType

LCD type

required

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
44
45
46
47
48
49
50
51
52
53
def logi_lcd_is_connected(self, lcd_type: LcdType) -> bool:
    """
    Check if a device of the type specified by the parameter is connected.

    :param lcd_type: LCD type
    :return: A result of execution
    """
    with suppress(AttributeError):
        return self.lcd_dll.LogiLcdIsConnected(lcd_type.value)  # type: ignore[attr-defined]
    return False

logi_lcd_mono_set_background

logi_lcd_mono_set_background(pixels: list[int]) -> bool

Set pixels as a rectangular area, 160 bytes wide and 43 bytes high.

Despite the display being monochrome, 8 bits per pixel are used here for simple manipulation of individual pixels.

Note: In order to use this function, the image size must be 160x43. The SDK will turn on the pixel on the screen if the value assigned to that byte is >= 128, it will remain off if the value is < 128.

Parameters:

Name Type Description Default

pixels

list[int]

List of 6880 (160x43) pixels as integer

required

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def logi_lcd_mono_set_background(self, pixels: list[int]) -> bool:
    """
    Set pixels as a rectangular area, 160 bytes wide and 43 bytes high.

    Despite the display being monochrome, 8 bits per pixel are used here for simple
    manipulation of individual pixels.

    Note: In order to use this function, the image size must be 160x43.
    The SDK will turn on the pixel on the screen if the value assigned to that byte is >= 128, it will remain off
    if the value is < 128.
    :param pixels: List of 6880 (160x43) pixels as integer
    :return: A result of execution
    """
    with suppress(AttributeError, CDefError):  # we need catch error since BYTE[] is a Windows specific
        return self.lcd_dll.LogiLcdMonoSetBackground(FFI().new('BYTE[]', pixels))  # type: ignore[attr-defined]
    return False

logi_lcd_mono_set_text

logi_lcd_mono_set_text(line_no: int, text: str) -> bool

Set the specified text in the requested line on the monochrome lcd device connected.

Parameters:

Name Type Description Default

line_no

int

The monochrome LCD has four (4) lines, so this parameter can be any number from zero (0) to three (3)

required

text

str

The text to display

required

Returns:

Type Description
bool

A result of execution

Source code in src/dcspy/sdk/lcd_sdk.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def logi_lcd_mono_set_text(self, line_no: int, text: str) -> bool:
    """
    Set the specified text in the requested line on the monochrome lcd device connected.

    :param line_no: The monochrome LCD has four (4) lines, so this parameter can be any number from zero (0) to three (3)
    :param text: The text to display
    :return: A result of execution
    """
    with suppress(AttributeError):
        return self.lcd_dll.LogiLcdMonoSetText(line_no, FFI().new('wchar_t[]', text))  # type: ignore[attr-defined]
    return False

logi_lcd_shutdown

logi_lcd_shutdown() -> None

Kill the applet and frees memory used by the SDK.

Source code in src/dcspy/sdk/lcd_sdk.py
71
72
73
74
def logi_lcd_shutdown(self) -> None:
    """Kill the applet and frees memory used by the SDK."""
    with suppress(AttributeError):
        self.lcd_dll.LogiLcdShutdown()  # type: ignore[attr-defined]

logi_lcd_update

logi_lcd_update() -> None

Update the LCD.

Source code in src/dcspy/sdk/lcd_sdk.py
66
67
68
69
def logi_lcd_update(self) -> None:
    """Update the LCD."""
    with suppress(AttributeError):
        self.lcd_dll.LogiLcdUpdate()  # type: ignore[attr-defined]

update_display

update_display(image: Image) -> None

Update display LCD with image.

Parameters:

Name Type Description Default

image

Image

Image object from the Pillow library

required
Source code in src/dcspy/sdk/lcd_sdk.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
def update_display(self, image: Image.Image) -> None:
    """
    Update display LCD with image.

    :param image: Image object from the Pillow library
    """
    if self.logi_lcd_is_connected(LcdType.MONO):
        self.logi_lcd_mono_set_background(image.get_flattened_data())  # type: ignore[attr-defined]
        self.logi_lcd_update()
    elif self.logi_lcd_is_connected(LcdType.COLOR):
        self.logi_lcd_color_set_background(image.get_flattened_data())  # type: ignore[attr-defined]
        self.logi_lcd_update()
    else:
        LOG.warning('LCD is not connected')

update_text

update_text(txt: list[tuple[str, Color]]) -> None

Update display LCD with a list of a text.

For mono, LCD it takes four (4) elements of the list and displays as four (4) rows. For color, LCD takes eight (8) elements of the list and displays as eight (8) rows.

Parameters:

Name Type Description Default

txt

list[tuple[str, Color]]

List of strings to display, row by row

required
Source code in src/dcspy/sdk/lcd_sdk.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def update_text(self, txt: list[tuple[str, Color]]) -> None:
    """
    Update display LCD with a list of a text.

    For mono, LCD it takes four (4) elements of the list and displays as four (4) rows.
    For color, LCD takes eight (8) elements of the list and displays as eight (8) rows.
    :param txt: List of strings to display, row by row
    """
    title = txt.pop(0)
    title_txt = title[0]
    title_color = rgb(title[1])
    if self.logi_lcd_is_connected(LcdType.MONO):
        for line_no, txt_and_color in enumerate(txt[:4]):
            self.logi_lcd_mono_set_text(line_no, txt_and_color[0])
        self.logi_lcd_update()
    elif self.logi_lcd_is_connected(LcdType.COLOR):
        self.logi_lcd_color_set_title(title_txt, title_color)
        for line_no, txt_and_color in enumerate(txt):
            self.logi_lcd_color_set_text(line_no, txt_and_color[0], rgb(txt_and_color[1]))
        self.logi_lcd_update()
    else:
        LOG.warning('LCD is not connected')