Skip to content

Commit ea0904d

Browse files
committed
Second stage updating to ST BLE Sensor V5.1.0
Signed-off-by: Luca Pezzoni <luca.pezzoni@st.com>
1 parent a472e1f commit ea0904d

51 files changed

Lines changed: 441 additions & 124 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/com/st/bluems/ui/home/HomeViewModel.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.st.blue_sdk.common.Status
2121
import com.st.blue_sdk.models.ConnectionStatus
2222
import com.st.blue_sdk.models.Node
2323
import com.st.blue_sdk.models.NodeState
24-
import com.st.internal.BuildConfig
2524
import com.st.login.api.StLoginManager
2625
import com.st.preferences.StPreferences
2726
import com.st.user_profiling.model.LevelProficiency
@@ -151,14 +150,15 @@ class HomeViewModel @Inject constructor(
151150
}
152151

153152
fun readBetaCatalog() {
154-
viewModelScope.launch {
155-
val url: String = BuildConfig.BLUESTSDK_DB_BASE_BETA_URL
156-
blueManager.reset(url)
157-
_boardsDescription.value = blueManager.getBoardsDescription()
158-
//Log.i("DB","readBetaCatalog checkBoardsCatalogPresence = ${ _boardsDescription.value.size}")
159-
160-
}
153+
// viewModelScope.launch {
154+
// val url: String = BuildConfig.BLUESTSDK_DB_BASE_BETA_URL
155+
// blueManager.reset(url)
156+
// _boardsDescription.value = blueManager.getBoardsDescription()
157+
// //Log.i("DB","readBetaCatalog checkBoardsCatalogPresence = ${ _boardsDescription.value.size}")
158+
//
159+
// }
161160
//checkBoardsCatalogPresence()
161+
readReleaseCatalog()
162162
}
163163

164164
fun readReleaseCatalog() {

st_demo_showcase/src/main/java/com/st/demo_showcase/utils/Extensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fun List<String>?.toActions(
5858
fun Demo.isLoginRequired(): Boolean = when (this) {
5959
// Demo.Flow -> true
6060
// Demo.Cloud -> true
61-
Demo.ExtConfig -> true
61+
// Demo.ExtConfig -> true
6262
else -> false
6363
}
6464

st_high_speed_data_log/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ dependencies {
8484
// Hilt
8585
implementation "androidx.hilt:hilt-navigation-fragment:$hilt_navigation_fragment_version"
8686
implementation "com.google.dagger:hilt-android:$hilt_version"
87+
implementation project(path: ':st_preferences')
8788
kapt "com.google.dagger:hilt-compiler:$hilt_version"
8889

8990
// Tests

st_high_speed_data_log/src/main/java/com/st/hight_speed_data_log/HighSpeedDataLog.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import androidx.navigation.compose.composable
4949
import androidx.navigation.compose.rememberNavController
5050
import com.st.blue_sdk.board_catalog.models.DtmiContent
5151
import com.st.high_speed_data_log.R
52-
import com.st.hight_speed_data_log.composable.BottomAppBarItem
52+
import com.st.ui.composables.BottomAppBarItem
5353
import com.st.hight_speed_data_log.composable.HsdlSensors
5454
import com.st.hight_speed_data_log.composable.HsdlTags
5555
import com.st.hight_speed_data_log.composable.StopLoggingDialog
@@ -165,7 +165,7 @@ fun HighSpeedDataLog(
165165
modifier = modifier,
166166
isFloatingActionButtonDocked = true,
167167
topBar = {
168-
HsdlConfig.hsdlTabBar?.invoke(currentTitle)
168+
HsdlConfig.hsdlTabBar?.invoke(currentTitle, isLoading)
169169
},
170170
floatingActionButtonPosition = androidx.compose.material.FabPosition.Center,
171171
floatingActionButton = {
@@ -258,6 +258,7 @@ fun HighSpeedDataLog(
258258
HsdlSensors(
259259
sensors = sensors,
260260
status = status,
261+
isLoading = isLoading,
261262
onValueChange = onValueChange,
262263
onSendCommand = onSendCommand
263264
)
@@ -281,13 +282,15 @@ fun HighSpeedDataLog(
281282
HsdlTags(
282283
tags = tags,
283284
status = status,
285+
isLoading = isLoading,
284286
onValueChange = onValueChange,
285287
onSendCommand = onSendCommand
286288
)
287289
} else {
288290
VespucciHsdlTags(
289291
acquisitionInfo = acquisitionName,
290292
vespucciTags = vespucciTags,
293+
isLoading = isLoading,
291294
isLogging = isLogging,
292295
onTagChangeState = onTagChangeState
293296
)

st_high_speed_data_log/src/main/java/com/st/hight_speed_data_log/HighSpeedDataLogViewModel.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.st.blue_sdk.features.extended.pnpl.PnPL
1717
import com.st.blue_sdk.features.extended.pnpl.PnPLConfig
1818
import com.st.blue_sdk.features.extended.pnpl.request.PnPLCmd
1919
import com.st.blue_sdk.features.extended.pnpl.request.PnPLCommand
20+
import com.st.preferences.StPreferences
2021
import com.st.ui.composables.CommandRequest
2122
import dagger.hilt.android.lifecycle.HiltViewModel
2223
import kotlinx.coroutines.CoroutineScope
@@ -46,7 +47,9 @@ private typealias ComponentWithInterface = Pair<DtmiContent.DtmiComponentContent
4647

4748
@HiltViewModel
4849
class HighSpeedDataLogViewModel @Inject constructor(
49-
private val blueManager: BlueManager, private val coroutineScope: CoroutineScope
50+
private val blueManager: BlueManager,
51+
private val stPreferences: StPreferences,
52+
private val coroutineScope: CoroutineScope
5053
) : ViewModel() {
5154

5255
private var observeFeatureJob: Job? = null
@@ -245,7 +248,7 @@ class HighSpeedDataLogViewModel @Inject constructor(
245248
_isLoading.value = true
246249

247250
val componentWithInterface =
248-
blueManager.getDtmiModel(nodeId = nodeId)?.extractComponents(demoName = null)
251+
blueManager.getDtmiModel(nodeId = nodeId, isBeta = stPreferences.isBetaApplication())?.extractComponents(demoName = null)
249252
?: emptyList()
250253

251254
_sensors.value = componentWithInterface.hsdl2SensorsFilter()
@@ -304,7 +307,8 @@ class HighSpeedDataLogViewModel @Inject constructor(
304307
private suspend fun setName(nodeId: String) {
305308
val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
306309
val timeInMillis = calendar.timeInMillis
307-
val sdf = SimpleDateFormat("EEE MMM d yyyy HH:mm:ss", Locale.UK)
310+
val nameFormatter = HsdlConfig.datalogNameFormat ?: "EEE MMM d yyyy HH:mm:ss"
311+
val sdf = SimpleDateFormat(nameFormatter, Locale.UK)
308312
val datetime = sdf.format(Date(timeInMillis))
309313

310314
_acquisitionName.emit(datetime)

st_high_speed_data_log/src/main/java/com/st/hight_speed_data_log/HsdlConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ object HsdlConfig {
66

77
var tags: List<String> = emptyList()
88

9-
var hsdlTabBar: (@Composable (title: String) -> Unit)? = null
9+
var hsdlTabBar: (@Composable (title: String, isLoading: Boolean) -> Unit)? = null
1010

1111
var showStopDialog: Boolean = false
1212

1313
var isLogging: Boolean = false
1414

15+
var datalogNameFormat: String? = null
1516
}

st_high_speed_data_log/src/main/java/com/st/hight_speed_data_log/composable/HsdlSensors.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import kotlinx.serialization.json.JsonObject
2222
@Composable
2323
fun HsdlSensors(
2424
modifier: Modifier = Modifier,
25+
isLoading: Boolean,
2526
sensors: List<Pair<DtmiContent.DtmiComponentContent, DtmiContent.DtmiInterfaceContent>> = emptyList(),
2627
status: List<JsonObject>,
2728
onValueChange: (String, Pair<String, Any>) -> Unit,
@@ -39,6 +40,7 @@ fun HsdlSensors(
3940
Component(
4041
name = name,
4142
data = data,
43+
enabled = isLoading.not(),
4244
enableCollapse = true,
4345
isOpen = isOpen == name,
4446
componentModel = componentWithInterface.first,

st_high_speed_data_log/src/main/java/com/st/hight_speed_data_log/composable/HsdlTags.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kotlinx.serialization.json.JsonObject
1818
@Composable
1919
fun HsdlTags(
2020
modifier: Modifier = Modifier,
21+
isLoading: Boolean,
2122
tags: List<Pair<DtmiContent.DtmiComponentContent, DtmiContent.DtmiInterfaceContent>> = emptyList(),
2223
status: List<JsonObject>,
2324
onValueChange: (String, Pair<String, Any>) -> Unit,
@@ -32,6 +33,7 @@ fun HsdlTags(
3233
val name = componentWithInterface.first.name
3334
val data = (status.find { it.containsKey(name) })?.get(name)
3435
Component(
36+
enabled = isLoading.not(),
3537
name = name,
3638
data = data,
3739
enableCollapse = false,

st_high_speed_data_log/src/main/java/com/st/hight_speed_data_log/composable/VespucciHsdlTags.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import com.st.ui.theme.PreviewBlueMSTheme
4545
fun VespucciHsdlTags(
4646
modifier: Modifier = Modifier,
4747
acquisitionInfo: String,
48+
isLoading: Boolean,
4849
isLogging: Boolean,
4950
vespucciTags: Map<String, Boolean>,
5051
onTagChangeState: (String, Boolean) -> Unit = { _, _ -> /**NOOP**/ }
@@ -66,6 +67,7 @@ fun VespucciHsdlTags(
6667
Spacer(modifier = Modifier.height(height = LocalDimensions.current.paddingMedium))
6768

6869
TagsInfo(
70+
isLoading = isLoading,
6971
isLogging = isLogging,
7072
vespucciTags = vespucciTags,
7173
onTagChangeState = onTagChangeState
@@ -168,6 +170,7 @@ fun AcquisitionInfo(
168170
@Composable
169171
fun TagsInfo(
170172
modifier: Modifier = Modifier,
173+
isLoading: Boolean,
171174
isLogging: Boolean,
172175
vespucciTags: Map<String, Boolean> = emptyMap(),
173176
onTagChangeState: (String, Boolean) -> Unit = { _, _ -> /**NOOP**/ }
@@ -222,7 +225,7 @@ fun TagsInfo(
222225
vespucciTags.forEach { tag ->
223226
TagListItem(
224227
tag = tag.key,
225-
isEnabled = isLogging,
228+
isEnabled = isLogging && isLoading.not(),
226229
isChecked = tag.value,
227230
onCheckChange = { checked ->
228231
onTagChangeState(tag.key, checked)
@@ -293,6 +296,7 @@ private fun VespucciHsdlTagsPreview() {
293296
VespucciHsdlTags(
294297
acquisitionInfo = "Fri May 26 2023 13:47:27",
295298
isLogging = false,
299+
isLoading = false,
296300
vespucciTags = mapOf("Prova" to true, "Test" to false, "Mock" to true)
297301
)
298302
}
@@ -305,6 +309,20 @@ private fun VespucciHsdlTagsLoggingPreview() {
305309
VespucciHsdlTags(
306310
acquisitionInfo = "Fri May 26 2023 13:47:27",
307311
isLogging = true,
312+
isLoading = false,
313+
vespucciTags = mapOf("Prova" to true, "Test" to false, "Mock" to true)
314+
)
315+
}
316+
}
317+
318+
@Preview(showBackground = true)
319+
@Composable
320+
private fun VespucciHsdlTagsLoadingPreview() {
321+
PreviewBlueMSTheme {
322+
VespucciHsdlTags(
323+
acquisitionInfo = "Fri May 26 2023 13:47:27",
324+
isLogging = false,
325+
isLoading = true,
308326
vespucciTags = mapOf("Prova" to true, "Test" to false, "Mock" to true)
309327
)
310328
}

st_led_control/src/main/java/com/st/led_control/LedControlFragment.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,8 @@ class LedControlFragment : Fragment() {
7979

8080
mLedImage.setOnClickListener {
8181
if(mCurrentDevice!=null) {
82-
mLedStatus = if (mLedStatus) {
83-
mLedImage.setImageResource(R.drawable.stm32wb_led_off)
84-
false
85-
} else {
86-
mLedImage.setImageResource(R.drawable.stm32wb_led_on)
87-
true
88-
}
82+
mLedStatus = mLedStatus==false
83+
changeLedStatusImage(mLedStatus)
8984
viewModel.writeSwitchCommand(nodeId, mCurrentDevice!!,mLedStatus)
9085
}
9186
}
@@ -95,6 +90,13 @@ class LedControlFragment : Fragment() {
9590
return binding.root
9691
}
9792

93+
private fun changeLedStatusImage(newState: Boolean) {
94+
when(newState) {
95+
true -> mLedImage.setImageResource(R.drawable.stm32wb_led_on)
96+
false -> mLedImage.setImageResource(R.drawable.stm32wb_led_off)
97+
}
98+
}
99+
98100
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
99101
super.onViewCreated(view, savedInstanceState)
100102

@@ -172,24 +174,30 @@ class LedControlFragment : Fragment() {
172174
val node = viewModel.getNode(nodeId)
173175

174176
if(node!=null) {
175-
mCurrentDevice =
176-
node.advertiseInfo?.getDeviceId()
177-
?.let { P2PConfiguration.getDeviceIdByBoardId(it.toInt()) }
177+
mCurrentDevice = node.advertiseInfo?.let {
178+
val deviceId = it.getDeviceId().toInt()
179+
val sdkVersion = it.getProtocolVersion().toInt()
180+
P2PConfiguration.getDeviceIdByBoardId(deviceId,sdkVersion)
181+
}
182+
// node.advertiseInfo?.getDeviceId()
183+
// ?.let { P2PConfiguration.getDeviceIdByBoardId(it.toInt()) }
178184
}
179185

180186
if (mCurrentDevice != null) {
181187
showDeviceDetected(mCurrentDevice!!)
182188
}
183189

184190
if (node != null) {
185-
if (node.boardType == Boards.Model.WBA_BOARD) { // there is no notion of P2PServer 1, P2PServer 2, etc. for WBA
191+
if (node.familyType == Boards.Family.WBA_FAMILY) { // there is no notion of P2PServer 1, P2PServer 2, etc. for WBA
186192
showDeviceDetected(P2PConfiguration.DeviceId.Device1)
187193
}
188194

189195
if(node.rssi!=null) {
190196
mRssiText.text = getString(R.string.stm32wb_rssiFormat, node.rssi!!.rssi)
191197
}
192198
}
199+
200+
changeLedStatusImage(mLedStatus)
193201
}
194202

195203
override fun onPause() {

0 commit comments

Comments
 (0)