eltariel / njak

Driver software for buttons and lights a la Pimoroni Keybow
GNU General Public License v3.0
0 stars 0 forks source link

Not Just A Keypad

Python interface for GPIO keypads and APA102 RGB LEDs. Inspired by the Pimoroni Keybow.

Requirements

Hardware prep

If you're running a raspi, add the following in your /boot/config.txt if they're not there, and reboot:

dtparam=spi=on
dtoverlay=swc2

Software deps

These can be installed on Raspberry Pi OS like this:

sudo apt install python3-spidev python3-gpiozero python3-rpi.gpio

Setup

One-off

As root:

./init-usb-gadget.sh
python3 njak.py

Installation

Currently a bit messy, you'll need to do all of this by hand.

Key Mapping

Layout

The physical mapping is defined in the layout array in config.py. This is an array of 12 tuples of (led index, key gpio) and they're configured by default to match the Keybow (because that's what I'm working with).

9(0, 20)   A(4, 16)   B(8, 26)
6(1, 6)    7(5, 12)   8(9, 13)
3(2, 22)   4(6, 24)   5(A, 5)
0(3, 17)   1(7, 27)   2(B, 23)

Key handlers

The key mappings and other behaviours are specified in the constructor of the Njak class. This creates a number of handlers that get bound to the GPIO keys. The handlers must accept two arguments: the gpiozero Button instance and the njak Key object.

The Bitmap HID report contains a helper to generate handlers for key presses.

Layers

Key handlers are grouped into layers. Key 0 (bottom left on the Keybow) is reserved to switch between layers. Currently, layers are defined in a 2D array in the Njak constructor and passed into the Keypad class. It's a little broken but I'm working on it...

Switch between layers by holding key 0 and then pressing the key corresponding to the desired layer. The key representing the selected layer will go dark.

Default layers:

  1. Keys 0 - 9 and enter
  2. Every key is F13. I use it for Discord PTT :P

Future:

LED magic

TODO