public void SendPacket(int bank, CommandPacket commandPacket)
        {
            IOutputPort dataPort;
            switch (bank)
            {
                case 0:
                    dataPort = _portLayout.BankOneDataPort;
                    break;
                case 1:
                    dataPort = _portLayout.BankTwoDataPort;
                    break;
                default:
                    throw new Exception("invalid bank");
            }

            ulong command = commandPacket.GetCommand();

            ShiftOut(dataPort, _portLayout.ClockPort, BitOrder.MSBFirst, ((byte)(command >> 24)));
            ShiftOut(dataPort, _portLayout.ClockPort, BitOrder.MSBFirst, ((byte)(command >> 16)));
            ShiftOut(dataPort, _portLayout.ClockPort, BitOrder.MSBFirst, ((byte)(command >> 8)));
            ShiftOut(dataPort, _portLayout.ClockPort, BitOrder.MSBFirst, ((byte)command));

            _logger.Log("Shifted command packet:");
            _logger.Log(command.ToString()); //maybe?
        }
        public void RedValuePlacedCorrectly()
        {
            var packet = new CommandPacket {RedCommand = 1023};

            var command = packet.GetCommand();

            Assert.AreEqual("11111111110000000000", Convert.ToString(command, 2));
        }
        public void DefaultConstructorHasAllFieldsZero()
        {
            var packet = new CommandPacket();

            Assert.AreEqual(packet.CommandMode, 0);
            Assert.AreEqual(packet.RedCommand, 0);
            Assert.AreEqual(packet.GreenCommand, 0);
            Assert.AreEqual(packet.BlueCommand, 0);
        }
        private CommandPacket CreateControlPacket()
        {
            var packet = new CommandPacket
            {
                CommandMode = 00, //write to voltage (current) control registers
                RedCommand = 127,
                GreenCommand = 127,
                BlueCommand = 127
            };

            return packet;
        }
        private CommandPacket CreateColorPacket(int bank, int r, int g, int b)
        {
            var packet = new CommandPacket
            {
                CommandMode = 00, //write to PWM control registers
                RedCommand = r,
                GreenCommand = g,
                BlueCommand = b
            };

            return packet;
        }
        public void PushArrayToDisplay()
        {
            //for jagged arrays, we could pad with dummy packets on the end to even out the array into a square

            for (int channel = 0; channel < NumChannels; channel++)
            {
                var colorPackets = new CommandPacket[NumBanks];
                var controlPackets = new CommandPacket[NumBanks];

                for (int bank = 0; bank < NumBanks; bank++)
                {
                    colorPackets[bank] = CreateColorPacket(bank, _rgbArray[bank][channel][0], _rgbArray[bank][channel][1], _rgbArray[bank][channel][2]);
                    controlPackets[bank] = CreateControlPacket();
                }
                _portManager.SendPacketArray(colorPackets);
            }

            _portManager.Latch();

            //_portManager.SendPacketArray(controlPackets);
            //_portManager.Latch();
        }