Beispiel #1
0
	def __init__(self):
		self.imageNumber = None
		self.inTimelapse = False
		self.gcodeFile = None

		self.captureDir = settings().getBaseFolder("timelapse_tmp")
		self.movieDir = settings().getBaseFolder("timelapse")
		self.snapshotUrl = settings().get("webcam", "snapshot")
Beispiel #2
0
def getConnectionOptions():
	"""
	 Retrieves the available ports, baudrates, prefered port and baudrate for connecting to the printer.
	"""
	return {
		"ports": comm.serialList(),
		"baudrates": comm.baudrateList(),
		"portPreference": settings().get("serial", "port"),
		"baudratePreference": settings().getInt("serial", "baudrate")
	}
Beispiel #3
0
def main():
	from optparse import OptionParser

	defaultHost = settings().get("server", "host")
	defaultPort = settings().get("server", "port")

	parser = OptionParser(usage="usage: %prog [options]")
	parser.add_option("-d", "--debug", action="store_true", dest="debug",
		help="Enable debug mode")
	parser.add_option("--host", action="store", type="string", default=defaultHost, dest="host",
		help="Specify the host on which to bind the server, defaults to %s if not set" % (defaultHost))
	parser.add_option("--port", action="store", type="int", default=defaultPort, dest="port",
		help="Specify the port on which to bind the server, defaults to %s if not set" % (defaultPort))
	(options, args) = parser.parse_args()

	run(host=options.host, port=options.port, debug=options.debug)
Beispiel #4
0
def baudrateList():
	ret = [250000, 230400, 115200, 57600, 38400, 19200, 9600]
	prev = settings().getInt("serial", "baudrate")
	if prev in ret:
		ret.remove(prev)
		ret.insert(0, prev)
	return ret
Beispiel #5
0
def setSettings():
	s = settings()
	if request.values.has_key("serial_port"):
		s.set("serial", "port", request.values["serial_port"])
	if request.values.has_key("serial_baudrate"):
		s.set("serial", "baudrate", request.values["serial_baudrate"])

	s.save()
	return getSettings()
Beispiel #6
0
	def createMovie(self):
		ffmpeg = settings().get("webcam", "ffmpeg")
		if ffmpeg is None:
			return

		input = os.path.join(self.captureDir, "tmp_%05d.jpg")
		output = os.path.join(self.movieDir, "%s_%s.mpg" % (os.path.splitext(self.gcodeFile)[0], time.strftime("%Y%m%d%H%M%S")))
		subprocess.call([
			ffmpeg, '-i', input, '-vcodec', 'mpeg2video', '-pix_fmt', 'yuv420p', '-r', '25', '-y',
			 '-b:v', '1500k', '-f', 'vob', output
		])
Beispiel #7
0
def getFinishedTimelapses():
	files = []
	basedir = settings().getBaseFolder("timelapse")
	for osFile in os.listdir(basedir):
		if not fnmatch.fnmatch(osFile, "*.mpg"):
			continue
		files.append({
			"name": osFile,
			"size": os.stat(os.path.join(basedir, osFile)).st_size
		})
	return files
Beispiel #8
0
	def __init__(self, port = None, baudrate = None, callbackObject = None):
		if port == None:
			port = settings().get("serial", "port")
		if baudrate == None:
			settingsBaudrate = settings().getInt("serial", "baudrate")
			if settingsBaudrate is None:
				baudrate = 0
			else:
				baudrate = settingsBaudrate
		if callbackObject == None:
			callbackObject = MachineComPrintCallback()

		self._port = port
		self._baudrate = baudrate
		self._callback = callbackObject
		self._state = self.STATE_NONE
		self._serial = None
		self._baudrateDetectList = baudrateList()
		self._baudrateDetectRetry = 0
		self._temp = 0
		self._bedTemp = 0
		self._targetTemp = 0
		self._bedTargetTemp = 0
		self._gcodeList = None
		self._gcodePos = 0
		self._commandQueue = queue.Queue()
		self._logQueue = queue.Queue(256)
		self._feedRateModifier = {}
		self._currentZ = -1
		self._heatupWaitStartTime = 0
		self._heatupWaitTimeLost = 0.0
		self._printStartTime100 = None
		
		self.thread = threading.Thread(target=self._monitor)
		self.thread.daemon = True
		self.thread.start()
Beispiel #9
0
def connect():
	port = None
	baudrate = None
	if request.values.has_key("port"):
		port = request.values["port"]
	if request.values.has_key("baudrate"):
		baudrate = request.values["baudrate"]
	if request.values.has_key("save"):
		settings().set("serial", "port", port)
		settings().set("serial", "baudrate", baudrate)
		settings().save()
	printer.connect(port=port, baudrate=baudrate)
	return jsonify(state="Connecting")
Beispiel #10
0
def serialList():
	baselist=[]
	if os.name=="nt":
		try:
			key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
			i=0
			while(1):
				baselist+=[_winreg.EnumValue(key,i)[1]]
				i+=1
		except:
			pass
	baselist = baselist + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*")
	prev = settings().get("serial", "port")
	if prev in baselist:
		baselist.remove(prev)
		baselist.insert(0, prev)
	if isDevVersion():
		baselist.append("VIRTUAL")
	return baselist
Beispiel #11
0
def getSettings():
	s = settings()
	return jsonify({
		"serial_port": s.get("serial", "port"),
		"serial_baudrate": s.get("serial", "baudrate")
	})
Beispiel #12
0
def deleteTimelapse(filename):
	if allowed_file(filename, set(["mpg"])):
		secure = os.path.join(settings().getBaseFolder("timelapse"), secure_filename(filename))
		if os.path.exists(secure):
			os.remove(secure)
	return getTimelapseData()
Beispiel #13
0
def downloadTimelapse(filename):
	if allowed_file(filename, set(["mpg"])):
		return send_from_directory(settings().getBaseFolder("timelapse"), filename, as_attachment=True)
Beispiel #14
0
def index():
	return render_template(
		"index.html",
		webcamStream=settings().get("webcam", "stream"),
		enableTimelapse=(settings().get("webcam", "snapshot") is not None and settings().get("webcam", "ffmpeg") is not None)
	)
Beispiel #15
0
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'

from flask import Flask, request, render_template, jsonify, send_from_directory, abort, url_for
from werkzeug import secure_filename

from printer_webui.printer import Printer, getConnectionOptions
from printer_webui.settings import settings
import timelapse

import os
import fnmatch

BASEURL = "/ajax/"
SUCCESS = {}

UPLOAD_FOLDER = settings().getBaseFolder("uploads")

app = Flask("printer_webui")
printer = Printer()

@app.route("/")
def index():
	return render_template(
		"index.html",
		webcamStream=settings().get("webcam", "stream"),
		enableTimelapse=(settings().get("webcam", "snapshot") is not None and settings().get("webcam", "ffmpeg") is not None)
	)

#~~ Printer state

@app.route(BASEURL + "state", methods=["GET"])