-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from mathoudebine/feature/system-monitor
Release 2.0.0: system monitor
- Loading branch information
Showing
97 changed files
with
2,818 additions
and
662 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,6 @@ dmypy.json | |
|
||
# PyCharm | ||
.idea/ | ||
|
||
# Git mergetool backup | ||
*.orig |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
config: | ||
# Configuration values to set up basic communication | ||
# Set your COM port e.g. COM3 for Windows, /dev/ttyACM0 for Linux... | ||
# COM_PORT: "/dev/ttyACM0" | ||
# COM_PORT: "COM3" | ||
COM_PORT: "AUTO" | ||
|
||
# Theme to use (located in res/themes) | ||
# THEME: Terminal_theme | ||
# THEME: Landscape6Grid | ||
THEME: 3.5inchTheme2_theme | ||
|
||
display: | ||
# Display resolution in portrait orientation | ||
# Do not use this setting to rotate display! Display orientation is managed by themes | ||
DISPLAY_WIDTH: 320 | ||
DISPLAY_HEIGHT: 480 | ||
|
||
# Display Brightness | ||
# Set this as the desired %, 0 being completely dark and 100 being max brightness | ||
# Warning: screen can get very hot at high brightness! | ||
BRIGHTNESS: 20 | ||
|
||
# Display revision: A or B (for "flagship" version, use B) | ||
# To identify your revision: https://github.com/mathoudebine/turing-smart-screen-python/wiki/Hardware-revisions | ||
REVISION: A |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import queue | ||
import sys | ||
|
||
import yaml | ||
|
||
from library.log import logger | ||
|
||
|
||
def load_yaml(configfile): | ||
with open(configfile, "r") as stream: | ||
yamlconfig = yaml.safe_load(stream) | ||
return yamlconfig | ||
|
||
|
||
PATH = sys.path[0] | ||
CONFIG_DATA = load_yaml("config.yaml") | ||
|
||
try: | ||
theme_path = "res/themes/" + CONFIG_DATA['config']['THEME'] + "/" | ||
logger.info("Loading theme %s from %s" % (CONFIG_DATA['config']['THEME'], theme_path + "theme.yaml")) | ||
THEME_DATA = load_yaml(theme_path + "theme.yaml") | ||
THEME_DATA['PATH'] = theme_path | ||
except: | ||
logger.error("Theme not found or contains errors!") | ||
try: | ||
sys.exit(0) | ||
except: | ||
os._exit(0) | ||
|
||
# Queue containing the serial requests to send to the screen | ||
update_queue = queue.Queue() |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from library import config | ||
from library.lcd_comm import Orientation | ||
from library.lcd_comm_rev_a import LcdCommRevA | ||
from library.lcd_comm_rev_b import LcdCommRevB | ||
from library.log import logger | ||
|
||
THEME_DATA = config.THEME_DATA | ||
CONFIG_DATA = config.CONFIG_DATA | ||
|
||
|
||
def _get_full_path(path, name): | ||
if name: | ||
return path + name | ||
else: | ||
return None | ||
|
||
|
||
def _get_theme_orientation() -> Orientation: | ||
if THEME_DATA["display"]["DISPLAY_ORIENTATION"] == 'portrait': | ||
return Orientation.PORTRAIT | ||
elif THEME_DATA["display"]["DISPLAY_ORIENTATION"] == 'landscape': | ||
return Orientation.LANDSCAPE | ||
elif THEME_DATA["display"]["DISPLAY_ORIENTATION"] == 'reverse_portrait': | ||
return Orientation.REVERSE_PORTRAIT | ||
elif THEME_DATA["display"]["DISPLAY_ORIENTATION"] == 'reverse_landscape': | ||
return Orientation.REVERSE_LANDSCAPE | ||
else: | ||
logger.warning("Orientation '", THEME_DATA["display"]["DISPLAY_ORIENTATION"], "' unknown, using portrait") | ||
return Orientation.PORTRAIT | ||
|
||
|
||
class Display: | ||
def __init__(self): | ||
self.lcd = None | ||
if CONFIG_DATA["display"]["REVISION"] == "A": | ||
self.lcd = LcdCommRevA(com_port=CONFIG_DATA['config']['COM_PORT'], | ||
display_width=CONFIG_DATA["display"]["DISPLAY_WIDTH"], | ||
display_height=CONFIG_DATA["display"]["DISPLAY_HEIGHT"], | ||
update_queue=config.update_queue) | ||
elif CONFIG_DATA["display"]["REVISION"] == "B": | ||
self.lcd = LcdCommRevB(com_port=CONFIG_DATA['config']['COM_PORT'], | ||
display_width=CONFIG_DATA["display"]["DISPLAY_WIDTH"], | ||
display_height=CONFIG_DATA["display"]["DISPLAY_HEIGHT"], | ||
update_queue=config.update_queue) | ||
else: | ||
logger.error("Unknown display revision '", CONFIG_DATA["display"]["REVISION"], "'") | ||
|
||
def initialize_display(self): | ||
# Reset screen in case it was in an unstable state (screen is also cleared) | ||
self.lcd.Reset() | ||
|
||
# Send initialization commands | ||
self.lcd.InitializeComm() | ||
|
||
# Set brightness | ||
self.lcd.SetBrightness(CONFIG_DATA["display"]["BRIGHTNESS"]) | ||
|
||
# Set backplate RGB LED color (for supported HW only) | ||
self.lcd.SetBackplateLedColor(THEME_DATA['display']["DISPLAY_RGB_LED"]) | ||
|
||
# Set orientation | ||
self.lcd.SetOrientation(_get_theme_orientation()) | ||
|
||
def display_static_images(self): | ||
if THEME_DATA['static_images']: | ||
for image in THEME_DATA['static_images']: | ||
logger.debug(f"Drawing Image: {image}") | ||
self.lcd.DisplayBitmap( | ||
bitmap_path=THEME_DATA['PATH'] + THEME_DATA['static_images'][image].get("PATH"), | ||
x=THEME_DATA['static_images'][image].get("X", 0), | ||
y=THEME_DATA['static_images'][image].get("Y", 0), | ||
width=THEME_DATA['static_images'][image].get("WIDTH", 0), | ||
height=THEME_DATA['static_images'][image].get("HEIGHT", 0) | ||
) | ||
|
||
def display_static_text(self): | ||
if THEME_DATA['static_text']: | ||
for text in THEME_DATA['static_text']: | ||
logger.debug(f"Drawing Text: {text}") | ||
self.lcd.DisplayText( | ||
text=THEME_DATA['static_text'][text].get("TEXT"), | ||
x=THEME_DATA['static_text'][text].get("X", 0), | ||
y=THEME_DATA['static_text'][text].get("Y", 0), | ||
font=THEME_DATA['static_text'][text].get("FONT", "roboto-mono/RobotoMono-Regular.ttf"), | ||
font_size=THEME_DATA['static_text'][text].get("FONT_SIZE", 10), | ||
font_color=THEME_DATA['static_text'][text].get("FONT_COLOR", (0, 0, 0)), | ||
background_color=THEME_DATA['static_text'][text].get("BACKGROUND_COLOR", (255, 255, 255)), | ||
background_image=_get_full_path(THEME_DATA['PATH'], | ||
THEME_DATA['static_text'][text].get("BACKGROUND_IMAGE", None)) | ||
) | ||
|
||
|
||
display = Display() |
Oops, something went wrong.