Get status from Button

I’m building a toolchanger and i have mounted switches on the toolhead and on the magazin.

So the planned movements are:

  • Move with toolhead to tool park position
  • grap tool
  • move 10mm back
  • check if button from toolhead is closed and button from magazin is open → if not stop
  • toolchange successfully

Its my first time i write python and my first time inside a klipper module

the main part of my scripts look like:

park_x = self.start_x + self.parkpositions[targetTool][0]
        park_y = self.start_y + self.parkpositions[targetTool][1]
        toolhead.manual_move([ park_x - self.secure_x, park_y], self.speed_move_fast)
        toolhead.manual_move([park_x], self.speed_move_load)
        self.tool_current = targetTool
        toolhead.manual_move([park_x - self.check_tool_distance], self.speed_move_load)

        if not self.get_button_status(1, 0):
            raise self.printer.command_error("Tool load failed")

       toolhead.manual_move([ park_x - self.secure_x, park_y], self.speed_move_load)

But my problem is the function “self.get_button_status”.

I don’t know how i can check the button status at this moment.

i have tried it with

buttons = self.printer.load_object(config, "buttons")
buttons.register_buttons([magazinpin], self.magazin_button_callback)

but the callbacks are always to late

is this possible?


So i think i have found the missing comment
i hope it’s allowed to use it :smiley:

    def wait_for_button_status(self, tool, magazin, count):
        toolhead = self.printer.lookup_object('toolhead')
        for x in range(count):
            if ((tool == None or tool == self.status_tool_pos) and (magazin == None or magazin == self.status_magazin_pos)):
                return True
  "wait for button status count: %s Tool: t:%s q:%s Magazin: t:%s q:%s", x, tool, self.status_tool_pos, magazin, self.status_magazin_pos)

        return False

with wait_moves() it seems to work.

I don’t know if manual_move() is the correct way to move and it seems manual_move is always absolute?