Skip to content

Instantly share code, notes, and snippets.

@mrled
Last active March 23, 2024 01:29
Show Gist options
  • Save mrled/1b743ceee5f850907817d923d918814c to your computer and use it in GitHub Desktop.
Save mrled/1b743ceee5f850907817d923d918814c to your computer and use it in GitHub Desktop.
Ploopy Nano control by LED-Key BitMask shell script

A quick script to control lkbm firmware on the Ploopy Nano.

See this post for more features and more explanation.

#!/bin/sh
set -e
usage() {
cat <<ENDUSAGE
$0: Send commands to Ploopy Trackball Nano that is running LKBM firmware via caps/scroll/num lock LED signals
Usage: $0 [scroll|dpi|reset|status|help]
See <https://github.com/qmk/qmk_firmware/tree/master/keyboards/ploopyco/trackball_nano/keymaps/lkbm>.
ENDUSAGE
}
# Find the /sys/class/leds/* path for caps/num/scroll-lock
inputdev=/dev/input/by-id/usb-PloopyCo_Trackball_Nano-event-kbd
evntname="$(basename "$(readlink -f $inputdev)")"
# e.g. "event22"
sysclassdev=/sys/class/input/$evntname/device
sysinputname="$(echo $sysclassdev/*::capslock | sed 's|.*/\(input[0-9]*\).*|\1|')"
# e.g. "input1251"
caps=/sys/class/leds/$sysinputname::capslock/brightness
scroll=/sys/class/leds/$sysinputname::scrolllock/brightness
num=/sys/class/leds/$sysinputname::numlock/brightness
# We have to wait a very small amount of time or the LED changes don't seem to register
# I use busybox sleep but should also work with GNU sleep (untested)
lkbmwait() {
busybox sleep 0.0025s
}
# Toggle scroll behavior, between using the trackball as normal and using it as a 2D scroll ball
toggle_scroll() {
echo 1 > "$num"
lkbmwait
echo 0 > "$num"
lkbmwait
}
# Cycle between slow/med/fast DPI
cycle_dpi() {
echo 1 > "$caps"
lkbmwait
echo 0 > "$caps"
lkbmwait
}
# Enter reset mode to flash new firmware
enter_reset() {
echo 1 > "$caps"
lkbmwait
echo 1 > "$num"
lkbmwait
echo 0 > "$num"
lkbmwait
echo 0 > "$caps"
lkbmwait
}
# Read the current status of all the LEDs
read_status() {
c="$(cat "$caps")"
s="$(cat "$scroll")"
n="$(cat "$num")"
echo "Input device path: $inputdev"
echo "Event device name: $evntname"
echo "/sys/class even device: $sysclassdev"
echo "/sys/class input device: $sysinputname"
echo "Capslock: $c"
echo "Scroll lock: $s"
echo "Numlock: $n"
}
case "$1" in
scroll) toggle_scroll;;
dpi) cycle_dpi;;
reset) enter_reset;;
status) read_status;;
*) usage;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment