public void Load(Grid im) // Loads an image { image = im; Image_UpdateRequested = true; }
public static List<LED> GetNeededLEDs(Grid gr) { List<LED> leds = new List<LED>(); for (int i = 0; i < gr.Map.Count; i++) { for(int j = 0; j < gr.Map[i].Count; j++) { if(gr.Map[i][j].State) leds.Add(gr.Map[i][j]); } } return leds; }
private void Drive(DriveMode dm) // Drives the LEDs { switch (dm) { case DriveMode.Animation: // Animation Mode { if (!running) { running = true; Stopwatch sw = new Stopwatch(); while (!finish) { if (animation == null) { running = false; return; } Animation operation = new Animation(animation); Animation_UpdateRequested = false; DefaultConfiguartion(); List<List<LED>> leds = Animation.GetNeededLEDs(operation); while(!Animation_UpdateRequested) { for (int i = 0; i < operation.AnimationModel.Count; i++) { sw.Restart(); while (sw.ElapsedMilliseconds < operation.Durations[i]) { for (int j = 0; j < leds[i].Count; j++) { UpdateLED(leds[i][j]); UpdateLED(leds[i][j], !leds[i][j].State); } if (cancelAnimation.IsCancellationRequested) { running = false; return; } } sw.Stop(); } } } running = false; } } break; case DriveMode.Static: // Static Mode { if (!running) { running = true; while (!finish) { if (image == null) { running = false; return; } Grid operation = new Grid(image.Map); Image_UpdateRequested = false; DefaultConfiguartion(); List<LED> leds = Grid.GetNeededLEDs(operation); while(!Image_UpdateRequested) { for (int i = 0; i < leds.Count; i++) { UpdateLED(leds[i]); UpdateLED(leds[i], !leds[i].State); if (cancelAnimation.IsCancellationRequested) { running = false; return; } } } } running = false; } } break; } }