コード例 #1
0
        internal Gpio(PinMapping mapping, int rows)
        {
            AMask = 1U << mapping.A;
            BMask = 1U << mapping.B;
            CMask = 1U << mapping.C;

            ABCDEMask = AMask | BMask | CMask;

            if (rows > 16)
            {
                DMask      = 1U << mapping.D;
                ABCDEMask |= DMask;
            }

            if (rows > 32)
            {
                EMask      = 1U << mapping.E;
                ABCDEMask |= EMask;
            }

            OEMask    = 1U << mapping.OE;
            ClockMask = 1U << mapping.Clock;
            LatchMask = 1U << mapping.Latch;

            R1Mask = 1U << mapping.R1;
            G1Mask = 1U << mapping.G1;
            B1Mask = 1U << mapping.B1;
            R2Mask = 1U << mapping.R2;
            G2Mask = 1U << mapping.G2;
            B2Mask = 1U << mapping.B2;

            AllColorsMask = R1Mask | G1Mask | B1Mask | R2Mask | G2Mask | B2Mask;
        }
コード例 #2
0
        private int _chainColumns;           // how many matrices in one row of the chaining.

        /// <summary>
        /// Construct a new RGBLedMatrix object
        /// </summary>
        /// <param name="mapping">The Gpio pin mapping</param>
        /// <param name="width">The width in pixels of the matrix display area</param>
        /// <param name="height">The height in pixels of the matrix display area</param>
        /// <param name="chainRows">Number of the matrices rows in the chain</param>
        /// <param name="chainColumns">Number of the matrices columns in the chain</param>
        public RGBLedMatrix(PinMapping mapping, int width, int height, int chainRows = 1, int chainColumns = 1)
        {
            _chainRows    = chainRows;
            _chainColumns = chainColumns;

            _mapping = mapping;

            if (width < 8 || height < 8 || height % chainRows != 0)
            {
                throw new ArgumentException("Invalid rows or width values");
            }

            _deviceRows = height / chainRows;

            _gpio       = new Gpio(mapping, _deviceRows);
            _controller = new GpioController(PinNumberingScheme.Logical, _gpio);

            OpenAndWriteToPin(_mapping.A, PinValue.Low);
            OpenAndWriteToPin(_mapping.B, PinValue.Low);
            OpenAndWriteToPin(_mapping.C, PinValue.Low);

            if (_deviceRows > 16)
            {
                OpenAndWriteToPin(_mapping.D, PinValue.Low);
            }

            if (_deviceRows > 32)
            {
                _duration = (long)((double)Stopwatch.Frequency * 400 / 1E9);
                OpenAndWriteToPin(_mapping.E, PinValue.Low);
            }

            _fullChainWidth = width * chainRows;

            if (_fullChainWidth > 32)
            {
                _duration = (long)((double)Stopwatch.Frequency * 400 / 1E9);
            }

            // OE set High means disable output (confusing)
            OpenAndWriteToPin(_mapping.OE, PinValue.High);
            OpenAndWriteToPin(_mapping.Clock, PinValue.Low);
            OpenAndWriteToPin(_mapping.Latch, PinValue.Low);

            OpenAndWriteToPin(_mapping.R1, PinValue.Low);
            OpenAndWriteToPin(_mapping.G1, PinValue.Low);
            OpenAndWriteToPin(_mapping.B1, PinValue.Low);
            OpenAndWriteToPin(_mapping.R2, PinValue.Low);
            OpenAndWriteToPin(_mapping.G2, PinValue.Low);
            OpenAndWriteToPin(_mapping.B2, PinValue.Low);

            _rowSetMasks = new ulong[_deviceRows >> 1];

            for (int i = 1; i < _deviceRows >> 1; i++)
            {
                if ((i & 1) != 0)
                {
                    _rowSetMasks[i] |= _gpio.AMask;
                }

                if ((i & 2) != 0)
                {
                    _rowSetMasks[i] |= _gpio.BMask;
                }

                if ((i & 4) != 0)
                {
                    _rowSetMasks[i] |= _gpio.CMask;
                }

                if ((i & 8) != 0)
                {
                    _rowSetMasks[i] |= _gpio.DMask;
                }

                if ((i & 0x10) != 0)
                {
                    _rowSetMasks[i] |= _gpio.EMask;
                }
            }

            _colorsMake = new ulong[16]; // 8 for RGB1 and 8 for RGB2
            for (int i = 1; i < 8; i++)
            {
                if ((i & 1) != 0)
                {
                    _colorsMake[i]     |= _gpio.R1Mask;
                    _colorsMake[i + 8] |= _gpio.R2Mask;
                }

                if ((i & 2) != 0)
                {
                    _colorsMake[i]     |= _gpio.G1Mask;
                    _colorsMake[i + 8] |= _gpio.G2Mask;
                }

                if ((i & 4) != 0)
                {
                    _colorsMake[i]     |= _gpio.B1Mask;
                    _colorsMake[i + 8] |= _gpio.B2Mask;
                }
            }

            _colorsBuffer     = new byte[8 * _fullChainWidth * (_deviceRows >> 1)];
            _colorsBackBuffer = new byte[8 * _fullChainWidth * (_deviceRows >> 1)];

            _width = width;
            _rows  = height;

            _safeToDispose         = true;
            _swapRequested         = false;
            _startMeasureFrameTime = true;
        }