mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-04 07:14:20 +01:00
Merge pull request #107 from NordicSemiconductor/feature/logger
Add support for nRF Logger
This commit is contained in:
@@ -81,6 +81,7 @@ dependencies {
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ui.scanner
|
||||
|
||||
2
app/proguard-rules.pro
vendored
2
app/proguard-rules.pro
vendored
@@ -5,6 +5,8 @@
|
||||
-keep class org.simpleframework.xml.core.** { *; }
|
||||
-keep class org.simpleframework.xml.util.** { *; }
|
||||
|
||||
-keep class no.nordicsemi.android.log.** { *; }
|
||||
|
||||
-keepattributes ElementList, Root, InnerClasses, LineNumberTable
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
|
||||
@@ -12,6 +12,16 @@
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<queries>
|
||||
<package android:name="no.nordicsemi.android.log" />
|
||||
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="https" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:name=".NrfToolboxApplication"
|
||||
android:allowBackup="true"
|
||||
|
||||
@@ -14,7 +14,6 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import no.nordicsemi.android.nrftoolbox.BuildConfig
|
||||
import no.nordicsemi.android.nrftoolbox.ProfileDestination
|
||||
import no.nordicsemi.android.nrftoolbox.R
|
||||
@@ -24,6 +23,9 @@ import no.nordicsemi.android.theme.view.TitleAppBar
|
||||
private const val DFU_PACKAGE_NAME = "no.nordicsemi.android.dfu"
|
||||
private const val DFU_LINK = "https://play.google.com/store/apps/details?id=no.nordicsemi.android.dfu"
|
||||
|
||||
private const val LOGGER_PACKAGE_NAME = "no.nordicsemi.android.log"
|
||||
private const val LOGGER_LINK = "https://play.google.com/store/apps/details?id=no.nordicsemi.android.log"
|
||||
|
||||
@Composable
|
||||
fun HomeScreen() {
|
||||
val viewModel: HomeViewModel = hiltViewModel()
|
||||
@@ -141,6 +143,21 @@ fun HomeScreen() {
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
val loggerDescription = packageManger.getLaunchIntentForPackage(LOGGER_PACKAGE_NAME)?.let {
|
||||
R.string.logger_module_info
|
||||
} ?: R.string.dfu_module_install
|
||||
|
||||
FeatureButton(R.drawable.ic_logger, R.string.logger_module, R.string.logger_module_full, null, loggerDescription) {
|
||||
val intent = packageManger.getLaunchIntentForPackage(LOGGER_PACKAGE_NAME)
|
||||
if (intent != null) {
|
||||
context.startActivity(intent)
|
||||
} else {
|
||||
uriHandler.openUri(LOGGER_LINK)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Text(
|
||||
text = BuildConfig.VERSION_NAME,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
|
||||
9
app/src/main/res/drawable/ic_logger.xml
Normal file
9
app/src/main/res/drawable/ic_logger.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="1024dp"
|
||||
android:height="1024dp"
|
||||
android:viewportWidth="1024"
|
||||
android:viewportHeight="1024">
|
||||
<path
|
||||
android:pathData="M989.6,949.6L772.8,732.8c30.8,-33.4 55.3,-71.5 73,-113.4c20.6,-48.7 31,-100.4 31,-153.6s-10.4,-105 -31,-153.6c-19.9,-47 -48.3,-89.2 -84.6,-125.4c-36.2,-36.2 -78.4,-64.7 -125.4,-84.6c-48.7,-20.6 -100.4,-31 -153.6,-31s-105,10.4 -153.6,31c-47,19.9 -89.2,48.3 -125.4,84.6c-36.2,36.2 -64.7,78.4 -84.6,125.4c-20.6,48.7 -31,100.4 -31,153.6s10.4,105 31,153.6c19.9,47 48.3,89.2 84.6,125.4c36.2,36.2 78.4,64.7 125.4,84.6c48.7,20.6 100.4,31 153.6,31s105,-10.4 153.6,-31c34.6,-14.6 66.6,-33.9 95.5,-57.5l218,218c5.6,5.6 12.9,8.3 20.2,8.3s14.6,-2.8 20.2,-8.3C1000.8,978.8 1000.8,960.7 989.6,949.6zM482.2,803.4c-112.7,0 -212.6,-55.5 -274,-140.6h352.3c15.7,0 28.5,-12.8 28.5,-28.5s-12.8,-28.5 -28.5,-28.5H175c-15.8,-34.5 -25.9,-72.1 -29.2,-111.6h414.8c15.7,0 28.5,-12.8 28.5,-28.5s-12.8,-28.5 -28.5,-28.5H145.7c3.3,-39.5 13.5,-77.1 29.2,-111.6h385.5c15.7,0 28.5,-12.8 28.5,-28.5s-12.8,-28.5 -28.5,-28.5H208.2c61.4,-85.1 161.3,-140.6 274,-140.6c186.2,0 337.7,151.5 337.7,337.7C819.9,651.9 668.4,803.4 482.2,803.4z"
|
||||
android:fillColor="#00B3DC"/>
|
||||
</vector>
|
||||
@@ -21,6 +21,9 @@
|
||||
<string name="dfu_module_full">Device Firmware Update</string>
|
||||
<string name="dfu_module_info">Open DFU application.</string>
|
||||
<string name="dfu_module_install">Download from Google Play.</string>
|
||||
<string name="logger_module">nRF Logger</string>
|
||||
<string name="logger_module_full">nRF Logger</string>
|
||||
<string name="logger_module_info">Open nRF Logger application.</string>
|
||||
|
||||
<string name="viewmodel_profiles">ViewModel profiles</string>
|
||||
<string name="service_profiles">Service profiles</string>
|
||||
|
||||
5
lib_log/build.gradle
Normal file
5
lib_log/build.gradle
Normal file
@@ -0,0 +1,5 @@
|
||||
apply from: rootProject.file("library.gradle")
|
||||
|
||||
dependencies {
|
||||
implementation libs.nordic.log
|
||||
}
|
||||
7
lib_log/src/main/AndroidManifest.xml
Normal file
7
lib_log/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="no.nordicsemi.android.log">
|
||||
|
||||
<uses-permission android:name="no.nordicsemi.android.LOG"/>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,28 @@
|
||||
package no.nordicsemi.android.log
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import no.nordicsemi.android.log.annotation.LogLevel
|
||||
|
||||
internal const val LOG_TAG = "nRF Toolbox"
|
||||
|
||||
class ToolboxLogger(
|
||||
private val context: Context,
|
||||
private val key: String,
|
||||
) {
|
||||
|
||||
private var logSession: LogSession? = null
|
||||
|
||||
fun log(@LogLevel level: Int, message: String) {
|
||||
val logSession = getLogger()
|
||||
if (logSession != null) {
|
||||
Logger.log(logSession, LogContract.Log.Level.fromPriority(level), message)
|
||||
}
|
||||
Log.println(level, LOG_TAG, message)
|
||||
}
|
||||
|
||||
private fun getLogger(): LogSession? {
|
||||
logSession = logSession ?: Logger.newSession(context, key, LOG_TAG)
|
||||
return logSession
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ dependencies {
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.ui.scanner
|
||||
|
||||
implementation libs.lifecycle.service
|
||||
|
||||
@@ -5,13 +5,13 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
implementation libs.nordic.navigation
|
||||
implementation libs.nordic.theme
|
||||
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.ui.scanner
|
||||
|
||||
implementation libs.bundles.compose
|
||||
|
||||
@@ -36,8 +36,7 @@ import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse
|
||||
import no.nordicsemi.android.ble.common.callback.bps.BloodPressureMeasurementResponse
|
||||
import no.nordicsemi.android.ble.common.callback.bps.IntermediateCuffPressureResponse
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.bps.data.BPSData
|
||||
import no.nordicsemi.android.bps.data.copyWithNewResponse
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import java.util.*
|
||||
|
||||
@@ -50,7 +49,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
|
||||
internal class BPSManager(
|
||||
@ApplicationContext context: Context,
|
||||
private val scope: CoroutineScope
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -68,6 +68,10 @@ internal class BPSManager(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
@@ -11,18 +11,19 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import no.nordicsemi.android.bps.data.BPSData
|
||||
import no.nordicsemi.android.bps.data.BPSManager
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import javax.inject.Inject
|
||||
|
||||
@ViewModelScoped
|
||||
internal class BPSRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
fun downloadData(device: BluetoothDevice): Flow<BleManagerResult<BPSData>> = callbackFlow {
|
||||
val scope = this
|
||||
val manager = BPSManager(context, scope)
|
||||
val manager = BPSManager(context, scope, ToolboxLogger(context, "BPS"))
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
trySend(it)
|
||||
|
||||
@@ -5,11 +5,11 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.theme
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
@@ -45,6 +45,7 @@ import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.ble.ktx.suspendForValidResponse
|
||||
import no.nordicsemi.android.cgms.repository.toList
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import no.nordicsemi.android.utils.launchWithCatch
|
||||
import java.util.*
|
||||
@@ -62,7 +63,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
|
||||
internal class CGMManager(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var cgmStatusCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -95,8 +97,11 @@ internal class CGMManager(
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
super.log(priority, message)
|
||||
Log.d("CGM-PROFILE", message)
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
private inner class CGMManagerGattCallback : BleManagerGattCallback() {
|
||||
|
||||
@@ -9,10 +9,10 @@ import kotlinx.coroutines.launch
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.cgms.data.CGMData
|
||||
import no.nordicsemi.android.cgms.data.CGMManager
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.service.ConnectingResult
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
import java.lang.Exception
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -20,7 +20,7 @@ import javax.inject.Singleton
|
||||
class CGMRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val serviceManager: ServiceManager
|
||||
) {
|
||||
private var manager: CGMManager? = null
|
||||
|
||||
@@ -35,7 +35,7 @@ class CGMRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = CGMManager(context, scope)
|
||||
val manager = CGMManager(context, scope, ToolboxLogger(context, "CGMS"))
|
||||
this.manager = manager
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
|
||||
@@ -5,11 +5,11 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.theme
|
||||
implementation libs.nordic.navigation
|
||||
implementation libs.nordic.ui.scanner
|
||||
|
||||
@@ -24,6 +24,7 @@ package no.nordicsemi.android.csc.data
|
||||
import android.bluetooth.BluetoothGatt
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -32,8 +33,7 @@ import no.nordicsemi.android.ble.BleManager
|
||||
import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse
|
||||
import no.nordicsemi.android.ble.common.callback.csc.CyclingSpeedAndCadenceMeasurementResponse
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.csc.data.CSCData
|
||||
import no.nordicsemi.android.csc.data.WheelSize
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import java.util.*
|
||||
|
||||
@@ -46,6 +46,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
internal class CSCManager(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -65,6 +66,14 @@ internal class CSCManager(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
override fun getGattCallback(): BleManagerGattCallback {
|
||||
return CSCManagerGattCallback()
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.csc.data.CSCData
|
||||
import no.nordicsemi.android.csc.data.CSCManager
|
||||
import no.nordicsemi.android.csc.data.WheelSize
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.service.ConnectingResult
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
@@ -20,7 +21,7 @@ import javax.inject.Singleton
|
||||
class CSCRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val serviceManager: ServiceManager
|
||||
) {
|
||||
private var manager: CSCManager? = null
|
||||
|
||||
@@ -35,7 +36,7 @@ class CSCRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = CSCManager(context, scope)
|
||||
val manager = CSCManager(context, scope, ToolboxLogger(context, "CSC"))
|
||||
this.manager = manager
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
|
||||
@@ -5,6 +5,7 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.chart
|
||||
|
||||
@@ -14,8 +15,6 @@ dependencies {
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
implementation libs.nordic.log
|
||||
|
||||
implementation libs.bundles.compose
|
||||
implementation libs.androidx.core
|
||||
implementation libs.material
|
||||
|
||||
@@ -39,6 +39,7 @@ import no.nordicsemi.android.ble.common.callback.glucose.GlucoseMeasurementRespo
|
||||
import no.nordicsemi.android.ble.common.data.RecordAccessControlPointData
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import no.nordicsemi.android.utils.launchWithCatch
|
||||
import java.util.*
|
||||
@@ -58,7 +59,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID =
|
||||
internal class GLSManager @Inject constructor(
|
||||
@ApplicationContext
|
||||
context: Context,
|
||||
private val scope: CoroutineScope
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -77,6 +79,14 @@ internal class GLSManager @Inject constructor(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
override fun getGattCallback(): BleManagerGattCallback {
|
||||
return GlucoseManagerGattCallback()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.gls.data.GLSData
|
||||
import no.nordicsemi.android.gls.data.GLSManager
|
||||
import no.nordicsemi.android.gls.data.WorkingMode
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.utils.exhaustive
|
||||
import javax.inject.Inject
|
||||
@@ -21,14 +22,14 @@ import javax.inject.Inject
|
||||
@ViewModelScoped
|
||||
internal class GLSRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
private var manager: GLSManager? = null
|
||||
|
||||
fun downloadData(device: BluetoothDevice): Flow<BleManagerResult<GLSData>> = callbackFlow {
|
||||
val scope = this
|
||||
val managerInstance = manager ?: GLSManager(context, scope).apply {
|
||||
val managerInstance = manager ?: GLSManager(context, scope, ToolboxLogger(context, "GLS")).apply {
|
||||
try {
|
||||
connect(device)
|
||||
.useAutoConnect(false)
|
||||
|
||||
@@ -5,6 +5,7 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.chart
|
||||
|
||||
@@ -14,8 +15,6 @@ dependencies {
|
||||
implementation libs.nordic.navigation
|
||||
implementation libs.nordic.ui.scanner
|
||||
|
||||
implementation libs.nordic.log
|
||||
|
||||
implementation libs.bundles.compose
|
||||
implementation libs.androidx.core
|
||||
implementation libs.material
|
||||
|
||||
@@ -24,6 +24,7 @@ package no.nordicsemi.android.hrs.data
|
||||
import android.bluetooth.BluetoothGatt
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -34,6 +35,7 @@ import no.nordicsemi.android.ble.common.callback.hr.BodySensorLocationResponse
|
||||
import no.nordicsemi.android.ble.common.callback.hr.HeartRateMeasurementResponse
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.ble.ktx.suspendForValidResponse
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import no.nordicsemi.android.utils.launchWithCatch
|
||||
import java.util.*
|
||||
@@ -48,6 +50,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
internal class HRSManager(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -65,6 +68,14 @@ internal class HRSManager(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
override fun getGattCallback(): BleManagerGattCallback {
|
||||
return HeartRateManagerCallback()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.launch
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.hrs.data.HRSData
|
||||
import no.nordicsemi.android.hrs.data.HRSManager
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.service.ConnectingResult
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
@@ -19,7 +20,7 @@ import javax.inject.Singleton
|
||||
class HRSRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val serviceManager: ServiceManager
|
||||
) {
|
||||
private var manager: HRSManager? = null
|
||||
|
||||
@@ -34,7 +35,7 @@ class HRSRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = HRSManager(context, scope)
|
||||
val manager = HRSManager(context, scope, ToolboxLogger(context, "HRS"))
|
||||
this.manager = manager
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
|
||||
@@ -5,11 +5,11 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.theme
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
@@ -24,6 +24,7 @@ package no.nordicsemi.android.hts.data
|
||||
import android.bluetooth.BluetoothGatt
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -32,7 +33,7 @@ import no.nordicsemi.android.ble.BleManager
|
||||
import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse
|
||||
import no.nordicsemi.android.ble.common.callback.ht.TemperatureMeasurementResponse
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.hts.data.HTSData
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import java.util.*
|
||||
|
||||
@@ -45,6 +46,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
internal class HTSManager internal constructor(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -61,6 +63,14 @@ internal class HTSManager internal constructor(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
override fun getGattCallback(): BleManagerGattCallback {
|
||||
return HTManagerGattCallback()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.launch
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.hts.data.HTSData
|
||||
import no.nordicsemi.android.hts.data.HTSManager
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.service.ConnectingResult
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
@@ -19,7 +20,7 @@ import javax.inject.Singleton
|
||||
class HTSRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val serviceManager: ServiceManager
|
||||
) {
|
||||
private var manager: HTSManager? = null
|
||||
|
||||
@@ -34,7 +35,7 @@ class HTSRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = HTSManager(context, scope)
|
||||
val manager = HTSManager(context, scope, ToolboxLogger(context, "HTS"))
|
||||
this.manager = manager
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
|
||||
@@ -5,12 +5,12 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
|
||||
implementation libs.nordic.theme
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothGatt
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.bluetooth.BluetoothGattServer
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -36,8 +37,7 @@ import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse
|
||||
import no.nordicsemi.android.ble.common.data.alert.AlertLevelData
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.prx.data.AlarmLevel
|
||||
import no.nordicsemi.android.prx.data.PRXData
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import no.nordicsemi.android.utils.launchWithCatch
|
||||
import java.util.*
|
||||
@@ -52,6 +52,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
internal class PRXManager(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -74,6 +75,14 @@ internal class PRXManager(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
private inner class ProximityManagerGattCallback : BleManagerGattCallback() {
|
||||
override fun initialize() {
|
||||
super.initialize()
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.prx.data.AlarmLevel
|
||||
import no.nordicsemi.android.prx.data.PRXData
|
||||
import no.nordicsemi.android.prx.data.PRXManager
|
||||
@@ -36,7 +37,7 @@ class PRXRepository @Inject internal constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = PRXManager(context, scope)
|
||||
val manager = PRXManager(context, scope, ToolboxLogger(context, "PRX"))
|
||||
this.manager = manager
|
||||
manager.useServer(proximityServerManager)
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
|
||||
implementation libs.nordic.theme
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ package no.nordicsemi.android.rscs.data
|
||||
import android.bluetooth.BluetoothGatt
|
||||
import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -32,10 +33,8 @@ import no.nordicsemi.android.ble.BleManager
|
||||
import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse
|
||||
import no.nordicsemi.android.ble.common.callback.rsc.RunningSpeedAndCadenceMeasurementResponse
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.rscs.data.RSCSData
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import no.nordicsemi.android.utils.launchWithCatch
|
||||
import java.util.*
|
||||
|
||||
val RSCS_SERVICE_UUID: UUID = UUID.fromString("00001814-0000-1000-8000-00805F9B34FB")
|
||||
@@ -46,7 +45,8 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
|
||||
internal class RSCSManager internal constructor(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -63,6 +63,14 @@ internal class RSCSManager internal constructor(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
private inner class RSCManagerGattCallback : BleManagerGattCallback() {
|
||||
|
||||
override fun initialize() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.rscs.data.RSCSData
|
||||
import no.nordicsemi.android.rscs.data.RSCSManager
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
@@ -19,7 +20,7 @@ import javax.inject.Singleton
|
||||
class RSCSRepository @Inject constructor(
|
||||
@ApplicationContext
|
||||
private val context: Context,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val serviceManager: ServiceManager
|
||||
) {
|
||||
private var manager: RSCSManager? = null
|
||||
|
||||
@@ -34,7 +35,7 @@ class RSCSRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = RSCSManager(context, scope)
|
||||
val manager = RSCSManager(context, scope, ToolboxLogger(context, "RSCS"))
|
||||
this.manager = manager
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
|
||||
@@ -26,6 +26,7 @@ dependencies {
|
||||
implementation project(":lib_service")
|
||||
implementation project(":lib_theme")
|
||||
implementation project(":lib_utils")
|
||||
implementation project(":lib_log")
|
||||
|
||||
implementation libs.room.runtime
|
||||
implementation libs.room.ktx
|
||||
@@ -34,7 +35,6 @@ dependencies {
|
||||
implementation libs.nordic.ble.common
|
||||
implementation libs.nordic.ble.ktx
|
||||
|
||||
implementation libs.nordic.log
|
||||
implementation libs.nordic.theme
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothGattCharacteristic
|
||||
import android.bluetooth.BluetoothGattService
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
@@ -35,6 +36,7 @@ import no.nordicsemi.android.ble.WriteRequest
|
||||
import no.nordicsemi.android.ble.common.callback.battery.BatteryLevelResponse
|
||||
import no.nordicsemi.android.ble.ktx.asFlow
|
||||
import no.nordicsemi.android.ble.ktx.asValidResponseFlow
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.ConnectionObserverAdapter
|
||||
import no.nordicsemi.android.utils.EMPTY
|
||||
import no.nordicsemi.android.utils.launchWithCatch
|
||||
@@ -50,6 +52,7 @@ private val BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002A19-0000-1
|
||||
internal class UARTManager(
|
||||
context: Context,
|
||||
private val scope: CoroutineScope,
|
||||
private val logger: ToolboxLogger
|
||||
) : BleManager(context) {
|
||||
|
||||
private var batteryLevelCharacteristic: BluetoothGattCharacteristic? = null
|
||||
@@ -70,6 +73,14 @@ internal class UARTManager(
|
||||
}.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun log(priority: Int, message: String) {
|
||||
logger.log(priority, message)
|
||||
}
|
||||
|
||||
override fun getMinLogPriority(): Int {
|
||||
return Log.VERBOSE
|
||||
}
|
||||
|
||||
private inner class UARTManagerGattCallback : BleManagerGattCallback() {
|
||||
|
||||
override fun initialize() {
|
||||
|
||||
@@ -7,12 +7,11 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.log.ToolboxLogger
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.service.ConnectingResult
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
import no.nordicsemi.android.uart.data.*
|
||||
import no.nordicsemi.android.uart.data.UARTData
|
||||
import no.nordicsemi.android.uart.data.UARTManager
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -38,7 +37,7 @@ class UARTRepository @Inject internal constructor(
|
||||
}
|
||||
|
||||
fun start(device: BluetoothDevice, scope: CoroutineScope) {
|
||||
val manager = UARTManager(context, scope)
|
||||
val manager = UARTManager(context, scope, ToolboxLogger(context, "UART"))
|
||||
this.manager = manager
|
||||
|
||||
manager.dataHolder.status.onEach {
|
||||
|
||||
@@ -13,10 +13,7 @@ dependencyResolutionManagement {
|
||||
library('nordic-ble-ktx', 'no.nordicsemi.android:ble-ktx:2.4.0-beta03')
|
||||
library('nordic-scanner', 'no.nordicsemi.android.support.v18:scanner:1.6.0')
|
||||
|
||||
library('nordic-log', 'no.nordicsemi.android:log-timber:2.3.0')
|
||||
library('timber-main', 'com.jakewharton.timber:timber:5.0.1')
|
||||
library('timber-arcao', 'com.arcao:slf4j-timber:3.1')
|
||||
bundle('icons', ['nordic-log', 'timber-main', 'timber-arcao'])
|
||||
library('nordic-log', 'no.nordicsemi.android:log:2.3.0')
|
||||
|
||||
version('commonlibraries', '1.0.5')
|
||||
library('nordic-ui-scanner', 'no.nordicsemi.android.common', 'uiscanner').versionRef('commonlibraries')
|
||||
@@ -100,6 +97,7 @@ include ':profile_uart'
|
||||
include ':lib_service'
|
||||
include ':lib_theme'
|
||||
include ':lib_utils'
|
||||
include ':lib_log'
|
||||
|
||||
if (file('../Android-Common-Libraries').exists()) {
|
||||
includeBuild('../Android-Common-Libraries')
|
||||
|
||||
Reference in New Issue
Block a user