From 6db44b88ba050655e7efb6994b487b93e030ebb6 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 29 Jun 2022 09:23:07 +0200 Subject: [PATCH] wip: ploopyenc Signed-off-by: Gergely Nagy --- .../examples/PloopyEnc/Makefile | 48 ++++++++++++++ .../examples/PloopyEnc/PloopyEnc.ino | 65 +++++++++++++++++++ .../examples/PloopyEnc/flash.sh | 12 ++++ .../examples/PloopyEnc/sketch.json | 6 ++ 4 files changed, 131 insertions(+) create mode 100644 plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/Makefile create mode 100644 plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/PloopyEnc.ino create mode 100755 plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/flash.sh create mode 100644 plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/sketch.json diff --git a/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/Makefile b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/Makefile new file mode 100644 index 00000000..19019b31 --- /dev/null +++ b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/Makefile @@ -0,0 +1,48 @@ +# This makefile for a Kaleidoscope sketch pulls in all the targets +# required to build the example + + + + +ifneq ($(KALEIDOSCOPE_DIR),) +search_path += $(KALEIDOSCOPE_DIR) +endif + +ifneq ($(ARDUINO_DIRECTORIES_USER),) +search_path += $(ARDUINO_DIRECTORIES_USER)/hardware/keyboardio/avr/libraries/Kaleidoscope +endif + +ifeq ($(shell uname -s),Darwin) +search_path += $(HOME)/Documents/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope +else +search_path += $(HOME)/Arduino/hardware/keyboardio/avr/libraries/Kaleidoscope +endif + +sketch_makefile := etc/makefiles/sketch.mk + +$(foreach candidate, $(search_path), $(if $(wildcard $(candidate)/$(sketch_makefile)), $(eval ks_dir ?= $(candidate)))) + +ifneq ($(ks_dir),) + +$(info Using Kaleidoscope from $(ks_dir)) + +export KALEIDOSCOPE_DIR := $(ks_dir) +include $(ks_dir)/$(sketch_makefile) + +else + +$(info I can't find your Kaleidoscope installation.) +$(info ) +$(info I tried looking in:) +$(info ) +$(foreach candidate, $(search_path), $(info $(candidate))) +$(info ) +$(info The easiest way to fix this is to set the 'KALEIDOSCOPE_DIR' environment) +$(info variable to the location of your Kaleidoscope directory.) + +endif + + +null-target: + $(info You should never see this message) + @: diff --git a/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/PloopyEnc.ino b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/PloopyEnc.ino new file mode 100644 index 00000000..32821a3e --- /dev/null +++ b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/PloopyEnc.ino @@ -0,0 +1,65 @@ +// -*- mode: c++ -*- + +#include "Kaleidoscope.h" +#include "Kaleidoscope-FocusSerial.h" +#include "Kaleidoscope-EEPROM-Settings.h" +#include "Kaleidoscope-EEPROM-Keymap.h" +#include "Kaleidoscope-MouseKeys.h" +#include "Kaleidoscope-Macros.h" + +KEYMAPS( + [0] = KEYMAP(M(0), Key_B, Key_C, Key_D, Key_E, Key_NoKey), +); + +#define OPT_ENC1 PIN_F0 +#define OPT_ENC2 PIN_F4 +#define OPT_ENC1_MUX 0 +#define OPT_ENC2_MUX 4 + +void handleEncoder() { + uint16_t p1 = analogRead(OPT_ENC1_MUX); + uint16_t p2 = analogRead(OPT_ENC2_MUX); + + if (p1 != 0 || p2 != 0) { + Focus.send("p1=", p1, "p2=", p2, "\n"); + } +} + +const macro_t *macroAction(uint8_t macro_id, KeyEvent &event) { + if (!keyToggledOn(event.state)) { + return MACRO_NONE; + } + + switch (macro_id) { + case 0: + handleEncoder(); + break; + } + + return MACRO_NONE; +} + +KALEIDOSCOPE_INIT_PLUGINS( + Focus, + EEPROMSettings, + EEPROMKeymap, + MouseKeys, + Macros +); + +void setup() { + Kaleidoscope.setup(); + EEPROMKeymap.setup(5); + + DDR_INPUT(OPT_ENC1); + ENABLE_PULLUP(OPT_ENC1); + DDR_INPUT(OPT_ENC2); + ENABLE_PULLUP(OPT_ENC2); +} + +void loop() { + Kaleidoscope.loop(); + + handleEncoder(); + delay(10); +} diff --git a/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/flash.sh b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/flash.sh new file mode 100755 index 00000000..be8533ec --- /dev/null +++ b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/flash.sh @@ -0,0 +1,12 @@ +#! /bin/sh +set -e + +echo "* Building" +make OUTPUT_PATH=$(pwd)/_build + +echo "* Jumping to bootloader..." +DEVICE=/dev/ttyACM1 focus device.reset +sleep 2s + +echo "* Flashing..." +dfu-programmer atmega32u4 erase && dfu-programmer atmega32u4 flash _build/*-latest.hex && dfu-programmer atmega32u4 start diff --git a/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/sketch.json b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/sketch.json new file mode 100644 index 00000000..6a5dec07 --- /dev/null +++ b/plugins/Kaleidoscope-Hardware-Ploopy-Trackball-Mini/examples/PloopyEnc/sketch.json @@ -0,0 +1,6 @@ +{ + "cpu": { + "fqbn": "keyboardio:avr:ploopy_mini", + "port": "" + } +}