Skip to content

Commit

Permalink
Allow Users to directly set power on and off commands
Browse files Browse the repository at this point in the history
  • Loading branch information
PadLex committed May 21, 2021
1 parent 0627295 commit d040ef5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
8 changes: 2 additions & 6 deletions laser/laser.inx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
</page>

<page name="advanced_settings" gui-text="Advanced Settings">
<param name="laser_power_command" type="string" _gui-text="Laser Power Command">M3</param>
<param name="laser_off_command" type="string" _gui-text="Laser Off Command">M5</param>
<param name="tool_power_command" type="string" _gui-text="Tool Power Command">M3 S255;</param>
<param name="tool_off_command" type="string" _gui-text="Tool Off Command">M5;</param>
<param name="dwell_time" type="float" _gui-text="Dwell Time Before Moving (ms)">0</param>
<param name="laser_power_range" type="enum" _gui-text="Laser Power Range">
<item value="255">0-255</item>
<item value="12000">0-12000</item>
</param>
<spacer></spacer>
<param name="draw_debug" type="boolean" _gui-text="Draw Debug">true</param>
<param name="debug_line_width" type="float" _gui-text="Debug Line Width (px)">0.5</param>
Expand Down
16 changes: 5 additions & 11 deletions laser/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from svg_to_gcode.svg_parser import parse_root, Transformation, debug_methods
from svg_to_gcode.geometry import LineSegmentChain
from svg_to_gcode.compiler import Compiler, interfaces
from svg_to_gcode.formulas import linear_map
from svg_to_gcode import TOLERANCES

svg_name_space = "http://www.w3.org/2000/svg"
Expand All @@ -17,7 +16,7 @@
inx_filename = "laser.inx"


def generate_custom_interface(laser_off_command, laser_power_command, laser_power_range):
def generate_custom_interface(laser_off_command, laser_power_command):
"""Wrapper function for generating a Gcode interface with a custom laser power command"""

class CustomInterface(interfaces.Gcode):
Expand All @@ -27,14 +26,10 @@ def __init__(self):
super().__init__()

def laser_off(self):
return f"{laser_off_command};"
return f"{laser_off_command}"

def set_laser_power(self, power):
if power < 0 or power > 1:
raise ValueError(f"{power} is out of bounds. Laser power must be given between 0 and 1. "
f"The interface will scale it correctly.")

return f"{laser_power_command} S{linear_map(0, int(laser_power_range), power)};"
def set_laser_power(self, _):
return f"{laser_power_command}"

return CustomInterface

Expand Down Expand Up @@ -79,8 +74,7 @@ def effect(self):
self.debug(f"Footer file does not exist at {self.options.footer_path}")

# Customize header/footer
custom_interface = generate_custom_interface(self.options.laser_off_command, self.options.laser_power_command,
self.options.laser_power_range)
custom_interface = generate_custom_interface(self.options.tool_off_command, self.options.tool_power_command)
interface_instance = custom_interface()

if self.options.do_laser_off_start:
Expand Down

0 comments on commit d040ef5

Please sign in to comment.