Пример #1
0
        public override void Animate(IViewPublisher publisher, CancellationToken token)
        {
            for (int loopi = 0; loopi < 1000; loopi++)
            {
                DispatcherInvocker(() =>
                {
                    var colors = new List <Brush>();
                    for (int i = 0; i < TOTAL_LED; i++)
                    {
                        var green = BrushHelper.BuildBrush(0, 255, 0);
                        colors.Add(green);
                    }

                    for (int i = 0; i < 5; i++)
                    {
                        var ind     = rd.Next(0, TOTAL_LED);
                        colors[ind] = BrushHelper.BuildBrush(255, 255, 255);
                    }

                    publisher.UpdateAllLeds(colors);
                });

                token.ThrowIfCancellationRequested();
                WaitAction();
            }
        }
Пример #2
0
        private Brush getRandomBrush()
        {
            int r = rd.Next(0, 255);
            int g = rd.Next(0, 255);
            int b = rd.Next(0, 255);

            return(BrushHelper.BuildBrush(r, g, b));
        }
        public override void Animate(IViewPublisher publisher, CancellationToken token)
        {
            string path = string.Empty;

            MainWindow.MainDispatcher.Invoke(() =>
            {
                FolderBrowserDialog openFileDialog = new FolderBrowserDialog();
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    path = openFileDialog.SelectedPath;
                }
            });


            if (!string.IsNullOrEmpty(path))
            {
                var files = Directory.GetFiles(path);

                do
                {
                    foreach (var file in files)
                    {
                        var rows = File.ReadAllLines(file);
                        foreach (string row in rows)
                        {
                            if (row.Length >= (TOTAL_LED * 3 * 3)) // because 3 colors RGB , each color encoded on 3 char
                            {
                                DispatcherInvocker(() =>
                                {
                                    var colors = new List <Brush>();
                                    for (int id = 0; id < TOTAL_LED; id++)
                                    {
                                        var red   = Convert.ToInt32(row.Substring(id * 9, 3));
                                        var green = Convert.ToInt32(row.Substring(id * 9 + 3, 3));
                                        var blue  = Convert.ToInt32(row.Substring(id * 9 + 6, 3));

                                        var b = BrushHelper.BuildBrush(red, green, blue);
                                        colors.Add(b);
                                    }

                                    publisher.UpdateAllLeds(colors);
                                });


                                token.ThrowIfCancellationRequested();
                                WaitAction();
                            }
                        }
                    }
                } while (!token.IsCancellationRequested);
            }
        }
        public override void Animate(IViewPublisher publisher, CancellationToken token)
        {
            int  head    = 0;
            bool running = true;

            int loop = 0;

            while (loop < 1000)
            {
                DispatcherInvocker(() =>
                {
                    var colors = new List <Brush>();
                    for (int i = 0; i < TOTAL_LED; i++)
                    {
                        int blue = 0;
                        if (i == head)
                        {
                            blue = 50;
                        }
                        if ((i - 1) == head)
                        {
                            blue = 150;
                        }
                        if ((i - 2) == head)
                        {
                            blue = 255;
                        }

                        colors.Add(BrushHelper.BuildBrush(0, 0, blue));
                    }

                    publisher.UpdateAllLeds(colors);
                });

                token.ThrowIfCancellationRequested();
                head++;
                if (head > TOTAL_LED)
                {
                    head = 0;
                }
                WaitAction();
                loop++;
            }
        }
Пример #5
0
        public override void Animate(IViewPublisher publisher, CancellationToken token)
        {
            Brush colorRing1 = null;
            Brush colorRing2 = null;
            Brush colorRing3 = null;
            Brush colorRing4 = null;


            DispatcherInvocker(() =>
            {
                colorRing1 = BrushHelper.BuildBrush(0, 0, 0);
                colorRing2 = BrushHelper.BuildBrush(0, 0, 0);
                colorRing3 = BrushHelper.BuildBrush(0, 0, 0);
                colorRing4 = BrushHelper.BuildBrush(0, 0, 0);
            });

            while (true)
            {
                for (int loopi = 1; loopi <= 1530; loopi = loopi + 30)
                {
                    DispatcherInvocker(() =>
                    {
                        var colors = new List <Brush>();

                        colorRing4 = colorRing3;
                        colorRing3 = colorRing2;
                        colorRing2 = colorRing1;
                        colorRing1 = BrushHelper.RGBRadiant(loopi);

                        colors.AddRange(Enumerable.Repeat(colorRing4, 24).ToList());
                        colors.AddRange(Enumerable.Repeat(colorRing3, 16).ToList());
                        colors.AddRange(Enumerable.Repeat(colorRing2, 12).ToList());
                        colors.AddRange(Enumerable.Repeat(colorRing1, 8).ToList());

                        publisher.UpdateAllLeds(colors);
                    });

                    token.ThrowIfCancellationRequested();
                    WaitActionCustom(100);
                }
            }
        }
        public MainViewModel()
        {
            var defaultbrush  = BrushHelper.BuildBrush(255, 0, 0);
            var defaultColors = new List <Brush>();

            for (int i = 0; i < AbstractScenario.TOTAL_LED; i++)
            {
                defaultColors.Add(defaultbrush);
            }
            UpdateAllLeds(defaultColors);


            OnMyButtonClick        = new RelayCommand(cmd => OnMyButtonClickImpl());
            OnRecordScenearioClick = new RelayCommand(cmd => OnRecordScenearioClickImpl());

            _scenario = new ScenarioGenerator();

            var scenariiList = new ObservableCollection <string>();

            Enum.GetValues(typeof(EScenario)).Cast <EScenario>().ToList().ForEach(x => scenariiList.Add(x.ToString()));
            this.ScenarioCollection = scenariiList;
        }
        public override void Animate(IViewPublisher publisher, CancellationToken token)
        {
            do
            {
                for (int i = 0; i < 24; i++)
                {
                    DispatcherInvocker(() =>
                    {
                        //ring 1;
                        int a1 = i;

                        int b1 = i - 1;
                        if (b1 < 0)
                        {
                            b1 = b1 + 24;
                        }

                        int c1 = i - 2;
                        if (c1 < 0)
                        {
                            c1 = c1 + 24;
                        }


                        int d1 = i - 3;
                        if (d1 < 0)
                        {
                            d1 = d1 + 24;
                        }



                        //ring2
                        int a2 = secondRing[a1] + 24;

                        int b2 = a2 - 1;
                        if (b2 < 24)
                        {
                            b2 = b2 + 16;
                        }

                        int c2 = a2 - 2;
                        if (c2 < 24)
                        {
                            c2 = c2 + 16;
                        }



                        //ring3
                        int a3 = thirdRing[a1] + 24 + 16;

                        int b3 = a3 - 1;
                        if (b3 < (24 + 16))
                        {
                            b3 = b3 + 12;
                        }

                        //ring4

                        int a4 = fourthRing[a1] + 24 + 16 + 12;



                        var brushes = Enumerable.Repeat(0, 60).Select(x => BrushHelper.BuildBrush(0, 0, 0)).ToList();

                        brushes[d1] = BrushHelper.BuildBrush(0, 0, 40);
                        brushes[c1] = BrushHelper.BuildBrush(0, 0, 105);
                        brushes[b1] = BrushHelper.BuildBrush(0, 0, 175);
                        brushes[a1] = BrushHelper.BuildBrush(0, 0, 255);

                        //if(a1 != 0 && a1 != 6 && a1 != 12 && a1 != 18)
                        if (a1 != 4 && a1 != 10 && a1 != 16 && a1 != 22)
                        {
                            brushes[c2] = BrushHelper.BuildBrush(0, 0, 55);
                        }
                        brushes[b2] = BrushHelper.BuildBrush(0, 0, 150);
                        brushes[a2] = BrushHelper.BuildBrush(0, 0, 255);


                        brushes[b3] = BrushHelper.BuildBrush(0, 0, 120);
                        brushes[a3] = BrushHelper.BuildBrush(0, 0, 255);

                        brushes[a4] = BrushHelper.BuildBrush(0, 0, 255);

                        publisher.UpdateAllLeds(brushes);
                    });

                    token.ThrowIfCancellationRequested();
                    WaitActionCustom(30);
                }
            } while (!token.IsCancellationRequested);
        }