/// <summary> /// Send commands to the display /// </summary> private void SendCommand(params byte[] Command) { foreach (var data in Command) { i2cDevice.WriteByte(0x80, data); } }
public void UpdateGyroConfig(II2CDevice device) { device.WriteByte(CTRL_REG1_G, this.OutputDataRate); device.WriteByte(CTRL_REG2_G, this.HighPassFilter); device.WriteByte(CTRL_REG3_G, this.InteruptDRDY); device.WriteByte(CTRL_REG4_G, this.ScaleAndUpdate); device.WriteByte(CTRL_REG5_G, this.FIFOHPFINT1); }
public void UpdateAccelConfig(II2CDevice device) { /* CTRL_REG0_XM (0x1F) (Default value: 0x00) Bits (7-0): BOOT FIFO_EN WTM_EN 0 0 HP_CLICK HPIS1 HPIS2 BOOT - Reboot memory content (0: normal, 1: reboot) FIFO_EN - Fifo enable (0: disable, 1: enable) WTM_EN - FIFO watermark enable (0: disable, 1: enable) HP_CLICK - HPF enabled for click (0: filter bypassed, 1: enabled) HPIS1 - HPF enabled for interrupt generator 1 (0: bypassed, 1: enabled) HPIS2 - HPF enabled for interrupt generator 2 (0: bypassed, 1 enabled) */ byte reg0Config = (byte)((HPFEnabledGenerator2 ? 1 : 0) << 7 & (HPFEnabledGenerator1 ? 1 : 0) << 6 & (HPFEnabledForClick ? 1 : 0) << 5 & (FifoWatermarkEnabled ? 1 : 0) << 2 & (FifoEnabled ? 1 : 0) << 1 & (RebootMemory ? 1 : 0)); /* CTRL_REG1_XM (0x20) (Default value: 0x07) Bits (7-0): AODR3 AODR2 AODR1 AODR0 BDU AZEN AYEN AXEN AODR[3:0] - select the acceleration data rate: 0000=power down, 0001=3.125Hz, 0010=6.25Hz, 0011=12.5Hz, 0100=25Hz, 0101=50Hz, 0110=100Hz, 0111=200Hz, 1000=400Hz, 1001=800Hz, 1010=1600Hz, (remaining combinations undefined). BDU - block data update afor accel AND mag 0: Continuous update 1: Output registers aren't updated until MSB and LSB have been read. AZEN, AYEN, and AXEN - Acceleration x/y/z-axis enabled. 0: Axis disabled, 1: Axis enabled */ byte reg1Config = (byte)((XAxisEnabled ? 1 : 0) << 7 & (YAxisEnabled ? 1 : 0) << 6 & (ZAxisEnabled ? 1 : 0) << 5 & (BlockDataUpdateForAccelAndMag ? 1 : 0) << 4 & (int) DataRate); /* CTRL_REG2_XM (0x21) (Default value: 0x00) Bits (7-0): ABW1 ABW0 AFS2 AFS1 AFS0 AST1 AST0 SIM ABW[1:0] - Accelerometer anti-alias filter bandwidth 00=773Hz, 01=194Hz, 10=362Hz, 11=50Hz AFS[2:0] - Accel full-scale selection 000=+/-2g, 001=+/-4g, 010=+/-6g, 011=+/-8g, 100=+/-16g AST[1:0] - Accel self-test enable 00=normal (no self-test), 01=positive st, 10=negative st, 11=not allowed SIM - SPI mode selection 0=4-wire, 1=3-wire */ byte reg2Config = (byte)((SPI3WireMode ? 1 : 0) << 7 & (int)SelfTest << 5 & (int)Scale << 2 & (int)AntiAliasFilterBandwidth); device.WriteByte(DOFConsts.CTRL_REG0_XM, reg0Config); device.WriteByte(DOFConsts.CTRL_REG1_XM, reg1Config); device.WriteByte(DOFConsts.CTRL_REG2_XM, reg2Config); // NOTE: Not sure how this register should be set documentation says: /* CTRL_REG3_XM is used to set interrupt generators on INT1_XM Bits (7-0): P1_BOOT P1_TAP P1_INT1 P1_INT2 P1_INTM P1_DRDYA P1_DRDYM P1_EMPTY */ // Accelerometer data ready on INT1_XM (0x04) device.WriteByte(DOFConsts.CTRL_REG3_XM, 0x04); }