Skip to content
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

Merge dev into main #16

Merged
merged 34 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3582884
add new unified install script

phillipthelen Feb 19, 2024
44702f8
improve wifi icon rendering
phillipthelen Feb 19, 2024
b675075
move all display communication out of display.py
phillipthelen Feb 19, 2024
9aae293
Improved shutdown sequence
phillipthelen Feb 22, 2024
6c27c2e
Allow serial port to be configured
phillipthelen Feb 22, 2024
591c81b
allow filament sensor name to be configured
phillipthelen Feb 22, 2024
261c22d
correctly handle leds not being there
phillipthelen Feb 22, 2024
6448f03
log unhandled input
phillipthelen Feb 27, 2024
6862e03
fix setting outer bed temp manually
phillipthelen Feb 27, 2024
49a0ea7
improve display initialization in some cases
phillipthelen Feb 27, 2024
ddd4d4c
Updated filament sensor to "filament_sensor" elegoo_neptune4.py
halfmanbear Mar 25, 2024
9d1ef2c
filament_sensor fix display.py
halfmanbear Apr 6, 2024
7be6354
Handle " // probe at" messages only if we are in PRINTING_KAMP page (…
anarsoul Apr 9, 2024
f92eb14
add more tests
phillipthelen Apr 9, 2024
023afba
fix formatting
phillipthelen Apr 9, 2024
ccab0f9
connect directly to moonraker. Fixes #9
phillipthelen Apr 9, 2024
513a1ec
fix test requirement
phillipthelen Apr 9, 2024
8f42624
Add more tests
phillipthelen Apr 9, 2024
49c01d1
Fix safe get for config
phillipthelen Apr 10, 2024
aaf82b6
additional tests
phillipthelen Apr 10, 2024
6e5250a
test fixes
phillipthelen Apr 10, 2024
4264520
load custom filament sensor name at right time
phillipthelen Apr 25, 2024
e7c7197
remove print statements
phillipthelen Apr 25, 2024
909d829
fix navigation on printing_adjust page
phillipthelen Apr 25, 2024
135b98a
fix adjusting printing temps
phillipthelen Apr 25, 2024
5a459c9
fix setting printer target temp
phillipthelen Apr 25, 2024
109944b
typo
phillipthelen Apr 25, 2024
f27fa28
use correct name
phillipthelen Apr 25, 2024
ee24845
reset probe count when new mesh probe is started
phillipthelen Apr 25, 2024
f832e17
Fix setting fan speed during print
phillipthelen Apr 25, 2024
e0ca1f7
Fix print adjustment settings (#15)
bdg-8 May 18, 2024
f25b29b
fix files navigation
phillipthelen May 18, 2024
5e0a588
change confusing light names
phillipthelen May 18, 2024
8817dbe
add debugging related to an open issue
phillipthelen May 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = tests/*
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
pip install -r requirements.txt
- name: run tests with pytest
run: |
pytest
pytest --cov-config=.coveragerc --cov=. tests
1,155 changes: 628 additions & 527 deletions display.py

Large diffs are not rendered by default.

183 changes: 183 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#!/bin/bash

SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

OLD_SERVICE_FILE="/etc/systemd/system/OpenNept4une.service"
SERVICE_FILE="/etc/systemd/system/display.service"
SCRIPT_PATH="$SCRIPTPATH/display.py"
VENV_PATH="$SCRIPTPATH/venv"
LOG_FILE="/var/log/display.log"
MOONRAKER_ASVC="$HOME/printer_data/moonraker.asvc"

R=$'\e[1;91m' # Red ${R}
G=$'\e[1;92m' # Green ${G}
Y=$'\e[1;93m' # Yellow ${Y}
M=$'\e[1;95m' # Magenta ${M}
C=$'\e[96m' # Cyan ${C}
NC=$'\e[0m' # No Color ${NC}

reset_env() {
sudo rm -rf "$SCRIPTPATH/venv"
rm -rf "$SCRIPTPATH/__pycache__"
}

install_env() {
sudo apt update
sudo apt install python3-venv -y

# Create and activate a Python virtual environment
echo "Creating and activating a virtual environment..."
python3 -m venv "$SCRIPTPATH/venv"
source "$SCRIPTPATH/venv/bin/activate"

# Install required Python packages
echo "Installing required Python packages..."
pip install -r "$SCRIPTPATH/requirements.txt"

# Deactivate the virtual environment
echo "Deactivating the virtual environment..."
deactivate

echo "Environment setup completed."
}

stop_service() {
if systemctl is-active --quiet OpenNept4une; then
# Stop the service silently
sudo service OpenNept4une stop >/dev/null 2>&1
# Disable the service silently
sudo service OpenNept4une disable >/dev/null 2>&1
sudo rm -f $OLD_SERVICE_FILE
fi

if systemctl is-active --quiet display; then
# Stop the service silently
sudo service display stop >/dev/null 2>&1
fi
}

disable_service() {
echo "Disabling the service..."
sudo systemctl disable display.service
}

create_service() {
# Create the systemd service file
echo "Creating systemd service file at $SERVICE_FILE..."
cat <<EOF | sudo tee $SERVICE_FILE > /dev/null
[Unit]
Description=OpenNept4une TouchScreen Display Service
After=klipper.service klipper-mcu.service moonraker.service
Wants=klipper.service moonraker.service
Documentation=man:display(8)

[Service]
ExecStartPre=/bin/sleep 10
ExecStart=$SCRIPTPATH/venv/bin/python $SCRIPTPATH/display.py
WorkingDirectory=$SCRIPTPATH
Restart=on-failure
CPUQuota=50%
RestartSec=10
User=$USER
ProtectSystem=full
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

# Reload systemd to read new service file
echo "Reloading systemd..."
sudo systemctl daemon-reload

# Enable and start the service
echo "Enabling and starting the service..."
sudo systemctl enable display.service
sudo systemctl start display.service
}

give_moonraker_control() {
echo "Allowing Moonraker to control display service"
grep -qxF 'display' $MOONRAKER_ASVC || echo 'display' >> $MOONRAKER_ASVC

sudo service moonraker restart
}

moonraker_update_manager() {
update_selection="display"
config_file="$HOME/printer_data/config/moonraker.conf"

if [ "$update_selection" = "OpenNept4une" ]; then
new_lines="[update_manager $update_selection]\n\
type: git_repo\n\
primary_branch: $current_branch\n\
path: $OPENNEPT4UNE_DIR\n\
is_system_service: False\n\
origin: $OPENNEPT4UNE_REPO"

elif [ "$update_selection" = "display" ]; then
current_display_branch=$(git -C "$DISPLAY_CONNECTOR_DIR" symbolic-ref --short HEAD 2>/dev/null)
new_lines="[update_manager $update_selection]\n\
type: git_repo\n\
primary_branch: $current_display_branch\n\
path: $DISPLAY_CONNECTOR_DIR\n\
virtualenv: $DISPLAY_CONNECTOR_DIR/venv\n\
requirements: requirements.txt\n\
origin: $DISPLAY_CONNECTOR_REPO"
else
echo -e "${R}Invalid argument. Please specify either 'OpenNept4une' or 'display_connector'.${NC}"
return 1
fi
# Check if the lines exist in the config file
if grep -qF "[update_manager $update_selection]" "$config_file"; then
# Lines exist, update them
perl -pi.bak -e "BEGIN{undef $/;} s|\[update_manager $update_selection\].*?((?:\r*\n){2}\|$)|$new_lines\$1|gs" "$config_file"
sync
else
# Lines do not exist, append them to the end of the file
echo -e "\n$new_lines" >> "$config_file"
fi
}

if [ ! -f "$SCRIPT_PATH" ]; then
echo "${R}Error: Script $SCRIPT_PATH not found.${NC}"
exit 1
fi

HELP="Please specify either 'full', 'env', 'service-install', 'service-disable' or 'moonraker'."

if [ "$1" ]; then
case "$1" in
"full")
reset_env
install_env
stop_service
create_service
give_moonraker_control
;;
"env")
reset_env
install_env
;;
"service-install")
stop_service
create_service
;;
"service-disable")
stop_service
disable_service
;;
"moonraker")
give_moonraker_control
moonraker_update_manager
;;
*)
echo "${R}Invalid argument $1. ${Y}$HELP${NC}"
exit 1
;;
esac
else
echo "${R}No arguments provided. ${Y}$HELP${NC}"
exit 1
fi
18 changes: 17 additions & 1 deletion src/communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ class DisplayCommunicator:
supported_firmware_versions = []
current_data = {}

ips = "--"

def __init__(
self,
logger: Logger,
model: str,
port: str,
event_handler,
baudrate: int = 115200,
timeout: int = 5,
) -> None:
self.display_name_override = None
self.display_name_line_color = None
self.z_display = "mm"

self.logger = logger
self.model = model
self.port = port
self.baudrate = baudrate
self.timeout = timeout
Expand All @@ -41,6 +49,9 @@ async def check_valid_version(self):
return False
return True

def get_device_name(self):
return self.model

def get_current_data(self, path):
index = 0
current = self.current_data
Expand All @@ -51,6 +62,9 @@ def get_current_data(self, path):
return None
return current

async def navigate_to(self, page_id):
await self.write(f"page {page_id}")

async def update_data(self, new_data, data_mapping=None, current_data=None):
if data_mapping is None:
data_mapping = self.data_mapping
Expand All @@ -75,7 +89,9 @@ async def update_data(self, new_data, data_mapping=None, current_data=None):
self.get_current_data(required_field)
for required_field in mapping_leaf.required_fields
]
formatted = mapping_leaf.format_with_required(value, *required_values)
formatted = mapping_leaf.format_with_required(
value, *required_values
)
for mapped_key in mapping_leaf.fields:
if mapping_leaf.field_type == "txt":
await self.write(
Expand Down
16 changes: 13 additions & 3 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from configparser import ConfigParser
from configparser import ConfigParser, NoOptionError, NoSectionError

TEMP_DEFAULTS = {
"pla": [210, 60],
Expand Down Expand Up @@ -28,14 +28,25 @@ def write_changes(self):
with open(self.file_path, "w") as configfile:
self.write(configfile)

def safe_get(self, section, key, default=None):
try:
return self.get(section, key)
except KeyError:
return default
except NoSectionError:
return default
except NoOptionError:
return default


def initialize_config_file(self):
if not os.path.exists(self.file_path):
self.logger.info("Creating config file")
self.add_section("general")
self.set(
"general",
"clean_filename_regex",
".*_(.*?_(?:[0-9]+h|[0-9]+m|[0-9]+s)+\.gcode)",
r".*_(.*?_(?:[0-9]+h|[0-9]+m|[0-9]+s)+\.gcode)",
)
self.add_section("LOGGING")
self.set("LOGGING", "file_log_level", "ERROR")
Expand Down Expand Up @@ -89,4 +100,3 @@ def initialize_config_file(self):

with open(self.file_path, "w") as configfile:
self.write(configfile)

19 changes: 19 additions & 0 deletions src/elegoo_custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from logging import Logger

from src.elegoo_display import ElegooDisplayCommunicator, ElegooDisplayMapper

MODEL_CUSTOM = "Custom"


class CustomDisplayCommunicator(ElegooDisplayCommunicator):
def __init__(
self,
logger: Logger,
model: str,
event_handler,
port: str,
baudrate: int = 115200,
timeout: int = 5,
) -> None:
super().__init__(logger, model, port, event_handler, baudrate, timeout)
self.mapper = ElegooDisplayMapper()
Loading