-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display inherits from base display #55
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,111 @@ | ||
import os | ||
|
||
from logger import app_logger | ||
from ..sensor.sensor import Sensor | ||
|
||
DISPLAY = None | ||
DEFAULT_RESOLUTION = (400, 240) | ||
|
||
SUPPORTED_DISPLAYS = { | ||
# display name, resolution if different from its class default | ||
"None": None, # DEFAULT_RESOLUTION | ||
"PiTFT": None, | ||
"MIP": None, # LPM027M128C, LPM027M128B | ||
"MIP_640": (640, 480), # LPM044M141A | ||
"MIP_Sharp": None, | ||
"MIP_Sharp_320": (320, 240), | ||
"Papirus": None, | ||
"DFRobot_RPi_Display": None, | ||
} | ||
|
||
class Display(Sensor): | ||
sensor = {} | ||
elements = () | ||
display = None | ||
send_display = False | ||
|
||
def sensor_init(self): | ||
self.detect_display() | ||
self.set_resolution() | ||
# default display (X window) | ||
class Display: | ||
has_color = True | ||
has_touch = True | ||
send = True | ||
|
||
self.reset() | ||
def __init__(self, config): | ||
self.config = config | ||
|
||
if not self.config.G_IS_RASPI: | ||
self.config.G_DISPLAY = "None" | ||
return | ||
@property | ||
def resolution(self): | ||
return getattr(self, "size", DEFAULT_RESOLUTION) | ||
|
||
if self.config.G_DISPLAY == "PiTFT": | ||
from .pitft_28_r import PiTFT28r | ||
def start_coroutine(self): | ||
pass | ||
|
||
self.display = PiTFT28r(self.config) | ||
elif self.config.G_DISPLAY in ("MIP", "MIP_640"): | ||
from .mip_display import MipDisplay | ||
def quit(self): | ||
pass | ||
|
||
self.display = MipDisplay(self.config) | ||
self.send_display = True | ||
elif self.config.G_DISPLAY in ("MIP_Sharp", "MIP_Sharp_320"): | ||
from .mip_sharp_display import MipSharpDisplay | ||
def update(self, buf, direct_update): | ||
pass | ||
|
||
self.display = MipSharpDisplay(self.config) | ||
self.send_display = True | ||
elif self.config.G_DISPLAY == "Papirus": | ||
from .papirus_display import PapirusDisplay | ||
def screen_flash_long(self): | ||
pass | ||
|
||
self.display = PapirusDisplay(self.config) | ||
self.send_display = True | ||
elif self.config.G_DISPLAY == "DFRobot_RPi_Display": | ||
from .dfrobot_rpi_display import DFRobotRPiDisplay | ||
def screen_flash_short(self): | ||
pass | ||
|
||
self.display = DFRobotRPiDisplay(self.config) | ||
self.send_display = True | ||
def change_brightness(self): | ||
pass | ||
|
||
def detect_display(self): | ||
hatdir = "/proc/device-tree/hat" | ||
product_file = hatdir + "/product" | ||
vendor_file = hatdir + "/vendor" | ||
|
||
if (os.path.exists(product_file)) and (os.path.exists(vendor_file)): | ||
with open(hatdir + "/product") as f: | ||
p = f.read() | ||
with open(hatdir + "/vendor") as f: | ||
v = f.read() | ||
app_logger.info(f"{product_file}: {p}") | ||
app_logger.info(f"{vendor_file}: {v}") | ||
def detect_display(): | ||
hatdir = "/proc/device-tree/hat" | ||
product_file = f"{hatdir}/product" | ||
vendor_file = f"{hatdir}/vendor" | ||
if os.path.exists(product_file) and os.path.exists(vendor_file): | ||
with open(product_file) as f: | ||
p = f.read() | ||
with open(vendor_file) as f: | ||
v = f.read() | ||
app_logger.info(f"{product_file}: {p}") | ||
app_logger.info(f"{vendor_file}: {v}") | ||
# set display | ||
if p.find("Adafruit PiTFT HAT - 2.4 inch Resistive Touch") == 0: | ||
return "PiTFT" | ||
elif (p.find("PaPiRus ePaper HAT") == 0) and (v.find("Pi Supply") == 0): | ||
return "Papirus" | ||
return None | ||
|
||
# set display | ||
if p.find("Adafruit PiTFT HAT - 2.4 inch Resistive Touch") == 0: | ||
self.config.G_DISPLAY = "PiTFT" | ||
elif (p.find("PaPiRus ePaper HAT") == 0) and (v.find("Pi Supply") == 0): | ||
self.config.G_DISPLAY = "Papirus" | ||
|
||
def set_resolution(self): | ||
for key in self.config.G_AVAILABLE_DISPLAY.keys(): | ||
if self.config.G_DISPLAY == key: | ||
self.config.G_WIDTH = self.config.G_AVAILABLE_DISPLAY[key]["size"][0] | ||
self.config.G_HEIGHT = self.config.G_AVAILABLE_DISPLAY[key]["size"][1] | ||
break | ||
def init_display(config): | ||
# default dummy display | ||
|
||
def has_touch(self): | ||
return self.config.G_AVAILABLE_DISPLAY[self.config.G_DISPLAY]["touch"] | ||
display = Display(config) | ||
|
||
def has_color(self): | ||
return self.config.G_AVAILABLE_DISPLAY[self.config.G_DISPLAY]["color"] | ||
if not config.G_IS_RASPI: | ||
config.G_DISPLAY = "None" | ||
return display | ||
|
||
def start_coroutine(self): | ||
if self.config.G_DISPLAY in ("MIP", "MIP_640", "MIP_Sharp", "MIP_Sharp_320"): | ||
self.display.start_coroutine() | ||
auto_detect = detect_display() | ||
|
||
def quit(self): | ||
if not self.config.G_IS_RASPI: | ||
return | ||
if self.config.G_DISPLAY == "PiTFT": | ||
pass | ||
elif ( | ||
self.config.G_DISPLAY in ("MIP", "MIP_640", "MIP_Sharp", "MIP_Sharp_320") | ||
and self.send_display | ||
): | ||
self.display.quit() | ||
elif self.config.G_DISPLAY in ("Papirus", "DFRobot_RPi_Display"): | ||
self.display.quit() | ||
if auto_detect is not None: | ||
config.G_DISPLAY = auto_detect | ||
|
||
def update(self, buf, direct_update): | ||
if not self.config.G_IS_RASPI or not self.send_display: | ||
return | ||
|
||
if direct_update and self.config.G_DISPLAY in ( | ||
"MIP", | ||
"MIP_Sharp", | ||
"MIP_Sharp_320", | ||
): | ||
self.display.update(buf, direct_update) | ||
elif self.config.G_DISPLAY in ("MIP", "MIP_640", "MIP_Sharp", "MIP_Sharp_320"): | ||
self.display.update(buf, direct_update=False) | ||
elif self.config.G_DISPLAY in ("Papirus", "DFRobot_RPi_Display"): | ||
self.display.update(buf) | ||
if config.G_DISPLAY == "PiTFT": | ||
from .pitft_28_r import _SENSOR_DISPLAY, PiTFT28r | ||
|
||
def screen_flash_long(self): | ||
if ( | ||
self.config.G_DISPLAY in ("MIP", "MIP_640", "MIP_Sharp", "MIP_Sharp_320") | ||
and self.send_display | ||
): | ||
self.display.inversion(0.8) | ||
# self.display.blink(1.0) | ||
if _SENSOR_DISPLAY: | ||
display = PiTFT28r(config) | ||
elif config.G_DISPLAY in ("MIP", "MIP_640"): | ||
from .mip_display import _SENSOR_DISPLAY, MipDisplay | ||
|
||
def screen_flash_short(self): | ||
if ( | ||
self.config.G_DISPLAY in ("MIP", "MIP_640", "MIP_Sharp", "MIP_Sharp_320") | ||
and self.send_display | ||
): | ||
self.display.inversion(0.3) | ||
|
||
def brightness_control(self): | ||
if not self.config.G_IS_RASPI: | ||
return | ||
if self.config.G_DISPLAY == "PiTFT": | ||
self.display.change_brightness() | ||
elif self.config.G_DISPLAY in ("MIP", "MIP_640") and self.send_display: | ||
self.display.change_brightness() | ||
if _SENSOR_DISPLAY: | ||
display = MipDisplay(config, SUPPORTED_DISPLAYS[config.G_DISPLAY]) | ||
elif config.G_DISPLAY in ("MIP_Sharp", "MIP_Sharp_320"): | ||
from .mip_sharp_display import _SENSOR_DISPLAY, MipSharpDisplay | ||
|
||
if _SENSOR_DISPLAY: | ||
display = MipSharpDisplay(config, SUPPORTED_DISPLAYS[config.G_DISPLAY]) | ||
elif config.G_DISPLAY == "Papirus": | ||
from .papirus_display import _SENSOR_DISPLAY, PapirusDisplay | ||
|
||
if _SENSOR_DISPLAY: | ||
display = PapirusDisplay(config) | ||
elif config.G_DISPLAY == "DFRobot_RPi_Display": | ||
from .dfrobot_rpi_display import _SENSOR_DISPLAY, DFRobotRPiDisplay | ||
|
||
if _SENSOR_DISPLAY: | ||
display = DFRobotRPiDisplay(config) | ||
|
||
return display |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If in X environment,
send
is not necessary. No buffer calculation is required.or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep my bad.
What about the change to asyncio you introduced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corrected code seems to be the old correct order of execution.
In the latest version, the proper code should be reconsidered.
https://github.com/CabbageDevelopment/qasync/blob/master/qasync/__init__.py#L332