Commit 6186ba0f authored by Nicholas Gar Hei Chan's avatar Nicholas Gar Hei Chan
Browse files

Restructured __init__.py

parent 1a4b44f5
......@@ -14,6 +14,7 @@ import sys
import os
import gcodeparser as gcp
import flask
class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
......@@ -22,6 +23,69 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.StartupPlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SimpleApiPlugin):
# ------------------------------------------------------------------------- #
# AUTO FDP CUSTOM FUNCTIONS #
# Implement custom logic and driving code here #
# ------------------------------------------------------------------------- #
def send_layer(self, layer):
""" Sends a layer to the Octoprint client
Parameters
----------
layer: gcodeparser.Layer
Layer object to send to the client.
"""
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):
""" Process a gcode file
Parameters
----------
payload: dict
File selected payload from the on-event handler.
"""
full_path = os.path.expanduser("~/.octoprint/uploads/{}".format(payload['name']))
self.model = gcp.parse_gcode(full_path)
self.num_layers = len(self.model.layers)
self.curr_layer = 0;
def sample_layer(self):
""" Sample a layer
"""
return True
def probe_point(self, x, y, z):
"""
Probe at selected x,y,z position. Move probe to point, extend probe, measure output, and report result
"""
self._logger.info('STARTING PROBE SEQUENCE')
probe_x = x - self.offsets['x']
probe_y = y - self.offsets['y']
probe_z = z + self.offsets['z']
# Go to 2mm above the sample position, accounting for tool offset
self._printer.commands('G0 X{} Y{} Z{}'.format(x+self.offsets['x'],
y+self.offsets['y'],
z+self.offsets['z']))
#TODO: EXTEND PROBE HERE
#TODO: READ PROBE VALUE HERE
#TODO: RETURN PROBE READING HERE
return True
# ------------------------------------------------------------------------- #
# OCTOPRINT DEFINED FUNCTIONS #
# Functions and event callbacks from octoprint #
# ------------------------------------------------------------------------- #
def __init__(self):
self.model = []
......@@ -50,19 +114,6 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
self.probe_point(10,10,10)
##~~ 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):
full_path = os.path.expanduser("~/.octoprint/uploads/{}".format(payload['name']))
self.model = gcp.parse_gcode(full_path)
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']))
......@@ -76,9 +127,14 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
self._logger.info('Waiting')
if event == 'ZChange':
data = self._printer.get_current_data()
self._logger.info('Layer changed. currentZ = {}'.format(data))
currentZ = data['currentZ']
try:
self.model.
current_layer = self.model.layer_heights.index(currentZ)
self._logger.info('Current layer: {}'.format(current_layer))
except:
self._logger.info('Not a valid layer at z = {}'.format(currentZ))
#self._logger.info('Layer changed. currentZ = {}'.format(data))
##~~ TemplatePlugin mixin
......@@ -88,12 +144,6 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
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(os.getcwd())
self._logger.info("autoFDP starting, retrieving saved settings...")
......@@ -129,33 +179,6 @@ class AutofdpPlugin(octoprint.plugin.SettingsPlugin,
#less=["less/autoFDP.less"]
)
##~~ CUSTOM FUNCTIONS FOR FAULT DETECTION PROBE
def sample_layer(self):
return True
def probe_point(self, x, y, z):
"""
Probe at selected x,y,z position. Move probe to point, extend probe, measure output, and report result
"""
self._logger.info('STARTING PROBE SEQUENCE')
probe_x = x - self.offsets['x']
probe_y = y - self.offsets['y']
probe_z = z + self.offsets['z']
# Go to 2mm above the sample position, accounting for tool offset
self._printer.commands('G0 X{} Y{} Z{}'.format(x+self.offsets['x'],
y+self.offsets['y'],
z+self.offsets['z']))
#TODO: EXTEND PROBE HERE
#TODO: READ PROBE VALUE HERE
#TODO: RETURN PROBE READING HERE
return True
##~~ Softwareupdate hook
def get_update_information(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment