Skip to content

Commit

Permalink
feat: surface groups (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Nov 25, 2023
1 parent 1055e4b commit c052ee0
Show file tree
Hide file tree
Showing 13 changed files with 1,600 additions and 661 deletions.
5 changes: 2 additions & 3 deletions lib/Data/ImportExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class DataImportExport extends CoreBase {

if (!config || !isFalsey(config.surfaces)) {
exp.surfaces = this.surfaces.exportAll(false)
exp.surfaceGroups = this.surfaces.exportAllGroups(false)
}

return exp
Expand Down Expand Up @@ -790,9 +791,7 @@ class DataImportExport extends CoreBase {
}

if (!config || config.surfaces) {
for (const [id, surface] of Object.entries(data.surfaces || {})) {
this.surfaces.importSurface(id, surface)
}
this.surfaces.importSurfaces(data.surfaceGroups || {}, data.surfaces || {})
}

if (!config || config.triggers) {
Expand Down
23 changes: 13 additions & 10 deletions lib/Data/Metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@ class DataMetrics extends CoreBase {
#cycle() {
this.logger.silly('cycle')

const devices = this.surfaces.getDevicesList().available

/**
* @type {string[]}
*/
const relevantDevices = []

try {
Object.values(devices).forEach((device) => {
if (device.id !== undefined && !device.id.startsWith('emulator:')) {
// remove leading "satellite-" from satellite device serial numbers.
const serialNumber = device.id.replace('satellite-', '')
// normalize serialNumber by md5 hashing it, we don't want/need the specific serialNumber anyways.
const deviceHash = crypto.createHash('md5').update(serialNumber).digest('hex')
if (deviceHash && deviceHash.length === 32) relevantDevices.push(deviceHash)
const surfaceGroups = this.surfaces.getDevicesList()
for (const surfaceGroup of surfaceGroups) {
if (!surfaceGroup.surfaces) continue

for (const surface of surfaceGroup.surfaces) {
if (surface.id && surface.isConnected && !surface.id.startsWith('emulator:')) {
// remove leading "satellite-" from satellite device serial numbers.
const serialNumber = surface.id.replace('satellite-', '')
// normalize serialnumber by md5 hashing it, we don't want/need the specific serialnumber anyways.
const deviceHash = crypto.createHash('md5').update(serialNumber).digest('hex')
if (deviceHash && deviceHash.length === 32) relevantDevices.push(deviceHash)
}
}
})
}
} catch (e) {
// don't care
}
Expand Down
1 change: 1 addition & 0 deletions lib/Data/Model/ExportModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ExportFullv4 extends ExportBase<'full'> {
custom_variables?: CustomVariablesModel
instances?: ExportInstancesv4
surfaces?: unknown
surfaceGroups?: unknown
}

export interface ExportPageModelv4 extends ExportBase<'page'> {
Expand Down
66 changes: 44 additions & 22 deletions lib/Internal/Surface.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,52 @@
import { combineRgb } from '@companion-module/base'
import LogController from '../Log/Controller.js'

/** @type {import('./Types.js').InternalActionInputField} */
const CHOICES_CONTROLLER = {
type: 'internal:surface_serial',
label: 'Surface / controller',
id: 'controller',
default: 'self',
includeSelf: true,
}
/** @type {import('./Types.js').InternalActionInputField[]} */
const CHOICES_SURFACE_GROUP_WITH_VARIABLES = [
{
type: 'checkbox',
label: 'Use variables for surface',
id: 'controller_from_variable',
default: false,
},
{
type: 'internal:surface_serial',
label: 'Surface / group',
id: 'controller',
default: 'self',
includeSelf: true,
isVisible: (options) => !options.controller_from_variable,
},
{
type: 'textinput',
label: 'Surface / group',
id: 'controller_variable',
default: 'self',
isVisible: (options) => !!options.controller_from_variable,
useVariables: true,
},
]

/** @type {import('./Types.js').InternalActionInputField[]} */
const CHOICES_CONTROLLER_WITH_VARIABLES = [
const CHOICES_SURFACE_ID_WITH_VARIABLES = [
{
type: 'checkbox',
label: 'Use variables for surface',
id: 'controller_from_variable',
default: false,
},
{
...CHOICES_CONTROLLER,
type: 'internal:surface_serial',
label: 'Surface / group',
id: 'controller',
default: 'self',
includeSelf: true,
useRawSurfaces: true,
isVisible: (options) => !options.controller_from_variable,
},
{
type: 'textinput',
label: 'Surface / controller',
label: 'Surface / group',
id: 'controller_variable',
default: 'self',
isVisible: (options) => !!options.controller_from_variable,
Expand Down Expand Up @@ -215,9 +237,9 @@ export default class Surface {
getActionDefinitions() {
return {
set_brightness: {
label: 'Surface: Set serialNumber to brightness',
label: 'Surface: Set to brightness',
options: [
...CHOICES_CONTROLLER_WITH_VARIABLES,
...CHOICES_SURFACE_ID_WITH_VARIABLES,

{
type: 'number',
Expand All @@ -233,8 +255,8 @@ export default class Surface {
},

set_page: {
label: 'Surface: Set serialNumber to page',
options: [...CHOICES_CONTROLLER_WITH_VARIABLES, ...CHOICES_PAGE_WITH_VARIABLES],
label: 'Surface: Set to page',
options: [...CHOICES_SURFACE_GROUP_WITH_VARIABLES, ...CHOICES_PAGE_WITH_VARIABLES],
},
set_page_byindex: {
label: 'Surface: Set by index to page',
Expand All @@ -255,20 +277,20 @@ export default class Surface {

inc_page: {
label: 'Surface: Increment page number',
options: [...CHOICES_CONTROLLER_WITH_VARIABLES],
options: [...CHOICES_SURFACE_GROUP_WITH_VARIABLES],
},
dec_page: {
label: 'Surface: Decrement page number',
options: [...CHOICES_CONTROLLER_WITH_VARIABLES],
options: [...CHOICES_SURFACE_GROUP_WITH_VARIABLES],
},

lockout_device: {
label: 'Surface: Lockout specified surface immediately.',
options: [...CHOICES_CONTROLLER_WITH_VARIABLES],
options: [...CHOICES_SURFACE_GROUP_WITH_VARIABLES],
},
unlockout_device: {
label: 'Surface: Unlock specified surface immediately.',
options: [...CHOICES_CONTROLLER_WITH_VARIABLES],
options: [...CHOICES_SURFACE_GROUP_WITH_VARIABLES],
},

lockout_all: {
Expand Down Expand Up @@ -346,7 +368,7 @@ export default class Surface {
}

setImmediate(() => {
this.#surfaceController.setDeviceLocked(theController, true, true)
this.#surfaceController.setSurfaceOrGroupLocked(theController, true, true)
})
}
return true
Expand All @@ -355,7 +377,7 @@ export default class Surface {
if (!theController) return true

setImmediate(() => {
this.#surfaceController.setDeviceLocked(theController, false, true)
this.#surfaceController.setSurfaceOrGroupLocked(theController, false, true)
})

return true
Expand Down Expand Up @@ -467,7 +489,7 @@ export default class Surface {
options: [
{
type: 'internal:surface_serial',
label: 'Surface / controller',
label: 'Surface / group',
id: 'controller',
},
{
Expand Down
1 change: 1 addition & 0 deletions lib/Internal/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type InternalInputField = (
type: 'internal:surface_serial'
includeSelf: boolean
default: string
useRawSurfaces?: boolean
}
| {
type: 'internal:page'
Expand Down
Loading

0 comments on commit c052ee0

Please sign in to comment.