forked from batourin/DanielsLightingLibrary
/
DMXFixture.cs
86 lines (76 loc) · 2.93 KB
/
DMXFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using Daniels.Common;
namespace Daniels.Lighting
{
public class DMXFixture: LightFixture
{
protected DMXFixtureConfig _config;
private BasicTriList _transport;
public DMXFixtureProfileConfig Profile { get { return _config.Profile; } }
public DMXFixture(LightGroup group, DMXFixtureConfig config, BasicTriList transport):base(config.Id, config.Name, group)
{
_config = config.Clone() as DMXFixtureConfig;
_transport = transport;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder(base.ToString());
sb.AppendLine("\tConfig: " + _config.ToString());
return sb.ToString();
}
public override bool Muted
{
get { return base.Muted; }
set
{
if (value != base.Muted)
{
base.Muted = value;
if(this.EffectiveMute)
setTransportValue(DMXChannel.Intensity, 0);
else
setTransportValue(DMXChannel.Intensity, EffectiveIntensity);
}
}
}
public override ushort Intensity
{
get { return base.Intensity; }
set
{
if (value != base.Intensity)
{
base.Intensity = value;
if (!this.EffectiveMute)
setTransportValue(DMXChannel.Intensity, EffectiveIntensity);
}
}
}
protected override void masterIntensityChanged(object sender, ReadOnlyEventArgs<ushort> e)
{
if (!this.EffectiveMute)
setTransportValue(DMXChannel.Intensity, EffectiveIntensity);
base.masterIntensityChanged(sender, e);
}
protected override void masterMuteChanged(object sender, ReadOnlyEventArgs<bool> e)
{
if (this.EffectiveMute)
setTransportValue(DMXChannel.Intensity, 0);
else
setTransportValue(DMXChannel.Intensity, EffectiveIntensity);
base.masterMuteChanged(sender, e);
}
protected void setTransportValue(DMXChannel channel, ushort value)
{
ushort transportScaledValue = (ushort)(256*value/65536);
uint transportChannel = (uint)(_config.BaseDMXChannel + Profile.DMXChannels[channel]);
_transport.UShortInput[transportChannel].UShortValue = transportScaledValue;
CrestronConsole.PrintLine("DMXFixture(\"{0}\"): setTransportValue: {1}:{2}", this.Name, channel.ToString(), transportScaledValue);
}
}
}