Skip to content

Commit

Permalink
[master] Simplify keyboard code
Browse files Browse the repository at this point in the history
  • Loading branch information
zored committed Jan 1, 2020
1 parent e8db0d0 commit 2f2d5ef
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions compiler/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,26 @@ class Keyboard {
get configName () {
throw new Error(`No keyboard config defined`)
}
get templateKey() {
return this.configName
}
get layoutCodeName () {
throw new Error(`No keyboard layout code name defined`)
}
getTemplateData (layers) {
return {}
const onLayerOn = layers.all.map(layer => `
case ${layer.codeName}:
` + (layer.enableCombos ? 'combo_enable(); ' : 'combo_disable(); ')
+ layer.lights.map(light => this.getLightCode(light)).join(' ') + `
break;
`).join('')

let data = {}
data[this.templateKey] = { onLayerOn }
return data
}
getLightCode (light) {
throw new Error('Undefined light code function.')
}
get layers () {
return this.config.layers
Expand All @@ -708,15 +723,14 @@ class ErgodoxEz extends Keyboard {
get layoutCodeName () {
return 'LAYOUT_ergodox'
}
getTemplateData (layers) {
const onLayerOn = layers.all.map(layer => `
case ${layer.codeName}:
` + (layer.enableCombos ? 'combo_enable(); ' : 'combo_disable(); ')
+ layer.lights.map(light => `ergodox_right_led_on(${light});`).join(' ') + `
break;
`).join('')

return { ergodox: { onLayerOn } }
get templateKey() {
return 'ergodox'
}
getLightCode (light) {
if (light < 1 || light > 3) {
throw new Error(`Unknow Ergodox light #${light}`)
}
return `ergodox_right_led_on(${light});`
}
}
class PlanckEz extends Keyboard {
Expand All @@ -726,17 +740,7 @@ class PlanckEz extends Keyboard {
get layoutCodeName () {
return 'LAYOUT_planck_grid'
}
getTemplateData (layers) {
const onLayerOn = layers.all.map(layer => `
case ${layer.codeName}:
` + (layer.enableCombos ? 'combo_enable(); ' : 'combo_disable(); ')
+ layer.lights.map(light => this._getLightCode(light)).join(' ') + `
break;
`).join('')

return { planck: { onLayerOn } }
}
_getLightCode (light) {
getLightCode (light) {
switch (light) {
case 1:
return `planck_ez_left_led_on();`
Expand Down

0 comments on commit 2f2d5ef

Please sign in to comment.