diff --git a/README.md b/README.md index b33f430..705b2bb 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ if (connectedXKeys.length) { * 'jog': Triggered when the jog wheel is moved. Emitted with (jogValue) * 'shuttle': Triggered when the shuttle is moved. Emitted with (shuttleValue) * 'joystick': Triggered when the joystick is moved. Emitted with ({x, y, z}) +* 'tbar': Triggered when the T-bar is moved. Emitted with (tbarPosition, rawPosition) * 'error': Triggered on error. Emitted with (error). @@ -165,6 +166,7 @@ These devices have been tested to work: * XK-80 * XK-68 Jog + Shuttle * XK-12 Jog +* XKE-124 T-bar ### Not tested devices (yet) @@ -175,7 +177,7 @@ Support for these devices is implemented, but not tested: * XK-16: Not tested * XK-12 Joystick: Not tested * XR-32: Not tested -* XKE-28: Not tested +* XKE-128: Not tested If you have access to any of the untested devices listed above, it would be very nice if you could provide some data to add to the tests! Just do diff --git a/examples/xkeys.js b/examples/xkeys.js index cfa0e90..6835bb2 100644 --- a/examples/xkeys.js +++ b/examples/xkeys.js @@ -30,3 +30,7 @@ myXkeysPanel.on('shuttle', shuttlePos => { myXkeysPanel.on('joystick', position => { console.log('Joystick has changed:' + position) // {x, y, z} }) +// Listen to t-bar changes: +myXkeysPanel.on('tbar', (position, rawPosition) => { + console.log('T-bar position has changed: ' + position + ' (uncalibrated: ' + rawPosition + ')') +}) diff --git a/examples/xkeys.ts b/examples/xkeys.ts index 0b73363..cb46879 100644 --- a/examples/xkeys.ts +++ b/examples/xkeys.ts @@ -16,7 +16,6 @@ myXkeysPanel.on('up', keyIndex => { // Turn off button light when released: myXkeysPanel.setBacklight(keyIndex, false) - myXkeysPanel.setBacklight(keyIndex, false) }) // Listen to jog wheel changes: @@ -31,3 +30,7 @@ myXkeysPanel.on('shuttle', shuttlePos => { myXkeysPanel.on('joystick', position => { console.log('Joystick has changed:' + position) // {x, y, z} }) +// Listen to t-bar changes: +myXkeysPanel.on('tbar', (position, rawPosition) => { + console.log('T-bar position has changed: ' + position + ' (uncalibrated: ' + rawPosition + ')') +}) diff --git a/src/products.ts b/src/products.ts index df84ff2..c4b8f17 100644 --- a/src/products.ts +++ b/src/products.ts @@ -17,6 +17,9 @@ export interface ProductBase { jogByte?: number hasShuttle?: true shuttleByte?: number + hasTbar?: true + tbarByte?: number + tbarByteRaw?: number } export interface ProductJog extends ProductBase { hasJog: true @@ -26,7 +29,12 @@ export interface ProductShuttle extends ProductBase { hasShuttle: true shuttleByte: number } -export type Product = ProductBase | ProductJog | ProductShuttle +export interface ProductTbar extends ProductBase { + hasTbar: true + tbarByte: number + tbarByteRaw: number +} +export type Product = ProductBase | ProductJog | ProductShuttle | ProductTbar export const PRODUCTS: {[name: string]: Product} = { XK24: { @@ -114,6 +122,19 @@ export const PRODUCTS: {[name: string]: Product} = { banks: 2, bankSize: 80 }, + XKE124TBAR: { + identifier: 'XKE-124 T-bar', + productId: [1275,1276,1277,1278], + columns: 16, + rows: 8, + hasPS: false, + hasTbar: true, + tbarByte: 30, + tbarByteRaw: 31, + banks: 2, + bankSize: 128, + disableKeys: [108,109,110,111] + }, XKE128: { // This has not been tested identifier: 'XKE-128', productId: [1227,1228,1229,1230], diff --git a/src/xkeys.ts b/src/xkeys.ts index b37528b..392ea8b 100644 --- a/src/xkeys.ts +++ b/src/xkeys.ts @@ -20,6 +20,10 @@ export interface AnalogStates { joystick_y?: number /** -127 to 127 */ joystick_z?: number + /** 0 to 255 */ + tbar?: number + /** 0 to 4096 */ + tbar_raw?: number } type Message = (string | number)[] @@ -167,6 +171,13 @@ export class XKeys extends EventEmitter { analogStates.joystick_z = (d < 128 ? d : d - 256) } + if (this.deviceType.hasTbar) { + let d = data[(this.deviceType.tbarByte || 0) - 2] // T-bar (calibrated) + analogStates.tbar = d + + d = data.readUInt16BE((this.deviceType.tbarByteRaw || 0) - 2) // T-bar (uncalibrated) + analogStates.tbar_raw = d + } // Disabled/nonexisting keys: if (this.deviceType.disableKeys) { @@ -209,6 +220,10 @@ export class XKeys extends EventEmitter { analogStateKey === 'shuttle' ) { this.emit(analogStateKey , analogStates[analogStateKey]) + } else if ( + analogStateKey === 'tbar_raw' + ) { + this.emit('tbar', analogStates.tbar, analogStates.tbar_raw) } else if ( analogStateKey === 'joystick_x' || analogStateKey === 'joystick_y' || @@ -219,7 +234,9 @@ export class XKeys extends EventEmitter { y: analogStates.joystick_y, z: analogStates.joystick_z }) - } else { + } else if ( + analogStateKey !== 'tbar' // ignore tbar updates because event is emitted on tbar_raw update + ) { throw new Error(`Internal error: Unknown analogStateKey: "${analogStateKey}"`) }