diff --git a/packages/quick-tsr/input/mappings.ts b/packages/quick-tsr/input/mappings.ts index 9654a9bad..bdc981f83 100644 --- a/packages/quick-tsr/input/mappings.ts +++ b/packages/quick-tsr/input/mappings.ts @@ -12,7 +12,7 @@ export const input: TSRInput = { universe: 0, featureChannels: { // Maps dimmer to channel 1: - "dimmer": 1, + "dimmer": 1 } }, }), diff --git a/packages/quick-tsr/input/timeline.ts b/packages/quick-tsr/input/timeline.ts index 76fc18f6b..b47a443f7 100644 --- a/packages/quick-tsr/input/timeline.ts +++ b/packages/quick-tsr/input/timeline.ts @@ -43,6 +43,21 @@ export const input: TSRInput = { } } }), + literal>({ + id: 'colour', + enable: { + start: Date.now(), + duration: 20 * 1000 + }, + layer: 'rgb0', + content: { + deviceType: DeviceType.ARTNET, + type: TimelineContentTypeArtNet.VALUES, + values: { + dimmer: 127 + } + } + }), // literal>({ // id: 'artnet11', // enable: { diff --git a/packages/timeline-state-resolver-types/src/generated/artnet.ts b/packages/timeline-state-resolver-types/src/generated/artnet.ts index abb5be5ee..3c0ae82e6 100644 --- a/packages/timeline-state-resolver-types/src/generated/artnet.ts +++ b/packages/timeline-state-resolver-types/src/generated/artnet.ts @@ -17,7 +17,7 @@ export interface ArtNetOptions { * This interface was referenced by `undefined`'s JSON-Schema definition * via the `patternProperty` "([a-z]\w*)|(\d+:\d+)". */ - [k: string]: 'invert' | 'last' | 'highest' | 'lowest' + [k: string]: 'highest' | 'lowest' | 'last' | 'invert' } } diff --git a/packages/timeline-state-resolver/src/integrations/artnet/$schemas/options.json b/packages/timeline-state-resolver/src/integrations/artnet/$schemas/options.json index b077f212b..282f27b83 100644 --- a/packages/timeline-state-resolver/src/integrations/artnet/$schemas/options.json +++ b/packages/timeline-state-resolver/src/integrations/artnet/$schemas/options.json @@ -32,7 +32,7 @@ "patternProperties": { "([a-z]\\w*)|(\\d+:\\d+)": { "type": "string", - "enum": ["invert", "last", "highest", "lowest"] + "enum": ["highest", "lowest", "last", "invert"] } }, "additionalProperties": false diff --git a/packages/timeline-state-resolver/src/integrations/artnet/index.ts b/packages/timeline-state-resolver/src/integrations/artnet/index.ts index a96f053a7..1894ae030 100644 --- a/packages/timeline-state-resolver/src/integrations/artnet/index.ts +++ b/packages/timeline-state-resolver/src/integrations/artnet/index.ts @@ -8,7 +8,10 @@ import { ArtNetOptions, StatusCode, ActionExecutionResult, - ArtNetDeviceCommand + ArtNetDeviceCommand, + Mappings, + MappingArtnetChannels, + Mapping } from 'timeline-state-resolver-types' import { CommandWithContext, Device } from '../../service/device' // import * as artnet from 'artnet' @@ -25,19 +28,19 @@ export interface ArtNetDeviceStateNew { data: channelData } -interface channelData { - channel: number - value: number - modifier: ChannelModifier -} - -enum ChannelModifier { +enum channelBehaviour { HIGHEST = 'highest', LOWEST = 'lowest', LAST = 'last', INVERT = 'invert', } +interface channelData { + channel: number + value: number + behavious: channelBehaviour +} + export interface ArtNetDeviceState { [address: string]: ArtNetDeviceStateContent } @@ -122,27 +125,53 @@ export class ArtNetDevice extends Device): ArtNetDeviceState { + convertTimelineStateToDeviceState( + state: Timeline.TimelineState, + mappings: Mappings + ): ArtNetDeviceState { + + // hello! // TODO: Convert the timeline state into your own (internal) ArtNetState // Tip: This is where you put the logic for "highest takes precedence" - const addrToArtNetMessage: ArtNetDeviceState = { + const addrToArtNetMessage: ArtNetDeviceState = { + } + + let updateValues: newData[] = [] - this.sendArtNetUniverse("127.0.0.1") + Object.values>(state.layers).forEach((layer) => { - // const artNetGroup = state.id - // console.log("layer:", artNetGroup) - // console.log(addrToArtNetMessage) - Object.values>(state.layers).forEach((layer) => { - if (layer.content.deviceType === DeviceType.ARTNET) { - - // console.log(layer) + const map = mappings[layer.layer] as Mapping | undefined + + if (layer.content.deviceType === DeviceType.ARTNET && map) { + + let newValues = layer.content.values // { dimmer: 42 } + let channelMapping = map.options.featureChannels // { dimmer: [1], RGB: [2,3,4] } + + Object.entries(channelMapping).forEach(([key, artnetChannels]) => { + const channelValues = newValues[key] // 42 + if (channelValues == null) return // Skip if no values + + // TODO: parse channels to create apporpriate data types, of number or array etc. + // const channelNumbers :number[]= parseChannels(artnetChannels) + + + + + updateValues.push({channel: artnetChannels as number, value:channelValues as number}) + }) + } }) + // const artNetGroup = state.id + // console.log("layer:", artNetGroup) + // console.log(addrToArtNetMessage) + // TODO: this should be moved elsewhere + this.sendArtNetUniverse(updateValues, this.options.host) return addrToArtNetMessage } @@ -210,7 +239,7 @@ export class ArtNetDevice extends Device { + newValues.forEach(element => { newUniverse.data[element.channel - 1] = element.value }); - console.log(newUniverse.host) + // console.log(newUniverse.host) - console.log(newUniverse.data.length) + // console.log(newUniverse.data.length) console.log(newUniverse.data) // sends entire artnet universe data with appropriate parameters