Skip to content

Commit f7d3169

Browse files
authored
Merge pull request #26 from JanLunge/coordmap-split-boards
supply coordmap for the coordmap helper, better naming of custom keyb…
2 parents a2f69af + ef71c47 commit f7d3169

File tree

6 files changed

+58
-45
lines changed

6 files changed

+58
-45
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pog",
3-
"version": "1.4.4",
3+
"version": "1.4.5",
44
"license": "MIT",
55
"description": "A KMK firmware configurator",
66
"main": "./out/main/index.js",

src/main/pythontemplates/code.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
export const codepy = `# Main Keyboard Configuration - v0.9.5
1+
export const codepy = `# Main Keyboard Configuration - v1.0.0
22
import board
33
import pog
4-
54
# check if we just want to run the coord_mappping Assistant
65
if pog.coordMappingAssistant:
7-
from coordmaphelper import KMKKeyboard
6+
from coordmaphelper import CoordMapKeyboard
87
if __name__ == '__main__':
9-
KMKKeyboard().go()
10-
exit()
8+
CoordMapKeyboard().go()
9+
print("Exiting Coord Mapping Assistant Because of an error")
1110
else:
12-
from kb import KMKKeyboard
13-
14-
# set the required features for you keyboard and keymap
15-
# add custom ones in the kb.py
11+
from kb import POGKeyboard
12+
# set the required features for you keyboard and keymap
13+
# add custom ones in the kb.py
1614
17-
keyboard = KMKKeyboard(features=pog.kbFeatures)
15+
keyboard = POGKeyboard(features=pog.kbFeatures)
1816
19-
# manage settings for our modules and extensions here
20-
keyboard.tapdance.tap_time = 200
17+
# manage settings for our modules and extensions here
18+
keyboard.tapdance.tap_time = 200
2119
22-
# Keymap
23-
import keymap
24-
keyboard.keymap = keymap.keymap
20+
# Keymap
21+
import keymap
22+
keyboard.keymap = keymap.keymap
2523
26-
# Encoder Keymap if available
27-
if pog.hasEncoders:
28-
keyboard.encoder_handler.map = keymap.encoderKeymap
24+
# Encoder Keymap if available
25+
if pog.hasEncoders:
26+
keyboard.encoder_handler.map = keymap.encoderKeymap
2927
30-
# Execute the keyboard loop
31-
if __name__ == '__main__':
32-
keyboard.go()
28+
# Execute the keyboard loop
29+
if __name__ == '__main__':
30+
keyboard.go()
3331
`
Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
export const coordmaphelperpy = `# coordmaphelper.py helper script to get your coord map - v1.0.0
1+
export const coordmaphelperpy = `# coordmaphelper.py v1.0.1
2+
import board
3+
import pog
4+
from kb import POGKeyboard
25
from kmk.keys import KC
3-
from kb import KMKKeyboard as _KMKKeyboard
46
from kmk.modules.macros import Press, Release, Tap, Macros
5-
import pog
6-
class KMKKeyboard(_KMKKeyboard):
7+
8+
class CoordMapKeyboard(POGKeyboard):
79
def __init__(self):
8-
super().__init__()
9-
macros = Macros()
10-
self.modules.append(macros)
11-
print("running coord_mapping assistant")
12-
print("press each key to get its coord_mapping value")
13-
# *2 for split keyboards, which will typically manage twice the number of keys
14-
# of one side. Having this N too large will have no impact (maybe slower boot..)
10+
super().__init__(features=['basic', 'macros'])
11+
print("Running coord_mapping assistant")
12+
print("Press each key to get its coord_mapping value")
13+
14+
if not hasattr(pog, 'keyCount') or pog.keyCount == 0:
15+
raise ValueError("pog.keyCount is not set or is zero")
16+
1517
N = pog.keyCount * 2
1618
coord_mapping = list(range(N))
17-
1819
layer = []
20+
print(f"coord_mapping = {coord_mapping}")
21+
print(f"Total keys: {N}")
1922
2023
for i in range(N):
2124
c, r = divmod(i, 100)
2225
d, u = divmod(r, 10)
23-
layer.append(
24-
KC.MACRO(
25-
Tap(getattr(KC, "N" + str(c))),
26-
Tap(getattr(KC, "N" + str(d))),
27-
Tap(getattr(KC, "N" + str(u))),
26+
print(f"Adding key {i} ({c}{d}{u})")
27+
try:
28+
layer.append(
29+
KC.MACRO(
30+
Tap(getattr(KC, f"N{c}")),
31+
Tap(getattr(KC, f"N{d}")),
32+
Tap(getattr(KC, f"N{u}")),
2833
Tap(KC.SPC),
34+
)
2935
)
30-
)
31-
self.keymap = [layer]`
36+
except AttributeError as e:
37+
print(f"Error creating macro for key {i}: {e}")
38+
39+
if not layer:
40+
raise ValueError("No keys were added to the layer")
41+
42+
print(f"Layer created with {len(layer)} keys")
43+
self.keymap = [layer]
44+
self.coord_mapping = coord_mapping
45+
print(f"Keymap initialized with {len(self.keymap[0])} keys")
46+
`

src/main/pythontemplates/kb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ export const kbpy = `# kb.py KB base config - v0.9.5
22
import board
33
import pog
44
5-
from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
5+
from kmk.kmk_keyboard import KMKKeyboard
66
from kmk.scanners import DiodeOrientation
77
from kmk.scanners.keypad import KeysScanner
88
9-
class KMKKeyboard(_KMKKeyboard):
9+
class POGKeyboard(KMKKeyboard):
1010
def __init__(self, features=['basic']):
1111
if "basic" in features:
1212
from kmk.modules.layers import Layers;

src/main/pythontemplates/keymap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Keymap Autogenerated by Pog do not edit
22
from kmk.keys import KC
3-
from kmk.modules.macros import Macros, Press, Release, Tap
3+
from kmk.modules.macros import Macros, Press, Release, Tap, Delay
44
import pog
55
import customkey
66
from kmk.modules.combos import Chord, Sequence

src/main/saveConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const handleKeymapSave = ({ pogConfig, serial }) => {
112112
// we are still writing the keymap file by hand
113113
const keymap = `# Keymap Autogenerated by Pog do not edit
114114
from kmk.keys import KC
115-
from kmk.modules.macros import Macros, Press, Release, Tap
115+
from kmk.modules.macros import Macros, Press, Release, Tap, Delay
116116
from kmk.modules.combos import Chord, Sequence
117117
118118
import pog

0 commit comments

Comments
 (0)