LS012B7DD01Display
- class quanser.devices.interfaces.LS012B7DD01Display
A Python wrapper for the Quanser Devices API interface to Sharp LS012B7DD01 displays.
Example
>>> from quanser.devices import LS012B7DD01Display >>> display = LS012B7DD01Display()
- close()
Close the display.
Example
>>> from quanser.devices import LS012B7DD01Display >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> ... ... >>> 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 LCD display.
>>> from quanser.devices import LS012B7DD01Display >>> import cv2 >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> 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)
Opens the Sharp LS012B7DD01 display.
Example
>>> from quanser.devices import LS012B7DD01Display >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> ... ... >>> 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 LS012B7DD01Display >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> 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 eleven bits in each word defining the pixels of that line. For example to define the letter T, the pattern would be:
pattern = np.array([0x0000, 0x0000, 0x0000, 0x01FC, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000], dtype=np.uint16)
0b00000000000 (0x0000) 0b00000000000 (0x0000) 0b00000000000 (0x0000) 0b00111111100 (0x01FC) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000100000 (0x0020) 0b00000000000 (0x0000) 0b00000000000 (0x0000) 0b00000000000 (0x0000) 0b00000000000 (0x0000) <= should generally be zero to allow for cursor
Note that only bits 0-10 are used. Bit 0 is the rightmost pixel and bit 10 is the leftmost pixel. The baseline is in pattern[11]. The top of a typical character is in pattern[3], although some characters go higher.
Examples
Print a custom character with three lines along the top, middle and bottom.
Using array:
>>> from quanser.devices import LS012B7DD01Display >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> character_code = 0o20 >>> pattern = array('H', [0x0000, 0x0000, 0x0000, 0x01FC, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000]) >>> display.setCharacter(character_code, pattern) >>> message = str(chr(character_code)) >>> display.printText(0, 0, message, len(message)) >>> ... ... >>> display.close()
Using numpy:
>>> from quanser.devices import LS012B7DD01Display >>> import numpy as np >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> character_code = 0o20 >>> pattern = np.array([0x0000, 0x0000, 0x0000, 0x01FC, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000], dtype = np.uint16) >>> display.setCharacter(character_code, pattern) >>> message = str(chr(character_code)) >>> display.printText(0, 0, message, len(message)) >>> ... ... >>> display.close()
- setDarkMode(dark)
Determine whether to use dark mode for the display.
- Parameters
dark (bool) –
True
to enable dark mode i.e., white text on a black background;False
to use normal mode i.e., black text on a white background.
Examples
Print “Hello, world!” in dark mode.
>>> from quanser.devices import LS012B7DD01Display >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> display.setDarkMode(True) >>> message = "Hello, world!" >>> display.printText(0, 0, message, len(message)) >>> ... ... >>> display.close()
- setRotation(rotate)
Determine whether to rotate the display 180 degrees.
- Parameters
rotate (bool) –
True
to rotate the displayFalse
to use the normal orientation
Examples
Print “Hello, world!” in the opposite orientation.
>>> from quanser.devices import LS012B7DD01Display >>> display = LS012B7DD01Display() >>> display.open("spi-cpu://localhost:2?word=8,baud=1000000,frame=1,memsize=990") >>> display.setRotation(True) >>> message = "Hello, world!" >>> display.printText(0, 0, message, len(message)) >>> ... ... >>> display.close()