Skip to content

Commit

Permalink
feat: videohub use 'destinations' as pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 8, 2023
1 parent 2b386e1 commit 7b3a1c2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
13 changes: 4 additions & 9 deletions lib/Service/VideohubPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class ServiceVideohubPanel extends ServiceBase {
}

listen() {
this.server = new VideohubServer()
this.server = new VideohubServer({
manualConfigure: true,
})

this.server.on('error', (e) => {
this.logger.debug(`listen-socket error: ${e}`)
Expand Down Expand Up @@ -102,14 +104,7 @@ class ServiceVideohubPanel extends ServiceBase {

const device = this.devices[fullId]
if (device) {
const keyIndex = button
// TODO - button index translation
device.device.doButton(keyIndex, true)

setTimeout(() => {
// Release after a short delay
device.device.doButton(keyIndex, false)
}, 20)
device.device.doButton(destination, button)
}
}
}
Expand Down
33 changes: 29 additions & 4 deletions lib/Surface/IP/VideohubPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SurfaceIPVideohubPanel extends EventEmitter {
this.info = {
type: deviceInfo.productName,
devicepath: deviceInfo.path,
configFields: ['brightness'],
configFields: ['brightness', 'videohub_page_count'],
deviceId: deviceInfo.path,
location: deviceInfo.remoteAddress,
}
Expand All @@ -46,6 +46,7 @@ class SurfaceIPVideohubPanel extends EventEmitter {

this._config = {
brightness: 100,
videohub_page_count: 0,
}
}

Expand All @@ -57,9 +58,16 @@ class SurfaceIPVideohubPanel extends EventEmitter {
return true
}

doButton(key, state) {
const xy = convertPanelIndexToXY(key, this.gridSize)
if (xy) this.emit('click', ...xy, state)
doButton(destination, button) {
const xy = convertPanelIndexToXY(button, this.gridSize)
if (xy) {
this.emit('click', ...xy, true, destination)

setTimeout(() => {
// Release after a short delay
this.emit('click', ...xy, false, destination)
}, 20)
}
}

clearDeck() {
Expand All @@ -69,11 +77,18 @@ class SurfaceIPVideohubPanel extends EventEmitter {
/* elgato-streamdeck functions */

setConfig(config, force) {
console.log('setup', config, force)
const newBrightness = Math.floor(config.brightness / 10)
if ((force || this._config.brightness != newBrightness) && config.brightness !== undefined) {
this._config.brightness = newBrightness
this.#setBrightness(newBrightness)
}

const page_count = Math.floor(config.videohub_page_count / 2) * 2
if (force || this._config.videohub_page_count != page_count) {
this._config.videohub_page_count = page_count
this.#setPageCount(page_count)
}
}

#setBrightness(value) {
Expand All @@ -85,6 +100,16 @@ class SurfaceIPVideohubPanel extends EventEmitter {
this.logger.error('Failed to set videohub panel brightness: ' + e?.toString())
}
}

#setPageCount(value) {
this.logger.silly('page count: ' + value)

try {
this.server.configureDevice(this.serverId, { destinationCount: value })
} catch (e) {
this.logger.error('Failed to set videohub panel destination count: ' + e?.toString())
}
}
}

export default SurfaceIPVideohubPanel
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"usb": "^2.9.0",
"utf-8-validate": "^6.0.3",
"winston": "^3.10.0",
"videohub-server": "^0.2.0",
"videohub-server": "^0.3.0",
"ws": "^8.13.0",
"xkeys": "npm:@julusian/xkeys@2.5.0-1"
},
Expand Down
14 changes: 14 additions & 0 deletions webui/src/Surfaces/EditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,20 @@ export const SurfaceEditModal = forwardRef(function SurfaceEditModal(_props, ref
/>
</CFormGroup>
)}
{deviceInfo.configFields?.includes('videohub_page_count') && (
<CFormGroup>
<CLabel htmlFor="videohub_page_count">Page Count</CLabel>
<CInput
name="videohub_page_count"
type="range"
min={0}
max={8}
step={2}
value={deviceConfig.videohub_page_count}
onChange={(e) => updateConfig('videohub_page_count', parseInt(e.currentTarget.value))}
/>
</CFormGroup>
)}
<CFormGroup>
<CLabel htmlFor="never_lock">Never Pin code lock</CLabel>
<CInputCheckbox
Expand Down

0 comments on commit 7b3a1c2

Please sign in to comment.