Last active
September 9, 2019 14:09
-
-
Save anecdata/cfdcd58805c14a29160e75f3f8b90016 to your computer and use it in GitHub Desktop.
CP 5.0.0-alpha.2 displayio EPD Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import board | |
import terminalio | |
import displayio | |
from adafruit_display_text.label import Label | |
from adafruit_ssd1675 import SSD1675 | |
from adafruit_il0373 import IL0373 | |
# PyPortal | |
pyportal = True | |
# | |
# ...OR... | |
# | |
# Feather M4 Express + choose your own EPD adventure: | |
ssd1675 = False # 2C | |
il0373 = False # 3C | |
if pyportal: | |
display = board.DISPLAY | |
epd_type = 'None' | |
else: | |
displayio.release_displays() | |
cs = board.D9 | |
dc = board.D10 | |
if ssd1675: | |
# Adafruit 2.13" Black and White FeatherWing | |
# https://github.com/adafruit/Adafruit_CircuitPython_SSD1675/blob/master/examples/ssd1675_simpletest.py | |
display_bus = displayio.FourWire(board.SPI(), command=dc, chip_select=cs, baudrate=1000000) | |
time.sleep(1) | |
display = SSD1675(display_bus, width=250, height=122, rotation=90, seconds_per_frame=10) | |
epd_type = 'ssd1675_2C' | |
elif il0373: | |
# Adafruit 2.13" Tri-Color FeatherWing | |
# https://github.com/adafruit/Adafruit_CircuitPython_IL0373/blob/master/examples/il0373_simpletest.py | |
display_bus = displayio.FourWire(board.SPI(), command=dc, chip_select=cs, baudrate=1000000) | |
time.sleep(1) | |
display = IL0373(display_bus, width=212, height=104, rotation=90, highlight_color=0xff0000, seconds_per_frame=30) | |
epd_type = 'il0373_3C' | |
with open('/VERSIONS.txt') as f: | |
cp_lib_bundle = f.readline().strip() | |
print(os.uname()[4], os.uname()[3], cp_lib_bundle) | |
loop = 0 | |
while True: | |
try: | |
# Wait, then display OnDiskBitmap | |
if epd_type is 'None': | |
time.sleep(1) | |
time_to_refresh = 0.0 | |
else: | |
time.sleep(display.time_to_refresh) | |
time_to_refresh = display.time_to_refresh | |
print("Disk", loop, epd_type, time_to_refresh) | |
with open("/display-ruler.bmp", "rb") as bitmap_file: | |
intro = displayio.Group(max_size=1) | |
ruler_bitmap = displayio.OnDiskBitmap(bitmap_file) | |
ruler = displayio.TileGrid(ruler_bitmap, pixel_shader=displayio.ColorConverter()) | |
intro.append(ruler) | |
time.sleep(time_to_refresh) | |
display.show(intro) | |
display.refresh() | |
time.sleep(1) # to keep it displayed on non-EPD displays before exiting context | |
# Wait, then display default CircuitPython terminal | |
if epd_type is 'None': | |
time.sleep(1) | |
time_to_refresh = 0.0 | |
else: | |
time.sleep(display.time_to_refresh) | |
time_to_refresh = display.time_to_refresh | |
print("None", loop, epd_type, time_to_refresh) | |
time.sleep(time_to_refresh) | |
display.show(None) | |
display.refresh() | |
except RuntimeError as e: # Refresh too soon | |
print(loop, epd_type, time_to_refresh, e) | |
loop += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment