position update works again

This commit is contained in:
Teja 2015-07-06 19:36:18 +02:00
parent 6148b82b7f
commit af6310f5d3
4 changed files with 19 additions and 345 deletions

View file

@ -51,172 +51,6 @@ def get_connection_options():
"autoconnect": settings().getBoolean(["serial", "autoconnect"])
}
#<<<<<<< HEAD
#class Printer():
# def __init__(self, fileManager, analysisQueue, printerProfileManager):
# from collections import deque
#
# self._logger = logging.getLogger(__name__)
# #self._estimationLogger = logging.getLogger("ESTIMATIONS")
# #self._printTimeLogger = logging.getLogger("PRINT_TIME")
#
# self._analysisQueue = analysisQueue
# self._fileManager = fileManager
# self._printerProfileManager = printerProfileManager
#
# # state
# # TODO do we really need to hold the temperature here?
# self._temp = None
# self._bedTemp = None
# self._targetTemp = None
# self._targetBedTemp = None
# self._temps = deque([], 300)
# self._tempBacklog = []
#
# self._latestMessage = None
# self._messages = deque([], 300)
# self._messageBacklog = []
#
# self._latestLog = None
# self._log = deque([], 300)
# self._logBacklog = []
#
# self._state = None
#
# self._currentZ = None
# self._machinePosition = "-"
# self._workPosition = "-"
#
# self._progress = None
# self._printTime = None
# self._printTimeLeft = None
#
# self._printAfterSelect = False
#
# # sd handling
# self._sdPrinting = False
# self._sdStreaming = False
# self._sdFilelistAvailable = threading.Event()
# self._streamingFinishedCallback = None
#
# self._selectedFile = None
# self._timeEstimationData = None
#
# # comm
# self._comm = None
#
# # callbacks
# self._callbacks = []
#
# # progress plugins
# self._lastProgressReport = None
# self._progressPlugins = plugin_manager().get_implementations(ProgressPlugin)
#
# self._stateMonitor = StateMonitor(
# ratelimit=0.5,
# updateCallback=self._sendCurrentDataCallbacks,
# addTemperatureCallback=self._sendAddTemperatureCallbacks,
# addLogCallback=self._sendAddLogCallbacks,
# addMessageCallback=self._sendAddMessageCallbacks
# )
# self._stateMonitor.reset(
# state={"text": self.getStateString(), "flags": self._getStateFlags()},
# jobData={
# "file": {
# "name": None,
# "size": None,
# "origin": None,
# "date": None
# },
# "estimatedPrintTime": None,
# "lastPrintTime": None,
# "filament": {
# "length": None,
# "volume": None
# }
# },
# progress={"completion": None, "filepos": None, "printTime": None, "printTimeLeft": None},
# currentZ=None
# )
#
# eventManager().subscribe(Events.METADATA_ANALYSIS_FINISHED, self.onMetadataAnalysisFinished)
# eventManager().subscribe(Events.METADATA_STATISTICS_UPDATED, self.onMetadataStatisticsUpdated)
#
# #~~ callback handling
#
# def registerCallback(self, callback):
# self._callbacks.append(callback)
# self._sendInitialStateUpdate(callback)
#
# def unregisterCallback(self, callback):
# if callback in self._callbacks:
# self._callbacks.remove(callback)
#
# def _sendAddTemperatureCallbacks(self, data):
# for callback in self._callbacks:
# try: callback.addTemperature(data)
# except: self._logger.exception("Exception while adding temperature data point")
#
# def _sendAddLogCallbacks(self, data):
# for callback in self._callbacks:
# try: callback.addLog(data)
# except: self._logger.exception("Exception while adding communication log entry")
#
# def _sendAddMessageCallbacks(self, data):
# for callback in self._callbacks:
# try: callback.addMessage(data)
# except: self._logger.exception("Exception while adding printer message")
#
# def _sendCurrentDataCallbacks(self, data):
# for callback in self._callbacks:
# try: callback.sendCurrentData(copy.deepcopy(data))
# except: self._logger.exception("Exception while pushing current data")
#
# def _sendTriggerUpdateCallbacks(self, type):
# for callback in self._callbacks:
# try: callback.sendEvent(type)
# except: self._logger.exception("Exception while pushing trigger update")
#
# def _sendFeedbackCommandOutput(self, name, output):
# for callback in self._callbacks:
# try: callback.sendFeedbackCommandOutput(name, output)
# except: self._logger.exception("Exception while pushing feedback command output")
#
# #~~ callback from metadata analysis event
#
# def onMetadataAnalysisFinished(self, event, data):
# if self._selectedFile:
# self._setJobData(self._selectedFile["filename"],
# self._selectedFile["filesize"],
# self._selectedFile["sd"])
#
# def onMetadataStatisticsUpdated(self, event, data):
# self._setJobData(self._selectedFile["filename"],
# self._selectedFile["filesize"],
# self._selectedFile["sd"])
#
# #~~ progress plugin reporting
#
# def _reportPrintProgressToPlugins(self, progress):
# if not progress or not self._selectedFile or not "sd" in self._selectedFile or not "filename" in self._selectedFile:
# return
#
# storage = "sdcard" if self._selectedFile["sd"] else "local"
# filename = self._selectedFile["filename"]
#
# def call_plugins(storage, filename, progress):
# for name, plugin in self._progressPlugins.items():
# try:
# plugin.on_print_progress(storage, filename, progress)
# except:
# self._logger.exception("Exception while sending print progress to plugin %s" % name)
#
# thread = threading.Thread(target=call_plugins, args=(storage, filename, progress))
# thread.daemon = False
# thread.start()
#
# #~~ printer commands
#=======
class PrinterInterface(object):
"""
@ -232,7 +66,6 @@ class PrinterInterface(object):
valid_heater_regex = re.compile("^(tool\d+|bed)$")
"""Regex for valid heater identifiers."""
#>>>>>>> upstream/maintenance
def connect(self, port=None, baudrate=None, profile=None):
"""

View file

@ -146,6 +146,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
except: self._logger.exception("Exception while adding printer message")
def _sendCurrentDataCallbacks(self, data):
print("current Data callback", self._callbacks)
for callback in self._callbacks:
try: callback.on_printer_send_current_data(copy.deepcopy(data))
except: self._logger.exception("Exception while pushing current data")
@ -255,11 +256,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
printer_profile = self._printerProfileManager.get_current_or_default()
movement_speed = printer_profile["axes"][axis]["speed"]
self.commands(["G91", "G1 %s%.4f F%d" % (axis.upper(), amount, movement_speed), "G90"])
# def jog(self, axis, amount):
# printer_profile = self._printerProfileManager.get_current_or_default()
# movement_speed = printer_profile["axes"][axis]["speed"]
# self.commands(["G91", "G1 %s%.4f F%d" % (axis.upper(), amount, movement_speed), "G90", "?"])
self.commands(["G91", "G1 %s%.4f F%d" % (axis.upper(), amount, movement_speed), "G90", "?"])
def home(self, axes):
if(settings().getBoolean(["feature", "grbl"])):
@ -966,7 +963,9 @@ class StateMonitor(object):
"job": self._job_data,
"currentZ": self._current_z,
"progress": self._progress,
"offsets": self._offsets
"offsets": self._offsets,
"workPosition": self._workPosition,
"machinePosition": self._machinePosition
}
def setWorkPosition(self, workPosition):

View file

@ -1,58 +1,3 @@
//<<<<<<< HEAD
//function PrinterStateViewModel(loginStateViewModel, timelapseViewModel, vectorConversionViewModel) {
// var self = this;
//
// self.loginState = loginStateViewModel;
//
// self.stateString = ko.observable(undefined);
// self.isErrorOrClosed = ko.observable(undefined);
// self.isOperational = ko.observable(undefined);
// self.isConnecting = ko.observable(undefined);
// self.isPrinting = ko.observable(undefined);
// self.isPaused = ko.observable(undefined);
// self.isError = ko.observable(undefined);
// self.isReady = ko.observable(undefined);
// self.isLoading = ko.observable(undefined);
// self.isSdReady = ko.observable(undefined);
//
// self.filename = ko.observable(undefined);
// self.progress = ko.observable(undefined);
// self.filesize = ko.observable(undefined);
// self.filepos = ko.observable(undefined);
// self.printTime = ko.observable(undefined);
// self.printTimeLeft = ko.observable(undefined);
// self.sd = ko.observable(undefined);
// self.timelapse = ko.observable(undefined);
//
// self.busyFiles = ko.observableArray([]);
//
// self.filament = ko.observableArray([]);
// self.estimatedPrintTime = ko.observable(undefined);
// self.lastPrintTime = ko.observable(undefined);
//
// self.currentHeight = ko.observable(undefined);
//
// self.conversion = vectorConversionViewModel;
//
//
// self.TITLE_PRINT_BUTTON_PAUSED = gettext("Restarts the print job from the beginning");
// self.TITLE_PRINT_BUTTON_UNPAUSED = gettext("Starts the print job");
// self.TITLE_PAUSE_BUTTON_PAUSED = gettext("Resumes the print job");
// self.TITLE_PAUSE_BUTTON_UNPAUSED = gettext("Pauses the print job");
//
// self.titlePrintButton = ko.observable(self.TITLE_PRINT_BUTTON_UNPAUSED);
// self.titlePauseButton = ko.observable(self.TITLE_PAUSE_BUTTON_UNPAUSED);
//
// self.estimatedPrintTimeString = ko.computed(function() {
// if (self.lastPrintTime())
// return formatDuration(self.lastPrintTime());
// if (self.estimatedPrintTime())
// return formatDuration(self.estimatedPrintTime());
// return "-";
// });
// self.byteString = ko.computed(function() {
// if (!self.filesize())
//=======
$(function() {
function PrinterStateViewModel(parameters) {
var self = this;
@ -102,7 +47,6 @@ $(function() {
return formatDuration(self.lastPrintTime());
if (self.estimatedPrintTime())
return formatDuration(self.estimatedPrintTime());
//>>>>>>> upstream/maintenance
return "-";
});
self.byteString = ko.computed(function() {
@ -144,97 +88,20 @@ $(function() {
return gettext("Pause");
});
//<<<<<<< HEAD
// var type = timelapse["type"];
// if (type == "zchange") {
// return gettext("On Z Change");
// } else if (type == "timed") {
// return gettext("Timed") + " (" + timelapse["options"]["interval"] + " " + gettext("sec") + ")";
// } else {
// return "-";
// }
// });
//
// self.fromCurrentData = function(data) {
// self._fromData(data);
// };
//
// self.fromHistoryData = function(data) {
// self._fromData(data);
// };
//
// self.fromTimelapseData = function(data) {
// self.timelapse(data);
// };
//
// self._fromData = function(data) {
// self._processStateData(data.state);
// self._processJobData(data.job);
// self._processProgressData(data.progress);
// self._processZData(data.currentZ);
// self._processBusyFiles(data.busyFiles);
// if(data.workPosition){
// self._processPos(data.workPosition);
// }
// };
//
// self._processPos = function(posStr) {
// // example posStr: "X: 73.0000 Y: 192.0000 Z: 0.0000"
// var parts = posStr.split(" ");
// var x = parseFloat(parts[1]).toFixed(2);
// var y = parseFloat(parts[3]).toFixed(2);
// self.currentPos({x:x, y:y});
// };
//
// self._processStateData = function(data) {
// var prevPaused = self.isPaused();
// self.stateString(gettext(data.text));
// self.isErrorOrClosed(data.flags.closedOrError);
// self.isOperational(data.flags.operational);
// self.isConnecting(data.text === "Connecting" || data.text === "Opening serial port");
// self.isPaused(data.flags.paused);
// self.isPrinting(data.flags.printing);
// self.isError(data.flags.error);
// self.isReady(data.flags.ready);
// self.isSdReady(data.flags.sdReady);
//
// if (self.isPaused() != prevPaused) {
// if (self.isPaused()) {
// self.titlePrintButton(self.TITLE_PRINT_BUTTON_PAUSED);
// self.titlePauseButton(self.TITLE_PAUSE_BUTTON_PAUSED);
//=======
self.timelapseString = ko.computed(function() {
var timelapse = self.timelapse();
if (!timelapse || !timelapse.hasOwnProperty("type"))
return "-";
var type = timelapse["type"];
if (type == "zchange") {
return gettext("On Z Change");
} else if (type == "timed") {
return gettext("Timed") + " (" + timelapse["options"]["interval"] + " " + gettext("sec") + ")";
//>>>>>>> upstream/maintenance
} else {
return "-";
}
//<<<<<<< HEAD
// }
// };
//
// self._processJobData = function(data) {
// if (data.file) {
// self.filename(data.file.name);
// self.filesize(data.file.size);
// self.sd(data.file.origin === "sdcard");
// } else {
// self.filename(undefined);
// self.filesize(undefined);
// self.sd(undefined);
// }
//=======
});
//>>>>>>> upstream/maintenance
self.fromCurrentData = function(data) {
self._fromData(data);
@ -248,21 +115,17 @@ $(function() {
self.timelapse(data);
};
//<<<<<<< HEAD
// var result = [];
// if (data.filament && typeof(data.filament) === "object" && _.keys(data.filament).length > 0) {
// for (var key in data.filament) {
// if (!_.startsWith(key, "tool") || !data.filament[key] || !data.filament[key].hasOwnProperty("length") || data.filament[key].length <= 0) continue;
//=======
self._fromData = function(data) {
self._processStateData(data.state);
self._processJobData(data.job);
self._processProgressData(data.progress);
self._processZData(data.currentZ);
self._processBusyFiles(data.busyFiles);
if(data.workPosition){
self._processPos(data.workPosition);
}
};
//>>>>>>> upstream/maintenance
self._processStateData = function(data) {
var prevPaused = self.isPaused();
@ -300,7 +163,6 @@ $(function() {
}
self.estimatedPrintTime(data.estimatedPrintTime);
self.lastPrintTime(data.lastPrintTime);
var result = [];
if (data.filament && typeof(data.filament) == "object" && _.keys(data.filament).length > 0) {
for (var key in data.filament) {
@ -362,38 +224,11 @@ $(function() {
self.show_safety_glasses_warning(callback);
};
//<<<<<<< HEAD
// };
//
// self.pause = function() {
// self._jobCommand("pause");
// };
//
// self.cancel = function() {
// self._jobCommand("cancel");
// };
//
//// self.convertWorkingArea = function(){
//// self.conversion.show2();
//// };
//
// self._jobCommand = function(command, callback) {
// $.ajax({
// url: API_BASEURL + "job",
// type: "POST",
// dataType: "json",
// contentType: "application/json; charset=UTF-8",
// data: JSON.stringify({command: command}),
// success: function(response) {
// if (callback != undefined) {
// callback();
//=======
self._processBusyFiles = function(data) {
var busyFiles = [];
_.each(data, function(entry) {
if (entry.hasOwnProperty("name") && entry.hasOwnProperty("origin")) {
busyFiles.push(entry.origin + ":" + entry.name);
//>>>>>>> upstream/maintenance
}
});
self.busyFiles(busyFiles);
@ -423,7 +258,7 @@ $(function() {
self._jobCommand("cancel");
};
self._jobCommand = function(command, callback) {
self._jobCommand = function(command, callback) {
$.ajax({
url: API_BASEURL + "job",
type: "POST",
@ -436,7 +271,15 @@ $(function() {
}
}
});
}
};
self._processPos = function (posStr) {
// example posStr: "X: 73.0000 Y: 192.0000 Z: 0.0000"
var parts = posStr.split(" ");
var x = parseFloat(parts[1]).toFixed(2);
var y = parseFloat(parts[3]).toFixed(2);
self.currentPos({x: x, y: y});
};
}
OCTOPRINT_VIEWMODELS.push([

View file

@ -785,7 +785,6 @@ class MachineCom(object):
# GRBL Position update
if self._grbl :
print ('state: ', self.getStateString(), line)
if 'MPos:' in line:
if grblLastStatus == line: