Example #1
0
        static bool AddNewTextFile(string pw, string fileName = null)
        {
            string text = null;
            var    ok   = false;

            Console.Clear();
            ConsoleEx.TitleBar(0, "Add Nex Text File", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.Write(0, 4, "File name>", ConsoleColor.Cyan);
            if (fileName == null)
            {
                fileName = Console.ReadLine();
                ConsoleEx.Write(0, 5, "Text file content>", ConsoleColor.Cyan);
                text = Console.ReadLine();
            }

            var newFile = _sfsManager.AddFile(fileName);

            if (text != null)
            {
                newFile.SetContentAsString(text);
            }
            var rr = _sfsManager.WriteAsFileSystem();

            if (rr)
            {
                Console.WriteLine("File saved", ConsoleColor.Cyan);
            }
            else
            {
                Console.WriteLine("Error saving file", ConsoleColor.Red);
            }

            Pause();
            return(ok);
        }
Example #2
0
        private static bool EncrypteFile(PrivatePublicKeyHelper ppk, string key, string keyType)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Encrypte File", ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Encrypte File With {0}", keyType), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteLine(0, 2, "Filename:", ConsoleColor.Cyan);
            var fileName = Console.ReadLine();

            ConsoleEx.WriteLine(0, 4, "", ConsoleColor.Cyan);

            if (!File.Exists(fileName))
            {
                ConsoleEx.WriteLine(0, 3, "Cannot find the file", ConsoleColor.Red);
                return(false);
            }

            var dataFile      = File.ReadAllBytes(fileName);
            var dataEncrypted = ppk.EncryptBuffer(dataFile, key);
            var tmpFile       = fileName + ENCRYPTED_EXTENSION;

            if (File.Exists(tmpFile))
            {
                File.Delete(tmpFile);
            }

            File.WriteAllBytes(tmpFile, dataEncrypted);

            Console.WriteLine(string.Format("Encyrpted file is located at {0}", tmpFile), ConsoleColor.Cyan);
            Pause();
            return(true);
        }
Example #3
0
        static void ShowFile(int fileIndex)
        {
            var fi = _sfsManager.FileInfos[fileIndex];

            Console.Clear();
            ConsoleEx.TitleBar(0, "Loading:" + fi.FileName, ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            fi = _sfsManager.LoadFileContent(fi);

            Console.Clear();
            ConsoleEx.TitleBar(0, "Viewing:" + fi.FileName, ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.Gotoxy(0, 1);

            if (fi.IsImage)
            {
                int exitCode = -1;
                var rr       = ExecuteProgram.ExecProgram("mspaint.exe", string.Format(@"""{0}""", fi.GetAsLocalTempFile()), true, ref exitCode, true, false);
                if (rr && exitCode == 0)
                {
                }
                else
                {
                    ConsoleEx.WriteLine(0, 3, "Cannot open the file", ConsoleColor.Red);
                    Pause();
                }
            }
            else
            {
                var text = fi.GetBufferAsUnicodeString();
                Console.WriteLine(text);
                Pause();
            }
            _sfsManager.Clean();
        }
Example #4
0
        public static void TrigonometrieOneColorDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);

            if (ledStrip.MaxLed <= 10)
            {
                wait *= 3;
            }

            var maxLed = ledStrip.MaxLed;
            var quit   = false;

            ledStrip.Brightness = 16;
            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Trigonometrie Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var _4Sin_div_PI   = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(radianV) / (1 * Math.PI), colorMinValue: 64);
            var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(3 * radianV) / (3 * Math.PI), colorMinValue: 64);
            var _4Sin5_div_5PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(5 * radianV) / (5 * Math.PI), colorMinValue: 32);
            var _4Sin7_div_7PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(7 * radianV) / (7 * Math.PI), colorMinValue: 32);

            // Green
            var greenColorVariation0 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin_div_PI, null);
            var greenColorVariation1 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, null);
            var greenColorVariation2 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin5_div_5PI, null);
            var greenColorVariation3 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin7_div_7PI, null);

            while (!quit)
            {
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation0, "4*Math.Sin(radianV)  /(1*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation1, "4*Math.Sin(3*radianV)/(3*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation2, "4*Math.Sin(5*radianV)/(5*Math.PI)"))
                {
                    break;
                }
                if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation3, "4*Math.Sin(7*radianV)/(7*Math.PI)"))
                {
                    break;
                }

                if (Console.KeyAvailable)
                {
                    if (Console.ReadKey().Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
            ledStrip.AllOff();
        }
Example #5
0
        public static void RGBDemo(APA102LEDStrip ledStrip)
        {
            int wait        = GetWaitTimeUnit(ledStrip);
            int waitStep    = 10;
            int maxWait     = 200;
            var quit        = false;
            var userMessage = "Speed:{0}. Use Left and Right keys to change the speed";

            ledStrip.Brightness = 22;
            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "RGB Demo");
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");
            ConsoleEx.WriteLine(0, 2, string.Format(userMessage, wait), ConsoleColor.DarkGray);

            while (!quit)
            {
                ledStrip.AddRGBSequence(true, 2, ledStrip.MaxLed - 1, Color.Blue);
                ledStrip.InsertRGBSequence(0, 14, Color.Red);
                ledStrip.ShowAndShiftRightAllSequence(wait);

                if (!Console.KeyAvailable)
                {
                    ledStrip.AddRGBSequence(true, 3, ledStrip.MaxLed - 1, Color.Green);
                    ledStrip.InsertRGBSequence(0, 16, Color.Red);
                    ledStrip.ShowAndShiftRightAllSequence(wait);
                }

                if (Console.KeyAvailable)
                {
                    while (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                        }
                        if (k == ConsoleKey.RightArrow)
                        {
                            wait += waitStep;
                            if (wait > maxWait)
                            {
                                wait = maxWait;
                            }
                        }
                        if (k == ConsoleKey.LeftArrow)
                        {
                            wait -= waitStep;
                            if (wait < 0)
                            {
                                wait = 0;
                            }
                        }
                    }
                    ConsoleEx.WriteLine(0, 2, string.Format(userMessage, wait), ConsoleColor.DarkGray);
                }
            }
            ledStrip.AllOff();
        }
Example #6
0
        static void GestureMode(Nusbio nusbio, GY_9960LLC gy_9960LLC)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Gesture Mode", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 5, "Q)uit");
            while (true)
            {
                Thread.Sleep(100);
                var isGestureAvailable = gy_9960LLC.isGestureAvailable();
                //ConsoleEx.WriteMenu(-1, 2, string.Format("InterruptOn:{0}, isGestureAvailable:{1}",
                Console.WriteLine(string.Format("InterruptOn:{0}, isGestureAvailable:{1}",
                                                gy_9960LLC.InterruptOn(), isGestureAvailable
                                                ));

                if (isGestureAvailable)
                {
                    var g = gy_9960LLC.readGesture();
                    if (g != GY_9960LLC.Direction.DIR_NONE)
                    {
                        Console.WriteLine(string.Format("Gest:{0}", g));
                    }
                }

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey();
                    if (k.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }
        }
Example #7
0
        private static bool DecrypteFile(PrivatePublicKeyHelper ppk, string key, string keyType)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Decrypte file with {0}", keyType), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.WriteLine(0, 2, "Filename:", ConsoleColor.Cyan);
            var fileName = Console.ReadLine();

            ConsoleEx.Gotoxy(0, 4);

            if (!File.Exists(fileName))
            {
                ConsoleEx.WriteLine(0, 3, "Cannot find the file", ConsoleColor.Red);
                Pause();
                return(false);
            }
            var sourceExtension = Path.GetExtension(fileName.Replace(ENCRYPTED_EXTENSION, ""));
            var dataFile        = File.ReadAllBytes(fileName);
            var dataEncrypted   = ppk.DecryptBuffer(dataFile, key);
            var tmpFile         = fileName + sourceExtension;

            File.WriteAllBytes(tmpFile, dataEncrypted);

            Console.WriteLine(string.Format("Encyrpted file is located at {0}", tmpFile), ConsoleColor.Cyan);
            Pause();
            return(true);
        }
Example #8
0
        static void ReadAndVerifyEEPROMPage(int numberOfPageToRead, int expectedSingleValue = -1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Performance test reading all {0}k no batch standard SPI code", _eeprom.MaxKByte));
            ConsoleEx.Gotoxy(0, 2);

            var totalErrorCount = 0;
            var t = Stopwatch.StartNew();

            byte[] buf;

            for (var p = 0; p < numberOfPageToRead; p++)
            {
                if (p % 50 == 0 || p < 5)
                {
                    Console.WriteLine("Reading page {0}", p);
                }

                // The method ReadPage, use the default SPI method to transfer data
                var r = _eeprom.ReadPage(p * _eeprom.PAGE_SIZE, _eeprom.PAGE_SIZE);
                if (r.Succeeded)
                {
                    buf = r.Buffer;
                    for (var i = 0; i < _eeprom.PAGE_SIZE; i++)
                    {
                        var expected = i;
                        if (p == 2)
                        {
                            expected = NEW_WRITTEN_VALUE_1;
                        }
                        if (p == 3)
                        {
                            expected = NEW_WRITTEN_VALUE_2;
                        }

                        if (expectedSingleValue != -1)
                        {
                            expected = expectedSingleValue;
                        }

                        if (buf[i] != expected)
                        {
                            Console.WriteLine("Failed Page:{0} [{1}] = {2}, expected {3}", p, i, buf[i], expected);
                            totalErrorCount++;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("ReadBuffer failure");
                }
            }
            t.Stop();
            Console.WriteLine("{0} error(s), Data:{1}kb, Time:{2}, {3:0.00} kb/s",
                              totalErrorCount,
                              _eeprom.PAGE_SIZE * numberOfPageToRead, t.ElapsedMilliseconds, _eeprom.MaxByte * 1.0 / t.ElapsedMilliseconds);
            Console.WriteLine("Hit enter key");
            Console.ReadLine();
        }
Example #9
0
 static void Cls(Nusbio nusbio)
 {
     Console.Clear();
     ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
     ConsoleEx.WriteMenu(-1, 5, "G)esture mode L)ight Sensor  Q)uit");
     ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
     ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
 }
Example #10
0
        static bool GeneratePrivateKeyPublicKey(string pw)
        {
            var ok = false;

            Console.Clear();
            ConsoleEx.TitleBar(0, "Generate new private/public key", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            Console.Clear();
            ConsoleEx.TitleBar(0, "Generate Private/Public Key", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            var keyInfo = ConsoleEx.Question(3, "Re generate the private key and publick key Y)es N)o", new List <char> {
                'Y', 'N'
            });

            if (keyInfo == 'N')
            {
                return(ok);
            }

            keyInfo = ConsoleEx.Question(3, "Are you sure you want to generate Private/Public Key Y)es N)o", new List <char> {
                'Y', 'N'
            });
            if (keyInfo == 'N')
            {
                return(ok);
            }

            ConsoleEx.WriteLine(0, 4, "Formatting...", ConsoleColor.Yellow);
            var ppk = new PrivatePublicKeyHelper(true);

            if (!_sfsManager.Format())
            {
                ConsoleEx.WriteLine(0, 3, "Format failed", ConsoleColor.Red);
            }

            ConsoleEx.WriteLine(0, 5, "Loading and saving files...", ConsoleColor.Yellow);
            var privatek = _sfsManager.AddFile("PrivateKey");

            privatek.SetContentAsString(ppk.PrivateKey);
            var publicK = _sfsManager.AddFile("PublicKey");

            publicK.SetContentAsString(ppk.PublicKey);
            var readmeTxt = _sfsManager.AddFile("ReadMe.txt");

            readmeTxt.SetContentAsString(LoremIpsum);
            var rr = _sfsManager.UpdateFileSystem();

            if (rr)
            {
                Console.WriteLine(string.Format("Keys were generated"), ConsoleColor.Cyan);
                ok = ReloadFileSystem(pw, ppk);
            }
            else
            {
                Console.WriteLine(string.Format("Error generating the keys"), ConsoleColor.Red);
            }

            Pause();
            return(ok);
        }
Example #11
0
        static void Cls(Nusbio nusbio)
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 5, "R)ainbow Demo  B)rightness Demo   S)equence Demo   RainboW) Demo [insync]");
            ConsoleEx.WriteMenu(-1, 9, "Q)uit");
            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
        }
Example #12
0
        static void Cls(Nusbio nusbio)
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.TitleBar(4, "A)nimate I)mage R)eset  Q)uit", ConsoleColor.White, ConsoleColor.DarkBlue);

            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
        }
Example #13
0
        public static void LineDemo(APA102LEDStrip ledStrip)
        {
            int wait = ledStrip.MaxLed <= 10 ? 55 : 0;
            var quit = false;

            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Line Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            while (!quit)
            {
                var j = 0;

                for (var i = 0; i < ledStrip.MaxLed; i++)
                {
                    // Remark: there should be a faster way to draw the line, by first setting all the led
                    // to black and only resetting the one in color. Once we light up all the led, we would
                    // turn them all off and re start... Todo, totry.
                    var bkColor = RGBHelper.Wheel(((i * 256 / ledStrip.MaxLed) + j));
                    ledStrip.AddRGBSequence(true, 2, i + 1, bkColor);
                    if (++j >= 256)
                    {
                        j = 0;
                    }
                    while (!ledStrip.IsFull)
                    {
                        ledStrip.AddRGBSequence(false, 2, Color.Black);
                    }

                    ledStrip.Show().Wait(wait);

                    Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)));

                    if (Console.KeyAvailable)
                    {
                        while (Console.KeyAvailable)
                        {
                            var k = Console.ReadKey(true).Key;
                            if (k == ConsoleKey.Q)
                            {
                                quit = true;
                                break;
                            }
                        }
                    }
                }
                ledStrip.Wait(wait * 3).AllOff();
            }
            ledStrip.AllOff();
        }
Example #14
0
        static void Cls(Nusbio nusbio)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.WriteMenu(-1, 4, "R)ead 10 pages   read A)ll 128k   read all B)yte mode 128k");
            ConsoleEx.WriteMenu(-1, 5, "W)rite 128k");
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
        }
Example #15
0
        static void Cls(Nusbio nusbio)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.WriteMenu(-1, 5, "B)ar scroll demo  I)ntensisty scroll demo  inT)ensisty demo 2  L)andscape demo");
            ConsoleEx.WriteMenu(-1, 7, "Q)uit");

            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);

            ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
        }
Example #16
0
        static void Cls(Nusbio nusbio)
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 5, "B)rightness Demo   R)GB Demo   S)croll Demo   SP)eed Demo");
            ConsoleEx.WriteMenu(-1, 7, "A)mp Test   RainboW) Demo   L)ine Demo ");
            ConsoleEx.WriteMenu(-1, 9, "1) Trigonometric green  2) Trigonometric red+gree");
            ConsoleEx.WriteMenu(-1, 11, "Q)uit");
            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
        }
Example #17
0
        static void WriteEEPROMPage(int numberOfPageToRead, int valueToWrite = -1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Writing EEPROM");
            ConsoleEx.WriteMenu(0, 1, "");

            var totalErrorCount = 0;
            var t = Stopwatch.StartNew();

            for (var p = 0; p < numberOfPageToRead; p++)
            {
                var refBuffer = new List <Byte>();
                for (var x = 0; x < _eeprom.PAGE_SIZE; x++)
                {
                    if (valueToWrite != -1)
                    {
                        refBuffer.Add((byte)valueToWrite);
                    }
                    else
                    {
                        if (p == 2)
                        {
                            refBuffer.Add((byte)NEW_WRITTEN_VALUE_1);
                        }
                        else if (p == 3)
                        {
                            refBuffer.Add((byte)NEW_WRITTEN_VALUE_2);
                        }
                        else
                        {
                            refBuffer.Add((byte)x);
                        }
                    }
                }

                if (p % 10 == 0)
                {
                    Console.WriteLine("Writing page {0}", p);
                }

                var r = _eeprom.WritePage(p * _eeprom.PAGE_SIZE, refBuffer.ToArray());
                if (!r)
                {
                    Console.WriteLine("WriteBuffer failure");
                }
            }
            t.Stop();
            Console.WriteLine("{0} error(s), Time:{1}", totalErrorCount, t.ElapsedMilliseconds);
            Console.WriteLine("Hit enter key");
            Console.ReadLine();
        }
Example #18
0
        static void ReadAndVerifyEEPROMPage_BatchRead(int numberOfPageToRead, int expectedSingleValue = -1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Performance test reading all {0}k in 4 pages batch mode", _eeprom.MaxKByte));
            ConsoleEx.Gotoxy(0, 2);

            var t = Stopwatch.StartNew();

            EEPROM_25AA256_UnitTests.PerformanceTest_ReadPage(_eeprom);
            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();
        }
Example #19
0
        public static void ScrollDemo(APA102LEDStrip ledStrip)
        {
            var wait = GetWaitTimeUnit(ledStrip);
            var quit = false;

            ledStrip.Brightness = 16;

            ledStrip.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Scroll Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            var bkColors = TargetColors.Replace("\r", "").Replace("\n", ",").Split(',').ToList();

            while (!quit)
            {
                foreach (var sBColor in bkColors)
                {
                    if (string.IsNullOrEmpty(sBColor.Trim()))
                    {
                        continue;
                    }

                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];

                    Console.WriteLine(String.Format("Background Color:{0}, Html:{1}, Dec:{2}",
                                                    bkColor.Name.PadRight(16),
                                                    APA102LEDStrip.ToHexValue(bkColor),
                                                    APA102LEDStrip.ToDecValue(bkColor)));

                    var fgColor = APA102LEDStrip.ToBrighter(bkColor, -10);

                    ledStrip.AddRGBSequence(true, 4, ledStrip.MaxLed - 1, bkColor);
                    ledStrip.InsertRGBSequence(0, 15, fgColor);
                    ledStrip.ShowAndShiftRightAllSequence(wait);

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStrip.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Example #20
0
        public static void BrigthnessDemo(APA102LEDStrip ledStrip0, APA102LEDStrip ledStrip1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Brightness Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 3, "Q)uit");

            ledStrip0.AllOff();
            ledStrip1.AllOff();
            var bkColors = TargetColors.Replace(Environment.NewLine, ",").Split(',').ToList();
            var wait     = 15;

            while (!Console.KeyAvailable)
            {
                foreach (var sBColor in bkColors)
                {
                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];

                    for (var b = 1; b <= APA102LEDStrip.MAX_BRIGHTNESS; b += 2)
                    {
                        ConsoleEx.Write(1, 2, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                        ledStrip0.SetColor(b, bkColor).Show();
                        ledStrip1.SetColor(b, bkColor).Show().Wait(wait);
                    }

                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    ledStrip0.Wait(wait * 10); // Wait when the fade in is done

                    for (var b = APA102LEDStrip.MAX_BRIGHTNESS; b >= 0; b -= 2)
                    {
                        ConsoleEx.Write(1, 2, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                        ledStrip0.SetColor(b, bkColor).Show();
                        ledStrip1.SetColor(b, bkColor).Show().Wait(wait);
                    }

                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                    ledStrip0.Wait(wait * 10); // Wait when the fade out is deon
                }
            }
            ledStrip0.AllOff();
            ledStrip1.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Example #21
0
        static void IntensistyDemo(IS31FL3731 ledMatrix16x9)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Intensisty Demo", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(0, 2, "Q)uit");
            var quit = false;
            var doubleBufferIndex = 1;

            // 8 intensities for each row
            // After 160, the intensity remain the same
            var intensities = new List <int>()
            {
                2, 8, 16, 32, 32 + 12, 64, 96, 96 + 24, 96 + 32
            };
            var intensityIndex = 0;

            ledMatrix16x9.Clear();

            while (!quit)
            {
                intensityIndex = 0;
                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++)
                    {
                        ledMatrix16x9.DrawPixel(x, y, intensities[intensityIndex]);
                        Console.Write("{0:000} ", intensities[intensityIndex]);
                    }
                    if (++intensityIndex >= intensities.Count)
                    {
                        intensityIndex = 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;

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey(true).Key;
                    if (k == ConsoleKey.Q)
                    {
                        quit = true;
                    }
                }
            }
        }
Example #22
0
        static void IntensistyScrollingDemo(IS31FL3731 ledMatrix16x9)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Intensisty Scrolling Demo", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(0, 2, "Q)uit");
            var sweep = new List <int>()
            {
                1, 2, 3, 4, 6, 8, 10, 15, 20, 30, 40, 60, 60, 40, 30, 20, 15, 10, 8, 6, 4, 3, 2, 1
            };

            var quit = false;
            var incr = 0;
            var doubleBufferIndex = 1;

            ledMatrix16x9.Clear();
            int modulo = 24;

            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) % modulo];
                        ledMatrix16x9.DrawPixel(x, y, intensity);
                        Console.Write("{0:000} ", intensity);
                    }
                }
                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++;

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey(true).Key;
                    if (k == ConsoleKey.Q)
                    {
                        quit = true;
                    }
                }
            }
        }
Example #23
0
        public static void RainbowDemo2(APA102LEDStrip ledStrip, int jStep)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            int brigthness = 6;
            int wait       = GetWaitTimeUnit(ledStrip) / 2;
            var quit       = false;

            ledStrip.AllOff();

            while (!quit)
            {
                for (var j = 0; j < 256; j += jStep)
                {
                    ConsoleEx.Gotoxy(0, 4);
                    ledStrip.Reset();

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        ledStrip.AddRGBSequence(false, brigthness, RGBHelper.Wheel((i * 256 / ledStrip.MaxLed) + j));
                    }
                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        var wheelIndex = (i * 256 / ledStrip.MaxLed) + j;
                        var bkColor    = ledStrip.LedColors[i];
                        Console.WriteLine(String.Format("Color:{0}, Wheel:{1}, rgb:{2}",
                                                        bkColor.Name, wheelIndex.ToString("000"), APA102LEDStrip.ToDecValue(bkColor)));
                    }
                    ledStrip.Show().Wait(wait);
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip.AllOff();
        }
Example #24
0
        private static void ExportKey(string keyXml, string keyName)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Export Key:" + keyName, ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.TitleBar(0, "Export " + keyName, ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            var tmpFile = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), keyName + ".txt");

            File.WriteAllText(tmpFile, keyXml);
            int exitCode = -1;
            var rr       = ExecuteProgram.ExecProgram("notepad.exe", string.Format(@"""{0}""", tmpFile), true, ref exitCode, true, false);

            BinSerializer.OverwriteFile(tmpFile);
            File.Delete(tmpFile);

            ConsoleEx.WriteLine(0, 2, string.Format("The {0} file, has been overwritten & deleted from the disk", keyName), ConsoleColor.Cyan);
            Pause();
        }
Example #25
0
        /// <summary>
        ///
        /// *** ATTENTION ***
        ///
        /// WHEN CONTROLLING AN APA LED STRIP WITH NUSBIO YOU MUST KNOW THE AMP CONSUMPTION.
        ///
        /// USB DEVICE ARE LIMITED TO 500 MILLI AMP.
        ///
        /// AN LED IN GENERAL CONSUMES FROM 20 TO 25 MILLI AMP. AN RGB LED CONSUMES 3 TIMES
        /// MORE IF THE RED, GREEN AND BLUE ARE SET TO THE 255, 255, 255 WHICH IS WHITE
        /// AT THE MAXIMUN INTENSISTY WHICH IS 31.
        ///
        /// YOU MUST KNOW WHAT IS THE MAXIMUN CONSUMPTION OF YOUR APA 102 RGB LEB STRIP WHEN THE
        /// RGB IS SET TO WHITE, WHITE, WHITE AND THE BRIGTHNESS IS AT THE MAXIMUM.
        ///
        ///    -------------------------------------------------------------------------------
        ///    --- NEVER GO OVER 300 MILLI AMP IF THE LED STRIP IS POWERED FROM THE NUSBIO ---
        ///    -------------------------------------------------------------------------------
        ///
        ///         POWER ONLY A LED STRIP OF 5 LED WHEN DIRECTLY PLUGGED INTO NUSBIO.
        ///
        /// THE FUNCTION AmpTest() WILL LIGHT UP THE FIRST LED OF THE STRIP AT MAXIMUM BRIGHTNESS.
        /// USE A MULTI METER TO WATCH THE AMP COMSUMPTION.
        ///
        /// IF YOU WANT TO POWER MORE THAN 5 LEDS, THERE ARE 2 SOLUTIONS:
        ///
        /// (1) ONLY FOR 6 to 10 LEDs. ADD BETWEEN NUSBIO VCC AND THE STRIP 5V PIN A 47 OHM RESISTORS.
        /// YOU WILL LOOSE SOME BRIGTHNESS, BUT IT IS SIMPLER. THE RESISTOR LIMIT THE CURRENT THAT
        /// CAN BE USED FROM THE USB.
        ///
        /// (2) USE A SECOND SOURCE OF POWER LIKE:
        ///
        ///  - A 5 VOLTS 1 AMPS ADAPTERS TO POWER A 30 LED STRIP
        ///  - A 5 VOLTS 2 AMPS ADAPTERS TO POWER A 60 LED STRIP
        ///
        /// ~~~ ATTENTION ~~~
        ///
        ///     WHEN USING A SECOND SOURCE OF POWER IN THE SAME BREADBOARD OR PCB, ~ NEVER ~
        ///     CONNECT THE POSISTIVE OF THE SECOND SOURCE OF POWER WITH THE NUSBIO VCC.
        ///
        /// SEE OUR WEB SITE 'LED STRIP TUTORIAL' FOR MORE INFO.
        ///
        /// </summary>
        /// <param name="ledStrip"></param>
        public static void AmpTest(APA102LEDStrip ledStrip)
        {
            int wait          = 37;
            var brightness    = 1;
            var maxBrightness = APA102LEDStrip.MAX_BRIGHTNESS / 2; // 7
            var quit          = false;

            ledStrip.AllOff();

            while (!quit)
            {
                Console.Clear();
                ConsoleEx.TitleBar(0, "Amp Consumption Test ");
                ConsoleEx.WriteMenu(-1, 2, string.Format("Brigthness:{0}  I)ncrease  D)ecrease", brightness));
                ConsoleEx.WriteMenu(-1, 3, "Q)uit");

                ledStrip.Reset();
                ledStrip.AddRGBSequence(true, brightness, ledStrip.MaxLed, Color.White);
                ledStrip.Show();

                var k = Console.ReadKey().Key;
                switch (k)
                {
                case ConsoleKey.Q: quit = true; break;

                case ConsoleKey.I:
                    brightness++;
                    if (brightness > maxBrightness)
                    {
                        brightness = maxBrightness;
                    }
                    break;

                case ConsoleKey.D:
                    brightness--;
                    if (brightness < 0)
                    {
                        brightness = 0;
                    }
                    break;
                }
            }
            ledStrip.AllOff();
        }
Example #26
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();
        }
Example #27
0
        static APA102LEDStrip.Extensions.LedPerMeter AskForStripType()
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            var r = ConsoleEx.Question(ConsoleEx.WindowHeight - 3, "Strip Type?    3)0 LED/Meter   6)0 LED/Meter  I) do not know", new List <Char>()
            {
                '3', '6', 'I'
            });

            switch (r)
            {
            case '3': return(APA102LEDStrip.Extensions.LedPerMeter._30LedPerMeter);

            case '6': return(APA102LEDStrip.Extensions.LedPerMeter._60LedPerMeter);
            }
            return(APA102LEDStrip.Extensions.LedPerMeter._30LedPerMeter);
        }
Example #28
0
        static int AskForLedCount()
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
            var r = ConsoleEx.Question(ConsoleEx.WindowHeight - 3, "Led Count?    1)0  3)0  6)0", new List <Char>()
            {
                '3', '6', '1'
            });

            switch (r)
            {
            case '1': return(10);

            case '3': return(30);

            case '6': return(60);
            }
            return(10);
        }
Example #29
0
        public static void ColorsSequence(APA102LEDStrip ledStripe0, APA102LEDStrip ledStripe1)
        {
            var wait = 300;
            var quit = false;

            ledStripe0.Brightness = 7;
            ledStripe0.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Color Sequence Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            var bkColors = TargetColors.Replace(Environment.NewLine, ",").Split(',').ToList();

            while (!quit)
            {
                foreach (var sBColor in bkColors)
                {
                    if (string.IsNullOrEmpty(sBColor.Trim()))
                    {
                        continue;
                    }

                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];
                    ConsoleEx.Gotoxy(1, 2);
                    ConsoleEx.WriteLine(string.Format("Background Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);

                    ledStripe0.Reset().AddRGBSequence(true, ledStripe0.Brightness, ledStripe0.MaxLed, bkColor).Show();
                    ledStripe1.Reset().AddRGBSequence(true, ledStripe1.Brightness, ledStripe0.MaxLed, bkColor).Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStripe0.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Example #30
0
        static bool FormatAndInitDisk()
        {
            var ok = false;

            Console.Clear();
            ConsoleEx.TitleBar(0, "Format and initialization", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            var keyInfo = ConsoleEx.Question(3, "Format and initialize disk Y)es N)o", new List <char> {
                'Y', 'N'
            });

            if (keyInfo == 'N')
            {
                return(ok);
            }

            ConsoleEx.WriteLine(0, 4, "Formatting...", ConsoleColor.Yellow);
            if (!_sfsManager.Format())
            {
                ConsoleEx.WriteLine(0, 3, "Format failed", ConsoleColor.Red);
                return(false);
            }

            ConsoleEx.WriteLine(0, 5, "Loading and saving files...", ConsoleColor.Yellow);
            _sfsManager.AddFile(@".\files\Readme.txt");
            _sfsManager.AddFile(@".\files\Shadow.jpg");
            var rr = _sfsManager.UpdateFileSystem();

            if (rr)
            {
                Console.WriteLine(string.Format("Keys were generated"), ConsoleColor.Cyan);
                ok = ReloadFileSystem();
            }
            else
            {
                Console.WriteLine(string.Format("Error generating the keys"), ConsoleColor.Red);
            }

            Pause();
            return(ok);
        }