/// <summary> /// Writes a data buffer then reads a data buffer from the I2C device. /// </summary> /// <param name="writeBuffer">Write buffer.</param> /// <param name="writeOffset">Offset into the write buffer.</param> /// <param name="writeLength">Number of bytes to write.</param> /// <param name="readBuffer">Read buffer.</param> /// <param name="readOffset">Offset into the read buffer.</param> /// <param name="readLength">Number of bytes to read.</param> /// <param name="numWritten">Number of bytes written successfully.</param> /// <param name="numRead">Number of bytes read successfully.</param> /// <returns><c>true</c> if all the required bytes are written and read successfully.</returns> public bool WriteRead(byte[] writeBuffer, int writeOffset, int writeLength, byte[] readBuffer, int readOffset, int readLength, out int numWritten, out int numRead) { lock (bus) { if (bus.disposed) { throw new ObjectDisposedException(); } return(SoftwareI2CBus.NativeI2CWriteRead((int)bus.clockPin, (int)bus.dataPin, clockRateKHz, address, writeBuffer, writeOffset, writeLength, readBuffer, readOffset, readLength, out numWritten, out numRead)); } }
static public void Disable() { if (i2cbus != null && i2cdev != null) { WriteToRegister(0x2A, 0);//bit 0 is 0 - standby isActived = false; i2cdev = null; i2cbus.Dispose(); i2cbus = null; } }
/// <summary> /// Disables the accelerometer to save power. /// </summary> public static void Disable() { if (!Accelerometer.IsEnabled) return; Accelerometer.WriteToRegister(0x2A, 0); Accelerometer.I2CDevice = null; Accelerometer.I2CBus.Dispose(); Accelerometer.I2CBus = null; Accelerometer.Enabled = false; }
/// <summary> /// Enables the accelerometer functionality if it was disabled. /// </summary> public static void Enable() { if (Accelerometer.IsEnabled) return; Accelerometer.I2CBus = new SoftwareI2CBus(Accelerometer.I2C_CLK, Accelerometer.I2C_DATA); Accelerometer.I2CDevice = Accelerometer.I2CBus.CreateI2CDevice(Accelerometer.I2C_ADDRESS, 400); //bit 0 is 1 - active //bit 0 is 0 - standby //bit 1 = 1: 8 bit accurate - fast mode read //bit 1 = 0: 10 bit accurate - normal mode read WriteToRegister(0x2A, 1); Accelerometer.Enabled = true; }
//const String TEXT_EXCEPTION_00 = "Accelerometer needs to be enable by calling Enable() function"; static public void Enable() { if (i2cbus == null) { i2cbus = new SoftwareI2CBus(i2c_clk, i2c_dat); } if (i2cdev == null) { i2cdev = i2cbus.CreateI2CDevice(0x1C, 400); } //bit 0 is 1 - active //bit 0 is 0 - standby //bit 1 = 1: 8 bit accurate - fast mode read //bit 1 = 0: 10 bit accurate - normal mode read isActived = true; WriteToRegister(0x2A, 1); //bit 0 is 1 - active }
internal I2CDevice(SoftwareI2CBus bus, ushort address, int clockRateKHz) { this.bus = bus; this.address = address; this.clockRateKHz = clockRateKHz; }
internal I2CDevice(SoftwareI2CBus bus, ushort address, int clockRateKHz) { this.bus = bus; this.address = address; this.clockRateKHz = clockRateKHz; }