Exemple #1
0
def jog():
	if not printer.isOperational() or printer.isPrinting():
		# do not jog when a print job is running or we don't have a connection
		return jsonify(SUCCESS)

	(movementSpeedX, movementSpeedY, movementSpeedZ, movementSpeedE) = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z", "e"]])
	if "x" in request.values.keys():
		# jog x
		x = request.values["x"]
		printer.commands(["G91", "G1 X%s F%d" % (x, movementSpeedX), "G90", "M114"])
	if "y" in request.values.keys():
		# jog y
		y = request.values["y"]
		printer.commands(["G91", "G1 Y%s F%d" % (y, movementSpeedY), "G90", "M114"])
	if "z" in request.values.keys():
		# jog z
		z = request.values["z"]
		printer.commands(["G91", "G1 Z%s F%d" % (z, movementSpeedZ), "G90", "M114"])
	if "homeXY" in request.values.keys():
		# home x/y
		printer.command("G28 X0 Y0")
	if "posX" in request.values.keys() and "posY" in request.values.keys():
		# go to position
		printer.commands(["G1 X%s Y%s F%d" % (request.values["posX"], request.values["posY"], movementSpeedX), "M114"])
	if "homeZ" in request.values.keys():
		# home z
		printer.command("G28 Z0")
	if "extrude" in request.values.keys():
		# extrude/retract
		length = request.values["extrude"]
		printer.commands(["G91", "G1 E%s F%d" % (length, movementSpeedE), "G90"])

	return jsonify(SUCCESS)
Exemple #2
0
def printerCommand():
	# TODO: document me
	if not printer.isOperational():
		return make_response("Printer is not operational", 409)

	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content type JSON", 400)

	data = request.json

	parameters = {}
	if "parameters" in data.keys():
		parameters = data["parameters"]

	commands = []
	if "command" in data.keys():
		commands = [data["command"]]
	elif "commands" in data.keys():
		commands = data["commands"]

	commandsToSend = []
	for command in commands:
		commandToSend = command
		if len(parameters) > 0:
			commandToSend = command % parameters
		commandsToSend.append(commandToSend)

	printer.commands(commandsToSend)

	return NO_CONTENT
Exemple #3
0
def printerCommand():
	# TODO: document me
	if not printer.isOperational():
		return make_response("Printer is not operational", 409)

	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content type JSON", 400)

	data = request.json

	parameters = {}
	if "parameters" in data.keys(): parameters = data["parameters"]

	commands = []
	if "command" in data.keys(): commands = [data["command"]]
	elif "commands" in data.keys(): commands = data["commands"]

	commandsToSend = []
	for command in commands:
		commandToSend = command
		if len(parameters) > 0:
			commandToSend = command % parameters
		commandsToSend.append(commandToSend)

	printer.commands(commandsToSend)

	return NO_CONTENT
Exemple #4
0
def printerCommand():
	if not printer.isOperational():
		return make_response("Printer is not operational", 409)

	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content type JSON", 400)

	data = request.json

	parameters = dict()
	if "parameters" in data.keys(): parameters = data["parameters"]

	if "command" in data and "commands" in data:
		return make_response("'command' and 'commands' are mutually exclusive", 400)
	elif "command" in data:
		commands = [data["command"]]
	elif "commands" in data and isinstance(data["commands"], (list, tuple)):
		commands = data["commands"]
	else:
		return make_response("Need either single 'command' or list of 'commands'", 400)

	commandsToSend = []
	for command in commands:
		commandToSend = command
		if len(parameters) > 0:
			commandToSend = command % parameters
		commandsToSend.append(commandToSend)

	printer.commands(commandsToSend)

	return NO_CONTENT
Exemple #5
0
def printerCommand():
    if not printer.is_operational():
        return make_response("Printer is not operational", 409)

    if "application/json" not in request.headers["Content-Type"]:
        return make_response("Expected content type JSON", 400)

    try:
        data = request.get_json()
    except BadRequest:
        return make_response("Malformed JSON body in request", 400)

    if data is None:
        return make_response("Malformed JSON body in request", 400)

    if "command" in data and "commands" in data:
        return make_response("'command' and 'commands' are mutually exclusive", 400)
    elif ("command" in data or "commands" in data) and "script" in data:
        return make_response(
            "'command'/'commands' and 'script' are mutually exclusive", 400
        )
    elif not ("command" in data or "commands" in data or "script" in data):
        return make_response("Need one of 'command', 'commands' or 'script'", 400)

    parameters = {}
    if "parameters" in data:
        parameters = data["parameters"]

    tags = {"source:api", "api:printer.command"}

    if "command" in data or "commands" in data:
        if "command" in data:
            commands = [data["command"]]
        else:
            if not isinstance(data["commands"], (list, tuple)):
                return make_response("'commands' needs to be a list", 400)
            commands = data["commands"]

        commandsToSend = []
        for command in commands:
            commandToSend = command
            if len(parameters) > 0:
                commandToSend = command % parameters
            commandsToSend.append(commandToSend)

        printer.commands(commandsToSend, tags=tags)

    elif "script" in data:
        script_name = data["script"]
        context = {"parameters": parameters}
        if "context" in data:
            context["context"] = data["context"]

        try:
            printer.script(script_name, context=context, tags=tags)
        except UnknownScript:
            return make_response("Unknown script: {script_name}".format(**locals()), 404)

    return NO_CONTENT
Exemple #6
0
 def sendPreferenctParameter(self, inProfile):
     from octoprint.server import printer
     if printer.isOperational():
         cmds = self.__send_all_update_epprom(inProfile)
         printer.commands(cmds)
         #cmd_eeprom = GcodeCommand("M500")
         #printer.command(cmd_eeprom)
     print("lkj sendPreferenctParameter")
     ''''''
     return
Exemple #7
0
	def sendPreferenctParameter(self, inProfile):		
		from octoprint.server import printer
		if printer.isOperational():
			cmds = self.__send_all_update_epprom(inProfile)
			printer.commands(cmds)
			#cmd_eeprom = GcodeCommand("M500")
			#printer.command(cmd_eeprom)				
		print("lkj sendPreferenctParameter")	
		''''''
		return
Exemple #8
0
def printerCommand():
    if not printer.is_operational():
        abort(409, description="Printer is not operational")

    if "application/json" not in request.headers["Content-Type"]:
        abort(400, description="Expected content type JSON")

    data = request.get_json()

    if data is None:
        abort(400, description="Malformed JSON body in request")

    if "command" in data and "commands" in data:
        abort(400, description="'command' and 'commands' are mutually exclusive")
    elif ("command" in data or "commands" in data) and "script" in data:
        abort(400, description="'command'/'commands' and 'script' are mutually exclusive")
    elif not ("command" in data or "commands" in data or "script" in data):
        abort(400, description="Need one of 'command', 'commands' or 'script'")

    parameters = {}
    if "parameters" in data:
        parameters = data["parameters"]

    tags = {"source:api", "api:printer.command"}

    if "command" in data or "commands" in data:
        if "command" in data:
            commands = [data["command"]]
        else:
            if not isinstance(data["commands"], (list, tuple)):
                abort(400, description="commands is invalid")
            commands = data["commands"]

        commandsToSend = []
        for command in commands:
            commandToSend = command
            if len(parameters) > 0:
                commandToSend = command % parameters
            commandsToSend.append(commandToSend)

        printer.commands(commandsToSend, tags=tags)

    elif "script" in data:
        script_name = data["script"]
        context = {"parameters": parameters}
        if "context" in data:
            context["context"] = data["context"]

        try:
            printer.script(script_name, context=context, tags=tags)
        except UnknownScript:
            abort(404, description="Unknown script")

    return NO_CONTENT
Exemple #9
0
def printerCommand():
	if not printer.is_operational():
		return make_response("Printer is not operational", 409)

	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content type JSON", 400)

	try:
		data = request.json
	except BadRequest:
		return make_response("Malformed JSON body in request", 400)

	if "command" in data and "commands" in data:
		return make_response("'command' and 'commands' are mutually exclusive", 400)
	elif ("command" in data or "commands" in data) and "script" in data:
		return make_response("'command'/'commands' and 'script' are mutually exclusive", 400)
	elif not ("command" in data or "commands" in data or "script" in data):
		return make_response("Need one of 'command', 'commands' or 'script'", 400)

	parameters = dict()
	if "parameters" in data:
		parameters = data["parameters"]

	tags = {"source:api", "api:printer.command"}

	if "command" in data or "commands" in data:
		if "command" in data:
			commands = [data["command"]]
		else:
			if not isinstance(data["commands"], (list, tuple)):
				return make_response("'commands' needs to be a list", 400)
			commands = data["commands"]

		commandsToSend = []
		for command in commands:
			commandToSend = command
			if len(parameters) > 0:
				commandToSend = command % parameters
			commandsToSend.append(commandToSend)

		printer.commands(commandsToSend, tags=tags)

	elif "script" in data:
		script_name = data["script"]
		context = dict(parameters=parameters)
		if "context" in data:
			context["context"] = data["context"]

		try:
			printer.script(script_name, context=context, tags=tags)
		except UnknownScript:
			return make_response("Unknown script: {script_name}".format(**locals()), 404)

	return NO_CONTENT
Exemple #10
0
def jog():
    if not printer.isOperational() or printer.isPrinting():
        # do not jog when a print job is running or we don't have a connection
        return jsonify(SUCCESS)

    (movementSpeedX, movementSpeedY, movementSpeedZ,
     movementSpeedE) = settings().get(
         ["printerParameters", "movementSpeed", ["x", "y", "z", "e"]])
    if "x" in request.values.keys():
        # jog x
        x = request.values["x"]
        printer.commands(["G91", "G1 X%s F%d" % (x, movementSpeedX), "G90"])
    if "y" in request.values.keys():
        # jog y
        y = request.values["y"]
        printer.commands(["G91", "G1 Y%s F%d" % (y, movementSpeedY), "G90"])
    if "z" in request.values.keys():
        # jog z
        z = request.values["z"]
        printer.commands(["G91", "G1 Z%s F%d" % (z, movementSpeedZ), "G90"])
    if "homeXY" in request.values.keys():
        # home x/y
        printer.command("G28 X0 Y0")
    if "homeZ" in request.values.keys():
        # home z
        printer.command("G28 Z0")
    if "extrude" in request.values.keys():
        # extrude/retract
        length = request.values["extrude"]
        printer.commands(
            ["G91", "G1 E%s F%d" % (length, movementSpeedE), "G90"])

    return jsonify(SUCCESS)
Exemple #11
0
def jog():
    if not printer.isOperational() or printer.isPrinting():
        # do not jog when a print job is running or we don't have a connection
        return jsonify(SUCCESS)

    (movementSpeedX, movementSpeedY, movementSpeedZ, movementSpeedE) = (
            settings.get('movement_speed', s) for s in 'xyze')
    if "x" in request.values.keys():
        # jog x
        x = request.values["x"]
        printer.commands(["G91", "G1 X%s F%d" % (x, movementSpeedX), "G90"])
    if "y" in request.values.keys():
        # jog y
        y = request.values["y"]
        printer.commands(["G91", "G1 Y%s F%d" % (y, movementSpeedY), "G90"])
    if "z" in request.values.keys():
        # jog z
        z = request.values["z"]
        printer.commands(["G91", "G1 Z%s F%d" % (z, movementSpeedZ), "G90"])
    if "homeXY" in request.values.keys():
        # home x/y
        printer.command("G28 X0 Y0")
    if "homeZ" in request.values.keys():
        # home z
        printer.command("G28 Z0")
    if "extrude" in request.values.keys():
        # extrude/retract
        length = request.values["extrude"]
        printer.commands(
            ["G91", "G1 E%s F%d" % (length, movementSpeedE), "G90"])
    return jsonify(SUCCESS)
Exemple #12
0
def controlPrinterPrinthead():
	if not printer.isOperational() or printer.isPrinting():
		# do not jog when a print job is running or we don't have a connection
		return make_response("Printer is not operational or currently printing", 403)

	valid_commands = {
		"jog": [],
		"home": ["axes"]
	}
	command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
	if response is not None:
		return response

	movementSpeed = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z"]], asdict=True)

	valid_axes = ["x", "y", "z"]
	##~~ jog command
	if command == "jog":
		# validate all jog instructions, make sure that the values are numbers
		validated_values = {}
		for axis in valid_axes:
			if axis in data:
				value = data[axis]
				if not isinstance(value, (int, long, float)):
					return make_response("Not a number for axis %s: %r" % (axis, value), 400)
				validated_values[axis] = value

		# execute the jog commands
		for axis, value in validated_values.iteritems():
			# TODO make this a generic method call (printer.jog(axis, value)) to get rid of gcode here
			printer.commands(["G91", "G1 %s%.4f F%d" % (axis.upper(), value, movementSpeed[axis]), "G90"])

	##~~ home command
	elif command == "home":
		validated_values = []
		axes = data["axes"]
		for axis in axes:
			if not axis in valid_axes:
				return make_response("Invalid axis: %s" % axis, 400)
			validated_values.append(axis)

		# execute the home command
		# TODO make this a generic method call (printer.home(axis, ...)) to get rid of gcode here
		printer.commands(["G91", "G28 %s" % " ".join(map(lambda x: "%s0" % x.upper(), validated_values)), "G90"])

	return jsonify(SUCCESS)
Exemple #13
0
def printerCommand():
    if "application/json" in request.headers["Content-Type"]:
        data = request.json

        parameters = {}
        if "parameters" in data.keys(): parameters = data["parameters"]

        commands = []
        if "command" in data.keys(): commands = [data["command"]]
        elif "commands" in data.keys(): commands = data["commands"]

        commandsToSend = []
        for command in commands:
            commandToSend = command
            if len(parameters) > 0:
                commandToSend = command % parameters
            commandsToSend.append(commandToSend)

        printer.commands(commandsToSend)

    return jsonify(SUCCESS)
Exemple #14
0
def printerCommand():
	if "application/json" in request.headers["Content-Type"]:
		data = request.json

		parameters = {}
		if "parameters" in data.keys(): parameters = data["parameters"]

		commands = []
		if "command" in data.keys(): commands = [data["command"]]
		elif "commands" in data.keys(): commands = data["commands"]

		commandsToSend = []
		for command in commands:
			commandToSend = command
			if len(parameters) > 0:
				commandToSend = command % parameters
			commandsToSend.append(commandToSend)

		printer.commands(commandsToSend)

	return jsonify(SUCCESS)
Exemple #15
0
def controlPrinterFeeder():
	if not printer.isOperational() or printer.isPrinting():
		# do not jog when a print job is running or we don't have a connection
		return make_response("Printer is not operational or currently printing", 403)

	valid_commands = {
		"extrude": ["amount"]
	}
	command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
	if response is not None:
		return response

	extrusionSpeed = settings().get(["printerParameters", "movementSpeed", "e"])

	if command == "extrude":
		amount = data["amount"]
		if not isinstance(amount, (int, long, float)):
			return make_response("Not a number for extrusion amount: %r" % amount, 400)

		# TODO make this a generic method call (printer.extruder([hotend,] amount)) to get rid of gcode here
		printer.commands(["G91", "G1 E%s F%d" % (data["amount"], extrusionSpeed), "G90"])

	return jsonify(SUCCESS)
Exemple #16
0
def printerCommand(data=None):
    # TODO: document me
    if not printer.isOperational():
        return make_response("Printer is not operational", 409)
    if data is None:
        return make_response("Expected content type JSON", 400)
    parameters = {}
    if "parameters" in data.keys(): parameters = data["parameters"]

    commands = []
    if "command" in data.keys(): commands = [data["command"]]
    elif "commands" in data.keys(): commands = data["commands"]

    commandsToSend = []
    for command in commands:
        commandToSend = command
        if len(parameters) > 0:
            commandToSend = command % parameters
        commandsToSend.append(commandToSend)

    printer.commands(commandsToSend)

    return NO_CONTENT
Exemple #17
0
def printerCommand():
	if not (printer.is_operational() or printer.is_locked()):
		return make_response("Printer is not operational", 409)

	if not "application/json" in request.headers["Content-Type"]:
		return make_response("Expected content type JSON", 400)

	try:
		data = request.json
	except BadRequest:
		return make_response("Malformed JSON body in request", 400)

	if "command" in data and "commands" in data:
		return make_response("'command' and 'commands' are mutually exclusive", 400)
	elif ("command" in data or "commands" in data) and "script" in data:
		return make_response("'command'/'commands' and 'script' are mutually exclusive", 400)
	elif not ("command" in data or "commands" in data or "script" in data):
		return make_response("Need one of 'command', 'commands' or 'script'", 400)

#<<<<<<< HEAD
#	commandsToSend = []
#	for command in commands:
#		commandToSend = command
#		if len(parameters) > 0:
#			commandToSend = command % parameters
#		commandsToSend.append(commandToSend)
#
#	if settings().getBoolean(["feature", "grbl"]):
#		commandsToSend.append("?")
#
#	printer.commands(commandsToSend)
#=======
	parameters = dict()
	if "parameters" in data:
		parameters = data["parameters"]

	if "command" in data or "commands" in data:
		if "command" in data:
			commands = [data["command"]]
		else:
			if not isinstance(data["commands"], (list, tuple)):
				return make_response("'commands' needs to be a list", 400)
			commands = data["commands"]

		commandsToSend = []
		for command in commands:
			commandToSend = command
			if len(parameters) > 0:
				commandToSend = command % parameters
			commandsToSend.append(commandToSend)

	if settings().getBoolean(["feature", "grbl"]):
		commandsToSend.append("?")
		printer.commands(commandsToSend)

	elif "script" in data:
		script_name = data["script"]
		context = dict(parameters=parameters)
		if "context" in data:
			context["context"] = data["context"]

		try:
			printer.script(script_name, context=context)
		except UnknownScript:
			return make_response("Unknown script: {script_name}".format(**locals()), 404)
#>>>>>>> upstream/maintenance

	return NO_CONTENT
Exemple #18
0
def jog():
	if not printer.isOperational() or printer.isPrinting():
		# do not jog when a print job is running or we don't have a connection
		return jsonify(SUCCESS)

	(movementSpeedX, movementSpeedY, movementSpeedZ, movementSpeedE) = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z", "e"]])
	if "x" in request.values.keys():
		# jog x
		x = request.values["x"]
		printer.commands(["G91", "G1 X%s F%d" % (x, movementSpeedX), "G90"])
	if "y" in request.values.keys():
		# jog y
		y = request.values["y"]
		printer.commands(["G91", "G1 Y%s F%d" % (y, movementSpeedY), "G90"])
	if "z" in request.values.keys():
		# jog z
		z = request.values["z"]
		printer.commands(["G91", "G1 Z%s F%d" % (z, movementSpeedZ), "G90"])
	if "homeXY" in request.values.keys():
		# home x/y
		printer.command("G28 X0 Y0")
	if "homeZ" in request.values.keys():
		# home z
		printer.command("G28 Z0")
	if "extrude" in request.values.keys():
		# extrude/retract
		length = request.values["extrude"]
		printer.commands(["G91", "G1 E%s F%d" % (length, movementSpeedE), "G90"])

	movementSpeed = settings().get(["printerParameters", "movementSpeed", ["x", "y", "z"]], asdict=True)

	valid_axes = ["x", "y", "z"]
	##~~ jog command
	if command == "jog":
		# validate all jog instructions, make sure that the values are numbers
		validated_values = {}
		for axis in valid_axes:
			if axis in data:
				value = data[axis]
				if not isinstance(value, (int, long, float)):
					return make_response("Not a number for axis %s: %r" % (axis, value), 400)
				validated_values[axis] = value

		# execute the jog commands
		for axis, value in validated_values.iteritems():
			# TODO make this a generic method call (printer.jog(axis, value)) to get rid of gcode here
			printer.commands(["G91", "G1 %s%.4f F%d" % (axis.upper(), value, movementSpeed[axis]), "G90"])

	##~~ home command
	elif command == "home":
		validated_values = []
		axes = data["axes"]
		for axis in axes:
			if not axis in valid_axes:
				return make_response("Invalid axis: %s" % axis, 400)
			validated_values.append(axis)

		# execute the home command
		# TODO make this a generic method call (printer.home(axis, ...)) to get rid of gcode here
		printer.commands(["G91", "G28 %s" % " ".join(map(lambda x: "%s0" % x.upper(), validated_values)), "G90"])

	return jsonify(SUCCESS)