Skip to content

Commit

Permalink
Add laser cutter mode change backend code
Browse files Browse the repository at this point in the history
  • Loading branch information
irlaec committed Oct 12, 2023
1 parent e305647 commit e616543
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions octoprint_mrbeam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class MrBeamPlugin(
TIME_NTP_SYNC_CHECK_INTERVAL_FAST = 10.0
TIME_NTP_SYNC_CHECK_INTERVAL_SLOW = 120.0

RESTART_OCTOPRINT_CMD = "sudo systemctl restart octoprint.service"

def __init__(self):
self.mrbeam_plugin_initialized = False
self._shutting_down = False
Expand Down Expand Up @@ -2049,6 +2051,7 @@ def get_api_commands(self):
high_temperature_warning_status=[],
request_hardware_errors=[],
dissmiss_notification=[],
laser_cutter_mode_change=[],
)

def on_api_command(self, command, data):
Expand Down Expand Up @@ -2185,6 +2188,8 @@ def on_api_command(self, command, data):
return self.handle_hardware_error_request(data)
elif command == "dissmiss_notification":
return self.handle_dissmiss_notification_request(data)
elif command == "laser_cutter_mode_change":
return self.handle_laser_cutter_mode_change(data)
return NO_CONTENT

def analytics_init(self, data):
Expand Down Expand Up @@ -2354,6 +2359,21 @@ def handle_dissmiss_notification_request(self, data):
self.user_notification_system.dismiss_notification(data.get("id", None))
return NO_CONTENT

def handle_laser_cutter_mode_change(self, data):
"""Handle a request to change the laser cutter mode
Args:
data: request data
Returns:
NO_CONTENT
"""
new_mode = data.get("mode", None)
if new_mode:
self._laser_cutter_mode_service.change_mode_by_id(new_mode)
self.restart_octoprint()
return NO_CONTENT

def take_undistorted_picture(self, is_initial_calibration):
from flask import make_response, jsonify

Expand Down Expand Up @@ -3195,6 +3215,11 @@ def _get_mac_addresses(self):
self._mac_addrs = interfaces
return self._mac_addrs

def restart_octoprint(self):
"""Calls the command to restart octoprint"""
self._logger.info("Restarting OctoPrint...")
exec_cmd(self.RESTART_OCTOPRINT_CMD)


# # MR_BEAM_OCTOPRINT_PRIVATE_API_ACCESS
# # Per default OP always accepts .stl files.
Expand Down

0 comments on commit e616543

Please sign in to comment.