WS0010Display

class quanser.devices.interfaces.WS0010Display

A Python wrapper for the Quanser Devices API interface to Sitronix WS0010 displays.

Example

>>> from quanser.devices import WS0010Display
>>> display = WS0010Display()
close()

Close the display.

Example

>>> from quanser.devices import WS0010Display
>>> display = WS0010Display()
>>> display.open("lcd://qbotplatform:1")
>>> ...
...
>>> display.close()
drawImage(pixel_row, pixel_column, image_size, image)

Draw an image on the display at the given pixel coordinates. The display is not cleared before drawing the image, so multiple images may be drawn at different locations on the display.

Parameters
  • pixel_row (int) – The pixel row at which to place the top edge of the image. A value of 0 corresponds to the top of the display.

  • pixel_column (int) – The pixel column at which to place the left edge of the image. A value of 0 corresponds to the left edge of the display.

  • image_size ((int, int)) – A tuple containing the height and width of the image as (height, width).

  • image (image) – The image to display as a 2D uint8 array that is image_height x image_width pixels and is stored in column-major order in memory. Each byte represents a single pixel in which a value less than or equal to 127 is either white or black, depending on whether dark mode is enabled, and a value greater than 127 is the opposite colour.

Examples

Draw a bitmap on the OLED display.

>>> from quanser.devices import WS0010Display
>>> import cv2
>>> display = WS0010Display()
>>> display.open("lcd://qbotplatform:1", True)
>>> img = cv2.imread('Sample.png', cv2.IMREAD_GRAYSCALE)
>>> # Transpose to convert row major to column major. Copy to make C-continuous.
>>> img_col_major = img.transpose().copy()
>>> display.drawImage(0, 0, img_col_major.shape, img_col_major)
>>> ...
...
>>> display.close()
open(uri='lcd://qbot_platform:1', graphics_mode=False)

Opens the WS0010 display.

Parameters
  • uri (string) – The URI indicating the communication channel with which to communicate with the display. For QBot Platform’s display, the URI should be “lcd://qbot_platform:1”. If this parameter is not specified, the default URI is set for the QBot Platform’s LCD display.

  • graphics_mode (bool) – True to use graphics mode. False to use text mode (the default).

Example

>>> from quanser.devices import WS0010Display
>>> display = WS0010Display()
>>> display.open("lcd://qbot_platform:1")
>>> ...
...
>>> display.close()
printText(line, column, message, length)

Print to the display.

Parameters
  • line (int) – The line where the message will be displayed. Line 0 is the first line.

  • column (int) – The column where the message will be displayed. Column 0 is the first column.

  • message (string) –

    The message to display. Unrecognized characters are skipped. If more than 16 characters would be printed on a line then the line is truncated. A newline will cause the characters to be displayed on the next line. As there are only two lines on the display there should only be one newline in the format string. Printing starts at the given line and column. Line 0 is the first line and column 0 is the first column.

    The format string is UTF-8 and does support Unicode (particularly, Katakana characters).

  • length (int) – The length of the message.

Example

Print ‘Hello, World!’ to the top, left corner of the display.

>>> from quanser.devices import WS0010Display
>>> display = WS0010Display()
>>> display.open("lcd://qbotplatform:1")
>>> message = "Hello, world!"
>>> display.printText(0, 0, message, len(message))
>>> ...
...
>>> display.close()
setCharacter(code, pattern)

Defines the character associated with the given character code.

Parameters
  • code (int) – Defines the character associated with the given character code. Valid character codes are 0x10 to 0x17 i.e., ‘’ to ‘’. Using these characters will produce the bitmap defined in the pattern for that character.

  • pattern (bytes) –

    The pattern defines each line of the character being defined, with the five bits in each byte defining the pixels of that line. For example to define the letter T, the pattern would be:

    pattern = b’@@@@@@'

    0b00011111 () 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000000 () <= should generally be zero to allow for cursor

    Note that only bits 0-4 are used. Bit 0 is the rightmost pixel and bit 4 is the leftmost pixel.

Examples

Print a custom character with three lines along the top, middle and bottom.

>>> from quanser.devices import WS0010Display
>>> display = WS0010Display()
>>> display.open("lcd://qbotplatform:1")
>>> character_code = 0o20
>>> pattern = b''
>>> display.setCharacter(character_code, pattern)
>>> message = str(chr(character_code))
>>> display.printText(0, 0, message, len(message))
>>> ...
...
>>> display.close()

Print a pair of custom characters that give the appearance of a wifi signal strength indicator.

>>> from quanser.devices import WS0010Display
>>> display = WS0010Display()
>>> display.open("lcd://qbotplatform:1")
>>> character_code_left = 0o20
>>> pattern_left = b''
>>> character_code_right = 0o21
>>> pattern_right = b''
>>> display.setCharacter(character_code_left, pattern_left)
>>> display.setCharacter(character_code_right, pattern_right)
>>> message = str(chr(character_code_left)) + str(chr(character_code_right))
>>> display.printText(1, 1, message, len(message))
>>> ...
...
>>> display.close()