private void updateConfig() { // sleep the chip dev.WriteByteDataAsync((byte)Registers.Mode1, 0x10).Wait(); // do the updates var mode1 = (byte)(0x30 | ((UseExternalClock ? 1 : 0) << 6)); dev.WriteByteDataAsync((byte)Registers.Mode1, mode1).Wait(); var mode2 = (byte)(((int)OutputDrive << 2) | ((InvertOutput ? 1 : 0) << 4)); dev.WriteByteDataAsync((byte)Registers.Mode2, mode2).Wait(); //int prescaler = (int)Math.Round((25000000 / (4096 * frequency * 0.8963)) - 1); var prescaler = (int)Math.Round(6809.68 / frequency - 1.1157); // weird overshoot issue if (prescaler > 255) { Debug.WriteLine("NOTICE: PCA9685 frequency out of range. Clipping to 24 Hz"); prescaler = 255; } dev.WriteByteDataAsync((byte)Registers.Prescale, (byte)prescaler).Wait(); // wake up mode1 &= 0xEF; // clear the sleep flag dev.WriteByteDataAsync((byte)Registers.Mode1, mode1).Wait(); FlushAsync(true).Wait(); // we have to rewrite the PWM values (why?) }
/// <summary> /// Construct a new HMC5883L connected to the specified <see cref="I2C" /> port. /// </summary> /// <param name="i2c">The I2C port to use</param> /// <param name="rateKHz">The frequency, in kHz, to use.</param> public Hmc5883l(I2C i2c, int rateKHz = 100) { dev = new SMBusDevice(0x1E, i2c, rateKHz); var idA = dev.ReadByteDataAsync((byte)Registers.IdA).Result; var idB = dev.ReadByteDataAsync((byte)Registers.IdB).Result; var idC = dev.ReadByteDataAsync((byte)Registers.IdC).Result; if (idA != 0x48 || idB != 0x34 || idC != 0x33) { Debug.WriteLine("WARNING: this library may not be compatible with the attached chip"); } dev.WriteByteDataAsync((byte)Registers.ConfigA, 0x1C).Wait(); dev.WriteByteDataAsync((byte)Registers.Mode, 0x00).Wait(); // continuous conversion Range = RangeSetting.GAIN_1_3; }
/// <summary> /// Construct a new IS31FL3236 /// </summary> /// <param name="i2c">The I2C peripheral this chip is attached to</param> /// <param name="rateKhz">The frequency, in kHz, that should be used to communicate with the chip</param> /// <param name="sdb">The (optional) hardware shutdown pin, SDB</param> public Is31fl3236(I2C i2c, int rateKhz = 100, bool ad0 = false, DigitalOut sdb = null) : base(36, false, true) { if (sdb != null) { sdb.DigitalValue = true; } dev = new SMBusDevice(0x3C, i2c, rateKhz); dev.WriteByteDataAsync((byte)Registers.Shutdown, 0x01).Wait(); }
internal override void LedStateChanged(Led led) { var index = 16 * (led.Channel / ((int)package / 8)) + led.Channel % ((int)package / 8); data.Set(index, led.State); if (AutoFlush) { // if we're autoflushing, only send the LED we need to update var address = (byte)(index / 8); dev.WriteByteDataAsync(address, data.GetBytes()[address]).Wait(); } }
public Pca9632(I2C i2c) { dev = new SMBusDevice(0x62, i2c); mode1.Ai = RegisterAutoIncrement.AutoIncrementAllRegisters; mode1.Sleep = false; dev.WriteByteDataAsync((byte)Registers.Mode1, mode1.ToByte()).Wait(); // clear PWM values dev.WriteBufferDataAsync((byte)Registers.Pwm0 | 0x80, new byte[4] { 0x00, 0x00, 0x00, 0x00 }).Wait(); ledOut.Ldr0 = LedOutputState.LedPwm; ledOut.Ldr1 = LedOutputState.LedPwm; ledOut.Ldr2 = LedOutputState.LedPwm; ledOut.Ldr3 = LedOutputState.LedPwm; dev.WriteByteDataAsync((byte)Registers.LedOut, ledOut.ToByte()).Wait(); Pins.Add(new Pin(this, 0)); Pins.Add(new Pin(this, 1)); Pins.Add(new Pin(this, 2)); Pins.Add(new Pin(this, 3)); }