Example #1
0
        public void Parse(string[] str)
        {
            // Parse packet type
            _packetType = (PacketType)Enum.Parse(typeof(PacketType), str[0]);

            // Parse buttons, accepting empty strings as None
            if (_packetType == PacketType.Extension21 || string.IsNullOrWhiteSpace(str[1]))
            {
                _buttons = WiiMoteButtons.None;
            }
            else
            {
                _buttons = (WiiMoteButtons)Enum.Parse(typeof(WiiMoteButtons), str[1]);
            }

            // Parse rest of data
            _data = HexString.Parse(str[2]);
        }
Example #2
0
        public WiiMoteFrame(BinaryReader stream)
        {
            // We can skip length, as this is implicit
            stream.ReadByte();

            if (stream.ReadByte() != 0xA1)
            {
                throw new Exception("Input stream signature does not match.");
            }

            _packetType = (PacketType)stream.ReadByte();

            if (_packetType != PacketType.Extension21)
            {
                _buttons = (WiiMoteButtons)stream.ReadUInt16();
            }

            _data = stream.ReadBytes(GetDataSize(_packetType));
        }