-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ptosiek/display-confからのプルリクエスト#55をマージする
Display inherits from base display
- Loading branch information
Showing
17 changed files
with
280 additions
and
317 deletions.
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 = False | ||
|
||
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.