Skip to content

Commit

Permalink
Pulling mapping data and channel data to create a dummy universe
Browse files Browse the repository at this point in the history
Co-authored-by: Julian Waller <[email protected]>
  • Loading branch information
lukejdav and Julusian committed Apr 11, 2024
1 parent d3a2918 commit 68db2f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/quick-tsr/input/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const input: TSRInput = {
universe: 0,
featureChannels: {
// Maps dimmer to channel 1:
"dimmer": 1,
"dimmer": 1

Check failure on line 15 in packages/quick-tsr/input/mappings.ts

View workflow job for this annotation

GitHub Actions / Lint (quick-tsr)

Replace `"dimmer":·1` with `dimmer:·1,`
}

Check failure on line 16 in packages/quick-tsr/input/mappings.ts

View workflow job for this annotation

GitHub Actions / Lint (quick-tsr)

Insert `,`
},
}),
Expand Down
15 changes: 15 additions & 0 deletions packages/quick-tsr/input/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ export const input: TSRInput = {
}
}
}),
literal<TSRTimelineObj<TimelineContentArtNetAny>>({
id: 'colour',
enable: {
start: Date.now(),
duration: 20 * 1000
},
layer: 'rgb0',
content: {
deviceType: DeviceType.ARTNET,
type: TimelineContentTypeArtNet.VALUES,
values: {
dimmer: 127
}
}
}),
// literal<TSRTimelineObj<TimelineContentArtNetAny>>({
// id: 'artnet11',
// enable: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"patternProperties": {
"([a-z]\\w*)|(\\d+:\\d+)": {
"type": "string",
"enum": ["invert", "last", "highest", "lowest"]
"enum": ["highest", "lowest", "last", "invert"]
}
},
"additionalProperties": false
Expand Down
81 changes: 52 additions & 29 deletions packages/timeline-state-resolver/src/integrations/artnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
ArtNetOptions,
StatusCode,
ActionExecutionResult,
ArtNetDeviceCommand
ArtNetDeviceCommand,
Mappings,
MappingArtnetChannels,
Mapping

Check failure on line 14 in packages/timeline-state-resolver/src/integrations/artnet/index.ts

View workflow job for this annotation

GitHub Actions / Lint (timeline-state-resolver)

Insert `,`
} from 'timeline-state-resolver-types'
import { CommandWithContext, Device } from '../../service/device'
// import * as artnet from 'artnet'
Expand All @@ -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
}
Expand Down Expand Up @@ -122,27 +125,53 @@ export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNe
}

// still under work
convertTimelineStateToDeviceState(state: Timeline.TimelineState<TSRTimelineContent>): ArtNetDeviceState {
convertTimelineStateToDeviceState(
state: Timeline.TimelineState<TSRTimelineContent>,
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<Timeline.ResolvedTimelineObjectInstance<TSRTimelineContent>>(state.layers).forEach((layer) => {

// const artNetGroup = state.id
// console.log("layer:", artNetGroup)
// console.log(addrToArtNetMessage)

Object.values<Timeline.ResolvedTimelineObjectInstance<TSRTimelineContent>>(state.layers).forEach((layer) => {
if (layer.content.deviceType === DeviceType.ARTNET) {

// console.log(layer)
const map = mappings[layer.layer] as Mapping<MappingArtnetChannels> | 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
}

Expand Down Expand Up @@ -210,7 +239,7 @@ export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNe
// // updates sendArtnet with new values only
// }

private async sendArtNetUniverse(host: string, fps: number = 44, mode: string = 'full') {
private async sendArtNetUniverse(newValues: newData[], host: string, fps: number = 44, mode: string = 'full') {

let newUniverse:ArtNetUniverse = {
host: host,
Expand All @@ -226,22 +255,16 @@ export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNe
dataChanged: []
}

newUniverse.data[511] = 1
// newUniverse.data[511] = 1
newUniverse.data.fill(0,0,512)

let updateValues: newData[] = [
{channel: 22, value: 255},
{channel: 45, value: 255},
{channel: 101, value: 127}
]

updateValues.forEach(element => {
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

Expand Down

0 comments on commit 68db2f8

Please sign in to comment.