PauseAtHeightRepRapFirmwareDuet.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from ..Script import Script
  2. class PauseAtHeightRepRapFirmwareDuet(Script):
  3. def getSettingDataString(self):
  4. return """{
  5. "name": "Pause at height for RepRapFirmware DuetWifi / Duet Ethernet / Duet Maestro",
  6. "key": "PauseAtHeightRepRapFirmwareDuet",
  7. "metadata": {},
  8. "version": 2,
  9. "settings":
  10. {
  11. "pause_height":
  12. {
  13. "label": "Pause height",
  14. "description": "At what height should the pause occur",
  15. "unit": "mm",
  16. "type": "float",
  17. "default_value": 5.0
  18. }
  19. }
  20. }"""
  21. def execute(self, data):
  22. current_z = 0.
  23. pause_z = self.getSettingValueByKey("pause_height")
  24. layers_started = False
  25. for layer_number, layer in enumerate(data):
  26. lines = layer.split("\n")
  27. for line in lines:
  28. if ";LAYER:0" in line:
  29. layers_started = True
  30. continue
  31. if not layers_started:
  32. continue
  33. if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
  34. current_z = self.getValue(line, 'Z')
  35. if current_z != None:
  36. if current_z >= pause_z:
  37. prepend_gcode = ";TYPE:CUSTOM\n"
  38. prepend_gcode += "; -- Pause at height (%.2f mm) --\n" % pause_z
  39. prepend_gcode += self.putValue(M = 226) + "\n"
  40. layer = prepend_gcode + layer
  41. data[layer_number] = layer # Override the data of this layer with the modified data
  42. return data
  43. break
  44. return data