コード例 #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);
        }
コード例 #2
0
ファイル: Demo.cs プロジェクト: jbukys/Nusbio.Samples
        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;
        }
コード例 #3
0
ファイル: Demo.cs プロジェクト: jbukys/Nusbio.Samples
        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;
                    }
                }
            }
        }
コード例 #4
0
ファイル: Demo.cs プロジェクト: jbukys/Nusbio.Samples
        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;
                    }
                }
            }
        }
コード例 #5
0
        public static void BrigthnessDemo(APA102LEDStrip ledStrip)
        {
            int maxBrightness = APA102LEDStrip.MAX_BRIGHTNESS / 2;
            int wait          = GetWaitTimeUnit(ledStrip) / 2;
            int step          = 1;

            ledStrip.AllOff();
            Console.Clear();
            ConsoleEx.WriteMenu(-1, 3, "Q)uit");
            while (!Console.KeyAvailable)
            {
                for (var b = 1; b <= maxBrightness; b += step)
                {
                    ledStrip.Reset();
                    for (var l = 0; l < ledStrip.MaxLed; l++)
                    {
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Red, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Green, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Blue, b);
                        }
                    }
                    ConsoleEx.Write(0, 0, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                    ledStrip.Show().Wait(wait);
                }
                ledStrip.Wait(wait * 10);
                for (var b = maxBrightness; b >= 1; b -= step)
                {
                    ledStrip.Reset();
                    for (var l = 0; l < ledStrip.MaxLed; l++)
                    {
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Red, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Green, b);
                        }
                        if (!ledStrip.IsFull)
                        {
                            ledStrip.AddRGB(Color.Blue, b);
                        }
                    }
                    ConsoleEx.Write(0, 0, string.Format("Brightness {0:00}", b), ConsoleColor.DarkCyan);
                    ledStrip.Show().Wait(wait);
                }
                //ledStrip.AllOff();
                ledStrip.Wait(wait * 10);
                if (Console.KeyAvailable)
                {
                    break;
                }
            }
            ledStrip.AllOff();
            var k = Console.ReadKey(true).Key;
        }
コード例 #6
0
ファイル: Demo.cs プロジェクト: jbukys/Nusbio.Samples
        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;
                    }
                }
            }
        }
コード例 #7
0
ファイル: Demo.cs プロジェクト: jbukys/Nusbio.Samples
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

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

            var  sclPin            = NusbioGpio.Gpio0; // White
            var  sdaPin            = NusbioGpio.Gpio1; // Green
            byte MCP23008_I2C_ADDR = 0x20;             // Microship MCP 23008 = 8 gpios

            // Gpio 0 and 1 are reserved for I2C Bus
            var standardOutputGpios = new List <NusbioGpio>()
            {
                NusbioGpio.Gpio2,
                NusbioGpio.Gpio3,
                NusbioGpio.Gpio4,
                NusbioGpio.Gpio5,
                NusbioGpio.Gpio6,
                NusbioGpio.Gpio7
            };
            var extendedOutputGpios = new List <string>()
            {
                NusbioGpioEx.Gpio8,
                NusbioGpioEx.Gpio9,
                NusbioGpioEx.Gpio10,
                NusbioGpioEx.Gpio11,
                NusbioGpioEx.Gpio12,
                NusbioGpioEx.Gpio13,
                NusbioGpioEx.Gpio14,
#if !GPIO_15_AS_INPUT
                NusbioGpioEx.Gpio15, // Configured as input
#endif
            };

            using (var nusbio = new Nusbio(serialNumber)) // ,
            {
                _mcp = new MCP23008(nusbio, sdaPin, sclPin);
                _mcp.Begin(MCP23008_I2C_ADDR);

                Cls(nusbio);

                #if GPIO_15_AS_INPUT
                var inputGpio = NusbioGpioEx.Gpio15;
                _mcp.SetPinMode(inputGpio, PinMode.InputPullUp);
                #endif

                while (nusbio.Loop())
                {
                    #if GPIO_15_AS_INPUT
                    if (_mcp.GPIOS[inputGpio].DigitalRead() == PinState.High)
                    {
                        ConsoleEx.Write(0, 2, string.Format("[{0}] Button Down", DateTime.Now), ConsoleColor.Cyan);
                    }
                    else
                    {
                        ConsoleEx.Write(0, 2, string.Format("[{0}] Button Up     ", DateTime.Now), ConsoleColor.Cyan);
                    }
                    #endif

                    foreach (var eg in extendedOutputGpios)
                    {
                        _mcp.GPIOS[eg].State = !_mcp.GPIOS[eg].State;
                        _mcp.GPIOS[eg].DigitalWrite(_mcp.GPIOS[eg].State);
                    }
                    //foreach (var sg in standardOutputGpios)
                    //{
                    //    nusbio.GPIOS[sg].State = !nusbio.GPIOS[sg].State;
                    //    nusbio.GPIOS[sg].DigitalWrite(nusbio.GPIOS[sg].State);
                    //}
                    TimePeriod.Sleep(500);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.A)
                        {
                            Cls(nusbio);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            _mcp.AllOff();
                            break;
                        }
                    }
                }
            }
            Console.Clear();
        }