protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); object value; if (data.TryGetValue(DataElements.Pan, out value)) { this.pan = ((double)value).Limit(0, 540); } if (data.TryGetValue(DataElements.Tilt, out value)) { this.tilt = ((double)value).Limit(0, 270); } #if TRACE_IDATA int id = 0; foreach (var kvp in data) { id++; this.log.Verbose("{3} {0}. {1} = {2}", id, kvp.Key, kvp.Value, this.Name); } #endif }
protected virtual void SetFromIData(ILogicalDevice logicalDevice, IData data) { object value; bool masterPower = true; var masterPowerDevice = logicalDevice as IHasMasterPower; if (masterPowerDevice != null) { masterPower = masterPowerDevice.MasterPower; } if (data.TryGetValue(DataElements.Brightness, out value)) { this.colorBrightness.Brightness = (double)value * (masterPower ? 1 : 0); } else { bool?power = data.GetValue <bool>(DataElements.Power); if (power.HasValue) { this.colorBrightness.Brightness = (power.Value && masterPower) ? 1 : 0; } } if (data.TryGetValue(DataElements.Color, out value)) { this.colorBrightness.Color = (Color)value; } }
protected virtual void SetModel(ILogicalDevice model) { _model = model; DeviceNumber = _model.DeviceNumber; DeviceName = _model.DeviceName; DeviceDescription = _model.DeviceDescription; }
protected virtual void OutputFromIData(ILogicalDevice logicalDevice, IData data) { if (data.TryGetValue(DataElements.Command, out object value)) { if (value is byte[] arr) { byte lastByte = this.autoResetCommand; lock (this) { foreach (byte b in arr) { DmxOutputPort.SendDimmerValue(this.startDmxChannel, b); lastByte = b; } } if (this.autoResetAfter.HasValue && lastByte != this.autoResetCommand) { this.resetTimer.Change(this.autoResetAfter.Value, TimeSpan.FromMilliseconds(-1)); } else { this.resetTimer.Change(Timeout.Infinite, Timeout.Infinite); } } } }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); object value; if (data.TryGetValue(DataElements.StrobeSpeed, out value)) this.strobeSpeed = (double)value; }
private void StopCurrentTask(ILogicalDevice device, Cue.CueParts cuePart) { if (this.currentInstance == null) { return; } this.currentInstance.StopExistingTask(device, cuePart); }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); object value; if (data.TryGetValue(DataElements.Pan, out value)) this.pan = ((double)value).Limit(0, 540); if (data.TryGetValue(DataElements.Tilt, out value)) this.tilt = ((double)value).Limit(0, 270); }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); object value; if (data.TryGetValue(DataElements.StrobeSpeed, out value)) { this.strobeSpeed = (double)value; } }
public TestLight(Switch logicalDevice) { Executor.Current.Register(this); this.logicalDevice = logicalDevice; logicalDevice.PowerChanged += (sender, e) => { this.control.Color = e.NewState ? Color.Green : Color.Black; }; }
public void StopExistingTask(ILogicalDevice device, Cue.CueParts cuePart) { var key = Tuple.Create(device, cuePart); Task existingTask; if (this.tasks.TryGetValue(key, out existingTask)) { // Stop existing Executor.Current.StopManagedTask(existingTask); } }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); if (data.ContainsKey(DataElements.ColorAmber) || data.ContainsKey(DataElements.ColorRGB) || data.ContainsKey(DataElements.ColorUltraViolet) || data.ContainsKey(DataElements.ColorWhite)) { object value; componentMaster = (this.colorBrightness.Brightness * (1 - Executor.Current.Blackout.Value)).GetByteScale(); Color colorRGB; if (data.TryGetValue(DataElements.ColorRGB, out value)) { colorRGB = (Color)value; } else { colorRGB = this.colorBrightness.Color; } componentRed = colorRGB.R; componentGreen = colorRGB.G; componentBlue = colorRGB.B; //TODO: WhiteOut if (data.TryGetValue(DataElements.ColorAmber, out value)) { componentAmber = ((double)value).GetByteScale(); } if (data.TryGetValue(DataElements.ColorWhite, out value)) { componentWhite = ((double)value).GetByteScale(); } if (data.TryGetValue(DataElements.ColorUltraViolet, out value)) { componentUV = ((double)value).GetByteScale(); } } else { var rgbaw = RgbConverter.GetRGBAW(this.colorBrightness.Color); componentMaster = this.colorBrightness.Brightness.GetByteScale(); componentRed = rgbaw.R; componentGreen = rgbaw.G; componentBlue = rgbaw.B; componentAmber = rgbaw.A; componentWhite = rgbaw.W; } }
public TestLight(Dimmer logicalDevice) { this.logicalDevice = logicalDevice; logicalDevice.BrightnessChanged += (sender, e) => { this.control.Color = Color.FromArgb(e.NewBrightness.GetByteScale(), e.NewBrightness.GetByteScale(), e.NewBrightness.GetByteScale()); this.control.Text = string.Format("{0:0%}", e.NewBrightness); }; WireUpStrobe(logicalDevice as StrobeDimmer); }
public TestPixel1D(IUpdateActionParent parent, IPixel1D2 logicalDevice) : this(parent, logicalDevice.Pixels) { this.logicalDevice = logicalDevice; logicalDevice.ImageChanged.Subscribe(x => { this.outputBitmap = new Bitmap(x); this.newDataAvailable = true; }); }
public TestPixel2D(IUpdateActionParent parent, IPixel2D2 logicalDevice) : this(parent, logicalDevice.PixelWidth, logicalDevice.PixelHeight) { this.logicalDevice = logicalDevice; logicalDevice.ImageChanged.Subscribe(x => { this.outputBitmap = new Bitmap(x); this.newDataAvailable = true; }); }
protected override void SetModel(ILogicalDevice model) { base.SetModel(model); (_model as IRuntimeDevice).TcpDeviceConnection.ConnectionRestoredAction += OnConnectionRestored; (_model as IRuntimeDevice).TcpDeviceConnection.ConnectionLostAction += OnConnectionLost; (_model as IRuntimeDevice).DeviceInitialized += OnDeviceInitialized; (_model as IRuntimeDevice).DeviceValuesUpdated += OnDeviceValuesUpdated; DefectStateViewModel.Model = (_model as IRuntimeDevice).DefectState; AnalogDataViewModel.Model = (_model as IRuntimeDevice).AnalogData; (_model as IRuntimeDevice).TcpDeviceConnection.TransactionCompleteAction += () => { QueryIndicatorViewModel?.BeginIndication(); }; }
public TestLight(ColorDimmer logicalDevice) { this.logicalDevice = logicalDevice; logicalDevice.ColorChanged += (sender, e) => { var hsv = new HSV(e.NewColor); hsv.Value = hsv.Value * e.NewBrightness; this.control.Color = hsv.Color; this.control.Text = string.Format("{0:0%}", e.NewBrightness); }; WireUpStrobe(logicalDevice as StrobeColorDimmer); }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IPhysicalDevice physicalDeviceCasted = item.As <IPhysicalDevice>(); if ((physicalDeviceCasted != null)) { this._parent.PhysicalDevice.Add(physicalDeviceCasted); } ILogicalDevice logicalDeviceCasted = item.As <ILogicalDevice>(); if ((logicalDeviceCasted != null)) { this._parent.LogicalDevice.Add(logicalDeviceCasted); } }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); object value; if (data.TryGetValue(DataElements.Pan, out value)) { this.pan = ((double)value).Limit(0, 540); } if (data.TryGetValue(DataElements.Tilt, out value)) { this.tilt = ((double)value).Limit(0, 270); } }
private void MibCheck(int cueId, ILogicalDevice device) { //FIXME: Doesn't check for bounce/loop var brightnessDevice = device as IReceivesBrightness; if (brightnessDevice == null) { return; } if (brightnessDevice.Brightness > 0) { // Not black return; } for (int i = cueId + 1; i < this.cues.Count; i++) { var cue = this.cues[i]; var panTiltDevice = device as IReceivesPanTilt; bool moved = false; if (panTiltDevice != null) { if (cue.PartPan != null && cue.PartPan.MoveInBlack) { GetControlledObserverPan(panTiltDevice).OnNext(cue.PartPan.Destination); moved = true; } if (cue.PartTilt != null && cue.PartTilt.MoveInBlack) { GetControlledObserverTilt(panTiltDevice).OnNext(cue.PartTilt.Destination); moved = true; } } if (moved) { break; } } }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { IPhysicalDevice physicalDeviceItem = item.As <IPhysicalDevice>(); if (((physicalDeviceItem != null) && this._parent.PhysicalDevice.Remove(physicalDeviceItem))) { return(true); } ILogicalDevice logicalDeviceItem = item.As <ILogicalDevice>(); if (((logicalDeviceItem != null) && this._parent.LogicalDevice.Remove(logicalDeviceItem))) { return(true); } return(false); }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); if (data.ContainsKey(DataElements.ColorAmber) || data.ContainsKey(DataElements.ColorRGB) || data.ContainsKey(DataElements.ColorUltraViolet) || data.ContainsKey(DataElements.ColorWhite)) { object value; componentMaster = (this.colorBrightness.Brightness * (1 - Executor.Current.Blackout.Value)).GetByteScale(); Color colorRGB; if (data.TryGetValue(DataElements.ColorRGB, out value)) colorRGB = (Color)value; else colorRGB = this.colorBrightness.Color; componentRed = colorRGB.R; componentGreen = colorRGB.G; componentBlue = colorRGB.B; //TODO: WhiteOut if (data.TryGetValue(DataElements.ColorAmber, out value)) componentAmber = ((double)value).GetByteScale(); if (data.TryGetValue(DataElements.ColorWhite, out value)) componentWhite = ((double)value).GetByteScale(); if (data.TryGetValue(DataElements.ColorUltraViolet, out value)) componentUV = ((double)value).GetByteScale(); } else { var rgbaw = RgbConverter.GetRGBAW(this.colorBrightness.Color); componentMaster = this.colorBrightness.Brightness.GetByteScale(); componentRed = rgbaw.R; componentGreen = rgbaw.G; componentBlue = rgbaw.B; componentAmber = rgbaw.A; componentWhite = rgbaw.W; } }
protected virtual void SetPumpFromIData(ILogicalDevice logicalDevice, IData data) { bool masterPower = true; if (logicalDevice is IHasMasterPower masterPowerDevice) { masterPower = masterPowerDevice.MasterPower; } if (data.TryGetValue(DataElements.Throughput, out object value)) { this.pumpThroughput = (double)value * (masterPower ? 1 : 0); } else { bool?power = data.GetValue <bool>(DataElements.Power); if (power.HasValue) { this.pumpThroughput = (power.Value && masterPower) ? 1 : 0; } } }
public void AddNewTask(ILogicalDevice device, Cue.CueParts cuePart, Task task, Action mibCheck = null) { var key = Tuple.Create(device, cuePart); this.tasks[key] = task; task.ContinueWith(x => { this.tasks.Remove(key); }); if (mibCheck != null) { task.ContinueWith(x => { if (!x.IsCanceled) { mibCheck(); } }); } }
protected override void SetFromIData(ILogicalDevice logicalDevice, IData data) { base.SetFromIData(logicalDevice, data); object value; if (data.TryGetValue(DataElements.Pan, out value)) this.pan = ((double)value).Limit(0, 540); if (data.TryGetValue(DataElements.Tilt, out value)) this.tilt = ((double)value).Limit(0, 270); #if TRACE_IDATA int id = 0; foreach (var kvp in data) { id++; log.Trace("{3} {0}. {1} = {2}", id, kvp.Key, kvp.Value, this.Name); } #endif }
public TestPixel1D(Pixel1D logicalDevice) { Executor.Current.Register(this); this.logicalDevice = logicalDevice; this.numberOfPixels = logicalDevice.Pixels; logicalDevice.PixelChanged += (sender, e) => { var hsv = new HSV(e.NewColor); hsv.Value = hsv.Value * e.NewBrightness; Color c = hsv.Color; lock (lockObject) { if (!this.changedPixels.Any()) this.firstChange.Restart(); this.pixelData[e.Channel] = c; this.changedPixels.Add((byte)e.Channel); receivedUpdates++; } }; logicalDevice.MultiPixelChanged += (sender, e) => { var newColors = new Color[e.NewValues.Length]; for(int i = 0; i < e.NewValues.Length; i++) { var hsv = new HSV(e.NewValues[i].Color); hsv.Value = hsv.Value * e.NewValues[i].Brightness; newColors[i] = hsv.Color; } lock (lockObject) { if (!this.changedPixels.Any()) this.firstChange.Restart(); int readOffset = 0; for (int i = 0; i < newColors.Length; i++) { int dataOffset = e.StartChannel + i; this.pixelData[dataOffset] = newColors[readOffset++]; this.changedPixels.Add((byte)(e.StartChannel + i)); } receivedUpdates++; } }; this.changedPixels = new HashSet<byte>(); this.cancelSource = new System.Threading.CancellationTokenSource(); this.firstChange = new System.Diagnostics.Stopwatch(); this.pixelData = new Color[this.numberOfPixels]; this.senderTask = new Task(x => { while (!this.cancelSource.IsCancellationRequested) { lock (lockObject) { if (this.changedPixels.Any()) { this.firstChange.Stop(); this.sentUpdates++; //Console.WriteLine("Sending {0} changes to SIM. Oldest {1:N2}ms. Recv: {2} Sent: {3}", // this.changedPixels.Count, this.firstChange.Elapsed.TotalMilliseconds, // receivedUpdates, sentUpdates); if (this.changedPixels.Count <= 2) { foreach (var channel in this.changedPixels) { control.SetPixel(channel, this.pixelData[channel]); } } else { // Send everything control.SetPixels(0, this.pixelData); } this.changedPixels.Clear(); } } System.Threading.Thread.Sleep(10); } }, this.cancelSource.Token, TaskCreationOptions.LongRunning); this.senderTask.Start(); }
public void StopExistingTask(ILogicalDevice device, Cue.CueParts cuePart) { var key = Tuple.Create(device, cuePart); Task existingTask; if (this.tasks.TryGetValue(key, out existingTask)) { // Stop existing Executor.Current.StopManagedTask(existingTask); } }
public void AddNewTask(ILogicalDevice device, Cue.CueParts cuePart, Task task, Action mibCheck = null) { var key = Tuple.Create(device, cuePart); this.tasks[key] = task; task.ContinueWith(x => { this.tasks.Remove(key); }); if (mibCheck != null) { task.ContinueWith(x => { if (!x.IsCanceled) mibCheck(); }); } }
private void StopCurrentTask(ILogicalDevice device, Cue.CueParts cuePart) { if (this.currentInstance == null) return; this.currentInstance.StopExistingTask(device, cuePart); }
private void MibCheck(int cueId, ILogicalDevice device) { //FIXME: Doesn't check for bounce/loop var brightnessDevice = device as IReceivesBrightness; if (brightnessDevice == null) return; if (brightnessDevice.Brightness > 0) // Not black return; for (int i = cueId + 1; i < this.cues.Count; i++) { var cue = this.cues[i]; var panTiltDevice = device as IReceivesPanTilt; bool moved = false; if (panTiltDevice != null) { if (cue.PartPan != null && cue.PartPan.MoveInBlack) { GetControlledObserverPan(panTiltDevice).OnNext(cue.PartPan.Destination); moved = true; } if (cue.PartTilt != null && cue.PartTilt.MoveInBlack) { GetControlledObserverTilt(panTiltDevice).OnNext(cue.PartTilt.Destination); moved = true; } } if (moved) break; } }
protected virtual void SetFromIData(ILogicalDevice logicalDevice, IData data) { object value; bool masterPower = true; var masterPowerDevice = logicalDevice as IHasMasterPower; if (masterPowerDevice != null) masterPower = masterPowerDevice.MasterPower; if (data.TryGetValue(DataElements.Brightness, out value)) this.colorBrightness.Brightness = (double)value * (masterPower ? 1 : 0); else { bool? power = data.GetValue<bool>(DataElements.Power); if (power.HasValue) this.colorBrightness.Brightness = (power.Value && masterPower) ? 1 : 0; } if (data.TryGetValue(DataElements.Color, out value)) this.colorBrightness.Color = (Color)value; }