Skip to content

Commit

Permalink
Merge pull request #4 from Autodrop3d/feature/gcode_at_commands
Browse files Browse the repository at this point in the history
Feature/gcode at commands
  • Loading branch information
jneilliii authored Jun 5, 2021
2 parents 9d0a0a3 + 21b0a34 commit 2898bdc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
36 changes: 32 additions & 4 deletions octoprint_autodrop3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self):
self.auto_eject_active = False
self.server_url = None
self.at_commands_to_monitor = None
self.at_commands_to_process = {}
self.polling_interval = 0
self.job_queue_timer = None
self.job_queue_polling = False
Expand Down Expand Up @@ -320,11 +321,37 @@ def stop_repeated_timer(self, timer=None):

# ~~ @ command processing hook on queuing phase, no long running processes, thread

def custom_atcommand_handler(self, comm, phase, command, parameters, tags=None, *args, **kwargs):
if command not in self.at_commands_to_monitor:
def at_command_handler(self, comm, phase, command, parameters, tags=None, *args, **kwargs):
if not any(map(lambda r: r["command"] == command, self.at_commands_to_monitor)):
return

self._logger.debug("received @ command: \"{}\" with parameters: \"{}\"".format(command, parameters))


# ~~ gcode queing hook

def gcode_queueing_handler(self, comm_instance, phase, cmd, cmd_type, gcode, *args, ** kwargs):
if not any(map(lambda r: r["command"] == cmd.split()[0].replace("@", ""), self.at_commands_to_monitor)):
return

return ["M400", "M118 AUTODROP3D {}".format(cmd.split()[0].replace("@", "")), "@pause"]

# ~~ gcode received hook

def gcode_received_handler(self, comm, line, *args, **kwargs):
if not line.startswith("AUTODROP3D"):
return line

command_list = line.split()[1:]
command = command_list[0]
parameters = command_list[1:]
if command:
for at_command in self.at_commands_to_monitor:
if at_command["command"] == command:
self._logger.debug("received @ command: \"{}\" with parameters: \"{}\"".format(command, parameters))
exec("{}".format(at_command["python"]))
if self._printer.is_paused():
self._printer.resume_print()
return line

# ~~ SimpleApiPlugin mixin

Expand Down Expand Up @@ -455,6 +482,7 @@ def __plugin_load__():
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.comm.protocol.atcommand.queuing": __plugin_implementation__.custom_atcommand_handler,
"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.gcode_queueing_handler,
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.gcode_received_handler,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
}
13 changes: 11 additions & 2 deletions octoprint_autodrop3d/static/js/autodrop3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $(function() {
self.job_file = ko.observable(false);
self.job_status = ko.observable(false);
self.new_at_command = ko.observable('');
self.selected_command = ko.observable();
self.print_events = {PrintStarted: 'started', PrintCancelled: 'has been canceled', PrintFailed: 'has failed', PrintDone: 'complete', Error: 'errored'}
self.job_id = ko.pureComputed(function(){
return self.job_file().replace(/^.*\/(.*).gcode$/gm, '$1');
Expand Down Expand Up @@ -178,10 +179,18 @@ $(function() {
}

self.add_at_command = function(){
self.settingsViewModel.settings.plugins.autodrop3d.at_commands_to_monitor.push(self.new_at_command());
self.selected_command({'command': ko.observable(self.new_at_command()), 'python': ko.observable('')});
self.settingsViewModel.settings.plugins.autodrop3d.at_commands_to_monitor.push(self.selected_command());
$('#autodrop3d_command_editor').modal('show');
self.new_at_command('');
}

self.edit_at_command = function(data){
self.selected_command(data);
$('#autodrop3d_command_editor').modal('show');
console.log(self.selected_command());
}

self.remove_at_command = function(data){
self.settingsViewModel.settings.plugins.autodrop3d.at_commands_to_monitor.remove(data);
}
Expand All @@ -190,6 +199,6 @@ $(function() {
OCTOPRINT_VIEWMODELS.push({
construct: autodrop3dViewModel,
dependencies: [ "settingsViewModel" ],
elements: [ "#settings_plugin_autodrop3d", "#navbar_plugin_autodrop3d" ]
elements: [ "#settings_plugin_autodrop3d", "#navbar_plugin_autodrop3d", "#autodrop3d_command_editor" ]
});
});
8 changes: 1 addition & 7 deletions octoprint_autodrop3d/templates/autodrop3d_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@
<input type="number" min="10" class="input-small" data-bind="value: settingsViewModel.settings.plugins.autodrop3d.polling_interval"/>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Enable GPIO') }}</label>
<div class="controls">
<input class="input-checkbox" type="checkbox" data-bind="checked: settingsViewModel.settings.plugins.autodrop3d.use_gpio"/>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Write File on Complete') }}</label>
<div class="controls">
Expand All @@ -61,7 +55,7 @@
<div class="controls">
<!-- ko foreach: settingsViewModel.settings.plugins.autodrop3d.at_commands_to_monitor -->
<div class="row-fluid">
<div class="span5" data-bind="text: $data"></div><div class="span2"><button class="btn btn-mini btn-danger" data-bind="click: $parent.remove_at_command"><i class="fa fa-trash-o"></i></button></div>
<div class="span5" data-bind="text: $data.command"></div><div class="span2"><div class="btn-group"><button class="btn btn-mini" data-bind="click: $parent.edit_at_command"><i class="fa fa-pencil"></i></button><button class="btn btn-mini btn-danger" data-bind="click: $parent.remove_at_command"><i class="fa fa-trash-o"></i></button></div></div>
</div>
<!-- /ko -->
</div>
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Autodrop3D"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.2rc2"
plugin_version = "0.2.0rc1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand All @@ -33,7 +33,7 @@
plugin_license = "MIT"

# Any additional requirements besides OctoPrint should be listed here
plugin_requires = []
plugin_requires = ["RPi.GPIO"]

### --------------------------------------------------------------------------------------------------------------------
### More advanced options that you usually shouldn't have to touch follow after this point
Expand Down

0 comments on commit 2898bdc

Please sign in to comment.