Merge branch 'maintenance' into devel
# Conflicts: # setup.py # src/octoprint/cli/plugins.py # src/octoprint/events.py # src/octoprint/filemanager/__init__.py # src/octoprint/logging/__init__.py # src/octoprint/plugins/announcements/__init__.py # src/octoprint/plugins/appkeys/__init__.py # src/octoprint/plugins/forcelogin/__init__.py # src/octoprint/plugins/forcelogin/static/js/main.js # src/octoprint/plugins/forcelogin/templates/forcelogin_index.jinja2 # src/octoprint/plugins/pluginmanager/static/css/pluginmanager.css # src/octoprint/plugins/printer_safety_check/__init__.py # src/octoprint/plugins/softwareupdate/__init__.py # src/octoprint/plugins/virtual_printer/virtual.py # src/octoprint/printer/__init__.py # src/octoprint/printer/estimation.py # src/octoprint/printer/standard.py # src/octoprint/server/__init__.py # src/octoprint/server/api/__init__.py # src/octoprint/server/api/settings.py # src/octoprint/server/api/system.py # src/octoprint/server/apps/__init__.py # src/octoprint/server/util/__init__.py # src/octoprint/server/util/flask.py # src/octoprint/server/util/sockjs.py # src/octoprint/server/views.py # src/octoprint/settings.py # src/octoprint/slicing/__init__.py # src/octoprint/static/js/app/helpers.js # src/octoprint/static/js/app/main.js # src/octoprint/static/js/app/viewmodels/settings.js # src/octoprint/static/js/app/viewmodels/temperature.js # src/octoprint/templates/dialogs/settings/accesscontrol.jinja2 # src/octoprint/templates/dialogs/settings/api.jinja2 # src/octoprint/templates/initscript.jinja2 # src/octoprint/templates/tabs/control.jinja2 # src/octoprint/timelapse.py # src/octoprint/users.py # src/octoprint/util/comm.py # src/octoprint/util/gcodeInterpreter.py # src/octoprint/vendor/sockjs/tornado/transports/rawwebsocket.py # src/octoprint/vendor/sockjs/tornado/transports/websocket.py # translations/messages.pot
This commit is contained in:
commit
c0096c41a0
108 files changed
+9629
-4660
No files matched your search
@@ -23,7 +23,7 @@ from serial import SerialTimeoutException
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.plugin import plugin_manager
|
||||
from octoprint.util import RepeatedTimer, to_bytes
|
||||
from octoprint.util import RepeatedTimer, monotonic_time, to_bytes, to_unicode
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -54,7 +54,7 @@ class VirtualPrinter(object):
|
||||
self._seriallog.addHandler(seriallog_handler)
|
||||
self._seriallog.setLevel(logging.INFO)
|
||||
|
||||
self._seriallog.info("-"*78)
|
||||
self._seriallog.info(u"-"*78)
|
||||
|
||||
self._read_timeout = read_timeout
|
||||
self._write_timeout = write_timeout
|
||||
@@ -93,7 +93,9 @@ class VirtualPrinter(object):
|
||||
self.targetTemp = [0.0] * self.temperatureCount
|
||||
self.bedTemp = self._ambient_temperature
|
||||
self.bedTargetTemp = 0.0
|
||||
self.lastTempAt = time.time()
|
||||
self.chamberTemp = self._ambient_temperature
|
||||
self.chamberTargetTemp = 0.0
|
||||
self.lastTempAt = monotonic_time()
|
||||
|
||||
self._relative = True
|
||||
self._lastX = 0.0
|
||||
@@ -274,7 +276,7 @@ class VirtualPrinter(object):
|
||||
pass
|
||||
|
||||
def _processIncoming(self):
|
||||
next_wait_timeout = time.time() + self._waitInterval
|
||||
next_wait_timeout = monotonic_time() + self._waitInterval
|
||||
buf = b""
|
||||
while self.incoming is not None and not self._killed:
|
||||
self._simulateTemps()
|
||||
@@ -285,12 +287,17 @@ class VirtualPrinter(object):
|
||||
|
||||
try:
|
||||
data = self.incoming.get(timeout=0.01)
|
||||
data = to_bytes(data, encoding="ascii", errors="replace")
|
||||
self.incoming.task_done()
|
||||
except queue.Empty:
|
||||
if self._sendWait and time.time() > next_wait_timeout:
|
||||
if self._sendWait and monotonic_time() > next_wait_timeout:
|
||||
self._send("wait")
|
||||
next_wait_timeout = time.time() + self._waitInterval
|
||||
next_wait_timeout = monotonic_time() + self._waitInterval
|
||||
continue
|
||||
except Exception:
|
||||
if self.incoming is None:
|
||||
# just got closed
|
||||
break
|
||||
|
||||
if data is not None:
|
||||
buf += data
|
||||
@@ -301,7 +308,7 @@ class VirtualPrinter(object):
|
||||
else:
|
||||
continue
|
||||
|
||||
next_wait_timeout = time.time() + self._waitInterval
|
||||
next_wait_timeout = monotonic_time() + self._waitInterval
|
||||
|
||||
if data is None:
|
||||
continue
|
||||
@@ -310,8 +317,6 @@ class VirtualPrinter(object):
|
||||
self._dont_answer = False
|
||||
continue
|
||||
|
||||
data = data.strip()
|
||||
|
||||
# strip checksum
|
||||
if b"*" in data:
|
||||
checksum = int(data[data.rfind(b"*") + 1:])
|
||||
@@ -377,7 +382,7 @@ class VirtualPrinter(object):
|
||||
|
||||
data += b"\n"
|
||||
|
||||
data = data.decode("ascii").strip()
|
||||
data = to_unicode(data, encoding="ascii", errors="replace").strip()
|
||||
|
||||
if data.startswith("!!DEBUG:") or data.strip() == "!!DEBUG":
|
||||
debug_command = ""
|
||||
@@ -482,6 +487,12 @@ class VirtualPrinter(object):
|
||||
# type: (str) -> None
|
||||
self._parseBedCommand(data, wait=True, support_r=True)
|
||||
|
||||
def _gcode_M141(self, data):
|
||||
self._parseChamberCommand(data)
|
||||
|
||||
def _gcode_M191(self, data):
|
||||
self._parseChamberCommand(data, wait=True, support_r=True)
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
def _gcode_M105(self, data):
|
||||
# type: (str) -> bool
|
||||
@@ -685,7 +696,7 @@ class VirtualPrinter(object):
|
||||
|
||||
def _gcode_G28(self, data):
|
||||
# type: (str) -> None
|
||||
self._performMove(data)
|
||||
self._home(data)
|
||||
|
||||
def _gcode_G0(self, data):
|
||||
# type: (str) -> None
|
||||
@@ -707,8 +718,8 @@ class VirtualPrinter(object):
|
||||
_timeout = float(matchS.group(1))
|
||||
|
||||
if self._sendBusy and self._busyInterval > 0:
|
||||
until = time.time() + _timeout
|
||||
while time.time() < until:
|
||||
until = monotonic_time() + _timeout
|
||||
while monotonic_time() < until:
|
||||
time.sleep(self._busyInterval)
|
||||
self._send("busy:processing")
|
||||
else:
|
||||
@@ -722,8 +733,8 @@ class VirtualPrinter(object):
|
||||
timeout = 60
|
||||
|
||||
if self._sendBusy and self._busyInterval > 0:
|
||||
until = time.time() + timeout
|
||||
while time.time() < until:
|
||||
until = monotonic_time() + timeout
|
||||
while monotonic_time() < until:
|
||||
time.sleep(self._busyInterval)
|
||||
self._send("busy:processing")
|
||||
else:
|
||||
@@ -1005,6 +1016,12 @@ class VirtualPrinter(object):
|
||||
else:
|
||||
allTempsString = "B:%.2f %s" % (self.bedTemp, allTempsString)
|
||||
|
||||
if settings().getBoolean(["devel", "virtualPrinter", "hasChamber"]):
|
||||
if includeTarget:
|
||||
allTempsString = "C:%.2f /%.2f %s" % (self.chamberTemp, self.chamberTargetTemp, allTempsString)
|
||||
else:
|
||||
allTempsString = "C:%.2f %s" % (self.chamberTemp, allTempsString)
|
||||
|
||||
if settings().getBoolean(["devel", "virtualPrinter", "includeCurrentToolInTemps"]):
|
||||
if includeTarget:
|
||||
output = "T:%.2f /%.2f %s" % (self.temp[self.currentExtruder], self.targetTemp[self.currentExtruder], allTempsString)
|
||||
@@ -1014,9 +1031,28 @@ class VirtualPrinter(object):
|
||||
output = allTempsString
|
||||
else:
|
||||
if includeTarget:
|
||||
output = "T:%.2f /%.2f B:%.2f /%.2f" % (self.temp[0], self.targetTemp[0], self.bedTemp, self.bedTargetTemp)
|
||||
t = "T:%.2f /%.2f" % (self.temp[0], self.targetTemp[0])
|
||||
else:
|
||||
output = "T:%.2f B:%.2f" % (self.temp[0], self.bedTemp)
|
||||
t = "T:%.2f" % self.temp[0]
|
||||
|
||||
if settings().getBoolean(["devel", "virtualPrinter", "hasBed"]):
|
||||
if includeTarget:
|
||||
b = "B:%.2f /%.2f" % (self.bedTemp, self.bedTargetTemp)
|
||||
else:
|
||||
b = "B:%.2f" % self.bedTemp
|
||||
else:
|
||||
b = ""
|
||||
|
||||
if settings().getBoolean(["devel", "virtualPrinter", "hasChamber"]):
|
||||
if includeTarget:
|
||||
c = "C:%.2f /%.2f" % (self.chamberTemp, self.chamberTargetTemp)
|
||||
else:
|
||||
c = "C:%.2f" % self.chamberTemp
|
||||
else:
|
||||
c = ""
|
||||
|
||||
output = t + " " + b + " " + c
|
||||
output = output.strip()
|
||||
|
||||
output += " @:64\n"
|
||||
return output
|
||||
@@ -1059,6 +1095,9 @@ class VirtualPrinter(object):
|
||||
|
||||
def _parseBedCommand(self, line, wait=False, support_r=False):
|
||||
# type: (str, bool, bool) -> None
|
||||
if not settings().getBoolean(["devel", "virtualPrinter", "hasBed"]):
|
||||
return
|
||||
|
||||
only_wait_if_higher = True
|
||||
try:
|
||||
self.bedTargetTemp = float(re.search(r'S([0-9]+)', line).group(1))
|
||||
@@ -1075,12 +1114,30 @@ class VirtualPrinter(object):
|
||||
if settings().getBoolean(["devel", "virtualPrinter", "repetierStyleTargetTemperature"]):
|
||||
self._send("TargetBed:%d" % self.bedTargetTemp)
|
||||
|
||||
def _parseChamberCommand(self, line, wait=False, support_r=False):
|
||||
if not settings().getBoolean(["devel", "virtualPrinter", "hasChamber"]):
|
||||
return
|
||||
|
||||
only_wait_if_higher = True
|
||||
try:
|
||||
self.chamberTargetTemp = float(re.search('S([0-9]+)', line).group(1))
|
||||
except:
|
||||
if support_r:
|
||||
try:
|
||||
self.chamberTargetTemp = float(re.search('R([0-9]+)', line).group(1))
|
||||
only_wait_if_higher = False
|
||||
except:
|
||||
pass
|
||||
|
||||
if wait:
|
||||
self._waitForHeatup("chamber", only_wait_if_higher)
|
||||
|
||||
def _performMove(self, line):
|
||||
# type: (str) -> None
|
||||
matchX = re.search(r"X([0-9.]+)", line)
|
||||
matchY = re.search(r"Y([0-9.]+)", line)
|
||||
matchZ = re.search(r"Z([0-9.]+)", line)
|
||||
matchE = re.search(r"E([0-9.]+)", line)
|
||||
matchX = re.search(r"X(-?[0-9.]+)", line)
|
||||
matchY = re.search(r"Y(-?[0-9.]+)", line)
|
||||
matchZ = re.search(r"Z(-?[0-9.]+)", line)
|
||||
matchE = re.search(r"E(-?[0-9.]+)", line)
|
||||
matchF = re.search(r"F([0-9.]+)", line)
|
||||
|
||||
duration = 0.0
|
||||
@@ -1171,10 +1228,10 @@ class VirtualPrinter(object):
|
||||
|
||||
def _setPosition(self, line):
|
||||
# type: (str) -> None
|
||||
matchX = re.search(r"X([0-9.]+)", line)
|
||||
matchY = re.search(r"Y([0-9.]+)", line)
|
||||
matchZ = re.search(r"Z([0-9.]+)", line)
|
||||
matchE = re.search(r"E([0-9.]+)", line)
|
||||
matchX = re.search(r"X(-?[0-9.]+)", line)
|
||||
matchY = re.search(r"Y(-?[0-9.]+)", line)
|
||||
matchZ = re.search(r"Z(-?[0-9.]+)", line)
|
||||
matchE = re.search(r"E(-?[0-9.]+)", line)
|
||||
|
||||
if matchX is None and matchY is None and matchZ is None and matchE is None:
|
||||
self._lastX = self._lastY = self._lastZ = self._lastE[self.currentExtruder] = 0
|
||||
@@ -1200,6 +1257,30 @@ class VirtualPrinter(object):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def _home(self, line):
|
||||
x = y = z = e = None
|
||||
|
||||
if "X" in line:
|
||||
x = True
|
||||
if "Y" in line:
|
||||
y = True
|
||||
if "Z" in line:
|
||||
z = True
|
||||
if "E" in line:
|
||||
e = True
|
||||
|
||||
if x is None and y is None and z is None and e is None:
|
||||
self._lastX = self._lastY = self._lastZ = self._lastE[self.currentExtruder] = 0
|
||||
else:
|
||||
if x:
|
||||
self._lastX = 0
|
||||
if y:
|
||||
self._lastY = 0
|
||||
if z:
|
||||
self._lastZ = 0
|
||||
if e:
|
||||
self._lastE = 0
|
||||
|
||||
def _writeSdFile(self, filename):
|
||||
# type: (str) -> None
|
||||
filename = filename
|
||||
@@ -1281,7 +1362,7 @@ class VirtualPrinter(object):
|
||||
# type: (str, bool) -> None
|
||||
delta = 1
|
||||
delay = 1
|
||||
last_busy = time.time()
|
||||
last_busy = monotonic_time()
|
||||
|
||||
self._heatingUp = True
|
||||
try:
|
||||
@@ -1292,15 +1373,18 @@ class VirtualPrinter(object):
|
||||
elif heater == "bed":
|
||||
test = lambda: self.bedTemp < self.bedTargetTemp - delta or (not only_wait_if_higher and self.bedTemp > self.bedTargetTemp + delta)
|
||||
output = lambda: "B:%0.2f" % self.bedTemp
|
||||
elif heater == "chamber":
|
||||
test = lambda: self.chamberTemp < self.chamberTargetTemp - delta or (not only_wait_if_higher and self.chamberTemp > self.chamberTargetTemp + delta)
|
||||
output = lambda: "C:%0.2f" % self.chamberTemp
|
||||
else:
|
||||
return
|
||||
|
||||
while not self._killed and self._heatingUp and test():
|
||||
self._simulateTemps(delta=delta)
|
||||
self._send(output())
|
||||
if self._sendBusy and time.time() - last_busy >= self._busyInterval:
|
||||
if self._sendBusy and monotonic_time() - last_busy >= self._busyInterval:
|
||||
self._send("echo:busy: processing")
|
||||
last_busy = time.time()
|
||||
last_busy = monotonic_time()
|
||||
time.sleep(delay)
|
||||
except AttributeError:
|
||||
if self.outgoing is not None:
|
||||
@@ -1317,8 +1401,8 @@ class VirtualPrinter(object):
|
||||
os.remove(f)
|
||||
|
||||
def _simulateTemps(self, delta=0.5):
|
||||
timeDiff = self.lastTempAt - time.time()
|
||||
self.lastTempAt = time.time()
|
||||
timeDiff = self.lastTempAt - monotonic_time()
|
||||
self.lastTempAt = monotonic_time()
|
||||
|
||||
def simulate(actual, target, ambient):
|
||||
if target > 0 and abs(actual - target) > delta:
|
||||
@@ -1344,6 +1428,7 @@ class VirtualPrinter(object):
|
||||
continue
|
||||
self.temp[i] = simulate(self.temp[i], self.targetTemp[i], self._ambient_temperature)
|
||||
self.bedTemp = simulate(self.bedTemp, self.bedTargetTemp, self._ambient_temperature)
|
||||
self.chamberTemp = simulate(self.chamberTemp, self.chamberTargetTemp, self._ambient_temperature)
|
||||
|
||||
def _processBuffer(self):
|
||||
while self.buffered is not None:
|
||||
@@ -1362,6 +1447,9 @@ class VirtualPrinter(object):
|
||||
|
||||
def write(self, data):
|
||||
# type: (bytes) -> int
|
||||
data = to_bytes(data, errors="replace")
|
||||
u_data = to_unicode(data, errors="replace")
|
||||
|
||||
if self._debug_awol:
|
||||
return len(data)
|
||||
|
||||
@@ -1374,13 +1462,13 @@ class VirtualPrinter(object):
|
||||
return 0
|
||||
|
||||
if b"M112" in data and self._supportM112:
|
||||
self._seriallog.info("<<< {}".format(data.strip().decode("utf-8")))
|
||||
self._seriallog.info("<<< {}".format(u_data))
|
||||
self._kill()
|
||||
return len(data)
|
||||
|
||||
try:
|
||||
written = self.incoming.put(data, timeout=self._write_timeout, partial=True)
|
||||
self._seriallog.info("<<< {}".format(data.strip().decode("utf-8")))
|
||||
self._seriallog.info("<<< {}".format(u_data))
|
||||
return written
|
||||
except queue.Full:
|
||||
self._logger.info("Incoming queue is full, raising SerialTimeoutException")
|
||||
@@ -1416,8 +1504,8 @@ class VirtualPrinter(object):
|
||||
|
||||
try:
|
||||
# fetch a line from the queue, wait no longer than timeout
|
||||
line = self.outgoing.get(timeout=timeout)
|
||||
self._seriallog.info(">>> {}".format(line.strip()))
|
||||
line = to_unicode(self.outgoing.get(timeout=timeout), errors="replace")
|
||||
self._seriallog.info(u">>> {}".format(line.strip()))
|
||||
self.outgoing.task_done()
|
||||
return to_bytes(line)
|
||||
except queue.Empty:
|
||||
@@ -1491,9 +1579,9 @@ class CharCountingQueue(queue.Queue):
|
||||
elif timeout < 0:
|
||||
raise ValueError("'timeout' must be a positive number")
|
||||
else:
|
||||
endtime = time.time() + timeout
|
||||
endtime = monotonic_time() + timeout
|
||||
while not self._will_it_fit(item):
|
||||
remaining = endtime - time.time()
|
||||
remaining = endtime - monotonic_time()
|
||||
if remaining <= 0.0:
|
||||
raise queue.Full
|
||||
self.not_full.wait(remaining)
|
||||
|
||||
Reference in new issue
Block a user