Skip to content

Commit

Permalink
Added a "display on LCD" setting
Browse files Browse the repository at this point in the history
Fixed an issue with the OpenSCAD path setting.
  • Loading branch information
kartchnb committed Oct 20, 2022
1 parent 12ccd79 commit c6bd8eb
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 39 deletions.
33 changes: 28 additions & 5 deletions AutoTowersGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ def openScadPathSetting(self)->str:



_displayOnLcdSetting = True

_displayOnLcdSettingChanged = pyqtSignal()

def setDisplayOnLcdSetting(self, value)->None:
self._displayOnLcdSetting = value
self._displayOnLcdSettingChanged.emit()

@pyqtProperty(bool, notify=_displayOnLcdSettingChanged, fset=setDisplayOnLcdSetting)
def displayOnLcdSetting(self)->bool:
return self._displayOnLcdSetting



@pyqtSlot()
def removeButtonClicked(self)->None:
''' Called when the remove button is clicked to remove the generated Auto Tower from the scene'''
Expand All @@ -213,13 +227,19 @@ def pluginSettingsModified(self)->None:

# Create a settings dictionary to dump to the settings file
pluginSettings = {
'openscad path': self.openScadPathSetting
'openscad path': self.openScadPathSetting,
'display on lcd': self.displayOnLcdSetting,
}

# Save the settings to the settings file
with open(self._pluginSettingsFilePath, 'w') as settingsFile:
json.dump(pluginSettings, settingsFile)

# Remove the tower so it can be generated
if self._autoTowerGenerated:
self._removeAutoTower()
Message('The AutoTower was removed because plugin settings were changed').show()



def _loadPluginSettings(self)->None:
Expand All @@ -234,6 +254,9 @@ def _loadPluginSettings(self)->None:
self.setOpenScadPathSetting(pluginSettings['openscad path'])
self._openScadInterface.SetOpenScadPath(self.openScadPathSetting)

# Read in the 'display to LCD' setting
self.setDisplayOnLcdSetting(pluginSettings['display on lcd'])

except (FileNotFoundError, KeyError):
pass

Expand Down Expand Up @@ -485,7 +508,7 @@ def _onMachineChanged(self)->None:
In this case, the Auto Tower needs to be removed and regenerated '''
if self._autoTowerGenerated:
self._removeAutoTower()
Message('The Auto Tower has been removed because the active machine was changed', title=self._pluginName).show()
Message('The Auto Tower was removed because the active machine was changed', title=self._pluginName).show()



Expand All @@ -497,14 +520,14 @@ def _onPrintSettingChanged(self, setting_key, property_name)->None:
if setting_key in self._currentController.getCriticalProperties:
self._removeAutoTower()
setting_label = CuraApplication.getInstance().getMachineManager().activeMachine.getProperty(setting_key, 'label')
Message(f'The Auto Tower has been removed because the Cura setting "{setting_label}" has changed since the tower was generated', title=self._pluginName).show()
Message(f'The Auto Tower was removed because the Cura setting "{setting_label}" has changed since the tower was generated', title=self._pluginName).show()



def _postProcess(self, output_device)->None:
''' This callback is called just before gcode is generated for the model
(this happens when the sliced model is sent to the printer or a file '''

if self._autoTowerGenerated:
# Retrieve the g-code from the scene
scene = Application.getInstance().getController().getScene()
Expand All @@ -531,4 +554,4 @@ def _postProcess(self, output_device)->None:
gcode[0] = gcode[0] + self._gcodeProcessedMarker + '\n'

# Call the tower controller post-processing callback to modify the g-code
gcode = self._towerControllerPostProcessingCallback(gcode)
gcode = self._towerControllerPostProcessingCallback(gcode, self.displayOnLcdSetting)
2 changes: 1 addition & 1 deletion Controllers/BedLevelPatternContoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def dialogAccepted(self)->None:



def postProcess(self, gcode)->list:
def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# No post-processing needs to be done for this pattern
Expand Down
4 changes: 2 additions & 2 deletions Controllers/FanTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ def dialogAccepted(self)->None:



def postProcess(self, gcode)->list:
def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# Call the post-processing script
gcode = FanTower_PostProcessing.execute(gcode, self._startPercent, self._percentChange, self._sectionLayers, self._baseLayers, self.maintainBridgeValue)
gcode = FanTower_PostProcessing.execute(gcode, self._startPercent, self._percentChange, self._sectionLayers, self._baseLayers, self.maintainBridgeValue, displayOnLcd)

return gcode
4 changes: 2 additions & 2 deletions Controllers/FlowTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ def dialogAccepted(self)->None:


# This function is called by the main script when it's time to post-process the tower model
def postProcess(self, gcode)->list:
def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# Call the post-processing script
gcode = FlowTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers)
gcode = FlowTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, displayOnLcd)

return gcode
4 changes: 2 additions & 2 deletions Controllers/RetractTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ def dialogAccepted(self)->None:


# This function is called by the main script when it's time to post-process the tower model
def postProcess(self, gcode)->list:
def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# Call the post-processing script
gcode = RetractTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, self._towerType)
gcode = RetractTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, self._towerType, displayOnLcd)

return gcode
6 changes: 3 additions & 3 deletions Controllers/SpeedTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ def dialogAccepted(self)->None:


# This function is called by the main script when it's time to post-process the tower model
def postProcess(self, gcode)->list:
def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# Call the post-processing script
if self._towerType == 'Travel Speed':
# Query the current print speed
currentPrintSpeed = Application.getInstance().getGlobalContainerStack().getProperty('speed_print', 'value')
gcode = TravelSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, currentPrintSpeed)
gcode = TravelSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, currentPrintSpeed, displayOnLcd)
else:
gcode = MiscSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, self._towerType)
gcode = MiscSpeedTower_PostProcessing.execute(gcode, self._startValue, self._valueChange, self._sectionLayers, self._baseLayers, self._towerType, displayOnLcd)

return gcode
4 changes: 2 additions & 2 deletions Controllers/TempTowerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ def dialogAccepted(self)->None:


# This function is called by the main script when it's time to post-process the tower model
def postProcess(self, gcode)->list:
def postProcess(self, gcode, displayOnLcd=False)->list:
''' This method is called to post-process the gcode before it is sent to the printer or disk '''

# Call the post-processing script
gcode = TempTower_PostProcessing.execute(gcode, self._startTemperature, self._temperatureChange, self._sectionLayers, self._baseLayers)
gcode = TempTower_PostProcessing.execute(gcode, self._startTemperature, self._temperatureChange, self._sectionLayers, self._baseLayers, displayOnLcd)

return gcode
12 changes: 8 additions & 4 deletions Postprocessing/FanTower_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ def is_start_of_layer(line: str) -> bool:



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, maintainBridgeValue=False):
def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, maintainBridgeValue, displayOnLcd):
Logger.log('d', 'AutoTowersGenerator beginning FanTower post-processing')
Logger.log('d', f'Start speed = {startValue}%')
Logger.log('d', f'Speed change = {valueChange}%')
Logger.log('d', f'Base layers = {baseLayers}')
Logger.log('d', f'Section layers = {sectionLayers}')
Logger.log('d', f'Display on LCD = {displayOnLcd}')

# Document the settings in the g-code
gcode[0] = gcode[0] + f';FanTower start fan % = {startValue}, fan % change = {valueChange}\n'
Expand Down Expand Up @@ -65,7 +66,8 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, maintainB
currentFanValue = int((currentValue * 255)/100) # 100% = 255 pour ventilateur
lines[lineIndex] = f'M106 S{currentFanValue} ; AutoTowersGenerator Resuming fan speed of {currentValue}% after bridge'
afterBridge = False
lines.insert(lineIndex + 1, f'M117 Speed {currentValue}%')
if displayOnLcd:
lines.insert(lineIndex + 1, f'M117 Speed {currentValue}%; AutoTowersGenerator added')
else:
lineIndex = lines.index(line)
afterBridge = True
Expand All @@ -86,14 +88,16 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, maintainB
Logger.log('d', f'Start of first section at layer {layerIndex - 2} - setting fan speed to {currentValue}%')
currentFanValue = int((currentValue * 255)/100) # 100% = 255 pour ventilateur
lines.insert(lineIndex + 1, f'M106 S{currentFanValue} ; AutoTowersGenerator setting fan speed to {currentValue}% for the first section')
lines.insert(lineIndex + 2, f'M117 Speed {currentValue}% ; AutoTowersGenerator added')
if displayOnLcd:
lines.insert(lineIndex + 2, f'M117 Speed {currentValue}% ; AutoTowersGenerator added')

if ((layerIndex-baseLayers) % sectionLayers == 0) and (layerIndex > baseLayers):
currentValue += valueChange
Logger.log('d', f'Start of new section at layer {layerIndex - 2} - setting fan speed to {currentValue}%')
currentFanValue = int((currentValue * 255)/100) # 100% = 255 pour ventilateur
lines.insert(lineIndex + 1, f'M106 S{currentFanValue} ; AutoTowersGenerator setting fan speed to {currentValue}% for the next section')
lines.insert(lineIndex + 2, f'M117 Speed {currentValue}% ; AutoTowersGenerator added')
if displayOnLcd:
lines.insert(lineIndex + 2, f'M117 Speed {currentValue}% ; AutoTowersGenerator added')


result = '\n'.join(lines)
Expand Down
8 changes: 5 additions & 3 deletions Postprocessing/FlowTower_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def is_start_of_layer(line: str) -> bool:



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers):
def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, displayOnLcd):
Logger.log('d', 'AutoTowersGenerator beginning FlowTower post-processing')
Logger.log('d', f'Starting value = {startValue}')
Logger.log('d', f'Value change = {valueChange}')
Expand Down Expand Up @@ -51,14 +51,16 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers):
if layerIndex == baseLayers:
Logger.log('d', f'Start of first section layer {layerIndex - 2} - setting flow rate to {currentValue}')
lines.insert(lineIndex + 1, f'M221 S{currentValue} ; AutoTowersGenerator setting flow rate to {currentValue} for first section')
lines.insert(lineIndex + 2, f'M117 Flow {currentValue} ; AutoTowersGenerator added')
if displayOnLcd:
lines.insert(lineIndex + 2, f'M117 Flow {currentValue} ; AutoTowersGenerator added')

# If the end of a section has been reached, decrease the temperature
if ((layerIndex - baseLayers) % sectionLayers == 0) and (layerIndex > baseLayers):
currentValue += valueChange
Logger.log('d', f'New section at layer {layerIndex - 2} - setting flow rate to {currentValue}')
lines.insert(lineIndex + 1, f'M221 S{currentValue} ; AutoTowersGenerator setting flow rate to {currentValue} for next section')
lines.insert(lineIndex + 2, f'M117 Flow {currentValue} ; AutoTowersGenerator addeds')
if displayOnLcd:
lines.insert(lineIndex + 2, f'M117 Flow {currentValue} ; AutoTowersGenerator addeds')

result = '\n'.join(lines)
gcode[layerIndex] = result
Expand Down
8 changes: 5 additions & 3 deletions Postprocessing/MiscSpeedTower_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def is_start_of_layer(line: str) -> bool:



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType):
def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType, displayOnLcd):
Logger.log('d', f'AutoTowersGenerator beginning SpeedTower {towerType} post-processing')
Logger.log('d', f'Starting speed = {startValue}')
Logger.log('d', f'Speed change = {valueChange}')
Expand Down Expand Up @@ -74,7 +74,8 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType
Logger.log('d', f'Setting RepRap pressure value to {float(currentValue):.3f}')

lines.insert(lineIndex + 1, command)
lines.insert(lineIndex + 2, lcd_gcode)
if displayOnLcd:
lines.insert(lineIndex + 2, lcd_gcode)

if ((layerIndex-baseLayers) % sectionLayers == 0) and ((layerIndex - baseLayers) > 0):
Logger.log('d', f'New section at layer {layerIndex - 2}')
Expand Down Expand Up @@ -102,7 +103,8 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType
Logger.log('d', f'Setting RepRap pressure value to {float(currentValue):.3f}')

lines.insert(lineIndex + 1, command)
lines.insert(lineIndex + 2, lcd_gcode)
if displayOnLcd:
lines.insert(lineIndex + 2, lcd_gcode)

result = '\n'.join(lines)
gcode[layerIndex] = result
Expand Down
9 changes: 5 additions & 4 deletions Postprocessing/RetractTower_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def is_reset_extruder_line(line: str) -> bool:



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType):
def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType, displayOnLcd):
Logger.log('d', 'AutoTowersGenerator beginning RetractTower post-processing')
Logger.log('d', f'Starting value = {startValue}')
Logger.log('d', f'Value change = {valueChange}')
Expand All @@ -67,9 +67,9 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType
save_e = -1

if towerType == 'Speed':
lcd_gcode = f'M117 SPD {startValue:.1f}mm/s'
lcd_gcode = f'M117 SPD {startValue:.1f}mm/s ; AutoTowersGenerator added'
else:
lcd_gcode = f'M117 DST {startValue: .1f}mm'
lcd_gcode = f'M117 DST {startValue: .1f}mm ; AutoTowersGenerator added'

current_e = 0
current_f = 0
Expand Down Expand Up @@ -167,7 +167,8 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, towerType
lcd_gcode = f'M117 DST {startValue:.1f}mm ; AutoTowersGenerator added'

# Add M117 to add message on LCD
lines.insert(lineIndex + 1, lcd_gcode)
if displayOnLcd:
lines.insert(lineIndex + 1, lcd_gcode)

result = '\n'.join(lines)
gcode[layerIndex] = result
Expand Down
8 changes: 5 additions & 3 deletions Postprocessing/TempTower_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def is_start_of_layer(line: str) -> bool:



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers):
def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, displayOnLcd):
Logger.log('d', 'AutoTowersGenerator beginning TempTower post-processing')
Logger.log('d', f'Starting temperature = {startValue}')
Logger.log('d', f'Temperature change = {valueChange}')
Expand Down Expand Up @@ -50,14 +50,16 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers):
if layerIndex == baseLayers:
Logger.log('d', f'Start of first section layer {layerIndex - 2} - setting temp to {currentValue}')
lines.insert(lineIndex + 1, f'M104 S{currentValue} ; AutoTowersGenerator setting temperature to {currentValue} for first section')
lines.insert(lineIndex + 2, f'M117 Temp {currentValue} ; AutoTowersGenerator added')
if displayOnLcd:
lines.insert(lineIndex + 2, f'M117 Temp {currentValue} ; AutoTowersGenerator added')

# If the end of a section has been reached, decrease the temperature
if ((layerIndex - baseLayers) % sectionLayers == 0) and (layerIndex > baseLayers):
currentValue += valueChange
Logger.log('d', f'New section at layer {layerIndex - 2} - setting temp to {currentValue}')
lines.insert(lineIndex + 1, f'M104 S{currentValue} ; AutoTowersGenerator setting temperature to {currentValue} for next section')
lines.insert(lineIndex + 2, f'M117 Temp {currentValue} ; AutoTowersGenerator addeds')
if displayOnLcd:
lines.insert(lineIndex + 2, f'M117 Temp {currentValue} ; AutoTowersGenerator added')

result = '\n'.join(lines)
gcode[layerIndex] = result
Expand Down
5 changes: 4 additions & 1 deletion Postprocessing/TravelSpeedTower_PostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def is_travel_speed_line(line: str) -> bool:



def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, referenceSpeed):
def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, referenceSpeed, displayOnLcd):
''' Post-process gcode sliced by Cura
startValue = the starting travel speed (mm/s)
valueChange = the amount to change the travel speed for each section (mm/s)
Expand Down Expand Up @@ -85,6 +85,9 @@ def execute(gcode, startValue, valueChange, sectionLayers, baseLayers, reference
new_line = line.replace(f'F{oldSpeedResult.group(1)}', f'F{newSpeed:.1f}') + f' ; AutoTowersGenerator changing speed from {(oldSpeed/60):.1f}mm/s to {(newSpeed/60):.1f}mm/s'

lines[lineIndex] = new_line

if displayOnLcd:
lines.insert(lineIndex + 1, f'M117 Speed {(newSpeed/60):.1f}mm/s ; AutoTowersGenerator added')

result = '\n'.join(lines)
gcode[layerIndex] = result
Expand Down
Loading

0 comments on commit c6bd8eb

Please sign in to comment.