From f338bccc3bf3161f727fa276ff7246fff4bb5329 Mon Sep 17 00:00:00 2001 From: Arksine Date: Tue, 18 Aug 2020 08:48:57 -0400 Subject: [PATCH] paneldue: Add support for the piezo buzzer Signed-off-by: Eric Callahan --- moonraker/plugins/paneldue.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/moonraker/plugins/paneldue.py b/moonraker/plugins/paneldue.py index 9cd84d6..48a58ce 100644 --- a/moonraker/plugins/paneldue.py +++ b/moonraker/plugins/paneldue.py @@ -144,7 +144,7 @@ class PanelDue: self.printer_state = { 'gcode_move': {}, 'toolhead': {}, 'virtual_sdcard': {}, 'fan': {}, 'display_status': {}, 'print_stats': {}, - 'idle_timeout': {}} + 'idle_timeout': {}, 'gcode_macro PANELDUE_BEEP': {}} self.extruder_count = 0 self.heaters = [] self.is_ready = False @@ -154,6 +154,7 @@ class PanelDue: # Set up macros self.confirmed_gcode = "" self.mbox_sequence = 0 + self.beep_sequence = 0 self.available_macros = {} self.confirmed_macros = { "RESTART": "RESTART", @@ -188,9 +189,6 @@ class PanelDue: self.server.register_event_handler( "server:gcode_response", self.handle_gcode_response) - self.server.register_remote_method( - "paneldue_beep", self.handle_paneldue_beep) - # These commands are directly executued on the server and do not to # make a request to Klippy self.direct_gcodes = { @@ -250,7 +248,7 @@ class PanelDue: self.printer_state = { 'gcode_move': {}, 'toolhead': {}, 'virtual_sdcard': {}, 'fan': {}, 'display_status': {}, 'print_stats': {}, - 'idle_timeout': {}} + 'idle_timeout': {}, 'gcode_macro PANELDUE_BEEP': {}} sub_args = {k: None for k in self.printer_state.keys()} self.extruder_count = 0 self.heaters = [] @@ -287,12 +285,22 @@ class PanelDue: self.printer_state[obj].update(items) else: self.printer_state[obj] = items + if "gcode_macro PANELDUE_BEEP" in status: + # This only processes a paneldue beep when the macro's + # variables have changed + params = self.printer_state["gcode_macro PANELDUE_BEEP"] + try: + self.handle_paneldue_beep(**params) + except Exception: + logging.exception("Unable to process PANELDUE_BEEP") - def handle_paneldue_beep(self, frequency, duration): - duration = int(duration * 1000.) - self.ioloop.spawn_callback( - self.write_response, - {'beep_freq': frequency, 'beep_length': duration}) + def handle_paneldue_beep(self, sequence, frequency, duration): + if sequence != self.beep_sequence: + self.beep_sequence = sequence + duration = int(duration * 1000.) + self.ioloop.spawn_callback( + self.write_response, + {'beep_freq': frequency, 'beep_length': duration}) async def process_line(self, line): # If we find M112 in the line then skip verification