public CalculationReslut FindWireCeossSection(Wire wire, LedStrip ledStrip, decimal maxVoltageDrop, decimal maxCrossSection) { foreach (var cs in Definitions.WireCrossSections.Where(x => x.CrossSection <= maxCrossSection).OrderBy(x => x.CrossSection)) { // Condition 1 - Max Current if (ledStrip.Current > cs.CrossSection * MaxCurrentPer1mm2) { continue; } // Condition 2 - Max Voltage Drop var resistance = wire.WireType.Resistivity * M2toMM2 * wire.Lenght * NumberOfWiresInCircut / cs.CrossSection; var voltageDrop = resistance * ledStrip.Current; if (voltageDrop > maxVoltageDrop) { continue; } // Both conditions met, so return result return(new CalculationReslut { VoltageDrop = voltageDrop, CrossSection = cs }); } return(null); }
/// <summary> /// This is a thread worker. It performs the continuous animation until Stop is called. /// </summary> private void AnimateContinuosly() { var startFrameTime = DateTime.UtcNow; using (var tickLock = new ManualResetEvent(false)) { while (IsPendingStop == false) { startFrameTime = DateTime.UtcNow; FrameNumber = (FrameNumber == UInt64.MaxValue) ? 1 : FrameNumber + 1; lock (SyncLock) { CurrentAnimation.PaintNextFrame(); LedStrip.Render(); } var elapsedToFrame = MillisecondsPerFrame - Convert.ToInt32(DateTime.UtcNow.Subtract(startFrameTime).TotalMilliseconds); if (elapsedToFrame <= 0) { "Frames are lagging. Increase the frequency or simplify the rendering logic." .Warn(); // typeof(LedStripWorker)); continue; } tickLock.WaitOne(elapsedToFrame); } } }
/// <summary> /// Should stop the task immediately and synchronously /// </summary> public void Stop() { lock (SyncLock) { if (LedStrip == null) { return; } IsPendingStop = true; using (var sleepLock = new ManualResetEvent(false)) { while (_animationThread.ThreadState == ThreadState.Running) { sleepLock.WaitOne(1); } } _animationThread = null; LedStrip.ClearPixels(); LedStrip.Render(); LedStrip.Render(); LedStrip = null; } }
public void Update() { if (Effect.WouldUpdate()) { Effect.FrameUpdate(LedStrip.Pixels); } LedStrip.Show(); }
public static void TestLedStrip() { var exitAnimation = false; var thread = new Thread(() => { var strip = new LedStrip(60 * 4); var millisecondsPerFrame = 1000 / 25; var lastRenderTime = DateTime.UtcNow; var tailSize = strip.LedCount; byte red = 0; while (!exitAnimation) { strip.ClearPixels(); red = red >= 254 ? default(byte) : (byte)(red + 1); for (var i = 0; i < tailSize; i++) { strip[i].Brightness = i / (tailSize - 1f); strip[i].R = red; strip[i].G = (byte)(255 - red); strip[i].B = (byte)(strip[i].Brightness * 254); } var delayMilliseconds = (int)DateTime.UtcNow.Subtract(lastRenderTime).TotalMilliseconds; delayMilliseconds = millisecondsPerFrame - delayMilliseconds; if (delayMilliseconds > 0 && exitAnimation == false) { Thread.Sleep(delayMilliseconds); } else { $"Lagging framerate: {delayMilliseconds} milliseconds".Info(); } lastRenderTime = DateTime.UtcNow; strip.Render(); } strip.ClearPixels(); strip.Render(); }); thread.Start(); Console.Write("Press any key to stop and clear"); Console.ReadKey(true); Console.WriteLine(); exitAnimation = true; }
public bool ShouldFadeLed(LedStrip ledStrip, int delay, bool ignoreFullBrightness = false) { if (!ledStrip.IsBrightnessGoingUp() || (!ledStrip.IsFadePlanned() && (ledStrip.GetCurrentBrightness() < ledStrip.GetMaxLevelPwm() || ignoreFullBrightness))) { FadeInfo fadePlan = ledStrip.GetFadePlan(); return(fadePlan == null || fadePlan.GetStartOnMillis() > delay + millis()); } return(false); }
private void CLedStrip_SelectedIndexChanged(object sender, EventArgs e) { if (cLedStrip.SelectedItem == null) { return; } internalChangeLock = true; ledStrip = (LedStrip)cLedStrip.SelectedItem; cStripType.SelectedItem = ledStrip.Type; cVoltage.SelectedItem = ledStrip.Voltage; nCurrent.Value = ledStrip.Current; tStripLenght.Text = ledStrip.Lenght.ToString(); internalChangeLock = false; }
/// <summary> /// Testing method for LedStrip module (function never returns) /// </summary> static void TestLedStrip() { //test led strip var pins = new[] { FEZRaptor.Socket18.Pin3, FEZRaptor.Socket18.Pin4, FEZRaptor.Socket18.Pin5, FEZRaptor.Socket18.Pin6, FEZRaptor.Socket18.Pin7, FEZRaptor.Socket18.Pin8, FEZRaptor.Socket18.Pin9 }; var ledStrip = new LedStrip(pins); int counter = 0; while (true) { ledStrip.SetLeds(counter); if (counter >= ledStrip.LedCount) { counter = 0; } counter++; Thread.Sleep(200); } }
// Starts our capture service and initializes our LEDs private void StartCaptureServices(CancellationToken ct) { if (CaptureMode == 0) { return; } LedData ledData = DataUtil.GetObject <LedData>("LedData") ?? new LedData(true); try { _strip = new LedStrip(ledData); LogUtil.Write("Initialized LED strip..."); } catch (TypeInitializationException e) { LogUtil.Write("Type init error: " + e.Message); } _grabber = new StreamCapture(_camTokenSource.Token); if (_grabber == null) { return; } Task.Run(() => SubscribeBroadcast(ct), ct); }
public ICueBridge() { CUESDK.LoadCUESDK(); CorsairProtocolDetails details = CUESDK.CorsairPerformProtocolHandshake(); CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl); int devCount = CUESDK.CorsairGetDeviceCount(); Debug.WriteLine("CorsairGetDeviceCount: {1}", "", devCount); for (int deviceIndex = 0; deviceIndex < devCount; deviceIndex++) { IntPtr deviceInfoPointer = CUESDK.CorsairGetDeviceInfo(deviceIndex); CorsairDeviceInfo DeviceInfo = (CorsairDeviceInfo)Marshal.PtrToStructure(deviceInfoPointer, typeof(CorsairDeviceInfo)); IntPtr ledPositionPointer = CUESDK.CorsairGetLedPositionsByDeviceIndex(deviceIndex); CorsairLedPositions LedPositions = (CorsairLedPositions)Marshal.PtrToStructure(ledPositionPointer, typeof(CorsairLedPositions)); switch (DeviceInfo.type) { case CorsairDeviceType.Keyboard: Debug.WriteLine("Keyboard LedPosition: {1}", "", LedPositions.numberOfLed); Keyboard = new Keyboard(); Keyboard.LedPositions = LedPositions; Keyboard.DeviceInfo = DeviceInfo; Keyboard.CorsairDeviceIndex = deviceIndex; break; case CorsairDeviceType.LightningNodePro: Debug.WriteLine("LightningNodePro LedPosition: {1}", "", LedPositions.numberOfLed); LedStrip = new LedStrip(); LedStrip.LedPositions = LedPositions; LedStrip.DeviceInfo = DeviceInfo; LedStrip.CorsairDeviceIndex = deviceIndex; break; } Debug.WriteLine("DeviceInfo: {1}", "", DeviceInfo.type); } }
public static void TestLedStripGraphics() { BitmapBuffer pixels = null; try { using (var bitmap = new System.Drawing.Bitmap(Path.Combine(Runtime.EntryAssemblyDirectory, "fractal.jpg"))) { $"Loaded bitmap with format {bitmap.PixelFormat}".Info(); pixels = new BitmapBuffer(bitmap); $"Loaded Pixel Data: {pixels.Data.Length} bytes".Info(); } } catch (Exception ex) { $"Error Loading image: {ex.Message}".Error(); } var exitAnimation = false; var useDynamicBrightness = false; var frameRenderTimes = new Queue <int>(); var frameTimes = new Queue <int>(); var thread = new Thread(() => { var strip = new LedStrip(60 * 4, 1, 1000000); // 1 Mhz is sufficient for such a short strip (only 240 LEDs) var millisecondsPerFrame = 1000 / 25; var lastRenderTime = DateTime.UtcNow; var currentFrameNumber = 0; var currentBrightness = 0.8f; var currentRow = 0; var currentDirection = 1; while (!exitAnimation) { // Push pixels into the Frame Buffer strip.SetPixels(pixels, 0, currentRow, currentBrightness); // Move the current row slowly at FPS currentRow += currentDirection; if (currentRow >= pixels.ImageHeight) { currentRow = pixels.ImageHeight - 2; currentDirection = -1; } else if (currentRow <= 0) { currentRow = 1; currentDirection = 1; } if (useDynamicBrightness) { currentBrightness = 0.05f + 0.80f * (currentRow / (pixels.ImageHeight - 1f)); } // Stats and sleep time var delayMilliseconds = (int)DateTime.UtcNow.Subtract(lastRenderTime).TotalMilliseconds; frameRenderTimes.Enqueue(delayMilliseconds); delayMilliseconds = millisecondsPerFrame - delayMilliseconds; if (delayMilliseconds > 0 && exitAnimation == false) { Thread.Sleep(delayMilliseconds); } else { $"Lagging framerate: {delayMilliseconds} milliseconds".Info(); } frameTimes.Enqueue((int)DateTime.UtcNow.Subtract(lastRenderTime).TotalMilliseconds); lastRenderTime = DateTime.UtcNow; // Push the framebuffer to SPI strip.Render(); if (currentFrameNumber == int.MaxValue) { currentFrameNumber = 0; } else { currentFrameNumber++; } if (frameRenderTimes.Count >= 2048) { frameRenderTimes.Dequeue(); } if (frameTimes.Count >= 20148) { frameTimes.Dequeue(); } } strip.ClearPixels(); strip.Render(); var avg = frameRenderTimes.Average(); $"Frames: {currentFrameNumber + 1}, FPS: {Math.Round((1000f / frameTimes.Average()), 3)}, Strip Render: {Math.Round(avg, 3)} ms, Max FPS: {Math.Round(1000 / avg, 3)}".Info(); strip.Render(); }); thread.Start(); Console.Write("Press any key to stop and clear"); Console.ReadKey(true); Console.WriteLine(); exitAnimation = true; }
public void Deactivate() { Effect.Deactivate(LedStrip.Pixels); LedStrip.Show(); }
/// <summary> /// Initializes a new instance of the <see cref="LedStripPixel"/> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="baseAddress">The base address.</param> public LedStripPixel(LedStrip owner, int baseAddress) { Owner = owner; BaseAddress = baseAddress; }