forked from OctoPrint/OctoPrint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# coding=utf-8 | ||
__author__ = "Gina Häußge <[email protected]>" | ||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' | ||
|
||
from printer_webui.settings import settings | ||
|
||
import os | ||
import threading | ||
import urllib | ||
import time | ||
|
||
class Timelapse(object): | ||
def __init__(self): | ||
self.imageNumber = None | ||
self.inTimelapse = False | ||
self.gcodeFile = None | ||
|
||
self.captureDir = settings().getBaseFolder("timelapse") | ||
self.snapshotUrl = settings().get("webcam", "snapshot") | ||
|
||
def onPrintjobStarted(self, gcodeFile): | ||
self.startTimelapse(gcodeFile) | ||
|
||
def onPrintjobStopped(self): | ||
self.stopTimelapse() | ||
|
||
def onPrintjobProgress(self, oldPos, newPos, percentage): | ||
pass | ||
|
||
def onZChange(self, oldZ, newZ): | ||
pass | ||
|
||
def startTimelapse(self, gcodeFile): | ||
self.imageNumber = 0 | ||
self.inTimelapse = True | ||
self.gcodeFile = os.path.basename(gcodeFile) | ||
|
||
def stopTimelapse(self): | ||
self.imageNumber = None | ||
self.inTimelapse = False | ||
|
||
def captureImage(self): | ||
if self.captureDir is None: | ||
return | ||
|
||
filename = os.path.join(self.captureDir, "tmp_%i.jpg" % (self.imageNumber)) | ||
self.imageNumber += 1; | ||
|
||
captureThread = threading.Thread(target=self.captureWorker, kwargs={"filename": filename}) | ||
captureThread.start() | ||
|
||
def captureWorker(self, filename): | ||
urllib.urlretrieve(self.snapshotUrl, filename) | ||
|
||
class ZTimelapse(Timelapse): | ||
def __init__(self): | ||
Timelapse.__init__(self) | ||
|
||
def onZChange(self, oldZ, newZ): | ||
self.captureImage() | ||
|
||
class TimedTimelapse(Timelapse): | ||
def __init__(self, interval=1): | ||
Timelapse.__init__(self) | ||
|
||
self.interval = interval | ||
if self.interval < 1: | ||
self.interval = 1 # force minimum interval of 1s | ||
|
||
self.timerThread = None | ||
|
||
def onPrintjobStarted(self): | ||
Timelapse.onPrintjobStarted(self) | ||
if self.timerThread is not None: | ||
return | ||
|
||
self.timerThread = threading.Thread(target=self.timerWorker) | ||
self.timerThread.start() | ||
|
||
def timerWorker(self): | ||
while self.inTimelapse: | ||
self.captureImage() | ||
time.sleep(self.interval) |