Пример #1
0
        public static UInt32 Read24Bits(II2C device, byte reg, ByteOrder byteOrder, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };
                device.Write(addr);

                byte[] data = device.Read(3);

                switch (byteOrder)
                {
                case ByteOrder.BigEndian:
                    return((UInt32)((data[0] << 16) | (data[1] << 8) | data[2]));

                case ByteOrder.LittleEndian:
                    return((UInt32)((data[2] << 16) | (data[1] << 8) | data[0]));

                default:
                    throw new SensorException($"Unsupported byte order {byteOrder}");
                }
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
 private void ConnectToI2CDevices()
 {
     try
     {
         _i2CDevice = I2CDeviceFactory.Singleton.Create(_i2CAddress);
     }
     catch (Exception exception)
     {
         throw new SensorException("Failed to connect to HTS221", exception);
     }
 }
 private void ConnectToI2CDevices()
 {
     try
     {
         _accelGyroI2CDevice = I2CDeviceFactory.Singleton.Create(_accelGyroI2CAddress);
         _magI2CDevice       = I2CDeviceFactory.Singleton.Create(_magI2CAddress);
     }
     catch (Exception exception)
     {
         throw new SensorException("Failed to connect to LSM9DS1", exception);
     }
 }
Пример #4
0
        public static void Write(II2C device, byte reg, byte command, string exceptionMessage)
        {
            try
            {
                byte[] buffer = { reg, command };

                device.Write(buffer);
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Пример #5
0
        public static byte Read8Bits(II2C device, byte reg, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };
                device.Write(addr);

                return(device.Read(1)[0]);
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Пример #6
0
        public static byte[] ReadBytes(II2C device, byte reg, int count, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };
                device.Write(addr);

                return(device.Read(count));
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Пример #7
0
 public GpioButtonCore(II2C i2cWire, GpioPin pinToMonitor)
 {
     _i2CWire      = i2cWire;
     _pinToMonitor = pinToMonitor;
 }
Пример #8
0
 public DeviceIO(II2C i2C, IDutGpio gpio, AsyncPolicyWrap policyWrap)
 {
     I2C         = i2C;
     Gpio        = gpio;
     _policyWrap = policyWrap;
 }
Пример #9
0
 public Apds9660GestureSensor(II2C device, IDigitalWriteRead gpio = null, int?interruptPin = null)
 {
     Device       = device;
     Gpio         = gpio;
     InterruptPin = interruptPin;
 }
Пример #10
0
 public Mlx90614(II2C device, byte address = 0)
 {
     Device  = device;
     Address = address;
 }
Пример #11
0
 public MainI2CDevice(byte address)
 {
     _device = I2CDeviceFactory.Singleton.Create(address);
 }
Пример #12
0
 protected I2CDevice(II2C i2c) : base(i2c)
 {
 }