luma.core.device

class luma.core.device.device(const=None, serial_interface=None)[source]

Bases: luma.core.mixin.capabilities

Base class for display driver classes

Note

Direct use of the command() and data() methods are discouraged: Screen updates should be effected through the display() method, or preferably with the luma.core.render.canvas context manager.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters
  • width (int) – The device width.

  • height (int) – The device height.

  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.

cleanup()[source]

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)[source]

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)[source]

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters

level (int) – Desired contrast level in the range of 0-255.

data(data)[source]

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)

Should be overridden in sub-classed implementations.

Parameters

image (PIL.Image.Image) – An image to display.

Raises

NotImplementedError

hide()[source]

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters

image (PIL.Image.Image) – An image to pre-process.

Returns

A new processed image.

Return type

PIL.Image.Image

show()[source]

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.core.device.dummy(width=128, height=64, rotate=0, mode='RGB', **kwargs)[source]

Bases: luma.core.device.device

Pseudo-device that acts like a physical display, except that it does nothing other than retain a copy of the displayed image. It is mostly useful for testing. Supports 24-bit color depth.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters
  • width (int) – The device width.

  • height (int) – The device height.

  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.

cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters

level (int) – Desired contrast level in the range of 0-255.

data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and makes a copy of it for later use/inspection.

Parameters

image (PIL.Image.Image) – Image to display.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters

image (PIL.Image.Image) – An image to pre-process.

Returns

A new processed image.

Return type

PIL.Image.Image

show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.core.device.linux_framebuffer(device=None, framebuffer=None, bgr=False, **kwargs)[source]

Bases: luma.core.device.device

Pseudo-device that acts like a physical display, except that it renders to a Linux framebuffer device at /dev/fbN (where N=0, 1, …). This is specifically targetted to allow the luma classes to be used on higher-resolution displays that leverage kernel-based display drivers.

Parameters
  • device – the Linux framebuffer device (e.g. /dev/fb0). If no device is given, the device is determined from the FRAMEBUFFER environmental variable instead. See https://www.kernel.org/doc/html/latest/fb/framebuffer.html for more details.

  • framebuffer – Framebuffer rendering strategy, currently instances of diff_to_previous (default, if not specified) or full_frame.

  • bgr – Set to True if device pixels are BGR order (rather than RGB). Note: this flag is currently supported on 24 and 32-bit color depth devices only.

New in version 2.0.0.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters
  • width (int) – The device width.

  • height (int) – The device height.

  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.

cleanup()[source]

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd)

Sends a command or sequence of commands through to the delegated serial interface.

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters

level (int) – Desired contrast level in the range of 0-255.

data(data)

Sends a data byte or sequence of data bytes through to the delegated serial interface.

display(image)[source]

Takes a PIL.Image and converts it for consumption on the given /dev/fbX framebuffer device.

Parameters

image (PIL.Image.Image) – Image to display.

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters

image (PIL.Image.Image) – An image to pre-process.

Returns

A new processed image.

Return type

PIL.Image.Image

show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.

class luma.core.device.parallel_device(const=None, serial_interface=None, exec_time=None, **kwargs)[source]

Bases: luma.core.device.device

Wrapper class to manage communications with devices that can operate in four or eight bit modes.

Note

parallel_devices require specific timings which are managed by using time.sleep to cause the process to block for small amounts of time. If your application is especially time sensitive, consider running the drivers in a separate thread.

New in version 1.16.0.

capabilities(width, height, rotate, mode='1')

Assigns attributes such as width, height, size and bounding_box correctly oriented from the supplied parameters.

Parameters
  • width (int) – The device width.

  • height (int) – The device height.

  • rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

  • mode (str) – The supported color model, one of "1", "RGB" or "RGBA" only.

cleanup()

Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

If persist is True, the device will not be switched off.

This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

clear()

Initializes the device memory with an empty (blank) image.

command(*cmd, exec_time=None, only_low_bits=False)[source]

Sends a command or sequence of commands through to the serial interface. If operating in four bit mode, expands each command from one byte values (8 bits) to two nibble values (4 bits each)

Parameters
  • cmd (int) – A spread of commands.

  • exec_time (float) – Amount of time to wait for the command to finish execution. If not provided, the device default will be used instead

  • only_low_bits (bool) – If True, only the lowest four bits of the command will be sent. This is necessary on some devices during initialization

contrast(level)

Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

Parameters

level (int) – Desired contrast level in the range of 0-255.

data(data)[source]

Sends a sequence of bytes through to the serial interface. If operating in four bit mode, expands each byte from a single value (8 bits) to two nibble values (4 bits each)

Parameters

data (list) – a sequence of bytes to send to the display

display(image)

Should be overridden in sub-classed implementations.

Parameters

image (PIL.Image.Image) – An image to display.

Raises

NotImplementedError

hide()

Switches the display mode OFF, putting the device in low-power sleep mode.

preprocess(image)

Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the super method.

Parameters

image (PIL.Image.Image) – An image to pre-process.

Returns

A new processed image.

Return type

PIL.Image.Image

show()

Sets the display mode ON, waking the device out of a prior low-power sleep mode.