internal override void SetGlobalBrightness(double brightness) { if (brightness > 0) { dev.WriteByteAsync((byte)((byte)Commands.Brightness | ((int)Math.Round(brightness * 16) - 1))).Wait(); dev.WriteByteAsync((byte)Commands.Blink | 0x01).Wait(); } else { dev.WriteByteAsync((byte)Commands.Blink | 0x00).Wait(); } }
/// <summary> /// Construct a new HT16K33 16x8 LED driver /// </summary> /// <param name="i2c">The I2c port to use with this display.</param> /// <param name="address">The 7-bit I2c address to use</param> /// <param name="package">Which package is used</param> public Ht16k33(I2C i2c, byte address, Package package) : base((int)package, true, false) { dev = new SMBusDevice(address, i2c); dev.WriteByteAsync(0x21); Brightness = 1.0; this.package = package; }
public async Task UpdateAsync() { await dev.WriteByteAsync(0x00).ConfigureAwait(false); var response = await dev.ReadDataAsync(6).ConfigureAwait(false); var lx = (response[0] & 0x3F) - 32; var ly = (response[1] & 0x3F) - 32; var rx = (response[2] >> 7) | ((response[1] & 0xC0) >> 5) | (((response[0] & 0xC0) >> 3) - 16); var ry = (response[2] & 0x1F) - 16; leftStick.X = lx > 0 ? lx / 31f : lx / 32f; leftStick.Y = ly > 0 ? ly / 31f : ly / 32f; rightStick.X = rx > 0 ? rx / 15f : rx / 16f; rightStick.Y = ry > 0 ? ry / 15f : ry / 16f; var lt = ((response[2] & 0x60) >> 2) | (response[3] >> 5); var rt = response[3] & 0x1F; leftTriggerForce = lt / 31f; rightTriggerForce = rt / 31f; var array = new BitArray(response.Skip(4).Take(2).ToArray()); ((DigitalInPeripheralPin)R.Input).DigitalValue = !array[1]; ((DigitalInPeripheralPin)Plus.Input).DigitalValue = !array[2]; ((DigitalInPeripheralPin)Home.Input).DigitalValue = !array[3]; ((DigitalInPeripheralPin)Minus.Input).DigitalValue = !array[4]; ((DigitalInPeripheralPin)L.Input).DigitalValue = !array[5]; // D-Pad stuff var temp = dPad; if (!array[6]) { dPad = DPadState.Down; } else if (!array[7]) { dPad = DPadState.Right; } else if (!array[8]) { dPad = DPadState.Up; } else if (!array[9]) { dPad = DPadState.Left; } else { dPad = DPadState.None; } if (temp != dPad) { DPadStateChanged?.Invoke(this, new DPadStateEventArgs { NewValue = dPad }); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DPad))); } ((DigitalInPeripheralPin)ZR.Input).DigitalValue = !array[10]; ((DigitalInPeripheralPin)X.Input).DigitalValue = !array[11]; ((DigitalInPeripheralPin)A.Input).DigitalValue = !array[12]; ((DigitalInPeripheralPin)Y.Input).DigitalValue = !array[13]; ((DigitalInPeripheralPin)B.Input).DigitalValue = !array[14]; ((DigitalInPeripheralPin)ZL.Input).DigitalValue = !array[15]; }
public Bh1750(I2C i2c, bool addressPin = false, int rate = 100) { this.dev = new SMBusDevice((byte)(addressPin ? 0x5C : 0x23), i2c, rate); Task.Run(() => dev.WriteByteAsync(0x07)).Wait(); // reset Resolution = LuxResolution.High; }
/// <summary> /// Reset to default /// </summary> /// <returns>An awaitable task that completes when finished</returns> public Task ResetToDefault() { return(dev.WriteByteAsync((byte)Command.ResetToDefault)); }