public void LightningPattern(CancellationToken token) { var random = new Random(); using (var rpi = new WS281x(settings)) { while (true) { if (token.IsCancellationRequested) { this.logger.Information("Cancelling Lightning Pattern..."); break; } var blue = random.NextDouble(); if (blue < 100) { blue = 100; } rpi.SetBrightness((int)(255 * random.NextDouble())); rpi.SetAll(Color.FromArgb(255, 100, 100, (int)blue)); Thread.Sleep((int)(2000 * random.NextDouble())); rpi.SetBrightness(0); Thread.Sleep((int)(5000 * random.NextDouble())); } } }
public void FadePixels(CancellationToken token, Pixels pixels) { using (var rpi = new WS281x(settings)) { rpi.SetAll(Color.FromArgb(255, pixels.r, pixels.g, pixels.b)); while (true) { for (double x = 0.0; x <= 2.0 * Math.PI; x += (5.0 / 255.0)) { if (token.IsCancellationRequested) { this.logger.Information("Cancelling Fade Pattern..."); break; } rpi.SetBrightness((int)(255.0 * Math.Abs(Trig.Sin(x)))); Thread.Sleep(10); } } } }
public void ReloadData() { _sd = DataUtil.GetSystemData(); LedData?d0 = DataUtil.GetDevice <LedData>("0"); LedData?d1 = DataUtil.GetDevice <LedData>("1"); if (!SystemUtil.IsRaspberryPi() || d0 == null || d1 == null || _d0 == null || _d1 == null) { _d0 = d0; _d1 = d1; return; } if (d0.StripType != _d0.StripType || d1.StripType != _d1.StripType) { _ws281X?.Dispose(); LoadStrips(d0, d1); } _d0 = d0; _d1 = d1; if (_ws281X == null) { LoadStrips(_d0, _d1); } _use0 = _d0.Enable; _use1 = _d1.Enable; _enableAbl = _sd.EnableAutoBrightness; _ablVolts = _sd.AblVolts; _ablAmps = _sd.AblAmps; if (_use0) { _s0Brightness = (int)(_d0.Brightness / 100f * 255f); _s0MaxBrightness = _s0Brightness; _ws281X?.SetBrightness(_s0Brightness); } if (_use1) { _s1Brightness = (int)(_d1.Brightness / 100f * 255f); _s1MaxBrightness = _s1Brightness; _ws281X?.SetBrightness(_s1Brightness, 1); } }