Thanks @Oliver
I checked that mksclient binary a bit, it does not do any error checking, so we can patch the binary easily to just open the wrong thing, and silently do nothing. I made this python script that does just that:
import mmap
import argparse
file_path = "/home/sovol/printer_data/build/mksclient"
def patch_binary(write_null):
search = b"/sys/class/gpio/expor"
searchlen = len(search)
with open(file_path, 'r+b') as f:
mm = mmap.mmap(f.fileno(), 0)
pos1 = mm.find(search)
pos2 = mm.find(search, pos1 + searchlen)
if pos1 == -1:
print("Missing first patch point")
mm.close()
return
if pos2 == -1:
print("Missing second patch point")
mm.close()
return
print("found at:", pos1, pos2, "patching")
mm[pos1 + searchlen] = 0 if write_null else ord('t')
mm[pos2 + searchlen] = 0 if write_null else ord('t')
mm.flush()
mm.close()
print("Patched:", file_path)
parser = argparse.ArgumentParser(description="Patch a binary file.")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--klipper", action="store_true", help="Let klipper control the camera led")
group.add_argument("--printer", action="store_true", help="Let the printer touch screen control the camera led")
args = parser.parse_args()
patch_binary(args.klipper)
Save it somewhere on the sovol machine. Then run these commands via ssh:
systemctl stop makerbase-client.service
cp printer_data/build/mksclient printer_data/build/mksclient.backup
python3 patch_led.py --klipper
sudo reboot
(And if you want to back to normal, run python3 patch_led.py --printer
)
After the reboot, add this to the printer.cfg via the web interface in the “machine” section:
[output_pin cameralight]
pin: rpi:gpiochip2/gpio3
Then you’ll have a camera light toggle in the miscellaneous section of the dashboard.
And can run gcode like SET_PIN PIN=cameralight VALUE=1
And setup any gcode macro you like around this. Like turn it on for the whole print. Or configure it in machine.cfg to turn on when the stepper motors are engaged. Happy hacking