Skip to content

Commit

Permalink
using addrToArtNetMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukejdav committed Apr 18, 2024
1 parent 68db2f8 commit 9c42c52
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 71 deletions.
28 changes: 14 additions & 14 deletions packages/quick-tsr/input/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const input: TSRInput = {
universe: 0,
featureChannels: {
"dimmer": 6,
"RGB": [7,8,9],
"RGB": [7,9,11],
}
},
}),
Expand All @@ -39,18 +39,18 @@ export const input: TSRInput = {
}
},
}),
dimmerGroup0: literal<Mapping<SomeMappingArtnet>>({
device: DeviceType.ARTNET,
deviceId: 'universe0',
options: {
mappingType: MappingArtnetType.Channels,
universe: 0,
featureChannels: {
// Maps dimmers to channel group:
"dimmers": [11, 12, 13, 14, 15, 16, 17, 18],
}
},
}),
// dimmerGroup0: literal<Mapping<SomeMappingArtnet>>({
// device: DeviceType.ARTNET,
// deviceId: 'universe0',
// options: {
// mappingType: MappingArtnetType.Channels,
// universe: 0,
// featureChannels: {
// // Maps dimmers to channel group:
// "dimmers": [11, 12, 13, 14, 15, 16, 17, 18],
// }
// },
// }),

everything: literal<Mapping<SomeMappingArtnet>>({
device: DeviceType.ARTNET,
Expand All @@ -60,7 +60,7 @@ export const input: TSRInput = {
universe: 0,
featureChannels: {
// "everything": ['1-50', '100-512'],
"everything": '1-512'
"all": '12-18'

}
},
Expand Down
23 changes: 19 additions & 4 deletions packages/quick-tsr/input/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const input: TSRInput = {
id: 'grey',
enable: {
start: Date.now(),
duration: 20 * 1000
duration: 5 * 1000
},
layer: 'dimmer0',
content: {
Expand All @@ -31,7 +31,7 @@ export const input: TSRInput = {
literal<TSRTimelineObj<TimelineContentArtNetAny>>({
id: 'white',
enable: {
start: Date.now() + 1000,
start: Date.now() + 5000,
duration: 20 * 1000
},
layer: 'dimmer0',
Expand All @@ -44,17 +44,32 @@ export const input: TSRInput = {
}
}),
literal<TSRTimelineObj<TimelineContentArtNetAny>>({
id: 'colour',
id: 'group1',
enable: {
start: Date.now(),
duration: 16 * 1000
},
layer: 'everything',
content: {
deviceType: DeviceType.ARTNET,
type: TimelineContentTypeArtNet.VALUES,
values: {
all: 127
}
}
}),
literal<TSRTimelineObj<TimelineContentArtNetAny>>({
id: 'rgbColour',
enable: {
start: Date.now() + 2000,
duration: 20 * 1000
},
layer: 'rgb0',
content: {
deviceType: DeviceType.ARTNET,
type: TimelineContentTypeArtNet.VALUES,
values: {
dimmer: 127
RGB: [255,127,255],
}
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ export interface TimelineContentArtNet extends TimelineContentArtNetBase {
// }
}

// commented out
export interface ArtNetDeviceCommand {
channel: number
value: number
}

// commented out
export interface ArtNetCommandContent {
ID: string
values: number | Array<number>
Expand Down
115 changes: 63 additions & 52 deletions packages/timeline-state-resolver/src/integrations/artnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ interface channelData {
}

export interface ArtNetDeviceState {
[address: string]: ArtNetDeviceStateContent
[channel: string]: ArtNetDeviceStateContent
}

interface ArtNetDeviceStateContent extends ArtNetCommandContent {
interface ArtNetDeviceStateContent {
fromTLObject: string
value: number
}

export interface ArtNetCommandWithContext extends CommandWithContext{

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

View workflow job for this annotation

GitHub Actions / Lint (timeline-state-resolver)

Insert `·`
Expand All @@ -56,6 +57,7 @@ export interface ArtNetCommandWithContext extends CommandWithContext{
}

// needs somthing to resolvew timeline names, this may not be the place
// commented out
export interface TimelineContentArtNetValues extends ArtNetCommandContent {

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

View workflow job for this annotation

GitHub Actions / Lint (timeline-state-resolver)

An interface declaring no members is equivalent to its supertype

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

View workflow job for this annotation

GitHub Actions / Lint (timeline-state-resolver)

Delete `⏎⏎`

}
Expand All @@ -76,11 +78,6 @@ interface ArtNetUniverse {
dataChanged: any[]
}

interface newData {
channel: number
value: number
}


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

View workflow job for this annotation

GitHub Actions / Lint (timeline-state-resolver)

Replace `⏎export·class·ArtNetDevice·extends·Device<ArtNetOptions,·ArtNetDeviceState,·ArtNetCommandWithContext>` with `export·class·ArtNetDevice·extends·Device<ArtNetOptions,·ArtNetDeviceState,·ArtNetCommandWithContext>·`
export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNetCommandWithContext>{

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

View workflow job for this annotation

GitHub Actions / Lint (timeline-state-resolver)

Delete `⏎↹`
Expand Down Expand Up @@ -130,48 +127,79 @@ export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNe
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 = {

}

let updateValues: newData[] = []

Object.values<Timeline.ResolvedTimelineObjectInstance<TSRTimelineContent>>(state.layers).forEach((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] }
let channelMapping = map.options.featureChannels // { dimmer: [1], RGB: [2,3,4], range: 12-24 }


// has some issus with mapping channels and timeline values when arrays are of different length
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)


// single channel and single value
// e.g. channel 2, value 255: 2:255
if (typeof channelValues === "number" && typeof artnetChannels === "number") {
addrToArtNetMessage[(map.options.universe).toString() + ":" + (artnetChannels).toString()] = {
fromTLObject: layer.id,
value: channelValues
}
}
// single channel and array of values, use first value
// e.g. channel 2, value [127, 255]: 2:127
else if (Array.isArray(channelValues) && typeof artnetChannels === "number") {
addrToArtNetMessage[(map.options.universe).toString() + ":" + (artnetChannels).toString()] = {
fromTLObject: layer.id,
value: channelValues[0]
}
}
// array of channels and single value, all channels the same value
// e.g. channel [2,3,4], value 255: 2:255, 3:255 etc.
else if (typeof channelValues === "number" && Array.isArray(artnetChannels)) {
addrToArtNetMessage[(map.options.universe).toString() + ":" + (artnetChannels).toString()] = {
fromTLObject: layer.id,
value: channelValues
}
}
// array of channels and array of values
// e.g. channel [2,3,4], values [255,255,255]
// close but not quite right, needs to fill with 0 correctly
else if (Array.isArray(channelValues) && Array.isArray(artnetChannels)) {
for(let i=0; i<artnetChannels.length; i++) {
addrToArtNetMessage[(map.options.universe).toString() + ":" + (artnetChannels[i]).toString()] = {
fromTLObject: layer.id,
value: channelValues[i]
}
}
}
// start and end channel and single value, all channels the same
// e.g. channel 12-24, value 255: 12:255, 13:255 ... 23:255, 24:255
else if (typeof channelValues === "number" && typeof artnetChannels === "string" && /^\d+\-\d+$/.test(artnetChannels)) {
let channelRange = artnetChannels.split('-')
for (let channel = parseInt(channelRange[0]); channel<= parseInt(channelRange[1]); channel++ ) {
addrToArtNetMessage[(map.options.universe).toString() + ":" + channel.toString()] = {
fromTLObject: layer.id,
value: channelValues
}
}
}


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)
console.log(addrToArtNetMessage)
return addrToArtNetMessage
}

Expand All @@ -192,7 +220,9 @@ export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNe

// send channelValue.value
// console.log(commands)
// let newCommands: ArtNetDeviceCommand = this.convertTimelineStateToDeviceState(newState)
let newCommands: ArtNetDeviceCommand = ({channel: 12, value: 255})

commands.push({
timelineObjId: '',
context: '',
Expand Down Expand Up @@ -223,23 +253,19 @@ export class ArtNetDevice extends Device<ArtNetOptions, ArtNetDeviceState, ArtNe
}

// placeholder
async sendCommand(/*cmd: ArtNetDeviceCommand*/): Promise<void> {
async sendCommand(cmd: any /*ArtNetDeviceCommand*/): Promise<void> {

// This is called when it's time to send the command
// console.log(cmd)
// Send the command
console.log("something sent")
// this.sendCommand(22)
this.sendArtNetUniverse(cmd, this.options.host)

}

// additonal methods for good implementation, currently unused

// private async updateArtNet() {
// private async updateArtNetUniverse() {
// // updates sendArtnet with new values only
// }

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

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

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

newValues.forEach(element => {
newUniverse.data[element.channel - 1] = element.value
});

// console.log(newUniverse.host)

// console.log(newUniverse.data.length)
console.log(newUniverse.data)
console.log('newUniverse.data', newUniverse.data)
// sends entire artnet universe data with appropriate parameters


}

}

// unsure if useful

// interface ArtNetDeviceState {
// [universe: string]: {
// [channel: string]: {
// value: number
// }
// }
// }
}

0 comments on commit 9c42c52

Please sign in to comment.