Basic Information:
Printer Model: BIGTREETECH MANTA M8P V2.0
MCU / Printerboard:STM32H7
Host / SBC:CB2
klippy (3).log (602.0 KB)
class myled:
def __init__(self, config):
self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode')
ppins = self.printer.lookup_object('pins')
pin_params = ppins.lookup_pin(config.get('pin'))
self.mcu = pin_params['chip']
self.oid = self.mcu.create_oid()
self.cmd_queue = self.mcu.alloc_command_queue()
self.pin = pin_params['pin']
self.mcu.register_config_callback(self.build_config)
self.pin_statue = config.getint('pin_statue',0)
self.gcode.register_command('MY_CUSTOM_COMMAND0', self.cmd_my_custom_command0, desc=self.cmd_my_custom_command_help)
self.gcode.register_command('MY_CUSTOM_COMMAND1', self.cmd_my_custom_command1, desc=self.cmd_my_custom_command_help)
if self.pin_statue != 0 and self.pin_statue != 1:
raise error("pin_statue must be 0 or 1 .now is:%d"%(self.pin_statue))
cmd_my_custom_command_help = "This is a debug command"
def cmd_my_custom_command0(self, gcmd):
value = 0
self.gcode.respond_info("haha_config_digital_out0 " + self.pin)
self.update_pin_cmd.send([self.oid, not not value])
#self.gcode.respond_info("This is a response from my custom command"+self.name+self.pin)
def cmd_my_custom_command1(self, gcmd):
value = 1
self.gcode.respond_info("haha_config_digital_out1 " + self.pin)
self.update_pin_cmd.send([self.oid, not not value])
#self.gcode.respond_info("This is a response from my custom command"+self.name+self.pin)
def build_config(self):
self.mcu.add_config_cmd("config_digital_out oid=%d pin=%s value=%d default_value=%d"" max_duration=%d" % (self.oid, self.pin, self.pin_statue,0, 16000))
self.update_pin_cmd = self.mcu.lookup_command("update_digital_out oid=%c value=%c", cq=self.cmd_queue)
def load_config(config):
return myled(config)
def load_config_prefix(config):
return myled(config)
CFG:
[myled]
pin:PD2
pin_statue:1
I added an LED module and controlled the on and off of the LED through MY_CUSTOM_COMMAND0 and MY_CUSTOM_COMMAND1. When I input MY_CUSTOM_COMMAND0, it works fine, but when I input MY_CUSTOM_COMMAND1, an error occurs and the MCU shuts down.