Throttling for progress reports (every 500ms for now) and mini bugfix

master
Gina Häußge 2013-01-06 17:11:32 +01:00
parent ddc3ff9563
commit 534a48ffd7
2 changed files with 10 additions and 11 deletions

View File

@ -4,7 +4,6 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp
import time
from threading import Thread
import datetime
import printer_webui.util.comm as comm
from printer_webui.util import gcodeInterpreter
@ -68,6 +67,9 @@ class Printer():
# callbacks
self._callbacks = []
# callback throttling
self._lastProgressReport = None
#~~ callback registration
def registerCallback(self, callback):
@ -178,6 +180,7 @@ class Printer():
return self._timelapse
def _setCurrentZ(self, currentZ):
print("Setting currentZ=%s" % str(currentZ))
self._currentZ = currentZ
for callback in self._callbacks:
@ -217,9 +220,13 @@ class Printer():
self._printTime = printTime
self._printTimeLeft = printTimeLeft
if self._lastProgressReport and self._lastProgressReport + 0.5 > time.time():
return
for callback in self._callbacks:
try: callback.progressChangeCB(self._progress, self._printTime, self._printTimeLeft)
except: pass
self._lastProgressReport = time.time()
def _addTemperatureData(self, temp, bedTemp, targetTemp, bedTargetTemp):
@ -345,7 +352,8 @@ class Printer():
"""
Callback method for the comm object, called upon change of the z-layer.
"""
oldZ = self.currentZ
print("Got callback for z change: " + str(newZ))
oldZ = self._currentZ
if self._timelapse is not None:
self._timelapse.onZChange(oldZ, newZ)

View File

@ -9,7 +9,6 @@ import tornadio2
import os
import fnmatch
import datetime
import time
from printer_webui.printer import Printer, getConnectionOptions, PrinterCallback
from printer_webui.settings import settings
@ -34,10 +33,6 @@ def index():
#~~ Printer state
class PrinterStateConnection(tornadio2.SocketConnection, PrinterCallback):
def __init__(self, session, endpoint=None):
tornadio2.SocketConnection.__init__(self, session, endpoint)
self._lastProgressReport = None
def on_open(self, info):
printer.registerCallback(self)
@ -52,9 +47,6 @@ class PrinterStateConnection(tornadio2.SocketConnection, PrinterCallback):
self.emit("zChange", {"currentZ": formattedCurrentZ})
def progressChangeCB(self, currentLine, printTimeInSeconds, printTimeLeftInMinutes):
if self._lastProgressReport and time.time() + 0.5 < self._lastProgressReport:
return
formattedPrintTime = None
if (printTimeInSeconds):
formattedPrintTime = _getFormattedTimeDelta(datetime.timedelta(seconds=printTimeInSeconds))
@ -63,7 +55,6 @@ class PrinterStateConnection(tornadio2.SocketConnection, PrinterCallback):
if (printTimeLeftInMinutes):
formattedPrintTimeLeft = _getFormattedTimeDelta(datetime.timedelta(minutes=printTimeLeftInMinutes))
self._lastProgressReport = time.time()
self.emit("printProgress", {
"currentLine": currentLine,
"printTime": formattedPrintTime,