private async Task LedTest(object o, DynamicEventArgs dynamicEventArgs) { if (dynamicEventArgs != null) { int led = dynamicEventArgs.Arg0; var colors = ColorUtil.EmptyList(_systemData.LedCount).ToArray(); colors[led] = Color.FromArgb(255, 0, 0); var sectors = ColorUtil.LedsToSectors(colors.ToList(), _systemData).ToArray(); var blackSectors = ColorUtil.EmptyList(_systemData.SectorCount).ToArray(); await SendColors(colors, sectors, 0, true); await Task.Delay(500); await SendColors(colors, blackSectors, 0, true); await Task.Delay(500); await SendColors(colors, sectors, 0, true); await Task.Delay(500); await SendColors(colors, blackSectors, 0, true); } foreach (var dev in _sDevices) { dev.Testing = false; } }
private async Task FlashDevice(object o, DynamicEventArgs dynamicEventArgs) { var devId = dynamicEventArgs.Arg0; var disable = false; var ts = new CancellationTokenSource(); try { } catch (Exception) { // Ignored } var bColor = Color.FromArgb(0, 0, 0, 0); var rColor = Color.FromArgb(255, 255, 0, 0); IColorTarget?device = null; foreach (var t in _sDevices) { if (t.Id != devId) { continue; } device = t; } if (device == null) { Log.Warning("Unable to find target device."); return; } device.Testing = true; Log.Information("Flashing device: " + devId); if (!device.Streaming) { disable = true; await device.StartStream(ts.Token); } await device.FlashColor(rColor); Thread.Sleep(500); await device.FlashColor(bColor); Thread.Sleep(500); await device.FlashColor(rColor); Thread.Sleep(500); await device.FlashColor(bColor); device.Testing = false; if (disable) { await device.StopStream(); } ts.Cancel(); ts.Dispose(); }
private async Task StartStream(object arg1, DynamicEventArgs arg2) { _gd = arg2.Arg0; _sd = DataUtil.GetSystemData(); var dims = new[] { _gd.LeftCount, _gd.RightCount, _gd.TopCount, _gd.BottomCount }; _builder = new FrameBuilder(dims); await _cs.SetMode(Udp); }
private async Task FlashSector(object o, DynamicEventArgs dynamicEventArgs) { var sector = dynamicEventArgs.Arg0; // When building center, we only need the v and h sectors. var dims = new[] { _systemData.VSectors, _systemData.VSectors, _systemData.HSectors, _systemData.HSectors }; var builder = new FrameBuilder(dims, true, _systemData.UseCenter); var col = Color.FromArgb(255, 255, 0, 0); var emptyColors = ColorUtil.EmptyColors(_systemData.LedCount); var emptySectors = ColorUtil.EmptyColors(_systemData.SectorCount); emptySectors[sector - 1] = col; var tMat = builder.Build(emptySectors); foreach (var dev in _sDevices) { if (dev.Enable) { dev.Testing = true; } } _splitter.DoSend = false; await _splitter.Update(tMat); var colors = _splitter.GetColors().ToArray(); var sectors = _splitter.GetSectors().ToArray(); await SendColors(colors, sectors, 0, true); await Task.Delay(500); await SendColors(emptyColors, emptySectors, 0, true); await Task.Delay(500); await SendColors(colors, sectors, 0, true); await Task.Delay(1000); await SendColors(emptyColors, emptySectors, 0, true); foreach (var dev in _sDevices) { if (dev.Enable) { dev.Testing = false; } } _splitter.DoSend = true; }
private Task ReloadLedData(object o, DynamicEventArgs dynamicEventArgs) { string ledId = dynamicEventArgs.Arg0; foreach (var dev in _sDevices) { if (dev.Id == ledId) { dev.ReloadData(); } } return(Task.CompletedTask); }
private async Task RefreshDeviceData(object o, DynamicEventArgs dynamicEventArgs) { var id = dynamicEventArgs.Arg0; if (string.IsNullOrEmpty(id)) { Log.Warning("Can't refresh null device: " + id); } foreach (var dev in _sDevices) { if (dev.Data.Id != id) { continue; } await dev.ReloadData().ConfigureAwait(false); if (_deviceMode != DeviceMode.Off && dev.Data.Enable && !dev.Streaming || dev.Id == "0") { await dev.StartStream(_targetTokenSource.Token); } if (_deviceMode == DeviceMode.Off || dev.Data.Enable || !dev.Streaming) { return; } Log.Information("Stopping disabled device: " + dev.Id); await dev.StopStream().ConfigureAwait(false); return; } var sda = DataUtil.GetDevice(id); // If our device is a real boy, start it and add it if (sda == null) { return; } var newDev = CreateDevice(sda); await newDev.StartStream(_targetTokenSource.Token).ConfigureAwait(false); var sDevs = _sDevices.ToList(); sDevs.Add(newDev); _sDevices = sDevs.ToArray(); }
private Task Mode(object arg1, DynamicEventArgs arg2) { _devMode = (DeviceMode)arg2.Arg0; return(Task.CompletedTask); }
private Task Mode(object arg1, DynamicEventArgs arg2) { return(_hubContext.Clients.All .SendAsync("frames", _colorService.Counter.Rates, CancellationToken.None)); }
private void EventFactory_RemoveDynamicRequest(object sender, DynamicEventArgs e) { container.Add(new RemoveDynamicCommand(e.Object, e.Dynamic)); }
private Task UpdateMode(object o, DynamicEventArgs dynamicEventArgs) { _streaming = dynamicEventArgs.Arg0 != 0; return(Task.CompletedTask); }
private async Task Mode(object o, DynamicEventArgs dynamicEventArgs) { var sd = DataUtil.GetSystemData(); var newMode = (DeviceMode)dynamicEventArgs.Arg0; bool init = dynamicEventArgs.Arg1 ?? false; if (init) { Log.Debug("Initializing mode."); } _deviceMode = newMode; // Don't unset auto-disable if init is set... if (_autoDisabled && !init) { _autoDisabled = false; DataUtil.SetItem("AutoDisabled", _autoDisabled); Log.Debug("Unsetting auto-disabled flag..."); } _streamTokenSource.Cancel(); if (_streamStarted && newMode == 0) { await StopStream(); } _streamTokenSource = new CancellationTokenSource(); if (_streamTokenSource.IsCancellationRequested) { Log.Warning("Token source has cancellation requested."); //return; } // Load our stream regardless ColorSource?stream = null; if (newMode == DeviceMode.Udp) { stream = sd.StreamMode == StreamMode.DreamScreen ? _streams["DreamScreen"] : _streams["UDP"]; } else if (newMode != DeviceMode.Off) { stream = _streams[newMode.ToString()]; } _stream = stream; if (stream != null) { Log.Debug("Toggling stream for " + newMode); _streamTask = stream.Start(_streamTokenSource.Token); _stream = stream; } else { if (newMode != DeviceMode.Off) { Log.Warning("Unable to acquire stream."); } } if (newMode != 0 && !_streamStarted && !_autoDisabled) { await StartStream(); } _deviceMode = newMode; Log.Information($"Device mode updated to {newMode}."); }