Commit 7c8319d7 authored by Nicholas Gar Hei Chan's avatar Nicholas Gar Hei Chan
Browse files

Initial commit

parents
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
[**.py]
indent_style = tab
[**.js]
indent_style = space
indent_size = 4
*.pyc
*.swp
.idea
*.iml
build
dist
*.egg*
.DS_Store
*.zip
include README.md
recursive-include octoprint_autoFDP/templates *
recursive-include octoprint_autoFDP/translations *
recursive-include octoprint_autoFDP/static *
# OctoPrint-Autofdp
**TODO:** Describe what your plugin does.
## Setup
Install via the bundled [Plugin Manager](https://docs.octoprint.org/en/master/bundledplugins/pluginmanager.html)
or manually using this URL:
https://github.com/you/OctoPrint-Autofdp/archive/master.zip
**TODO:** Describe how to install your plugin, if more needs to be done than just installing it via pip or through
the plugin manager.
## Configuration
**TODO:** Describe your plugin's configuration options (if any).
[python: */**.py]
[jinja2: */**.jinja2]
silent=false
extensions=jinja2.ext.autoescape, jinja2.ext.with_, jinja2.ext.do, octoprint.util.jinja.trycatch
[javascript: */**.js]
extract_messages = gettext, ngettext
Currently Cookiecutter generates the following helpful extras to this folder:
autoFDP.md
Data file for plugins.octoprint.org. Fill in the missing TODOs once your
plugin is ready for release and file a PR as described at
http://plugins.octoprint.org/help/registering/ to get it published.
This folder may be safely removed if you don't need it.
---
layout: plugin
id: autoFDP
title: OctoPrint-Autofdp
description: TODO
authors:
- Nicholas Chan
license: AGPLv3
# TODO
date: today's date in format YYYY-MM-DD, e.g. 2015-04-21
homepage: https://github.com/you/OctoPrint-Autofdp
source: https://github.com/you/OctoPrint-Autofdp
archive: https://github.com/you/OctoPrint-Autofdp/archive/master.zip
# TODO
# Set this to true if your plugin uses the dependency_links setup parameter to include
# library versions not yet published on PyPi. SHOULD ONLY BE USED IF THERE IS NO OTHER OPTION!
#follow_dependency_links: false
# TODO
tags:
- a list
- of tags
- that apply
- to your plugin
- (take a look at the existing plugins for what makes sense here)
# TODO
screenshots:
- url: url of a screenshot, /assets/img/...
alt: alt-text of a screenshot
caption: caption of a screenshot
- url: url of another screenshot, /assets/img/...
alt: alt-text of another screenshot
caption: caption of another screenshot
- ...
# TODO
featuredimage: url of a featured image for your plugin, /assets/img/...
# TODO
# You only need the following if your plugin requires specific OctoPrint versions or
# specific operating systems to function - you can safely remove the whole
# "compatibility" block if this is not the case.
compatibility:
# List of compatible versions
#
# A single version number will be interpretated as a minimum version requirement,
# e.g. "1.3.1" will show the plugin as compatible to OctoPrint versions 1.3.1 and up.
# More sophisticated version requirements can be modelled too by using PEP440
# compatible version specifiers.
#
# You can also remove the whole "octoprint" block. Removing it will default to all
# OctoPrint versions being supported.
octoprint:
- 1.2.0
# List of compatible operating systems
#
# Valid values:
#
# - windows
# - linux
# - macos
# - freebsd
#
# There are also two OS groups defined that get expanded on usage:
#
# - posix: linux, macos and freebsd
# - nix: linux and freebsd
#
# You can also remove the whole "os" block. Removing it will default to all
# operating systems being supported.
os:
- linux
- windows
- macos
- freebsd
# Compatible Python version
#
# Plugins should aim for compatibility for Python 2 and 3 for now, in which case the value should be ">=2.7,<4".
#
# Plugins that only wish to support Python 3 should set it to ">=3,<4".
#
# If your plugin only supports Python 2 (worst case, not recommended for newly developed plugins since Python 2
# is EOL), leave at ">=2.7,<3" - be aware that your plugin will not be allowed to register on the
# plugin repository if it only support Python 2.
python: ">=2.7,<3"
---
**TODO**: Longer description of your plugin, configuration examples etc. This part will be visible on the page at
http://plugins.octoprint.org/plugin/autoFDP/
# coding=utf-8
from __future__ import absolute_import
### (Don't forget to remove me)
# This is a basic skeleton for your plugin's __init__.py. You probably want to adjust the class name of your plugin
# as well as the plugin mixins it's subclassing from. This is really just a basic skeleton to get you started,
# defining your plugin as a template plugin, settings and asset plugin. Feel free to add or remove mixins
# as necessary.
#
# Take a look at the documentation on what other plugin mixins are available.
import octoprint.plugin
import sys
sys.path.insert(0, '/home/ngchan/devel/gcode-parser/gcode-parser')
import gcode_parser as gcp
import flask
class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.StartupPlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SimpleApiPlugin):
def __init__(self):
self.model = []
self.curr_layer = 0
self.num_layers = 0
##~~ SimpleApiPlugin mixin
def get_api_commands(self):
return dict(
change_layer=["inc"],
test_command=[]
)
def on_api_command(self, command, data):
if command == "change_layer":
if data["inc"] == "+1" and self.curr_layer < self.num_layers - 1:
self.curr_layer += 1
self.send_layer(self.curr_layer)
if data["inc"] == "-1" and self.curr_layer > 0:
self.curr_layer -= 1
self.send_layer(self.curr_layer)
if command == "test_command":
self._logger.info(data)
##~~ EventHandlerPlugin mixin
def send_layer(self, layer):
data = dict(layer_svg=self.model.layers[layer].to_svg_inline(500,self.model.max_x, self.model.max_y),
num_layers=len(self.model.layers),
curr_layer=self.curr_layer+1)
self._plugin_manager.send_plugin_message(self._identifier, data)
def process_gcode(self, payload):
self.model = gcp.parse_gcode("/home/ngchan/.octoprint/uploads/{}".format(payload['name']))
self.num_layers = len(self.model.layers)
self.curr_layer = 0;
def on_event(self, event, payload):
if event == 'FileSelected':
self._logger.info('File selected: "{}" at path "{}"'.format(payload['name'], payload['path']))
self.process_gcode(payload)
self._logger.info('GCODE Processed: {} layers'.format(self.num_layers))
self.send_layer(0)
if event == 'Dwelling': #G4 command received
self._logger.info('Dwell, sending a test command...')
self._printer.commands('G0 X10 Y10')
if event == 'Waiting': #M0, M1, M226 received
self._logger.info('Waiting')
##~~ TemplatePlugin mixin
def get_template_configs(self):
return [
dict(type="tab", custom_bindings=True),
dict(type="settings", custom_bindings=False)
]
# def get_template_vars(self):
# return dict(x_offset=self._settings.get(["x_offset"]),
# y_offset=self._settings.get(["y_offset"]),
# z_offset=self._settings.get(["z_offset"]))
##~~ StartupPlugin mixin
def on_after_startup(self):
self._logger.info("autoFDP starting...")
self._logger.info(self._settings.get(["x_offset"]))
##~~ SettingsPlugin mixin
def get_settings_defaults(self):
return dict(
# put your plugin's default settings here
x_offset="0",
y_offset="0",
z_offset="0"
)
def on_settings_save(self, data):
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
self._logger.info("SETTINGS HAVE BEEN CHANGED")
#TODO: PROBE UPDATE CODE HERE
test = self._settings.get(["x_offset"])
self._logger.info(test)
self._logger.info(str(type(test)))
##~~ AssetPlugin mixin
def get_assets(self):
# Define your plugin's asset files to automatically include in the
# core UI here.
return dict(
js=["js/autoFDP.js"],
#css=["css/autoFDP.css"],
#less=["less/autoFDP.less"]
)
##~~ Softwareupdate hook
def get_update_information(self):
# Define the configuration for your plugin to use with the Software Update
# Plugin here. See https://docs.octoprint.org/en/master/bundledplugins/softwareupdate.html
# for details.
return dict(
autoFDP=dict(
displayName="Autofdp Plugin",
displayVersion=self._plugin_version,
# version check: github repository
type="github_release",
user="you",
repo="OctoPrint-Autofdp",
current=self._plugin_version,
# update method: pip
pip="https://github.com/you/OctoPrint-Autofdp/archive/{target_version}.zip"
)
)
# If you want your plugin to be registered within OctoPrint under a different name than what you defined in setup.py
# ("OctoPrint-PluginSkeleton"), you may define that here. Same goes for the other metadata derived from setup.py that
# can be overwritten via __plugin_xyz__ control properties. See the documentation for that.
__plugin_name__ = "AutoFDP Plugin"
# Starting with OctoPrint 1.4.0 OctoPrint will also support to run under Python 3 in addition to the deprecated
# Python 2. New plugins should make sure to run under both versions for now. Uncomment one of the following
# compatibility flags according to what Python versions your plugin supports!
#__plugin_pythoncompat__ = ">=2.7,<3" # only python 2
#__plugin_pythoncompat__ = ">=3,<4" # only python 3
__plugin_pythoncompat__ = ">=2.7,<4" # python 2 and 3
def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = AutofdpPlugin()
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
/* TODO: Have your plugin's CSS files generated to here. */
/*
* View model for OctoPrint-Autofdp
*
* Author: Nicholas Chan
* License: AGPLv3
*/
$(function() {
function AutofdpViewModel(parameters) {
var self = this;
// assign the injected parameters, e.g.:
// self.loginStateViewModel = parameters[0];
// self.settingsViewModel = parameters[1];
// TODO: Implement your plugin's view model here.
self.settingsViewModel = parameters[0];
self.default_samples_per_layer = ko.observable("5");
self.current_layer = ko.observable("N/A");
self.total_layers = ko.observable("N/A");
self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin != "autoFDP") {
return;
}
if (data.layer_svg) {
document.getElementById('viewport').innerHTML = data.layer_svg;
}
if (data.num_layers) {
self.total_layers(data.num_layers)
}
if (data.curr_layer) {
self.current_layer(data.curr_layer)
}
};
self.increment_layer = function(data) {
OctoPrint.simpleApiCommand("autoFDP", "change_layer", {"inc": "+1"});
};
self.decrement_layer = function(data) {
OctoPrint.simpleApiCommand("autoFDP", "change_layer", {"inc": "-1"});
};
self.test_command = function(data) {
OctoPrint.simpleApiCommand("autoFDP", "test_command", {"key": "hello"});
};
}
/* view model class, parameters for constructor, container to bind to
* Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details
* and a full list of the available options.
*/
OCTOPRINT_VIEWMODELS.push({
// construct: AutofdpViewModel,
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ...
//dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ],
// Elements to bind to, e.g. #settings_plugin_autoFDP, #tab_plugin_autoFDP, ...
//elements: [ /* ... */ ]
construct: AutofdpViewModel,
dependencies: ["settingsViewModel"],
elements: ["#settings_plugin_autoFDP", "#tab_plugin_autoFDP"]
});
});
/*
* View model for OctoPrint-Autofdp
*
* Author: Nicholas Chan
* License: AGPLv3
*/
$(function() {
function AutofdpViewModel(parameters) {
var self = this;
// assign the injected parameters, e.g.:
// self.loginStateViewModel = parameters[0];
// self.settingsViewModel = parameters[1];
// TODO: Implement your plugin's view model here.
}
/* view model class, parameters for constructor, container to bind to
* Please see http://docs.octoprint.org/en/master/plugins/viewmodels.html#registering-custom-viewmodels for more details
* and a full list of the available options.
*/
OCTOPRINT_VIEWMODELS.push({
construct: AutofdpViewModel,
// ViewModels your plugin depends on, e.g. loginStateViewModel, settingsViewModel, ...
dependencies: [ /* "loginStateViewModel", "settingsViewModel" */ ],
// Elements to bind to, e.g. #settings_plugin_autoFDP, #tab_plugin_autoFDP, ...
elements: [ /* ... */ ]
});
});
// TODO: Put your plugin's LESS here, have it generated to ../css.
Put your plugin's Jinja2 templates here.
\ No newline at end of file
<h3>Probe Settings</h3>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label">X Offset</label>
<div class="controls">
<div class="input-append">
<input type="text" data-bind="value: settings.plugins.autoFDP.x_offset">
<span class="add-on">mm</span>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Y Offset</label>
<div class="controls">
<div class="input-append">
<input type="text" data-bind="value: settings.plugins.autoFDP.y_offset">
<span class="add-on">mm</span>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Z Offset</label>
<div class="controls">
<div class="input-append">
<input type="text" data-bind="value: settings.plugins.autoFDP.z_offset">
<span class="add-on">mm</span>
</div>
</div>
</div>
<span class="help-block">X,Y,Z offsets are measured from the nozzle to the probe tip in the standard coordinates of your specific printer. </span>
</form>
<div id="viewport">
<p>Select a file to begin GCODE processing...</p>
</div>
<div class="layer-pane row-fluid">
<div class="span6">
<button class="btn btn-primary btn-block" type="button" data-bind="click: decrement_layer">Previous layer</button>
</div>
<div class="span6">
<button class="btn btn-primary btn-block" type="button" data-bind="click: increment_layer">Next layer</button>
</div>
<h1>Layer Info</h1>
<p>Layer: <span data-bind="text: current_layer"></span>/<span data-bind="text: total_layers"></p>
</div>
<div class="settings-pane row-fluid">
<div class="span4">
<h1>Probe Info</h1>
<p>X Offset: <span data-bind="text: settingsViewModel.settings.plugins.autoFDP.x_offset"></span> mm</p>
<p>Y Offset: <span data-bind="text: settingsViewModel.settings.plugins.autoFDP.y_offset"></span> mm</p>
<p>Z Offset: <span data-bind="text: settingsViewModel.settings.plugins.autoFDP.z_offset"></span> mm</p>
</div>
<div class="span8">
<h1>User Settings</h1>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label">Samples per layer</label>
<div class="controls">
<input class="span6" type="number" min="1" data-bind="value: default_samples_per_layer">
</div>
</div>
<div class="control-group">
<label class="control-label">Layer spacing</label>
<div class="controls">
<input class="span6" type="number" min="1" placeholder="5">
</div>
</div>
</form>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-primary">Process GCODE</button>
<button type="button" class="btn">Reset to defaults</button>
</div>
###
# This file is only here to make sure that something like
#
# pip install -e .
#
# works as expected. Requirements can be found in setup.py.
###
.
[bdist_wheel]
universal = 1
# coding=utf-8
########################################################################################################################
### Do not forget to adjust the following variables to your own plugin.
# The plugin's identifier, has to be unique
plugin_identifier = "autoFDP"
# The plugin's python package, should be "octoprint_<plugin identifier>", has to be unique
plugin_package = "octoprint_autoFDP"
# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the
# plugin module
plugin_name = "OctoPrint-Autofdp"
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.0"
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
plugin_description = """TODO"""
# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
plugin_author = "Nicholas Chan"
# The plugin's author's mail address.
plugin_author_email = "ngchan@umich.edu"
# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
plugin_url = "https://github.com/you/OctoPrint-Autofdp"
# The plugin's license. Can be overwritten within OctoPrint's internal data via __plugin_license__ in the plugin module
plugin_license = "AGPLv3"
# Any additional requirements besides OctoPrint should be listed here
plugin_requires = []
### --------------------------------------------------------------------------------------------------------------------
### More advanced options that you usually shouldn't have to touch follow after this point
### --------------------------------------------------------------------------------------------------------------------
# Additional package data to install for this plugin. The subfolders "templates", "static" and "translations" will
# already be installed automatically if they exist. Note that if you add something here you'll also need to update
# MANIFEST.in to match to ensure that python setup.py sdist produces a source distribution that contains all your
# files. This is sadly due to how python's setup.py works, see also http://stackoverflow.com/a/14159430/2028598
plugin_additional_data = []
# Any additional python packages you need to install with your plugin that are not contained in <plugin_package>.*
plugin_additional_packages = []
# Any python packages within <plugin_package>.* you do NOT want to install with your plugin
plugin_ignored_packages = []
# Additional parameters for the call to setuptools.setup. If your plugin wants to register additional entry points,
# define dependency links or other things like that, this is the place to go. Will be merged recursively with the
# default setup parameters as provided by octoprint_setuptools.create_plugin_setup_parameters using
# octoprint.util.dict_merge.
#
# Example:
# plugin_requires = ["someDependency==dev"]
# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
additional_setup_parameters = {}
########################################################################################################################
from setuptools import setup
try:
import octoprint_setuptools
except:
print("Could not import OctoPrint's setuptools, are you sure you are running that under "
"the same python installation that OctoPrint is installed under?")
import sys
sys.exit(-1)