✨ action_command_prompt: PROMPT_SUPPORT capability support
Allow configuration of whether to enable the plugin if firmware support is detected, always or never. Handle PROMPT_SUPPORT capability report accordingly. See MarlinFirmware/Marlin#12982
This commit is contained in:
1 parent
2db230549e
commit
5d021d76a0
2 files changed
+63
-24
No files matched your search
@@ -41,15 +41,19 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.TemplatePlugin):
|
||||
|
||||
COMMAND = "M876"
|
||||
CAP_PROMPT_SUPPORT = "PROMPT_SUPPORT"
|
||||
|
||||
# noinspection PyMissingConstructor
|
||||
def __init__(self):
|
||||
self._prompt = None
|
||||
self._enable = "detected"
|
||||
self._command = None
|
||||
self._enable_emergency_sending = False
|
||||
self._enable_signal_support = False
|
||||
self._cap_prompt_support = False
|
||||
|
||||
def initialize(self):
|
||||
self._enable = self._settings.get([b"enable"])
|
||||
self._command = self._settings.get([b"command"])
|
||||
self._enable_emergency_sending = self._settings.get_boolean([b"enable_emergency_sending"])
|
||||
self._enable_signal_support = self._settings.get_boolean([b"enable_signal_support"])
|
||||
@@ -63,22 +67,20 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
#~ EventHandlerPlugin
|
||||
|
||||
def on_event(self, event, payload):
|
||||
if event == Events.CONNECTED and self._enable_signal_support:
|
||||
if event == Events.CONNECTED and self._enable == "always" and self._enable_signal_support:
|
||||
self._printer.commands(["{command} P1".format(command=self._command)])
|
||||
|
||||
#~ SettingsPlugin
|
||||
|
||||
def get_settings_defaults(self):
|
||||
return dict(command=self.COMMAND,
|
||||
|
||||
# TODO make this default to True once we have a capability report to listen to
|
||||
enable_emergency_sending=False,
|
||||
|
||||
# TODO make this default to True once we have a capability report to listen to
|
||||
enable_signal_support=False)
|
||||
return dict(enable="detected",
|
||||
command=self.COMMAND,
|
||||
enable_emergency_sending=True,
|
||||
enable_signal_support=True)
|
||||
|
||||
def on_settings_save(self, data):
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
self._enable = self._settings.get([b"enable"])
|
||||
self._command = self._settings.get([b"command"])
|
||||
self._enable_emergency_sending = self._settings.get_boolean([b"enable_emergency_sending"])
|
||||
self._enable_signal_support = self._settings.get_boolean([b"enable_signal_support"])
|
||||
@@ -162,7 +164,7 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
if gcode != self._command:
|
||||
return
|
||||
|
||||
if not self._enable_emergency_sending:
|
||||
if self._enable == "never" or (self._enable == "detected" and not self._cap_prompt_support) or not self._enable_emergency_sending:
|
||||
return
|
||||
|
||||
if not "S" in cmd:
|
||||
@@ -172,19 +174,36 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
# noinspection PyProtectedMember
|
||||
return comm_instance._emergency_force_send(cmd, u"Force-sending {} to the printer".format(self._command), gcode=gcode)
|
||||
|
||||
#~ capability reporting
|
||||
|
||||
def firmware_capability_handler(self, comm_instance, capability, enabled, already_defined, *args, **kwargs):
|
||||
if capability == self.CAP_PROMPT_SUPPORT and enabled:
|
||||
self._cap_prompt_support = True
|
||||
if self._enable == "detected" and self._enable_signal_support:
|
||||
self._printer.commands(["{command} P1".format(command=self._command)])
|
||||
|
||||
#~ prompt handling
|
||||
|
||||
def _show_prompt(self):
|
||||
if self._enable == "never" or (self._enable == "detected" and not self._cap_prompt_support):
|
||||
return
|
||||
|
||||
self._prompt.activate()
|
||||
self._plugin_manager.send_plugin_message(self._identifier, dict(action="show",
|
||||
text=self._prompt.text,
|
||||
choices=self._prompt.choices))
|
||||
|
||||
def _close_prompt(self):
|
||||
if self._enable == "never" or (self._enable == "detected" and not self._cap_prompt_support):
|
||||
return
|
||||
|
||||
self._prompt = None
|
||||
self._plugin_manager.send_plugin_message(self._identifier, dict(action="close"))
|
||||
|
||||
def _answer_prompt(self, choice):
|
||||
if self._enable == "never" or (self._enable == "detected" and not self._cap_prompt_support):
|
||||
return
|
||||
|
||||
self._close_prompt()
|
||||
self._printer.commands(["{command} S{choice}".format(command=self._command,
|
||||
choice=choice)])
|
||||
@@ -199,5 +218,6 @@ __plugin_license__ = "AGPLv3"
|
||||
__plugin_implementation__ = ActionCommandPromptPlugin()
|
||||
__plugin_hooks__ = {
|
||||
b"octoprint.comm.protocol.action": __plugin_implementation__.action_command_handler,
|
||||
b"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.gcode_queuing_handler
|
||||
b"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.gcode_queuing_handler,
|
||||
b"octoprint.comm.protocol.firmware.capabilities": __plugin_implementation__.firmware_capability_handler
|
||||
}
|
||||
+33
-14
@@ -2,24 +2,43 @@
|
||||
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Dialog command') }}</label>
|
||||
<label class="control-label">{{ _('Enable support')}}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.action_command_prompt.command">
|
||||
<div class="help-block">{{ _('Use this to define the dialog command. Default is <code>M876</code>. You normally should not have to change this.') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.action_command_prompt.enable_emergency_sending"> {{ _('Enable force sending of the configured command to bypass blocking firmware routines. Requires the firmware to report support of the <code>EMERGENCY_PARSER</code> capability.') }}
|
||||
<label class="radio">
|
||||
<input type="radio" name="pluginActionCommandPromptEnableGroup" value="detected" data-bind="checked: settings.plugins.action_command_prompt.enable"> {{ _('If detected as supported by the firmware (<code>PROMPT_SUPPORT</code> capability)') }}
|
||||
</label>
|
||||
<label class="radio">
|
||||
<input type="radio" name="pluginActionCommandPromptEnableGroup" value="always" data-bind="checked: settings.plugins.action_command_prompt.enable"> {{ _('Always') }}
|
||||
</label>
|
||||
<label class="radio">
|
||||
<input type="radio" name="pluginActionCommandPromptEnableGroup" value="never" data-bind="checked: settings.plugins.action_command_prompt.enable"> {{ _('Never') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.action_command_prompt.enable_signal_support"> {{ _('Enable signaling to the firmware that we support <code>prompt_*</code> actions.') }}
|
||||
</label>
|
||||
<div class="advanced_options">
|
||||
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', parent: '.advanced_options', container: '.hide' }"><i class="fa fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
|
||||
<div class="hide">
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Dialog command') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.plugins.action_command_prompt.command">
|
||||
<div class="help-block">{{ _('Use this to define the dialog command. Default is <code>M876</code>. You normally should not have to change this.') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.action_command_prompt.enable_emergency_sending"> {{ _('Enable force sending of the configured command to bypass blocking firmware routines if detected as supported. You normally should not have to change this.') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.action_command_prompt.enable_signal_support"> {{ _('Enable signaling to the firmware that we support <code>prompt_*</code> actions if detected as supported. You normally should not have to change this.') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
Reference in new issue
Block a user