Skip to content

Commit

Permalink
Merge pull request #102 from RubenVerborgh/fix/xke40-backlight
Browse files Browse the repository at this point in the history
Fix red/blue color addressing for XKE-40
  • Loading branch information
nytamin authored Aug 12, 2024
2 parents 838adff + 65f02b5 commit 207dde7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
13 changes: 8 additions & 5 deletions packages/core/src/xkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ export class XKeys extends EventEmitter {
} else if (this.product.backLightType === BackLightType.LINEAR) {
// The 40 buttons, that requires special mapping.

const ledIndex = keyIndex - 1 // 0 based linear numbering sort of...

const on: boolean = color.r > 0 || color.g > 0 || color.b > 0
const ledIndexBlue = keyIndex - 1 // 0 based linear numbering sort of...
const ledIndexRed = ledIndexBlue + this.product.backLight2offset

this._write([0, 181, ledIndex, on ? (flashing ? 2 : 1) : 0, 1])
this._write([0, 181, ledIndexBlue, color.b > 0 ? (flashing ? 2 : 1) : 0, 0])
this._write([0, 181, ledIndexRed, color.r > 0 || color.g > 0 ? (flashing ? 2 : 1) : 0, 0])
} else if (this.product.backLightType === BackLightType.LEGACY) {
const ledIndexBlue = (location.col - 1) * 8 + location.row - 1
const ledIndexRed = ledIndexBlue + (this.product.backLight2offset || 0)
Expand Down Expand Up @@ -549,7 +549,10 @@ export class XKeys extends EventEmitter {
blueIntensity = Math.max(Math.min(blueIntensity, 255), 0)
redIntensity = Math.max(Math.min(redIntensity, 255), 0)

if (this.product.backLightType === 2) {
if (
this.product.backLightType === BackLightType.LEGACY ||
this.product.backLightType === BackLightType.LINEAR
) {
this._write([0, 187, blueIntensity, redIntensity])
} else {
this._write([0, 187, blueIntensity])
Expand Down
36 changes: 32 additions & 4 deletions packages/node/src/__tests__/recordings/1355_XKE-40.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
},
{
"sentData": [
"00b500010100000000000000000000000000000000000000000000000000000000000000"
"00b500010000000000000000000000000000000000000000000000000000000000000000",
"00b528000000000000000000000000000000000000000000000000000000000000000000"
],
"method": "setBacklight",
"arguments": [
Expand All @@ -114,7 +115,8 @@
},
{
"sentData": [
"00b500020100000000000000000000000000000000000000000000000000000000000000"
"00b500020000000000000000000000000000000000000000000000000000000000000000",
"00b528000000000000000000000000000000000000000000000000000000000000000000"
],
"method": "setBacklight",
"arguments": [
Expand All @@ -126,7 +128,33 @@
},
{
"sentData": [
"00b500000100000000000000000000000000000000000000000000000000000000000000"
"00b500000000000000000000000000000000000000000000000000000000000000000000",
"00b528010000000000000000000000000000000000000000000000000000000000000000"
],
"method": "setBacklight",
"arguments": [
1,
"f00"
],
"anomaly": ""
},
{
"sentData": [
"00b500000000000000000000000000000000000000000000000000000000000000000000",
"00b528020000000000000000000000000000000000000000000000000000000000000000"
],
"method": "setBacklight",
"arguments": [
1,
"f00",
true
],
"anomaly": ""
},
{
"sentData": [
"00b500000000000000000000000000000000000000000000000000000000000000000000",
"00b528000000000000000000000000000000000000000000000000000000000000000000"
],
"method": "setBacklight",
"arguments": [
Expand Down Expand Up @@ -618,4 +646,4 @@
"description": "Button 40 released. Metadata: row: 2, col: 20, timestamp: 190528"
}
]
}
}

0 comments on commit 207dde7

Please sign in to comment.