Support KLE to PCB metadata and nets
This commit is contained in:
parent
cd0ae6d38b
commit
f955aac994
2 changed files with 40 additions and 7 deletions
|
@ -9,9 +9,15 @@ const pcbs_lib = require('./pcbs')
|
|||
|
||||
const process = async (raw, debug=false, logger=()=>{}) => {
|
||||
|
||||
const prefix = 'Interpreting format: '
|
||||
let empty = true
|
||||
let [config, format] = io.interpret(raw, logger)
|
||||
logger('Interpreting format: ' + format)
|
||||
let suffix = format
|
||||
if (format == 'KLE') {
|
||||
suffix = `${format} (Auto-debug)`
|
||||
debug = true
|
||||
}
|
||||
logger(prefix + suffix)
|
||||
|
||||
logger('Preprocessing input...')
|
||||
config = prepare.unnest(config)
|
||||
|
|
39
src/kle.js
39
src/kle.js
|
@ -1,14 +1,35 @@
|
|||
const u = require('./utils')
|
||||
const kle = require('kle-serial')
|
||||
const json5 = require('json5')
|
||||
|
||||
exports.convert = (config, logger) => {
|
||||
const keyboard = kle.Serial.deserialize(config)
|
||||
const result = {points: {zones: {}}}
|
||||
const result = {points: {zones: {}}, pcbs: {main: {}}}
|
||||
|
||||
// if the keyboard notes are valid JSON, they get added to each key as metadata
|
||||
let meta = {}
|
||||
try {
|
||||
meta = json5.parse(keyboard.meta.notes)
|
||||
} catch (ex) {
|
||||
// notes were not valid JSON, oh well...
|
||||
}
|
||||
|
||||
let index = 1
|
||||
for (const key of keyboard.keys) {
|
||||
const id = `key${index++}`
|
||||
const colid = `${id}col`
|
||||
const rowid = `${id}row`
|
||||
// we try to look at the first non-empty label
|
||||
const label = key.labels.filter(e => !!e)[0] || ''
|
||||
|
||||
// PCB nets can be specified through key labels
|
||||
let row_net = id
|
||||
let col_net = 'GND'
|
||||
if (label.match(/^\d+_\d+$/)) {
|
||||
const parts = label.split('_')
|
||||
row_net = `row_${parts[0]}`
|
||||
col_net = `col_${parts[1]}`
|
||||
}
|
||||
|
||||
// need to account for keycap sizes, as KLE anchors
|
||||
// at the corners, while we consider the centers
|
||||
|
@ -21,22 +42,28 @@ exports.convert = (config, logger) => {
|
|||
const diff_x = key.rotation_x - (key.x + key.width / 2)
|
||||
const diff_y = key.rotation_y - (key.y + key.height / 2)
|
||||
|
||||
// anchoring the per-key zone to the KLE-computed coords
|
||||
const converted = {
|
||||
anchor: {
|
||||
shift: [`${x} u`, `${-y} u`],
|
||||
},
|
||||
columns: {}
|
||||
}
|
||||
|
||||
// adding a column-level rotation with origin
|
||||
converted.columns[colid] = {
|
||||
rotate: -key.rotation_angle,
|
||||
origin: [`${diff_x} u`, `${-diff_y} u`],
|
||||
rows: {}
|
||||
}
|
||||
converted.columns[colid].rows[rowid] = {
|
||||
width: key.width,
|
||||
height: key.height,
|
||||
label: key.labels[0]
|
||||
}
|
||||
|
||||
// passing along metadata to each key
|
||||
converted.columns[colid].rows[rowid] = u.deepcopy(meta)
|
||||
converted.columns[colid].rows[rowid].width = key.width
|
||||
converted.columns[colid].rows[rowid].height = key.height
|
||||
converted.columns[colid].rows[rowid].label = label
|
||||
converted.columns[colid].rows[rowid].column_net = col_net
|
||||
converted.columns[colid].rows[rowid].row_net = row_net
|
||||
|
||||
result.points.zones[id] = converted
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue