aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2019-06-26 00:37:20 +0200
committerGuilhem Moulin <guilhem@fripost.org>2019-06-26 01:04:41 +0200
commit556f6d19a315775a366755061aa218c6909ca775 (patch)
tree8f0b07d21c22212465d7055fe1db582fe82a866d
parent931806b02c4531e3629ee92a8854abc9614739c5 (diff)
Add script to apply color maps.
Once again, credits to algernon for the maps: https://git.madhouse-project.org/algernon/Model01-Sketch/src/branch/master/tools/colormap
-rw-r--r--Makefile5
-rw-r--r--README9
-rw-r--r--src/colormap.map41
-rwxr-xr-xsrc/palette16
-rwxr-xr-xtools/apply-colormap94
5 files changed, 165 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index de05a90..ec992ae 100644
--- a/Makefile
+++ b/Makefile
@@ -32,3 +32,8 @@ AVRDUDE_CONF = /etc/avrdude.conf
#MONITOR_PORT = $(firstword $(wildcard /dev/serial/by-id/usb-keyboardio_Model_01_*))
include $(ARDMK_DIR)/Arduino.mk
+
+apply-colormap: ./src/palette ./src/colormap.map
+ DEVICE=$(DEVICE_PATH) ./tools/apply-colormap $^
+
+.PHONY: apply-colormap
diff --git a/README b/README
index 1a601c8..4374e16 100644
--- a/README
+++ b/README
@@ -48,3 +48,12 @@ Flash firmware
Press down the 'prog' key while the board is rebooting. You can release
it once it glows red.
+
+
+Apply the color map
+===================
+
+ ~$ make apply-colormap
+
+This requires a firmware supporting the Serial protocol. (Add
+ENABLE_SERIAL=1 to the build environment.)
diff --git a/src/colormap.map b/src/colormap.map
new file mode 100644
index 0000000..2ba99d4
--- /dev/null
+++ b/src/colormap.map
@@ -0,0 +1,41 @@
+## Map RxCy to a palette index. Coordinates can be found at
+## ./lib/hardware/keyboardio/avr/libraries/Kaleidoscope/doc/model01_coordinates.png
+
+
+# Dvorak
+
+0 0 0 0 0 0 0 1
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 5
+8 0 0 0 0 0 3 0
+
+2 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 6 0 0 0 0 0 0
+
+
+# Nav
+
+0 3 3 3 3 3 0 1
+0 7 6 2 6 7 6 0
+0 7 2 2 2 7 2 5
+0 0 6 0 6 0 3 0
+
+2 0 3 3 3 3 3 3
+0 0 8 8 2 8 0 3
+0 2 8 2 2 2 0 0
+0 0 0 0 0 0 0 0
+
+
+# Num
+
+0 0 0 0 0 0 0 1
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 5
+0 0 0 0 0 0 0 0
+
+2 0 0 0 0 0 0 0
+0 0 0 7 7 7 0 3
+0 3 7 7 7 7 3 3
+0 6 3 7 7 7 0 0
diff --git a/src/palette b/src/palette
new file mode 100755
index 0000000..a33d7c6
--- /dev/null
+++ b/src/palette
@@ -0,0 +1,16 @@
+ 0 0 0 # Black
+ 0 0 170 # Blue
+ 0 170 0 # Green
+ 0 170 170 # Cyan
+170 0 0 # Red
+170 0 170 # Magenta
+170 85 0 # Brown
+170 170 170 # Light grey
+ 85 85 85 # Dark grey
+ 85 85 255 # Bright blue
+ 85 255 85 # Bright green
+ 85 255 255 # Bright cyan
+255 85 85 # Bright red
+255 85 255 # Bright Magenta
+255 255 85 # Yellow
+255 255 255 # White / transparent
diff --git a/tools/apply-colormap b/tools/apply-colormap
new file mode 100755
index 0000000..dd35844
--- /dev/null
+++ b/tools/apply-colormap
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+#----------------------------------------------------------------------
+# A firmware Sketch for the Keyboardio Model 01 -- apply color maps
+# Copyright © 2019 Guilhem Moulin <guilhem@fripost.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#----------------------------------------------------------------------
+
+set -eu
+PATH=/usr/bin:/bin
+export PATH
+
+PALETTE="$1"
+COLORMAP="$2"
+
+DEFAULT_DEVICE_PATH=( /dev/serial/by-id/usb-keyboardio_Model_01_* )
+DEVICE_PATH="${DEVICE_PATH:-${DEFAULT_DEVICE_PATH[0]}}"
+stty -F "$DEVICE_PATH" 9600 raw -echo
+
+# cf. key_led_map in
+# ./lib/hardware/keyboardio/avr/libraries/Kaleidoscope/src/Kaleidoscope-Hardware-Model01.h
+
+declare -a LED_MAP=(
+ 3 4 11 12 19 20 26 27 36 37 43 44 51 52 59 60
+ 2 5 10 13 18 21 25 28 35 38 42 45 50 53 58 61
+ 1 6 9 14 17 22 24 29 34 39 41 46 49 54 57 62
+ 0 7 8 15 16 23 31 30 33 32 40 47 48 55 56 63
+)
+declare -a LED_RMAP_LEFT=() LED_RMAP_RIGHT=() LED_RMAP=()
+for ((r = 0; r < 4; r++)); do
+ for ((c = 0; c < 8; c++)); do
+ LED_RMAP_LEFT[${LED_MAP[r*16+c]}]=$((r*8+c))
+ LED_RMAP_RIGHT[${LED_MAP[r*16+8+c]}-32]=$((r*8+c))
+ done
+done
+
+transpose() {
+ local i offset=$(($1 + 1 - ${#LED_MAP[@]}))
+ MAPFILE[$1]="$2"
+ for ((i = 0; i < ${#LED_RMAP_LEFT[@]}; i++)); do
+ printf " %d" "${MAPFILE[offset+${LED_RMAP_LEFT[i]}]}"
+ done
+ for ((i = 0; i < ${#LED_RMAP_RIGHT[@]}; i++)); do
+ printf " %d" "${MAPFILE[offset+32+${LED_RMAP_RIGHT[i]}]}"
+ done
+}
+
+colormap() {
+ local colormap="$(mktemp --tmpdir)" fd
+ declare -a MAPFILE
+
+ # ugly workaround for the lack of O_TMPFILE
+ exec {fd}>"$colormap"
+ rm -f -- "$colormap"
+
+ sed -r "/^#/d; s/\\s+/\\n/g" <"$COLORMAP" | sed "/^\\s*$/d" >&$fd
+ printf "colormap.map"
+ mapfile -t -C transpose -c ${#LED_MAP[@]} <"/proc/self/fd/$fd"
+ printf "\\n"
+ {fd}>&-
+}
+
+palette() {
+ printf "palette"
+ sed "/^\\s*#/d; s/\\s*#.*//" <"$PALETTE" \
+ | sed -nr "1h;1!H; \${x; s/^\\s*/ /; s/\s+/ /g; p}"
+}
+
+serial_send() {
+ local fd
+ exec {fd}<"$DEVICE_PATH"
+ "$@" >"$DEVICE_PATH"
+ while IFS= read -r -u "$fd" x; do
+ x="${x%$'\r'}"
+ [ "$x" != "." ] || break
+ printf "%s\\n" "$x"
+ done
+ {fd}<&-
+}
+
+serial_send palette
+serial_send colormap