Skip to content

Commit

Permalink
Fixed KLE parsing for simple encoders
Browse files Browse the repository at this point in the history
  • Loading branch information
ValdisThomann committed Jan 29, 2023
1 parent f026e06 commit 6f9d696
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 25 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@the-via/reader",
"version": "1.5.4",
"version": "1.5.5",
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/the-via/reader.git"
Expand Down
39 changes: 15 additions & 24 deletions src/kle-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ export function findPivot(keys: Result[]): Result {

type GroupOptionMap<A> = {[group: string]: {[option: string]: A[]}};

function calculateDelta(a: Result, b: Result) {
// Find the left corner which can be modified by x2, y2
const [aX2 = 0, aY2 = 0, bX2 = 0, bY2 = 0] = [a.x2, a.y2, b.x2, b.y2];
return {
x: b.x - a.x + Math.min(0, bX2) - Math.min(0, aX2),
y: b.y - a.y + Math.min(0, bY2) - Math.min(0, aY2),
};
}

function getPivotPoint(a: Result) {
// complicated keys like ISO and BAE combine two rectangles
// so first identify the top-left most rectangle and then get that
Expand Down Expand Up @@ -245,22 +236,24 @@ const getKeyData = (normalizedLabels: string[], isDecal?: boolean) => {
let keyData = {} as any;
const fakeRowCol = [-1, -1];
const fakeGroupOption = [-1, 0];
if (
normalizedLabels[KeyDataIndex.ENCODER] &&
ENCODER_REGEX.test(normalizedLabels[KeyDataIndex.ENCODER])
) {
keyData['ei'] = +normalizedLabels[KeyDataIndex.ENCODER].slice(1);

const encoderLabel = normalizedLabels[KeyDataIndex.ENCODER];
if (encoderLabel && ENCODER_REGEX.test(encoderLabel)) {
keyData['ei'] = +encoderLabel.slice(1);
}
if (
normalizedLabels[KeyDataIndex.LED] &&
LED_REGEX.test(normalizedLabels[KeyDataIndex.LED])
) {
keyData['li'] = +normalizedLabels[KeyDataIndex.LED].slice(1);

const ledLabel = normalizedLabels[KeyDataIndex.LED];
if (ledLabel && LED_REGEX.test(ledLabel)) {
keyData['li'] = +ledLabel.slice(1);
}

const rowColLabel = normalizedLabels[KeyDataIndex.ROWCOL];
const [row, col] =
isDecal || (keyData['ei'] !== undefined && !rowColLabel)
? fakeRowCol
: extractPair(rowColLabel);

const groupLabel = normalizedLabels[KeyDataIndex.GROUP];
const [row, col] = isDecal
? fakeRowCol
: extractPair(normalizedLabels[KeyDataIndex.ROWCOL]);
const [group, option] = groupLabel
? extractPair(groupLabel)
: fakeGroupOption;
Expand Down Expand Up @@ -365,8 +358,6 @@ export function kleLayoutToVIALayout(kle: KLELayout): VIALayout {
// 6. Encoder + Matrix (Encoder with Click)
// 7. Encoder + Matrix + Group (Encoder with Click)
const colorCountKey = `${c}:${t}`;
const labels: string[] = n.split('\n');
let group, option, row, col;
let currKey: any = {};

const keyData = getKeyData(normalizeLabels(n, a), d);
Expand Down
203 changes: 203 additions & 0 deletions test/data/v2_has_simple_encoder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"name": "dynamis",
"vendorId": "0x6262",
"productId": "0x0001",
"lighting": "qmk_rgblight",
"matrix": {
"rows": 10,
"cols": 7
},
"layouts": {
"labels": [
"ISO Enter",
"Split Space",
"Split Left Shift",
"Split Right Shift",
"Split Backspace"
],
"keymap": [
[
{
"x": 15.5
},
"5,0\n\n\n4,1",
"9,0\n\n\n4,1"
],
[
{
"y": 0.25,
"x": 2.5
},
"0,0",
"0,1",
"0,2",
"0,3",
"0,4",
"0,5",
"0,6",
"5,6",
"5,5",
"5,4",
"5,3",
"5,2",
"5,1",
{
"w": 2
},
"5,0\n\n\n4,0"
],
[
{
"x": 2.5,
"w": 1.5
},
"1,0",
"1,1",
"1,2",
"1,3",
"1,4",
"1,5",
"1,6",
"6,6",
"6,5",
"6,4",
"6,3",
"6,2",
"6,1",
{
"w": 1.5
},
"6,0\n\n\n0,0",
{
"x": 4,
"w": 1.25,
"h": 2,
"w2": 1.5,
"h2": 1,
"x2": -0.25
},
"7,0\n\n\n0,1"
],
[
{
"x": 2.5,
"w": 1.75
},
"2,0",
"2,1",
"2,2",
"2,3",
"2,4",
"2,5",
"2,6",
"7,6",
"7,5",
"7,4",
"7,3",
"7,2",
{
"w": 2.25
},
"7,0\n\n\n0,0",
{
"x": 3
},
"7,1\n\n\n0,1"
],
[
{
"w": 1.25
},
"3,0\n\n\n2,1",
"3,1\n\n\n2,1",
{
"x": 0.25,
"w": 2.25
},
"3,1\n\n\n2,0",
"3,2",
"3,3",
"3,4",
"3,5",
"3,6",
"8,6",
"8,5",
"8,4",
"8,3",
"8,2",
{
"w": 2.75
},
"8,1\n\n\n3,0",
{
"x": 0.25
},
"9,1",
{
"a": 7
},
"e0",
{
"x": 0.25,
"a": 4,
"w": 1.75
},
"8,1\n\n\n3,1",
"8,0\n\n\n3,1"
],
[
{
"x": 2.5,
"w": 1.25
},
"4,0",
{
"w": 1.25
},
"4,1",
{
"w": 1.25
},
"4,2",
{
"w": 6.25
},
"4,3\n\n\n1,0",
{
"w": 1.25
},
"4,6",
{
"w": 1.25
},
"9,6",
{
"w": 1.25
},
"9,5",
{
"x": 0.5
},
"9,4",
"9,3",
"9,2"
],
[
{
"y": 0.25,
"x": 6.25,
"w": 2.25
},
"4,3\n\n\n1,1",
{
"w": 1.25
},
"4,4\n\n\n1,1",
{
"w": 2.75
},
"4,5\n\n\n1,1"
]
]
}
}
Loading

0 comments on commit 6f9d696

Please sign in to comment.