KlipperWrt icon indicating copy to clipboard operation
KlipperWrt copied to clipboard

[guide] Android phone snapshots - adb triggered

Open ihrapsa opened this issue 2 years ago • 0 comments

<----> <---->

Use adb tools to trigger phone camera through USB. This will allow to take snapshots on command allowing for a Klipper macro integration on Z layer change.

Inspired from here and here

🔢 Steps:

  1. Enable USB Debugging on your phone
  2. Download adb tools on your Klippy host or install it from repo: for OpenWrt that would be opkg install adb
  3. Install the unofficial klipper shell_command extension here by Arksine
    • That needs to be copied to klipper/klippy/extras/gcode_shell_command.py
    • Extra info and configurations here
  4. Insert the macros below in your printer.cfg 5.Inside your slicer call the ADB_TAKE_FRAME macro on z layer change
    • If you want timelapse with head parked either integrate the ADB_TAKE_FRAME into another macro that does just that OR
    • If you use Cura, there's a Time Lapse post proccessing script. See below
  5. Make sure camera app is running and the phone doesn't have a sleep timeout.
  6. Execute the ADB_START_SERVER macro to make sure adb-server is running and listening to commands. You can add this macro to your START GCODE if you want
  7. Focus and lock exposure to where your print will sit/be parked
  8. Print!

⌨️ useful adb commands:

adb shell input keyevent CAMERA  #this command will trigger
adb shell input keyevent FOCUS #this command will focus
adb shell input tap x y #will send a tap at x and y pixel coordinates.
adb shell input swipe x1 x2 y1 y2 #will send a swipe from (x1,y1) to (x2,y2)

Note!

  • Some cameras have timeouts. To avoid that, Open Camera app is recommended.
  • Otherwise, to wake the camera if it times out, we can send a swipe before triggering. (If we send a tap while the camera hasn't timed out yet, it will focus there and you might not want that if you use manual focus).This is still tricky and focus resets to center after every wakeup.

⚙️ Macro template

#this macro will start the adb server on the klippy host
[gcode_shell_command adb_start]
command: adb start-server
timeout: 3.
verbose: False
[gcode_macro ADB_START_SERVER]
gcode:
    RUN_SHELL_COMMAND CMD=adb_start


#this macro will take a snapshot on your android phone using adb shell command
[gcode_shell_command adb_trigger]
command: adb shell input keyevent KEYCODE_CAMERA
timeout: 3.
verbose: False
[gcode_macro ADB_TAKE_FRAME]
gcode:
    RUN_SHELL_COMMAND CMD=adb_trigger

After you copy the above macros to printer.cfg, buttons should appear here. You can manually execute them if you want to test: image


Static Timelapses

To create timelapses with the head out of the way, make another macro that parks the head and calls the ADB_TAKE_FRAME macro. Make sure to insert the newly created macro in your slicer layer change instead.

OR

If you use Cura, you can take advantage of the Time Lapse post proccesing script and insert the ADB_TAKE_FRAME in the Trigger camera command field

image

Here's a test print:

https://user-images.githubusercontent.com/40600040/128196837-dcf9d0b5-74ca-4d24-886b-8ce28c235260.mp4

Many thanks to Kruze17 for testing and helping!

ihrapsa avatar Jul 31 '21 17:07 ihrapsa