Created
October 9, 2018 16:37
-
-
Save jedie/03b1c4464cc4a97301091d98a17fd098 to your computer and use it in GitHub Desktop.
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
# https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/display | |
import time | |
import display | |
import machine | |
from machine import SPI | |
from micropython import const | |
class Display(display.TFT): | |
""" | |
Expand loboris TFT class | |
""" | |
def __init__(self, **init_kwargs): | |
super().__init__() | |
try: | |
self.init(**init_kwargs) | |
except OSError as err: | |
# e.g.: Error initializing display | |
print("ERROR: %s" % err) | |
for i in range(3, 0, -1): | |
print("Hard reset in %i Sek!" % i) | |
time.sleep(1) | |
machine.reset() | |
self.width, self.height = self.screensize() | |
self.resetwin() # Reset active display window to full screen size | |
self.clear(self.BLACK) | |
self.set_font(self.FONT_Default) | |
self.text(0, 0, "", self.BLACK) | |
def get_fonts(self): | |
fonts = [(attr_name, getattr(self, attr_name)) for attr_name in dir(self) if attr_name.startswith("FONT_")] | |
fonts.sort(key=lambda i: i[1]) | |
return tuple(fonts) | |
def set_font(self, font_id, rotate=0): | |
self.font(font_id, rotate=rotate) | |
self.font_width, self.font_height = self.fontSize() | |
def print(self, text, align=0, color=None, transparent=False): | |
if color is None: | |
color = self.WHITE | |
y = self.text_y() + self.font_height | |
if y >= self.height: | |
y = 0 | |
self.text(align, y, text, color, transparent=transparent) | |
class OdroidGoDisplay(Display): | |
""" | |
ODROID GO TFT | |
""" | |
def __init__(self): | |
super().__init__( | |
type=self.ILI9341, | |
width=320, | |
height=240, | |
speed=40000000, | |
miso=19, | |
mosi=23, | |
clk=18, | |
cs=5, | |
spihost=2, # SPI.VSPI_HOST, | |
dc=21, | |
bgr=True, | |
rot=self.LANDSCAPE_FLIP, | |
) | |
tft = OdroidGoDisplay() | |
tft.print("All existing fonts:", align=tft.CENTER, color=tft.CYAN) | |
fonts = tft.get_fonts() | |
for font_name, font_id in fonts: | |
text = "%i - %s" % (font_id, font_name) | |
print(text) | |
tft.set_font(font_id) | |
tft.print(text, transparent=True) | |
tft.deinit() | |
del tft | |
print("---END---") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment