Esempio n. 1
0
        public static void RainbowDemo(APA102LEDStrip ledStrip0, int jStep, APA102LEDStrip ledStrip1, bool inSync)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            int wait       = 13;
            var quit       = false;
            var maxStep    = 256;
            var brightness = 16;

            ledStrip0.AllOff();
            ledStrip1.AllOff();

            while (!quit)
            {
                var j2 = maxStep;
                for (var j = 0; j < maxStep; j += jStep)
                {
                    if (inSync) // If in sync both led show the same color else show opposite color
                    {
                        j2 = j;
                    }

                    ledStrip0.Reset();
                    ledStrip1.Reset();

                    for (var i = 0; i < ledStrip0.MaxLed; i++)
                    {
                        ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j)));
                    }

                    for (var i = 0; i < ledStrip1.MaxLed; i++)
                    {
                        ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2)));
                    }

                    foreach (var bkColor in ledStrip0.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}      ", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j), ConsoleColor.DarkCyan);
                    }
                    foreach (var bkColor in ledStrip1.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j2), ConsoleColor.DarkCyan);
                    }

                    ledStrip0.Show();
                    ledStrip1.Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                    j2--;
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
        }
Esempio n. 2
0
        public static void ComboWith6LedPanel(Nusbio nusbio, APA102LEDStrip ledStrip0, APA102LEDStrip ledStrip1 = null)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            int wait       = 50;
            var quit       = false;
            var maxStep    = 256;
            var brightness = 5;
            int jStep      = 8;

            ledStrip0.AllOff();
            ledStrip1.AllOff();

            var ledIndex        = -1;
            var maxLedIndex     = 4;
            var ledIndexTimeOut = new TimeOut(wait * 50);

            while (!quit)
            {
                var j2 = maxStep;
                for (var j = 0; j < maxStep; j += jStep)
                {
                    ledStrip0.Reset();
                    ledStrip1.Reset();

                    for (var i = 0; i < ledStrip0.MaxLed; i++)
                    {
                        ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j)));
                    }

                    for (var i = 0; i < ledStrip1.MaxLed; i++)
                    {
                        ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2)));
                    }

                    foreach (var bkColor in ledStrip0.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);
                    }
                    foreach (var bkColor in ledStrip1.LedColors)
                    {
                        ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);
                    }
                    j2 -= jStep;
                    if (j2 < 0)
                    {
                        j2 = maxStep;
                    }

                    ledStrip0.Show();
                    ledStrip1.Show().Wait(wait);

                    /*
                     * // Turn on and off led connected to gpio 0,1,2,3
                     * if (ledIndexTimeOut.IsTimeOut())
                     * {
                     *  if (ledIndex != -1)
                     *      nusbio[ledIndex].Low();
                     *  ledIndex++;
                     *  if (ledIndex == maxLedIndex)
                     *      ledIndex = 0;
                     *  nusbio[ledIndex].High();
                     * }
                     */

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
        }
Esempio n. 3
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");

            Nusbio.ActivateFastMode();

            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("nusbio not detected");
                return;
            }

            using (var nusbio = new Nusbio(serialNumber))
            {
                //_eeprom = new EEPROM_25AA1024(
                //   nusbio: nusbio,
                //   clockPin: NusbioGpio.Gpio4,
                //   mosiPin: NusbioGpio.Gpio5,
                //   misoPin: NusbioGpio.Gpio2,
                //   selectPin: NusbioGpio.Gpio6
                //   );


                _eeprom = new EEPROM_25AA1024(
                    nusbio: nusbio,
                    clockPin: NusbioGpio.Gpio0,
                    mosiPin: NusbioGpio.Gpio1,
                    misoPin: NusbioGpio.Gpio2,
                    selectPin: NusbioGpio.Gpio3
                    );

                _eeprom.Begin();

                // Noticed that we cannot detect if the EEPROM is connected or
                // not based on SPI command. The SPI command does not fail.
                // But return a buffer with garbage mostly all byte set to 255
                // So based on the expected data of the first page we could
                // detect of the EEPROM is connected or not
                var r = _eeprom.ReadPage(0, _eeprom.PAGE_SIZE * 4);
                if (r.Succeeded)
                {
                    if (r.Buffer[0] == 255)
                    {
                        Console.WriteLine("SPI EEPROM 25AA1024 not detected, hit enter to continue");
                        Console.ReadLine();
                    }
                }

                Cls(nusbio);

                while (nusbio.Loop())
                {
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;

                        if (k == ConsoleKey.W)
                        {
                            var a = ConsoleEx.Question(23, string.Format("Execute Write/Read/Write Test {0}k now Y)es, N)o", _eeprom.MaxKByte), new List <char>()
                            {
                                'Y', 'N'
                            });
                            if (a == 'Y')
                            {
                                Console.Clear(); ConsoleEx.TitleBar(0, "Writing EEPROM");

                                var testValue = 1 + 4 + 16 + 64;
                                _eeprom.WriteAll(0, EEPROM_25AA1024.MakeBuffer((byte)testValue, _eeprom.MaxByte), (pageIndex, maxPage) => ConsoleEx.WriteLine(0, 2, string.Format("{0:000} % done", 1.0 * pageIndex / maxPage * 100.0), ConsoleColor.Yellow));

                                Console.Clear(); ConsoleEx.TitleBar(0, "Reading EEPROM");
                                var dataRead = _eeprom.ReadAll(16, (pageIndex, maxPage) => ConsoleEx.WriteLine(0, 2, string.Format("{0:000} % done", 1.0 * pageIndex / maxPage * 100.0), ConsoleColor.Yellow));
                                for (var z = 0; z < _eeprom.MaxByte; z++)
                                {
                                    if (dataRead[z] != testValue)
                                    {
                                        throw new ArgumentException("Writing/Reading error");
                                    }
                                }
                                WriteEEPROMPage(512);
                                ReadAndVerifyEEPROMPage_BatchRead(512);
                            }
                        }

                        if (k == ConsoleKey.R)
                        {
                            ReadAndVerifyEEPROMPage(10);
                            Cls(nusbio);
                        }

                        if (k == ConsoleKey.A)
                        {
                            ReadAndVerifyEEPROMPage_BatchRead(512);
                            ReadAndVerifyEEPROMPage(512);
                        }
                        if (k == ConsoleKey.B)
                        {
                            // This mode is slow, only read the first 64 pages out of 512
                            ReadAndVerifyEEPROMOnyByteAtTheTime(64);
                        }

                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }

                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }
Esempio n. 4
0
        static void IntensistyScrollingDemo2(IS31FL3731 ledMatrix16x9)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Intensisty Demo", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(0, 2, "Q)uit");
            var sweep = new List <int>()
            {
                1, 2, 8, 16, 24, 32, 44, 64, 80, 96, 120, 128, 120, 96, 80, 64, 44, 32, 24, 16, 8, 4, 2, 1
            };

            var quit = false;
            var incr = 1;

            var moduleStepIndex = 0;
            var moduleSteps     = new List <int>()
            {
                2, 4, 6, 8, 10, 12, 16, 18, 20, 22
            };

            moduleSteps = new List <int>()
            {
                1, 3, 5, 7, 9, 11, 13, 15, 17, 19
            };

            var doubleBufferIndex = 1;

            ledMatrix16x9.Clear();

            while (!quit)
            {
                for (int y = 0; y < ledMatrix16x9.Height; y++)
                {
                    ConsoleEx.Write(0, y + 4, string.Format("{0:00} - ", y), ConsoleColor.Cyan);

                    for (int x = 0; x < ledMatrix16x9.Width; x++)
                    {
                        var intensity = sweep[(x + y + incr) % moduleSteps[moduleStepIndex]];
                        ledMatrix16x9.DrawPixel(x, y, intensity);
                        Console.Write("{0:000} ", intensity);

                        moduleStepIndex++;
                        if (moduleStepIndex >= moduleSteps.Count)
                        {
                            moduleStepIndex = 0;
                        }
                    }
                }
                var bytePerSecond = ledMatrix16x9.UpdateDisplay(doubleBufferIndex);
                ConsoleEx.WriteLine(0, 15, string.Format("{0:0.00} K byte/sec sent", bytePerSecond / 1024.0), ConsoleColor.Cyan);
                doubleBufferIndex = doubleBufferIndex == 1 ? 0 : 1;
                incr++;
                Thread.Sleep(50);

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey(true).Key;
                    if (k == ConsoleKey.Q)
                    {
                        quit = true;
                    }
                }
            }
        }
Esempio n. 5
0
        static void ReadAndVerifyEEPROMPage_BatchRead(int numberOfPageToRead, int expectedSingleValue = -1)
        {
            Console.Clear();

            var batchPageSize = 128; // Transfer batch of 32page x 256byte = 8k

            ConsoleEx.TitleBar(0, string.Format("Performance test reading all {0}k in {1} pages batch mode", _eeprom.MaxKByte, batchPageSize));
            ConsoleEx.Gotoxy(0, 2);

            var t = Stopwatch.StartNew();

            EEPROM_25AA1024_UnitTests.PerformanceTest_ReadPage(_eeprom, batchPageSize,
                                                               (pageIndex, maxPage) => ConsoleEx.WriteLine(0, 3, string.Format("{0:000} % done", 1.0 * pageIndex / maxPage * 100.0), ConsoleColor.Yellow));
            t.Stop();

            Console.WriteLine("Data:{0}kb, Time:{1}ms, {2:0.00} kb/s", _eeprom.MaxKByte, t.ElapsedMilliseconds, _eeprom.MaxByte * 1.0 / t.ElapsedMilliseconds);
            Console.WriteLine("Hit enter key");
            Console.ReadLine();
        }