private void OnBleHumidityCharacteristicChanged(object sender, CharacteristicChangeArgs e) { if (e.Data != null && e.Data.Length >= 4) { Int16 rawTemp = BitConverter.ToInt16(e.Data, 0); Int16 rawHum = BitConverter.ToInt16(e.Data, 2); TemperatureValue = ((double)(Int16)rawTemp / 65536) * 165 - 40; HumidityValue = ((double)rawHum / 65536) * 100; } }
private void OnBleBarometerCharacteristicsChanged(object sender, CharacteristicChangeArgs e) { if (e.Data != null && e.Data.Length >= 6) { BarometerValue value = new BarometerValue(); var temperature = e.Data[2] << 16 | e.Data[1] << 8 | e.Data[0]; var pressure = e.Data[5] << 16 | e.Data[4] << 8 | e.Data[3]; value.Temperature = temperature / 100.0f; value.Pressure = pressure / 100.0f; PressureValue = value; } }
private void OnBleMovementCharacteristicChanged(object sender, CharacteristicChangeArgs e) { if (e.Data != null && e.Data.Length >= 18) { Int16 GyroXRaw = BitConverter.ToInt16(e.Data, 0); Int16 GyroYRaw = BitConverter.ToInt16(e.Data, 2); Int16 GyroZRaw = BitConverter.ToInt16(e.Data, 4); Int16 AccXRaw = BitConverter.ToInt16(e.Data, 6); Int16 AccYRaw = BitConverter.ToInt16(e.Data, 8); Int16 AccZRaw = BitConverter.ToInt16(e.Data, 10); Int16 MagXRaw = BitConverter.ToInt16(e.Data, 12); Int16 MagYRaw = BitConverter.ToInt16(e.Data, 14); Int16 MagZRaw = BitConverter.ToInt16(e.Data, 16); MovementValue value = new MovementValue(); value.GyroX = GyroConvert(GyroXRaw); value.GyroY = GyroConvert(GyroYRaw); value.GyroZ = GyroConvert(GyroZRaw); value.AccX = AccelometerConvert(AccXRaw); value.AccY = AccelometerConvert(AccYRaw); value.AccZ = AccelometerConvert(AccZRaw); MovValue = value; } }
private void OnBleIRTemperatureCharacteristicsChanged(object sender, CharacteristicChangeArgs e) { if (e.Data != null && e.Data.Length >= 4) { IRTemperatureValue value = new IRTemperatureValue(); Int16 rawObjectTemp = BitConverter.ToInt16(e.Data, 0); Int16 rawAmbientTemp = BitConverter.ToInt16(e.Data, 2); const float SCALE_LSB = 0.03125f; float t; int it; it = (int)((rawObjectTemp) >> 2); t = ((float)(it)) * SCALE_LSB; value.ObjectTemperature = t; it = (int)((rawAmbientTemp) >> 2); t = (float)it; value.AmbientTemperature = t * SCALE_LSB; TemperatureValue = value; } }