Skip to content

Commit

Permalink
Write time for Omron devices again
Browse files Browse the repository at this point in the history
  • Loading branch information
weliem committed Jun 26, 2021
1 parent d629673 commit d90d3f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ internal class BluetoothHandler private constructor(private val context: Context
}

private suspend fun setupCTSnotifications(peripheral: BluetoothPeripheral) {
peripheral.getCharacteristic(CTS_SERVICE_UUID, CURRENT_TIME_CHARACTERISTIC_UUID)?.let {
peripheral.observe(it) { value ->
peripheral.getCharacteristic(CTS_SERVICE_UUID, CURRENT_TIME_CHARACTERISTIC_UUID)?.let { currentTimeCharacteristic ->
peripheral.observe(currentTimeCharacteristic) { value ->
val parser = BluetoothBytesParser(value)
val currentTime = parser.dateTime
Timber.i("Received device time: %s", currentTime)
Expand All @@ -110,7 +110,9 @@ internal class BluetoothHandler private constructor(private val context: Context
val interval = Math.abs(Calendar.getInstance().timeInMillis - currentTime.time)
if (currentTimeCounter == 1 && interval > 10 * 60 * 1000) {
parser.setCurrentTime(Calendar.getInstance())
// peripheral.writeCharacteristic(characteristic, parser.value, WriteType.WITH_RESPONSE)
scope.launch {
peripheral.writeCharacteristic(it, parser.value, WriteType.WITH_RESPONSE)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class BluetoothPeripheral internal constructor(

private fun connectionStateChangeUnsuccessful(status: HciStatus, previousState: Int, newState: Int) {
cancelPendingServiceDiscovery()
val servicesDiscovered = !services.isEmpty()
val servicesDiscovered = services.isNotEmpty()

// See if the initial connection failed
if (previousState == BluetoothProfile.STATE_CONNECTING) {
Expand Down

0 comments on commit d90d3f0

Please sign in to comment.