-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial VEC Footpedal support (#2944)
Co-authored-by: Julian Waller <git@julusian.co.uk>
- Loading branch information
1 parent
7cf0e6f
commit daad9b5
Showing
15 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
// @ts-nocheck | ||
/* | ||
* This file is part of the Companion project | ||
* Copyright (c) 2024 Peter Newman | ||
* Author: Peter Newman | ||
* | ||
* This program is free software. | ||
* You should have received a copy of the MIT licence as well as the Bitfocus | ||
* Individual Contributor License Agreement for companion along with | ||
* this program. | ||
* | ||
* You can be released from the requirements of the license by purchasing | ||
* a commercial license. Buying such a license is mandatory as soon as you | ||
* develop commercial activities involving the Companion software without | ||
* disclosing the source code of your own applications. | ||
* | ||
*/ | ||
|
||
import EventEmitter from 'events' | ||
import vecFootpedal from 'vec-footpedal' | ||
import LogController from '../../Log/Controller.js' | ||
|
||
const vecFootpedalInfo = { | ||
// Treat as: | ||
// 3 buttons | ||
totalCols: 3, | ||
totalRows: 1, | ||
|
||
buttons: [ | ||
[0, 0], | ||
[1, 0], | ||
[2, 0], | ||
], | ||
} | ||
|
||
function buttonToXy(modelInfo, info) { | ||
return modelInfo.buttons[info - 1] | ||
} | ||
|
||
class SurfaceUSBVECFootpedal extends EventEmitter { | ||
/** | ||
* @type {import('winston').Logger} | ||
* @access private | ||
* @readonly | ||
*/ | ||
#logger | ||
|
||
constructor(devicePath, contourShuttle, modelInfo, deviceInfo) { | ||
super() | ||
|
||
this.#logger = LogController.createLogger(`Surface/USB/VECFootpedal/${devicePath}`) | ||
|
||
this.vecFootpedal = vecFootpedal | ||
this.deviceInfo = deviceInfo | ||
this.modelInfo = modelInfo | ||
|
||
this.config = { | ||
// No config currently present | ||
} | ||
|
||
this.#logger.debug(`Adding VEC Footpedal USB device ${devicePath}`) | ||
|
||
this.info = { | ||
type: `VEC Footpedal ${this.deviceInfo.name}`, | ||
devicePath: devicePath, | ||
configFields: [], | ||
deviceId: `vecfootpedal:${this.deviceInfo.id}`, | ||
} | ||
|
||
this.gridSize = { | ||
columns: this.modelInfo.totalCols, | ||
rows: this.modelInfo.totalRows, | ||
} | ||
|
||
this.vecFootpedal.on('error', (error) => { | ||
console.error(error) | ||
this.emit('remove') | ||
}) | ||
|
||
this.vecFootpedal.on('buttondown', (info) => { | ||
const xy = buttonToXy(this.modelInfo, info) | ||
if (xy === undefined) { | ||
return | ||
} | ||
|
||
this.emit('click', ...xy, true) | ||
}) | ||
|
||
this.vecFootpedal.on('buttonup', (info) => { | ||
const xy = buttonToXy(this.modelInfo, info) | ||
if (xy === undefined) { | ||
return | ||
} | ||
|
||
this.emit('click', ...xy, false) | ||
}) | ||
|
||
this.vecFootpedal.on('disconnect', (error) => { | ||
console.error(error) | ||
this.emit('remove') | ||
}) | ||
} | ||
|
||
async #init() { | ||
this.#logger.debug(`VEC Footpedal ${this.deviceInfo.name} detected`) | ||
} | ||
|
||
/** | ||
* Open a VEC Footpedal | ||
* @param {string} devicePath | ||
* @returns {Promise<SurfaceUSBVECFootpedal>} | ||
*/ | ||
static async create(devicePath) { | ||
const pedal = vecFootpedal | ||
// We're doing device search via Companion so don't run it here too | ||
pedal.start(false) | ||
try { | ||
let deviceInfo = null | ||
let info = null | ||
pedal.connect(devicePath) | ||
deviceInfo = pedal.getDeviceByPath(devicePath) | ||
switch (deviceInfo.name) { | ||
case 'VEC Footpedal': | ||
info = vecFootpedalInfo | ||
break | ||
default: | ||
throw new Error(`Unknown VEC Footpedal device detected: ${deviceInfo.name}`) | ||
} | ||
if (!info) { | ||
throw new Error('Unsupported model') | ||
} | ||
|
||
const self = new SurfaceUSBVECFootpedal(devicePath, pedal, info, deviceInfo) | ||
|
||
await self.#init() | ||
|
||
return self | ||
} catch (e) { | ||
pedal.stop() | ||
|
||
throw e | ||
} | ||
} | ||
|
||
/** | ||
* Process the information from the GUI and what is saved in database | ||
* @param {Record<string, any>} config | ||
* @param {boolean=} _force | ||
* @returns false when nothing happens | ||
*/ | ||
setConfig(config, _force) { | ||
// No config currently present | ||
this.config = config | ||
} | ||
|
||
quit() { | ||
this.vecFootpedal.close() | ||
} | ||
|
||
draw() { | ||
// Should never be fired | ||
} | ||
|
||
clearDeck() { | ||
// Not relevant for this device | ||
} | ||
} | ||
|
||
export default SurfaceUSBVECFootpedal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
It is possible to use the VEC Footpedal with Companion since v3.4.0. | ||
|
||
Enable support for it in the Companion settings, and rescan for USB devices. | ||
|
||
The layout pretty closely matches what you would expect based on the device. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters