Skip to content

Commit

Permalink
Merge branch 'calibration'
Browse files Browse the repository at this point in the history
Conflicts:
	octoprint_OctoPNP/static/js/OctoPNP.js
  • Loading branch information
platsch committed Dec 17, 2015
2 parents b323de2 + eaf4d9d commit a5ca858
Show file tree
Hide file tree
Showing 4 changed files with 610 additions and 7 deletions.
62 changes: 56 additions & 6 deletions octoprint_OctoPNP/__init__.py
Expand Up @@ -22,6 +22,7 @@


import octoprint.plugin
import flask
import re
from subprocess import call
import os
Expand Down Expand Up @@ -50,7 +51,9 @@ class OctoPNP(octoprint.plugin.StartupPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin):
octoprint.plugin.AssetPlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.BlueprintPlugin):

STATE_NONE = 0
STATE_PICK = 1
Expand Down Expand Up @@ -114,16 +117,58 @@ def get_settings_defaults(self):

def get_template_configs(self):
return [
dict(type="tab", custom_bindings=True),
dict(type="settings", custom_bindings=False)
dict(type="tab", template="OctoPNP_tab.jinja2", custom_bindings=True),
dict(type="settings", template="OctoPNP_settings.jinja2", custom_bindings=True)
#dict(type="settings", custom_bindings=True)
]

def get_assets(self):
return dict(
js=["js/OctoPNP.js",
"js/smdTray.js"]
"js/smdTray.js",
"js/settings.js"]
)

# Define possible requests from GUI
def get_api_commands(self):
return dict(
getCameraImage=["imagetype"]
)

def on_api_command(self, command, data):
import flask
if command == "getCameraImage":
if data.get("imagetype") == "HEAD":
# Retrieve image from camera
if self._grabImages():
headPath = self._settings.get(["camera", "head", "path"])

#update UI
self._updateUI("HEADIMAGE", headPath)
self._logger.info("getCameraImage, type: " + data.get("imagetype"))

def on_api_get(self, request):
#if "force" in flask.request.values and flask.request.values["force"]
print request.values
#flask.request.values
return flask.jsonify(foo="bar")

@octoprint.plugin.BlueprintPlugin.route("/camera_image", methods=["GET"])
def getCameraImage(self):
result = ""
if "imagetype" in flask.request.values:
if (flask.request.values["imagetype"] == "HEAD") or (flask.request.values["imagetype"] == "BED"):
if self._grabImages():
headPath = self._settings.get(["camera", flask.request.values["imagetype"].lower(), "path"])
try:
f = open(headPath,"r")
result = flask.jsonify(src="data:image/" + os.path.splitext(headPath)[1] + ";base64,"+base64.b64encode(bytes(f.read())))
except IOError:
result = flask.jsonify(error="Unable to open Image after fetching. Image path: " + headPath)
else:
result = flask.jsonify(error="Unable to fetch image. Check octoprint log for details.")
return flask.make_response(result, 200)

# Use the on_event hook to extract XML data every time a new file has been loaded by the user
def on_event(self, event, payload):
#extraxt part informations from inline xmly
Expand Down Expand Up @@ -370,8 +415,13 @@ def _grabImages(self):
result = True
grabScript = self._settings.get(["camera", "grabScriptPath"])
#os.path.dirname(os.path.realpath(__file__)) + "/cameras/grab.sh"
if call([grabScript]) != 0:
self._logger.info("ERROR: camera not ready!")
try:
if call([grabScript]) != 0:
self._logger.info("ERROR: camera not ready!")
result = False
except:
self._logger.info("ERROR: Unable to execute camera grab script!")
self._logger.info("Script path: " + grabScript)
result = False
return result

Expand Down
2 changes: 1 addition & 1 deletion octoprint_OctoPNP/static/js/OctoPNP.js
Expand Up @@ -101,6 +101,6 @@ $(function() {
["settingsViewModel", "controlViewModel", "connectionViewModel"],

// Finally, this is the list of all elements we want this view model to be bound to.
[document.getElementById("tab_plugin_OctoPNP")]
"#tab_plugin_OctoPNP"
]);
});

0 comments on commit a5ca858

Please sign in to comment.