Skip to content

Commit 3e1d9cf

Browse files
committed
1.1.0 added rgb and encoder fixes
1 parent 56ece31 commit 3e1d9cf

File tree

14 files changed

+112
-75
lines changed

14 files changed

+112
-75
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ then just run it with dev to start
2626

2727

2828
# Tasks
29+
## bugs
30+
- [ ] maximum call stack error when closing the app
2931
## urgent
3032
- [x] check if a keyboard is connected (usb drive) in the keyboard selector preview
3133
- [x] show serial output in the gui

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.0.5",
3+
"version": "1.1.0",
44
"license": "MIT",
55
"description": "A KMK firmware configurator",
66
"main": "./out/main/index.js",

src/main/index.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, shell, BrowserWindow, ipcMain, Menu } from 'electron'
1+
import { app, shell, BrowserWindow, ipcMain, Menu, SerialPort } from 'electron'
22
import { join } from 'path'
33
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
44
import icon from '../../resources/icon.png?asset'
@@ -14,6 +14,7 @@ export { mainWindow }
1414

1515
const isMac = process.platform === 'darwin'
1616

17+
let triedToQuit = false
1718
const template: unknown = [
1819
// { role: 'appMenu' }
1920
...(isMac
@@ -181,9 +182,9 @@ app.on('window-all-closed', () => {
181182
})
182183
app.on('before-quit', (event) => {
183184
// Prevent the default behavior of this event
184-
if (debugPort !== undefined) {
185+
if (debugPort !== undefined && !triedToQuit) {
185186
event.preventDefault()
186-
187+
triedToQuit = true
187188
console.log('Preparing to quit...')
188189
debugPort.close(() => {
189190
console.log('Port closed')
@@ -233,19 +234,23 @@ const chunksize = 1200
233234

234235
const getBoardInfo = (port) => {
235236
return new Promise((res, rej) => {
236-
// connect to port and get the response
237-
const sport = new serialPort.SerialPort(
238-
{ path: port.path, baudRate, autoOpen: true },
239-
(e) => {}
240-
)
237+
// connect to port and get the response just once
238+
const sport = new serialPort.SerialPort({ path: port.path, baudRate, autoOpen: true }, (e) => {
239+
// if the connection fails reject the promise
240+
if (e) return rej(e)
241+
})
242+
241243
const sparser = sport.pipe(new ReadlineParser({ delimiter: '\n' }))
242244
sparser.once('data', (data) => {
243245
sport.close()
244-
res({ ...port, ...JSON.parse(data) })
246+
return res({ ...port, ...JSON.parse(data) })
245247
})
248+
// request the info
246249
sport.write('info_simple\n')
247250
})
248251
}
252+
253+
// timer helper function
249254
const timeout = (prom, time) => {
250255
let timer
251256
return Promise.race([prom, new Promise((_r, rej) => (timer = setTimeout(rej, time)))]).finally(
@@ -261,14 +266,15 @@ const scanForKeyboards = async () => {
261266
if (connectedKeyboardPort && connectedKeyboardPort.isOpen) connectedKeyboardPort.close()
262267
const ports = await serialPort.SerialPort.list()
263268
console.log('found the following raw ports:', ports)
264-
const circuitPythonPorts = ports.filter(port => {
269+
const circuitPythonPorts = ports.filter((port) => {
265270
// TODO: make sure the port is used for a pog keyboard
266271
// we dont want to send serial data to a REPL that is not a keyboard with pog firmware
267-
// maybe whitelist serialnumbers?
268-
let manufacturer = port.manufacturer
269-
manufacturer = manufacturer ? manufacturer.toLowerCase() : ''
270-
return manufacturer.endsWith("-pog") || manufacturer.startsWith("pog-") || manufacturer === 'pog'
271-
});
272+
const manufacturer = port.manufacturer ? port.manufacturer.toLowerCase() : ''
273+
// if the manufactuer is pog or has pog as suffix or prefix with the - we assume its a pog keyboard
274+
return (
275+
manufacturer.endsWith('-pog') || manufacturer.startsWith('pog-') || manufacturer === 'pog'
276+
)
277+
})
272278
const boards = (await Promise.allSettled(
273279
circuitPythonPorts.map(async (a) => await timeout(getBoardInfo(a), 2000))
274280
)) as {
@@ -290,7 +296,7 @@ const scanForKeyboards = async () => {
290296

291297
let currentPackage = ''
292298
let addedChunks = 0
293-
function crossSum(s) {
299+
function crossSum(s: string) {
294300
// Compute the cross sum
295301
let total = 0
296302
for (let i = 0; i < s.length; i++) {

src/main/pythontemplates/kb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class KMKKeyboard(_KMKKeyboard):
6161
if "rgb" in features:
6262
from kmk.extensions.RGB import RGB
6363
rgb = RGB(
64-
pixel_pin=board.GP3,
65-
num_pixels=16,
64+
pixel_pin=eval(pog.rgbPin),
65+
num_pixels=pog.rgbNumLeds,
6666
rgb_order=(1, 0, 2),
6767
val_limit=40, # Maximum brightness level. Only change if you know what you are doing!
6868
hue_default=10,

src/main/pythontemplates/pog.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ pins = ",".join(pinsArray)
5353
if len(pinsArray) == 1:
5454
pins = pins + ","
5555
56+
rgbPin = config["rgbPin"]
57+
rgbNumLeds = config["rgbNumLeds"]
58+
5659
matrixWiring = False
5760
directWiring = False
5861

src/main/saveConfig.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,6 @@ export const handleKeymapSave = ({ pogConfig, serial }) => {
9494

9595
// testing encoder enable
9696
if (pogConfig.encoders && pogConfig.encoders.length !== 0) {
97-
// pythonImports +=
98-
// '\nfrom kmk.modules.layers import Layers\n' +
99-
// 'from kmk.modules.encoder import EncoderHandler\n'
100-
// kmkAddons +=
101-
// '\nlayers = Layers()\n' +
102-
// 'encoder_handler = EncoderHandler()\n' +
103-
// 'keyboard.modules = [layers, encoder_handler]\n'
104-
105-
// still keeping the option to save the encoder keymap as raw code instead of the lookup
10697
let encoderPins = ''
10798
pogConfig.encoders.forEach((encoder) => {
10899
encoderPins += `(board.GP${encoder.pad_a}, board.GP${encoder.pad_b}, None,),`
@@ -118,42 +109,6 @@ export const handleKeymapSave = ({ pogConfig, serial }) => {
118109
encoderKeymap += '),\n'
119110
})
120111
}
121-
122-
// codeblock +=
123-
// '# Encoder\n' +
124-
// 'encoder_handler.pins = (\n' +
125-
// encoderPins +
126-
// '\n' +
127-
// ')\n' +
128-
// 'encoder_handler.map = [ \n' +
129-
// encoderKeymap + // layers
130-
// ']\n'
131-
// }
132-
// const mainConfig = `# Main Keyboard Configuration
133-
// print("Starting ${pogConfig.name || 'Keyboard'}")
134-
//
135-
// import board
136-
// from kb import KMKKeyboard
137-
// from kmk.modules.tapdance import TapDance
138-
// ${pythonImports}
139-
//
140-
// keyboard = KMKKeyboard()
141-
// ${kmkAddons}
142-
//
143-
// tapdance = TapDance()
144-
// tapdance.tap_time = 200
145-
// keyboard.modules.append(tapdance)
146-
//
147-
// # Keymap
148-
// from keymap import keymap
149-
// keyboard.keymap = keymap
150-
//
151-
// ${codeblock}
152-
//
153-
// if __name__ == '__main__':
154-
// keyboard.go()
155-
// `
156-
157112
// we are still writing the keymap file by hand
158113
const keymap = `# Keymap Autogenerated by Pog do not edit
159114
from kmk.keys import KC

src/main/selectKeyboard.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import * as fs from 'fs-extra'
22
import { currentKeyboard } from './store'
33
import { dialog } from 'electron'
44
import { connectedKeyboardPort, connectSerialKeyboard, serialBoards } from './index'
5-
// select a keyboard
5+
6+
// invoked from frontend to select a drive or folder load the conig from
67
export const handleSelectDrive = async () => {
78
const { canceled, filePaths } = await dialog.showOpenDialog({
89
properties: ['openDirectory']
910
})
10-
if (canceled) {
11-
return
12-
}
11+
if (canceled) return
1312
return await loadKeyboard(filePaths[0])
1413
}
1514
const loadKeyboard = async (path) => {
@@ -44,11 +43,11 @@ const loadKeyboard = async (path) => {
4443
}
4544
}
4645
export const selectKeyboard = async ({ path, id }: { path: string; id: string }) => {
47-
console.log(path,id)
48-
if(id){
46+
console.log(path, id)
47+
if (id) {
4948
// connect serial if available
5049
const port = serialBoards.value.find((a) => a.id === id)
51-
if(!port) return { error:'not a serial keyboard' }
50+
if (!port) return { error: 'not a serial keyboard' }
5251
console.log(serialBoards, id)
5352
await connectSerialKeyboard(port)
5453
connectedKeyboardPort.write('info\n')

src/main/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {app} from "electron";
1+
// Store for global variables
2+
import { app } from "electron";
23

34
export const appDir = app.getPath("appData") + "/pog/";
4-
// export let win = undefined
55
export const currentKeyboard = {
66
path: ""
77
}

src/renderer/src/components/KeyCap.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ const isSimple = computed(() => {
339339
340340
const keyElem = ref<VNodeRef | null>(null)
341341
const fixLabelWidth = () => {
342+
// key is eventually hidden with a layout variant
343+
if(!keyElem.value) return
342344
const label = keyElem.value.querySelector('.keylabel-main')
343345
const labels = keyElem.value.querySelector('.keylabels')
344346
if (label) {

src/renderer/src/components/KeyLayoutInfo.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,12 @@ const updateKey = () => {
293293
if (tmpKey.value.r !== '') props.layout[keyIndex].r = Number(tmpKey.value.r)
294294
if (tmpKey.value.rx !== '') props.layout[keyIndex].rx = Number(tmpKey.value.rx)
295295
if (tmpKey.value.ry !== '') props.layout[keyIndex].ry = Number(tmpKey.value.ry)
296-
if (tmpKey.value.directPinIndex !== '')
296+
if (tmpKey.value.directPinIndex !== '' && !isNaN(tmpKey.value.directPinIndex as any))
297297
props.layout[keyIndex].directPinIndex = Number(tmpKey.value.directPinIndex)
298-
if (tmpKey.value.encoderIndex !== '')
298+
else props.layout[keyIndex].directPinIndex = ""
299+
if (tmpKey.value.encoderIndex !== '' && !isNaN(Number(tmpKey.value.encoderIndex)))
299300
props.layout[keyIndex].encoderIndex = Number(tmpKey.value.encoderIndex)
301+
else props.layout[keyIndex].encoderIndex = undefined
300302
// if (
301303
// (tmpKey.value.matrix &&
302304
// tmpKey.value.matrix.length == 2 &&

0 commit comments

Comments
 (0)