Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 292
Control screen from your own code
This repository can be used to easily control your display from external Python code.
It will act as an abstraction library to handle specific protocols and capabilities of each supported smart screen models in a transparent way for the user.
Code on this page is extracted from the full example in simple-program.py
In your Pyhon code, import LcdComm modules.
# Import only the modules for LCD communicationfromlibrary.lcd.lcd_commimportOrientationfromlibrary.lcd.lcd_comm_rev_aimportLcdCommRevAfromlibrary.lcd.lcd_comm_rev_bimportLcdCommRevBfromlibrary.lcd.lcd_comm_rev_cimportLcdCommRevCfromlibrary.lcd.lcd_comm_rev_dimportLcdCommRevDThese modules contains:
- low-level communications management (serial port open/read/write/close)
- display configuration functions: set backlight, set orientation, set backplate RGB LEDs for rev. flasghip...
- wrapper functions to display basic graphical components: bitmap, text, progress bar...
First step in your program is to create a LcdComm object.
You need to identify your hardware revision. Then you can create an LcdCommRevA / B / C / ... for your smart screen model
lcd_comm=LcdCommRevA(com_port="AUTO", display_width=320, display_height=480) # ORlcd_comm=LcdCommRevB(...) /LcdCommRevC(...) / ...The given arguments are:
com_port: an absolute link to your serial port ("/dev/tty3","COM3"...) or"AUTO"to enable COM port autodiscoverydisplay_width: the width in pixels when in portrait orientationdisplay_height: the height in pixels when in portrait orientationupdate_queueoptional: a Queue where the LCD serial operations can be stored to be processed by another thread, orNoneif you want the serial operations to be processed sequentially by the main thread
Do not use display_width / display_height to rotate screen! Use SetOrientation() function.
LcdComm objects open the COM port at creation. You then have to initialize (and configure if needed) your display before using it:
# Reset screen in case it was in an unstable state (screen is also cleared)lcd_comm.Reset() # Optional, always initialize comm. after that# Send initialization commandslcd_comm.InitializeComm() # Mandatory!# Set brightness in % (⚠️ Turing / rev. A displays can get hot at high brightness!)lcd_comm.SetBrightness(level=25) # Optional# Set backplate RGB LED color (for supported HW only)lcd_comm.SetBackplateLedColor(led_color=(255, 255, 255)) # Optional# Set orientation (screen starts in Portrait)lcd_comm.SetOrientation(orientation=Orientation.PORTRAIT) # OptionalNote: you can configure your display at runtime, not only at startup. If you do a Reset(), be sure to run a InitializeComm() just after.
After your display has been initialized, you can display graphical content on it.
The screen only accepts bitmaps, so every graphical content (pictures, text, progress bar...) is generated as a bitmap then sent to screen.
Note: the bigger the content is, the longer it will take to display it.
Try to have big content (e.g. background pictures) displayed at the beginning of your program, then refresh only small parts of the screen at runtime.
# Define a background picturebackground="res/backgrounds/example.png"# Display background picturelcd_comm.DisplayBitmap(background) # Display a custom picturelcd_comm.DisplayBitmap("logo/icon.png", x=100, y=100)If you do not specify x and y, picture is displayed at 0,0 (top left corner). If you do not specify width and height, they are detected from your picture.
# Display custom text with solid backgroundlcd_comm.DisplayText("Custom italic text", x=5, y=150, font="roboto/Roboto-Italic.ttf", font_size=30, font_color=(0, 0, 255), background_color=(255, 255, 0)) # Display custom text with transparent backgroundlcd_comm.DisplayText("Transparent bold text", x=5, y=250, font="geforce/GeForce-Bold.ttf", font_size=30, font_color=(255, 255, 255), background_image=background)You can specify a font .ttf filename (fetched from res/fonts/ folder) as well as a font size and font color. For text to have a transparent background, you must provide the path to the image you used as background picture.
# Progress bar with solid background and outlinelcd_comm.DisplayProgressBar(x=10, y=40, width=140, height=30, min_value=0, max_value=100, value=bar_value, bar_color=(255, 255, 0), bar_outline=True, background_image=background) # Progress bar with transparent background and no outlinelcd_comm.DisplayProgressBar(x=160, y=40, width=140, height=30, min_value=0, max_value=19, value=bar_value, bar_color=(0, 255, 0), bar_outline=False, background_image=background)Progress bars can have outline or not. The outline will have the same color as the bar.
The bar_value must be inside [min_value, max_value].
For progress bars to have a transparent background, you must provide the path to the image you used as background picture.