[-] Remove contour clock writing
This commit is contained in:
@@ -9,7 +9,6 @@ import org.hydev.wearsync.BluePeri
|
|||||||
import org.hydev.wearsync.bles.decoders.*
|
import org.hydev.wearsync.bles.decoders.*
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import timber.log.Timber.DebugTree
|
import timber.log.Timber.DebugTree
|
||||||
import java.nio.ByteOrder
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
internal class BluetoothHandler private constructor(context: Context) {
|
internal class BluetoothHandler private constructor(context: Context) {
|
||||||
@@ -25,28 +24,24 @@ internal class BluetoothHandler private constructor(context: Context) {
|
|||||||
val temperatureChannel = Channel<TemperatureMeasurement>(UNLIMITED)
|
val temperatureChannel = Channel<TemperatureMeasurement>(UNLIMITED)
|
||||||
val weightChannel = Channel<WeightMeasurement>(UNLIMITED)
|
val weightChannel = Channel<WeightMeasurement>(UNLIMITED)
|
||||||
|
|
||||||
private fun handlePeripheral(peripheral: BluePeri) {
|
private fun BluePeri.handle() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
Timber.i("MTU is ${peripheral.requestMtu(185)}")
|
Timber.i("MTU is ${requestMtu(185)}")
|
||||||
peripheral.requestConnectionPriority(ConnectionPriority.HIGH)
|
requestConnectionPriority(ConnectionPriority.HIGH)
|
||||||
Timber.i("RSSI is ${peripheral.readRemoteRssi()}")
|
Timber.i("RSSI is ${readRemoteRssi()}")
|
||||||
Timber.i("Received: ${peripheral.read(ManufacturerDecoder())}")
|
Timber.i("Received: ${read(ManufacturerDecoder())}")
|
||||||
Timber.i("Received: ${peripheral.read(ModelDecoder())}")
|
Timber.i("Received: ${read(ModelDecoder())}")
|
||||||
Timber.i("Battery level: ${peripheral.read(BatteryDecoder())}")
|
Timber.i("Battery level: ${read(BatteryDecoder())}")
|
||||||
|
|
||||||
peripheral.observe(batteryChannel, BatteryDecoder())
|
observe(batteryChannel, BatteryDecoder())
|
||||||
peripheral.observe(heartRateChannel, HeartRateDecoder())
|
observe(heartRateChannel, HeartRateDecoder())
|
||||||
peripheral.observe(temperatureChannel, TemperatureDecoder())
|
observe(temperatureChannel, TemperatureDecoder())
|
||||||
peripheral.observe(weightChannel, WeightDecoder())
|
observe(weightChannel, WeightDecoder())
|
||||||
peripheral.observe(bloodPressureChannel, BloodPressureDecoder())
|
observe(bloodPressureChannel, BloodPressureDecoder())
|
||||||
peripheral.observe(pulseOxSpotChannel, PLXSpotDecoder())
|
observe(pulseOxSpotChannel, PLXSpotDecoder())
|
||||||
peripheral.observe(pulseOxContinuousChannel, PLXContinuousDecoder())
|
observe(pulseOxContinuousChannel, PLXContinuousDecoder())
|
||||||
setupGLXnotifications(peripheral)
|
setupGLXnotifications(this@handle)
|
||||||
|
|
||||||
peripheral.getCharacteristic(CONTOUR_SERVICE_UUID, CONTOUR_CLOCK)?.let {
|
|
||||||
writeContourClock(peripheral)
|
|
||||||
}
|
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
} catch (b: GattException) {
|
} catch (b: GattException) {
|
||||||
@@ -55,22 +50,6 @@ internal class BluetoothHandler private constructor(context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun writeContourClock(peripheral: BluePeri) {
|
|
||||||
val calendar = Calendar.getInstance()
|
|
||||||
val offsetInMinutes = calendar.timeZone.rawOffset / 60000
|
|
||||||
calendar.timeZone = TimeZone.getTimeZone("UTC")
|
|
||||||
val parser = BluetoothBytesParser(ByteOrder.LITTLE_ENDIAN)
|
|
||||||
parser.setIntValue(1, BluetoothBytesParser.FORMAT_UINT8)
|
|
||||||
parser.setIntValue(calendar[Calendar.YEAR], BluetoothBytesParser.FORMAT_UINT16)
|
|
||||||
parser.setIntValue(calendar[Calendar.MONTH] + 1, BluetoothBytesParser.FORMAT_UINT8)
|
|
||||||
parser.setIntValue(calendar[Calendar.DAY_OF_MONTH], BluetoothBytesParser.FORMAT_UINT8)
|
|
||||||
parser.setIntValue(calendar[Calendar.HOUR_OF_DAY], BluetoothBytesParser.FORMAT_UINT8)
|
|
||||||
parser.setIntValue(calendar[Calendar.MINUTE], BluetoothBytesParser.FORMAT_UINT8)
|
|
||||||
parser.setIntValue(calendar[Calendar.SECOND], BluetoothBytesParser.FORMAT_UINT8)
|
|
||||||
parser.setIntValue(offsetInMinutes, BluetoothBytesParser.FORMAT_SINT16)
|
|
||||||
peripheral.writeCharacteristic(CONTOUR_SERVICE_UUID, CONTOUR_CLOCK, parser.value, WriteType.WITH_RESPONSE)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun setupGLXnotifications(peripheral: BluePeri) {
|
private suspend fun setupGLXnotifications(peripheral: BluePeri) {
|
||||||
peripheral.observe(glucoseChannel, GlucoseDecoder())
|
peripheral.observe(glucoseChannel, GlucoseDecoder())
|
||||||
|
|
||||||
@@ -138,10 +117,6 @@ internal class BluetoothHandler private constructor(context: Context) {
|
|||||||
val GLUCOSE_SERVICE_UUID = UUID.fromString("00001808-0000-1000-8000-00805f9b34fb")
|
val GLUCOSE_SERVICE_UUID = UUID.fromString("00001808-0000-1000-8000-00805f9b34fb")
|
||||||
val GLUCOSE_RECORD_ACCESS_POINT_CHARACTERISTIC_UUID = UUID.fromString("00002A52-0000-1000-8000-00805f9b34fb")
|
val GLUCOSE_RECORD_ACCESS_POINT_CHARACTERISTIC_UUID = UUID.fromString("00002A52-0000-1000-8000-00805f9b34fb")
|
||||||
|
|
||||||
// Contour Glucose Service
|
|
||||||
val CONTOUR_SERVICE_UUID = UUID.fromString("00000000-0002-11E2-9E96-0800200C9A66")
|
|
||||||
val CONTOUR_CLOCK = UUID.fromString("00001026-0002-11E2-9E96-0800200C9A66")
|
|
||||||
|
|
||||||
private var instance: BluetoothHandler? = null
|
private var instance: BluetoothHandler? = null
|
||||||
val Context.ble get(): BluetoothHandler {
|
val Context.ble get(): BluetoothHandler {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@@ -160,7 +135,7 @@ internal class BluetoothHandler private constructor(context: Context) {
|
|||||||
central.observeConnectionState { peripheral, state ->
|
central.observeConnectionState { peripheral, state ->
|
||||||
Timber.i("Peripheral '${peripheral.name}' is $state")
|
Timber.i("Peripheral '${peripheral.name}' is $state")
|
||||||
when (state) {
|
when (state) {
|
||||||
ConnectionState.CONNECTED -> handlePeripheral(peripheral)
|
ConnectionState.CONNECTED -> peripheral.handle()
|
||||||
ConnectionState.DISCONNECTED -> scope.launch {
|
ConnectionState.DISCONNECTED -> scope.launch {
|
||||||
delay(15000)
|
delay(15000)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user