/// <summary> /// Make a temperature and humidity reading. /// </summary> public void Update() { _si7021.WriteByte(Registers.MeasureHumidityNoHold); // // Maximum conversion time is 12ms (page 5 of the datasheet). // Thread.Sleep(25); var data = _si7021.ReadBytes(3); var humidityReading = (ushort)((data[0] << 8) + data[1]); Humidity = ((125 * (float)humidityReading) / 65536) - 6; if (Humidity < 0) { Humidity = 0; } else { if (Humidity > 100) { Humidity = 100; } } data = _si7021.ReadRegisters(Registers.ReadPreviousTemperatureMeasurement, 2); var temperatureReading = (short)((data[0] << 8) + data[1]); Temperature = (float)(((175.72 * temperatureReading) / 65536) - 46.85); }
/// <summary> /// Force the sensor to make a reading and update the relevanyt properties. /// </summary> public void Read() { var controlRegister = _mag3110.ReadRegister((byte)Registers.Control1); controlRegister |= 0x02; _mag3110.WriteRegister((byte)Registers.Control1, controlRegister); var data = _mag3110.ReadRegisters((byte)Registers.XMSB, 6); X = (short)((data[0] << 8) | data[1]); Y = (short)((data[2] << 8) | data[3]); Z = (short)((data[4] << 8) | data[5]); }