Beispiel #1
0
        private static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: led-matrix-weather <openweathermap.org API key>");
                Console.WriteLine();
                Console.WriteLine("If wrong key is used or there is no network connection");
                Console.WriteLine("example data will be displayed.");
                Console.WriteLine();
                Console.WriteLine("For the first 30 seconds of execution");
                Console.WriteLine("IP addresses will be displayed instead of data.");
                return;
            }

            s_client = new Weather(args[0]);

            UpdateWeather();
            Task.Run(WeatherUpdater);
            Task.Run(IpsGetter);

            PinMapping   mapping = PinMapping.MatrixBonnetMapping32;
            RGBLedMatrix matrix  = new RGBLedMatrix(mapping, 64, 64, 2, 2);

            Task drawing = Task.Run(() =>
            {
                matrix.StartRendering();

                while (s_scenario is object)
                {
                    Action <RGBLedMatrix> scenario = s_scenario;

                    Stopwatch sw = Stopwatch.StartNew();
                    scenario(matrix);

                    if (sw.ElapsedMilliseconds < 100)
                    {
                        Debug.WriteLine("Scenario execution finished in less than 100ms. This is likely due to bug.");
                    }
                }
            });

            try
            {
                if (!Console.IsOutputRedirected)
                {
                    while (s_scenario is object && Console.ReadKey(intercept: true).Key != ConsoleKey.Q)
                    {
                        Thread.Sleep(10);
                    }

                    s_scenario = null;
                }

                drawing.Wait();
            }
            finally
            {
                matrix.Dispose();
            }
        }
Beispiel #2
0
        private void ArduinoSetup()
        {
            ledON = false;
            toggleLED.BackColor = Color.Red;

            serialPort = new ArduinoSerialPort("COM5", 115200);
            serialPort.Open();

            cwAnalogPinMapping  = new PinMapping(11);
            ccwAnalogPinMapping = new PinMapping(10);
            pinMapping          = new PinMapping(13);
            eStop = new PinMapping(8);
            serialPort.ComponentMappings.Add(cwAnalogPinMapping);
            serialPort.ComponentMappings.Add(ccwAnalogPinMapping);
            serialPort.ComponentMappings.Add(pinMapping);
            serialPort.ComponentMappings.Add(eStop);
            cwAnalogPinMapping.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            cwAnalogPinMapping.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            pinMapping.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            eStop.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            pinMapping.FeedbackEvent += new SkynetUtilities.FeedbackRecievedEventHandler(ResponsePackageRecieved);

            this.replyPackageTextBox.Text = "0";

            eStop.SetPin(true);
            stopped = false;
        }
Beispiel #3
0
        public void InitializeArduino()
        {
            serialPort = new ArduinoSerialPort("COM5", 115200);
            serialPort.Open();

            cwAnalogPinMapping  = new PinMapping(11);
            ccwAnalogPinMapping = new PinMapping(10);
            eStop = new PinMapping(8);
            serialPort.ComponentMappings.Add(cwAnalogPinMapping);
            serialPort.ComponentMappings.Add(ccwAnalogPinMapping);
            serialPort.ComponentMappings.Add(eStop);
            cwAnalogPinMapping.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            cwAnalogPinMapping.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            eStop.SetPinMode(SetPinModeStateCodes.OutputStateCode);
            eStop.SetPin(true);
        }
Beispiel #4
0
        /// <summary>
        /// Initialize a new Sn74hc595 device connected through GPIO (uses 3-5 pins)
        /// </summary>
        /// <param name="pinMapping">The pin mapping to use by the binding.</param>
        /// <param name="gpioController">The GPIO Controller used for interrupt handling.</param>
        /// <param name="shouldDispose">True (the default) if the GPIO controller shall be disposed when disposing this instance.</param>
        /// <param name="deviceCount">Count of (daisy-chained) shift registers. Default/minimum is 1.</param>
        public Sn74hc595(PinMapping pinMapping, GpioController gpioController = null, bool shouldDispose = true, int deviceCount = 1)
        {
            pinMapping.Validate();
            if (gpioController == null)
            {
                gpioController = new GpioController();
            }

            _controller    = gpioController;
            _shouldDispose = shouldDispose;
            _pinMapping    = pinMapping;
            _data          = _pinMapping.Data;
            _srclk         = _pinMapping.SrClk;
            _rclk          = _pinMapping.RClk;
            _deviceCount   = deviceCount;
            SetupPins();
        }
Beispiel #5
0
 /// <summary>
 /// Initialize a new Sn74hc595 device connected through both SPI and GPIO (SPI for writing data; GPIO for configuration; use 4-5 pins)
 /// </summary>
 /// <param name="spiDevice">SpiDevice used for serial communication.</param>
 /// <param name="pinMapping">The pin mapping to use by the binding</param>
 /// <param name="gpioController">The GPIO Controller used for interrupt handling</param>
 /// <param name="shouldDispose">True (the default) if the GPIO controller shall be disposed when disposing this instance</param>
 /// <param name="deviceCount">Count of (daisy-chained) shift registers. Default/minimum is 1.</param>
 public Sn74hc595(SpiDevice spiDevice, PinMapping pinMapping, GpioController gpioController = null, bool shouldDispose = true, int deviceCount = 1)
     : this(pinMapping, gpioController, shouldDispose, deviceCount)
 {
     _spiDevice = spiDevice;
 }
Beispiel #6
0
        private static void Main(string[] args)
        {
            Console.WriteLine($"Hello Matrix World!");

            // If using 64x64 with Bonnet (https://www.adafruit.com/product/3211), you can just do
            // PinMapping mapping = PinMapping.MatrixBonnetMapping64;

            // If using 32x32 with Bonnet (https://www.adafruit.com/product/3211), you can just do
            PinMapping mapping = PinMapping.MatrixBonnetMapping32;

            // If not using Bonnet, will need to provide the manual GPIO mapping using PinMapping

            // To create RGBLedMatrix for 32x32 panel, do the following
            RGBLedMatrix matrix = new RGBLedMatrix(mapping, 32, 32);

            // To create RGBLedMatrix for 64x64 panel, do the following
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 64, 64);

            // PinMapping mapping = PinMapping.MatrixBonnetMapping64;
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 64, 64);

            // If you chain 4 32x32 panels serially, you can do
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 128, 32);

            // If you chain 4 32x32 panels having 2 rows chaining (2 panels in first row an d2 panels in second row).
            // RGBLedMatrix matrix = new RGBLedMatrix(mapping, 64, 64, 2, 2);

            Task.Run(() =>
            {
                matrix.StartRendering();

                while (scenario != 0)
                {
                    switch (scenario)
                    {
                    case 1: Demo1(matrix); break;

                    case 2: Demo2(matrix); break;

                    case 3: Demo3(matrix); break;

                    case 4: Demo4(matrix); break;

                    case 5: Demo5(matrix); break;

                    case 6: Demo6(matrix); break;

                    case 7: Demo7(matrix); break;

                    case 8: Demo8(matrix); break;

                    default:
                        scenario = 2;
                        break;
                    }
                }
            });

            ConsoleKeyInfo cki;

            Console.WriteLine($"Press q to exit.");
            System.Interop.ThreadHelper.SetCurrentThreadHighPriority();

            do
            {
                cki = Console.ReadKey();

                if (cki.KeyChar == '+')
                {
                    matrix.PWMDuration = matrix.PWMDuration + 100;
                    Console.WriteLine($"     ({matrix.PWMDuration})");
                }

                if (cki.KeyChar == '-')
                {
                    matrix.PWMDuration = matrix.PWMDuration - 100;
                    Console.WriteLine($"     ({matrix.PWMDuration})");
                }

                if (cki.KeyChar == 'f')
                {
                    Console.WriteLine($"Frame Time: {matrix.FrameTime} \u00B5s");
                    Console.WriteLine($"Duration : { matrix.PWMDuration }");
                }

                if (cki.KeyChar >= '1' && cki.KeyChar <= '9')
                {
                    play     = false;
                    scenario = cki.KeyChar - '0';
                    Thread.Sleep(1000);
                }
            } while (cki.KeyChar != 'q');

            play     = false;
            scenario = 0;
            Thread.Sleep(1000);
            matrix.Dispose();
        }
Beispiel #7
0
        public void ComputePinMapping()
        {
            this.pinMap.Clear();

            List <string> bankA = new List <string>();

            for (int i = 0; i < 16; i++)
            {
                bankA.Add(this.GPIONames[i].Name);
            }

            List <string> bankB = new List <string>();

            for (int i = 16; i < 32; i++)
            {
                bankB.Add(this.GPIONames[i].Name);
            }

            foreach (BoardInfo plank in this.planks)
            {
                if (!plank.IsConfigured)
                {
                    continue;
                }

                List <int> usedPins = new List <int>();
                plank.PinMap.Clear();
                for (int i = 0; i < plank.GPIONames.Count; i++)
                {
                    if (plank.GPIONames[i].Name != "")
                    {
                        string lokiPin;
                        if (i < 16 && i < bankA.Count)
                        {
                            lokiPin = bankA[i];
                        }
                        else if (i < 32 && i - 16 < bankB.Count)
                        {
                            lokiPin = bankB[i - 16];
                        }
                        else
                        {
                            lokiPin = "N/C";
                        }
                        usedPins.Add(i);

                        PinMapping mapping = new PinMapping(lokiPin, plank, plank.GPIONames[i].Name, plank.GPIONames[i].Type);
                        plank.PinMap.Add(mapping);
                        this.pinMap.Add(mapping);
                    }
                }

                // Delete used pins
                for (int i = plank.GPIONames.Count - 1; i >= 0; i--)
                {
                    if (usedPins.Contains(i))
                    {
                        if (i < bankA.Count)
                        {
                            bankA.RemoveAt(i);
                        }
                        else if (i >= 16 && i - 16 < bankB.Count)
                        {
                            bankB.RemoveAt(i - 16);
                        }
                    }
                }
            }
        }
Beispiel #8
0
        public void ComputePinMapping()
        {
            this.pinMap.Clear();

            List<string> bankA = new List<string>();
            for (int i = 0; i < 16; i++)
                bankA.Add(this.GPIONames[i].Name);

            List<string> bankB = new List<string>();
            for (int i = 16; i < 32; i++)
                bankB.Add(this.GPIONames[i].Name);

            foreach (BoardInfo plank in this.planks)
            {
                if (!plank.IsConfigured)
                    continue;

                List<int> usedPins = new List<int>();
                plank.PinMap.Clear();
                for (int i = 0; i < plank.GPIONames.Count; i++)
                {
                    if (plank.GPIONames[i].Name != "")
                    {
                        string lokiPin;
                        if (i < 16 && i < bankA.Count)
                        {
                            lokiPin = bankA[i];
                        }
                        else if (i < 32 && i - 16 < bankB.Count)
                        {
                            lokiPin = bankB[i - 16];
                        }
                        else
                        {
                            lokiPin = "N/C";
                        }
                        usedPins.Add(i);

                        PinMapping mapping = new PinMapping(lokiPin, plank, plank.GPIONames[i].Name, plank.GPIONames[i].Type);
                        plank.PinMap.Add(mapping);
                        this.pinMap.Add(mapping);
                    }
                }

                // Delete used pins
                for (int i = plank.GPIONames.Count - 1; i >= 0; i--)
                {
                    if (usedPins.Contains(i))
                    {
                        if (i < bankA.Count)
                        {
                            bankA.RemoveAt(i);
                        }
                        else if (i >= 16 && i - 16 < bankB.Count)
                        {
                            bankB.RemoveAt(i - 16);
                        }
                    }
                }
            }
        }