diff options
author | Arksine <arksine.code@gmail.com> | 2020-06-19 06:26:09 -0400 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2020-06-24 19:07:33 -0400 |
commit | a31dd0ff0e3b38eeffa5d456967fd70a1d033087 (patch) | |
tree | 5d89b059575001c52946dce90cee77626b2149af | |
parent | 72962c5ca28789789509002fd7535da304b2f56c (diff) | |
download | kutter-a31dd0ff0e3b38eeffa5d456967fd70a1d033087.tar.gz kutter-a31dd0ff0e3b38eeffa5d456967fd70a1d033087.tar.xz kutter-a31dd0ff0e3b38eeffa5d456967fd70a1d033087.zip |
query_endstops: register "query_endstops/status" endpoint
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
-rw-r--r-- | klippy/extras/query_endstops.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/klippy/extras/query_endstops.py b/klippy/extras/query_endstops.py index 7209ca65..b7fc2d04 100644 --- a/klippy/extras/query_endstops.py +++ b/klippy/extras/query_endstops.py @@ -9,6 +9,10 @@ class QueryEndstops: self.printer = config.get_printer() self.endstops = [] self.last_state = {} + # Register webhook if server is available + webhooks = self.printer.lookup_object('webhooks') + webhooks.register_endpoint( + "query_endstops/status", self._handle_web_request) gcode = self.printer.lookup_object('gcode') gcode.register_command("QUERY_ENDSTOPS", self.cmd_QUERY_ENDSTOPS, desc=self.cmd_QUERY_ENDSTOPS_help) @@ -17,6 +21,17 @@ class QueryEndstops: self.endstops.append((mcu_endstop, name)) def get_status(self, eventtime): return {'last_query': {name: value for name, value in self.last_state}} + def _handle_web_request(self, web_request): + if web_request.get_method() != 'GET': + raise web_request.error("Invalid Request Method") + gc_mutex = self.printer.lookup_object('gcode').get_mutex() + toolhead = self.printer.lookup_object('toolhead') + with gc_mutex: + print_time = toolhead.get_last_move_time() + self.last_state = [(name, mcu_endstop.query_endstop(print_time)) + for mcu_endstop, name in self.endstops] + web_request.send({name: ["open", "TRIGGERED"][not not t] + for name, t in self.last_state}) cmd_QUERY_ENDSTOPS_help = "Report on the status of each endstop" def cmd_QUERY_ENDSTOPS(self, gcmd): # Query the endstops |