public void Configure() { _log.WriteMessage( $"Setting register1 {MODE1:X4}, resp: {I2C.WiringPiI2CWriteReg8(DeviceHandler, REGISTER1, MODE1)}"); _log.WriteMessage( $"Setting register2 {MODE2:X4}, resp: {I2C.WiringPiI2CWriteReg8(DeviceHandler, REGISTER2, MODE2)}"); _log.WriteMessage($"Validating registers..."); var tempRegValue = I2C.WiringPiI2CReadReg8(DeviceHandler, REGISTER1); if (tempRegValue == MODE1) { _log.WriteMessage("Register1 is ok"); } else { _log.WriteMessage($"Register1 is configured wrong {MODE1:X4} vs {tempRegValue:X4}"); throw new Exception("Register1 is configured wrong"); } tempRegValue = I2C.WiringPiI2CReadReg8(DeviceHandler, REGISTER2); if (tempRegValue == MODE2) { _log.WriteMessage("Register2 is ok"); } else { _log.WriteMessage($"Register2 is configured wrong {MODE2:X4} vs {tempRegValue:X4}"); throw new Exception("Register2 is configured wrong"); } }
public void SetPWM(int channel, int value) { var on = 0; var off = value; I2C.WiringPiI2CWriteReg8(DeviceHandler, LED0_ON_L + 4 * channel, on & 0xFF); I2C.WiringPiI2CWriteReg8(DeviceHandler, LED0_ON_H + 4 * channel, on >> 8); I2C.WiringPiI2CWriteReg8(DeviceHandler, LED0_OFF_L + 4 * channel, off & 0xFF); I2C.WiringPiI2CWriteReg8(DeviceHandler, LED0_OFF_H + 4 * channel, off >> 8); }
public void Reset() { _log.WriteMessage("Resetting device..."); var reg1Value = I2C.WiringPiI2CReadReg8(DeviceHandler, REGISTER1); _log.WriteMessage($"Obtained value: {reg1Value:X8}"); if (IsBitSet(reg1Value, 7)) { ClearBit(ref reg1Value, 4); Thread.Sleep(1); } SetBit(ref reg1Value, 7); I2C.WiringPiI2CWriteReg8(DeviceHandler, REGISTER1, 0x00); _log.WriteMessage($"Setting register1... {I2C.WiringPiI2CWriteReg8(DeviceHandler, REGISTER1, reg1Value)}"); Thread.Sleep(1); reg1Value = I2C.WiringPiI2CReadReg8(DeviceHandler, REGISTER1); _log.WriteMessage($"Register1 after resetting: {reg1Value:X8}"); }