Back to project page BLE-Heart-rate-variability-demo.
The source code is released under:
MIT License
If you think the Android project BLE-Heart-rate-variability-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.sample.hrv.sensor; /*from ww w . j a v a 2s . co m*/ import android.bluetooth.BluetoothGattCharacteristic; import static android.bluetooth.BluetoothGattCharacteristic.FORMAT_SINT8; import static android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8; /** * Created by steven on 9/23/13. * Modified by olli on 3/28/2014. */ public class BleSensorUtils { private BleSensorUtils() { } /** * Gyroscope, Magnetometer, Barometer, IR temperature * all store 16 bit two's complement values in the awkward format * LSB MSB, which cannot be directly parsed as getIntValue(FORMAT_SINT16, offset) * because the bytes are stored in the "wrong" direction. * * This function extracts these 16 bit two's complement values. * */ public static Integer shortSignedAtOffset(BluetoothGattCharacteristic c, int offset) { Integer lowerByte = c.getIntValue(FORMAT_UINT8, offset); if (lowerByte == null) return 0; Integer upperByte = c.getIntValue(FORMAT_SINT8, offset + 1); // Note: interpret MSB as signed. if (upperByte == null) return 0; return (upperByte << 8) + lowerByte; } public static Integer shortUnsignedAtOffset(BluetoothGattCharacteristic c, int offset) { Integer lowerByte = c.getIntValue(FORMAT_UINT8, offset); if (lowerByte == null) return 0; Integer upperByte = c.getIntValue(FORMAT_UINT8, offset + 1); // Note: interpret MSB as unsigned. if (upperByte == null) return 0; return (upperByte << 8) + lowerByte; } }