Beispiel #1
0
        public WiiNunchuk(I2C i2c)
        {
            dev = new SMBusDevice(0x52, i2c);
            dev.WriteDataAsync(new byte[] { 0xF0, 0x55 }).Wait();
            dev.WriteDataAsync(new byte[] { 0xFB, 0x00 }).Wait();

            C = new Button(new DigitalInPeripheralPin(this), false);
            Z = new Button(new DigitalInPeripheralPin(this), false);
        }
Beispiel #2
0
        /// <summary>
        ///     Flush the output data to the port expander
        /// </summary>
        /// <param name="force">Whether to force a full update, even if data doesn't appear to have changed.</param>
        /// <returns>An awaitable task that completes when finished</returns>
        public override async Task FlushAsync(bool force = false)
        {
            newValues = new byte[numBytes];
            for (var i = 0; i < Pins.Count; i++)
            {
                // recall that we make a pin a digital input by setting it high and reading from it
                if (Pins[i].DigitalValue || Pins[i].Mode == PortExpanderPinMode.DigitalInput)
                {
                    newValues[i / 8] |= (byte)(1 << (i % 8));
                }
                else
                {
                    newValues[i / 8] &= (byte)~(1 << (i % 8));
                }
            }

            var shouldResend = false;

            for (var i = 0; i < oldValues.Length; i++)
            {
                if (oldValues[i] != newValues[i])
                {
                    shouldResend = true;
                }
            }

            if (shouldResend || force)
            {
                newValues.CopyTo(oldValues, 0);

                await dev.WriteDataAsync(newValues).ConfigureAwait(false);
            }
        }
        public WiiClassicController(I2C i2c)
        {
            dev = new SMBusDevice(0x52, i2c);
            dev.WriteDataAsync(new byte[] { 0xF0, 0x55 }).Wait();
            dev.WriteDataAsync(new byte[] { 0xFB, 0x00 }).Wait();

            L     = new Button(new DigitalInPeripheralPin(this), false);
            R     = new Button(new DigitalInPeripheralPin(this), false);
            ZL    = new Button(new DigitalInPeripheralPin(this), false);
            ZR    = new Button(new DigitalInPeripheralPin(this), false);
            Home  = new Button(new DigitalInPeripheralPin(this), false);
            Plus  = new Button(new DigitalInPeripheralPin(this), false);
            Minus = new Button(new DigitalInPeripheralPin(this), false);
            A     = new Button(new DigitalInPeripheralPin(this), false);
            B     = new Button(new DigitalInPeripheralPin(this), false);
            X     = new Button(new DigitalInPeripheralPin(this), false);
            Y     = new Button(new DigitalInPeripheralPin(this), false);
        }
Beispiel #4
0
        private Task sendCommand(byte cmd)
        {
            var dat = new byte[] { 0x00, cmd };

            return(dev.WriteDataAsync(dat));
        }