Skip to content

Commit 803b689

Browse files
committed
v0.6.0
1 parent ec5aa8c commit 803b689

File tree

16 files changed

+519
-279
lines changed

16 files changed

+519
-279
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ then just run it with dev to start
2727
- [ ] use injection points from the pog.json for codeblocks
2828
- [ ] direct pin wiring support
2929
- [ ] bluetooth workflow
30+
- [ ] generate layout based on matrix + clear layout button / delete multiple
31+
- [ ] save a backup of the json in electron
3032

3133
## features
3234
- [x] dragging keys on the layout editor

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pog",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "A KMK firmware configurator",
55
"main": "./out/main/index.js",
66
"author": "Jan Lunge",
@@ -28,6 +28,7 @@
2828
"@vueuse/core": "^9.12.0",
2929
"@wlard/vue-class-store": "^3.0.0",
3030
"daisyui": "^2.50.0",
31+
"dayjs": "^1.11.7",
3132
"decompress": "^4.2.1",
3233
"electron-updater": "^5.3.0",
3334
"mini-svg-data-uri": "^1.4.4",

src/main/saveConfig.ts

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { currentKeyboard } from './store'
33
// save code.py based on pog.json
44

55
export const saveConfiguration = (data: string) => {
6-
const {pogConfig, writeFirmware} = JSON.parse(data)
6+
const { pogConfig, writeFirmware } = JSON.parse(data)
77
// write pog.json config
88
// write pog.json
99
fs.writeFile(currentKeyboard.path + '/pog.json', JSON.stringify(pogConfig, null, 4), () => {
@@ -72,41 +72,98 @@ export const handleKeymapSave = (pogConfig) => {
7272
encoderKeymap + // layers
7373
']\n'
7474
}
75-
const keymapString = `print("Starting")
75+
const mainConfig = `# Main Keyboard Configuration
76+
print("Starting ${pogConfig.name || 'Keyboard'}")
7677
7778
import board
78-
import supervisor
79-
import digitalio
8079
import storage
81-
import usb_cdc
82-
import usb_hid
8380
84-
from kmk.kmk_keyboard import KMKKeyboard
85-
from kmk.keys import KC
86-
from kmk.scanners import DiodeOrientation
81+
from kb import KMKKeyboard
82+
from kmk.modules.tapdance import TapDance
83+
84+
from storage import getmount
85+
from kmk.modules.split import Split, SplitType, SplitSide
8786
${pythonImports}
8887
8988
keyboard = KMKKeyboard()
9089
${kmkAddons}
9190
92-
# Cols
93-
keyboard.col_pins = (${pogConfig.colPins.map((a) => 'board.GP' + a).join(', ')})
94-
# Rows
95-
keyboard.row_pins = (${pogConfig.rowPins.map((a) => 'board.GP' + a).join(', ')})
96-
# Diode Direction
97-
keyboard.diode_orientation = DiodeOrientation.${pogConfig.diodeDirection}
91+
tapdance = TapDance()
92+
tapdance.tap_time = 200
93+
keyboard.modules.append(tapdance)
9894
9995
# Keymap
100-
keyboard.keymap = [
101-
${pogConfig.keymap.map((layer) => '[' + layer.join(', ') + ']').join(', ')}
102-
]
96+
from keymap import keymap
97+
keyboard.keymap = keymap
10398
10499
${codeblock}
105100
106101
if __name__ == '__main__':
107102
keyboard.go()
108103
`
109-
fs.writeFile(currentKeyboard.path + '/code.py', keymapString, () => {
104+
// write kb.py for basic config
105+
let pinSetup = ``
106+
if (pogConfig.wiringMethod === 'matrix') {
107+
pinSetup = `
108+
col_pins = (${pogConfig.colPins.map((a) => 'board.GP' + a).join(', ')})
109+
row_pins = (${pogConfig.rowPins.map((a) => 'board.GP' + a).join(', ')})
110+
diode_orientation = DiodeOrientation.${pogConfig.diodeDirection}
111+
`
112+
} else {
113+
pinSetup = `
114+
def __init__(self):
115+
# create and register the scanner
116+
self.matrix = KeysScanner(
117+
# require argument:
118+
pins=[${pogConfig.directPins.map((a) => 'board.GP' + a).join(', ')}],
119+
# optional arguments with defaults:
120+
value_when_pressed=False,
121+
pull=True,
122+
interval=0.02, # Debounce time in floating point seconds
123+
max_events=64
124+
)
125+
`
126+
}
127+
128+
const kbConfig = `# KB base config
129+
import board
130+
from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
131+
from kmk.scanners import DiodeOrientation
132+
from kmk.scanners import intify_coordinate as ic
133+
from kmk.scanners.keypad import KeysScanner
134+
135+
class KMKKeyboard(_KMKKeyboard):
136+
${pinSetup}
137+
`
138+
139+
const keymap = `# Keymap Autogenerated by Pog do not edit
140+
from kmk.keys import KC
141+
from kmk.handlers.sequences import send_string
142+
import customkeys
143+
144+
keymap = [
145+
${pogConfig.keymap.map((layer) => '[' + layer.join(', ') + ']').join(', ')}
146+
]
147+
`
148+
fs.writeFile(currentKeyboard.path + '/kb.py', kbConfig, () => {
149+
console.log('kb File written successfully\n')
150+
})
151+
fs.writeFile(currentKeyboard.path + '/code.py', mainConfig, () => {
110152
console.log('Firmware File written successfully\n')
111153
})
154+
fs.writeFile(currentKeyboard.path + '/keymap.py', keymap, () => {
155+
console.log('keymap File written successfully\n')
156+
})
157+
if (!fs.existsSync(currentKeyboard.path + '/customkeys.py')) {
158+
const defaultCustomKeys = `# These are yous custom keycodes do any needed imports at the top
159+
# then you can reference them in your keymap with for example customkeys.MyKey
160+
161+
from kmk.keys import KC
162+
163+
MyKey = KC.X
164+
`
165+
fs.writeFile(currentKeyboard.path + '/customkeys.py', defaultCustomKeys, () => {
166+
console.log('customkeys File written successfully\n')
167+
})
168+
}
112169
}

src/renderer/src/components/KeyCap.vue

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,24 @@
6161
width: keyTopWidth + 'px'
6262
}"
6363
></div>
64-
<div class="keylabels">
64+
<div class="keylabels" :class="{'has-args': hasArguments }">
6565
<!-- <div class="keylabel" :class="['keylabel-'+index]" v-for="(label,index) in keyData.labels">-->
6666
<!-- <div class="keylabel-inner">-->
6767
<!-- {{label}}-->
6868
<!-- </div>-->
6969
<!-- </div>-->
70-
<div v-if="!hasArguments" class="keylabel keylabel-center" v-html="mainLabel"></div>
71-
<div v-else class="keylabel">
72-
<div class="arg-top">{{ mainLabel }}</div>
73-
<div class="arg-bottom" :class="{ selected: argsSelected }">
74-
{{ argLabel }}
75-
</div>
76-
</div>
70+
<div class="keylabel keylabel-center" v-html="mainLabel"></div>
71+
7772
</div>
7873
</div>
7974
</template>
8075

8176
<script lang="ts" setup>
8277
import { computed, ref, watch } from 'vue'
83-
import { selectedLayer, selectedKeys, keyboardStore } from '../store'
78+
import { selectedLayer, selectedKeys } from '../store'
8479
import { matrixPositionToIndex, renderLabel } from '../helpers'
8580
86-
const props = defineProps(['keyData', 'keyIndex', 'mode', 'keymap', 'matrixWidth'])
81+
const props = defineProps(['keyData', 'keyIndex', 'mode', 'keymap', 'matrixWidth', 'layouts'])
8782
defineEmits(['selected'])
8883
8984
const keyGap = 4
@@ -110,7 +105,7 @@ const visible = computed(() => {
110105
const variant: number[] = props.keyData.variant
111106
if (variant) {
112107
if (variant.length !== 2) return false
113-
return keyboardStore.layouts[variant[0]].selected === variant[1]
108+
if (props.layouts[variant[0]]) return props.layouts[variant[0]].selected === variant[1]
114109
}
115110
// show keys that don't have variant
116111
return true
@@ -143,9 +138,8 @@ const keyHeight2 = computed(() => {
143138
return keyHeight2U.value * baseKeyWidth.value + (keyHeight2U.value - 1) * keyGap
144139
})
145140
const hasArguments = computed(() => {
146-
return false
147-
// if (!action.value) return false
148-
// return action.value.includes(')')
141+
if (!action.value) return false
142+
return action.value.includes(')')
149143
})
150144
const keyTopWidth = computed(() => {
151145
return keyWidth.value - keyGap * 2 - 4 //+ ((keyWidthU.value-1)*keyGap))
@@ -171,16 +165,16 @@ const mainLabel = computed(() => {
171165
return renderLabel(action.value)
172166
})
173167
174-
const argLabel = computed(() => {
175-
if (hasArguments.value && action.value) {
176-
const argAction = action.value.split('(')[1].replace(')', '')
177-
if (argAction.startsWith('KC.')) {
178-
return argAction.split('.')[1]
179-
}
180-
return argAction
181-
}
182-
return
183-
})
168+
// const argLabel = computed(() => {
169+
// if (hasArguments.value && action.value) {
170+
// const argAction = action.value.split('(')[1].replace(')', '')
171+
// if (argAction.startsWith('KC.')) {
172+
// return argAction.split('.')[1]
173+
// }
174+
// return argAction
175+
// }
176+
// return
177+
// })
184178
185179
const mainSelected = ref(false)
186180
const argsSelected = ref(false)
@@ -247,7 +241,7 @@ const rotationOrigin = computed(() => {
247241
.selected & {
248242
border-color: white;
249243
z-index: 4;
250-
box-shadow: rgba(0, 0, 0, 0.6) 2px 2px 8px 0;
244+
//box-shadow: rgba(0, 0, 0, 0.6) 2px 2px 8px 0;
251245
}
252246
}
253247
.keyborder-blocker {
@@ -257,7 +251,7 @@ const rotationOrigin = computed(() => {
257251
height: 52px;
258252
cursor: pointer;
259253
@apply rounded;
260-
z-index: 1;
254+
z-index: 5;
261255
}
262256
.keytop {
263257
position: absolute;
@@ -269,9 +263,9 @@ const rotationOrigin = computed(() => {
269263
background: #444;
270264
cursor: pointer;
271265
@apply rounded;
272-
z-index: 2;
266+
//z-index: 2;
267+
z-index: 6;
273268
.selected & {
274-
z-index: 5;
275269
}
276270
}
277271
.keylabels {
@@ -281,16 +275,17 @@ const rotationOrigin = computed(() => {
281275
left: 6px;
282276
top: 4px;
283277
right: 6px;
284-
z-index: 3;
278+
//z-index: 3;
279+
z-index: 7;
285280
.selected & {
286-
z-index: 6;
287281
}
288282
}
289283
.keylabel {
290284
font-size: 12px;
291285
position: absolute;
292286
width: 100%;
293287
height: calc(48px - 5px);
288+
@apply gap-1;
294289
295290
&-0 {
296291
left: 8px;
@@ -304,6 +299,7 @@ const rotationOrigin = computed(() => {
304299
}
305300
&-center {
306301
@apply flex items-center justify-center text-center;
302+
flex-wrap: wrap;
307303
}
308304
.arg-top {
309305
@apply text-center;
@@ -357,5 +353,16 @@ const rotationOrigin = computed(() => {
357353
i.mdi {
358354
font-size: 18px;
359355
}
356+
.has-args &{
357+
i.mdi{
358+
font-size: 14px;
359+
}
360+
}
361+
}
362+
.keylabel-small{
363+
font-size: 9px;
364+
font-weight: bold;
365+
font-style: italic;
366+
width: 100%;
360367
}
361368
</style>

0 commit comments

Comments
 (0)