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.