MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / printerPrintheadCommand

Function printerPrintheadCommand

src/astroprint/api/printer.py:279–337  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

277@api.route("/printer/printhead", methods=["POST"])
278@restricted_access
279def printerPrintheadCommand():
280 pm = printerManager()
281
282 valid_commands = {
283 "jog": [],
284 "home": ["axes"],
285 "babystepping": []
286 }
287 command, data, response = util.getJsonCommandFromRequest(request, valid_commands)
288 if not pm.isOperational() or command != "babystepping" and pm.isPrinting():
289 # do not jog when a print job is running or we don't have a connection
290 return make_response("Printer is not operational or currently printing", 409)
291
292 if response is not None:
293 return response
294
295 valid_axes = ["x", "y", "z"]
296 ##~~ jog command
297 if command == "jog":
298 # validate all jog instructions, make sure that the values are numbers
299 validated_values = {}
300 for axis in valid_axes:
301 if axis in data:
302 value = data[axis]
303 if not isinstance(value, (int, long, float)):
304 return make_response("Not a number for axis %s: %r" % (axis, value), 400)
305 validated_values[axis] = value
306
307 # execute the jog commands
308 for axis, value in validated_values.iteritems():
309 pm.jog(axis, value)
310
311 ##~~ home command
312 elif command == "home":
313 validated_values = []
314 axes = data["axes"]
315 for axis in axes:
316 if not axis in valid_axes:
317 return make_response("Invalid axis: %s" % axis, 400)
318 validated_values.append(axis)
319
320 # execute the home command
321 pm.home(validated_values)
322
323 ##~~ babystepping command
324 elif command == "babystepping":
325 if "amount" in data:
326 value = data['amount']
327
328 if not isinstance(value, (int, long, float)):
329 return make_response("Not a number for amount: %r" % (value), 400)
330
331 validated_values = {}
332 validated_values['amount'] = value
333
334 # execute the babystepping command
335 pm.babystepping(validated_values['amount'])
336

Callers

nothing calls this directly

Calls 7

printerManagerFunction · 0.90
appendMethod · 0.80
isOperationalMethod · 0.45
isPrintingMethod · 0.45
jogMethod · 0.45
homeMethod · 0.45
babysteppingMethod · 0.45

Tested by

no test coverage detected