Skip to content

Commit

Permalink
Second stage updating to ST BLE Sensor V5.1.0
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Pezzoni <luca.pezzoni@st.com>
  • Loading branch information
PezzoniL committed Oct 23, 2023
1 parent a472e1f commit ea0904d
Show file tree
Hide file tree
Showing 51 changed files with 441 additions and 124 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/com/st/bluems/ui/home/HomeViewModel.kt
Expand Up @@ -21,7 +21,6 @@ import com.st.blue_sdk.common.Status
import com.st.blue_sdk.models.ConnectionStatus
import com.st.blue_sdk.models.Node
import com.st.blue_sdk.models.NodeState
import com.st.internal.BuildConfig
import com.st.login.api.StLoginManager
import com.st.preferences.StPreferences
import com.st.user_profiling.model.LevelProficiency
Expand Down Expand Up @@ -151,14 +150,15 @@ class HomeViewModel @Inject constructor(
}

fun readBetaCatalog() {
viewModelScope.launch {
val url: String = BuildConfig.BLUESTSDK_DB_BASE_BETA_URL
blueManager.reset(url)
_boardsDescription.value = blueManager.getBoardsDescription()
//Log.i("DB","readBetaCatalog checkBoardsCatalogPresence = ${ _boardsDescription.value.size}")

}
// viewModelScope.launch {
// val url: String = BuildConfig.BLUESTSDK_DB_BASE_BETA_URL
// blueManager.reset(url)
// _boardsDescription.value = blueManager.getBoardsDescription()
// //Log.i("DB","readBetaCatalog checkBoardsCatalogPresence = ${ _boardsDescription.value.size}")
//
// }
//checkBoardsCatalogPresence()
readReleaseCatalog()
}

fun readReleaseCatalog() {
Expand Down
Expand Up @@ -58,7 +58,7 @@ fun List<String>?.toActions(
fun Demo.isLoginRequired(): Boolean = when (this) {
// Demo.Flow -> true
// Demo.Cloud -> true
Demo.ExtConfig -> true
// Demo.ExtConfig -> true
else -> false
}

Expand Down
1 change: 1 addition & 0 deletions st_high_speed_data_log/build.gradle
Expand Up @@ -84,6 +84,7 @@ dependencies {
// Hilt
implementation "androidx.hilt:hilt-navigation-fragment:$hilt_navigation_fragment_version"
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation project(path: ':st_preferences')
kapt "com.google.dagger:hilt-compiler:$hilt_version"

// Tests
Expand Down
Expand Up @@ -49,7 +49,7 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.st.blue_sdk.board_catalog.models.DtmiContent
import com.st.high_speed_data_log.R
import com.st.hight_speed_data_log.composable.BottomAppBarItem
import com.st.ui.composables.BottomAppBarItem
import com.st.hight_speed_data_log.composable.HsdlSensors
import com.st.hight_speed_data_log.composable.HsdlTags
import com.st.hight_speed_data_log.composable.StopLoggingDialog
Expand Down Expand Up @@ -165,7 +165,7 @@ fun HighSpeedDataLog(
modifier = modifier,
isFloatingActionButtonDocked = true,
topBar = {
HsdlConfig.hsdlTabBar?.invoke(currentTitle)
HsdlConfig.hsdlTabBar?.invoke(currentTitle, isLoading)
},
floatingActionButtonPosition = androidx.compose.material.FabPosition.Center,
floatingActionButton = {
Expand Down Expand Up @@ -258,6 +258,7 @@ fun HighSpeedDataLog(
HsdlSensors(
sensors = sensors,
status = status,
isLoading = isLoading,
onValueChange = onValueChange,
onSendCommand = onSendCommand
)
Expand All @@ -281,13 +282,15 @@ fun HighSpeedDataLog(
HsdlTags(
tags = tags,
status = status,
isLoading = isLoading,
onValueChange = onValueChange,
onSendCommand = onSendCommand
)
} else {
VespucciHsdlTags(
acquisitionInfo = acquisitionName,
vespucciTags = vespucciTags,
isLoading = isLoading,
isLogging = isLogging,
onTagChangeState = onTagChangeState
)
Expand Down
Expand Up @@ -17,6 +17,7 @@ import com.st.blue_sdk.features.extended.pnpl.PnPL
import com.st.blue_sdk.features.extended.pnpl.PnPLConfig
import com.st.blue_sdk.features.extended.pnpl.request.PnPLCmd
import com.st.blue_sdk.features.extended.pnpl.request.PnPLCommand
import com.st.preferences.StPreferences
import com.st.ui.composables.CommandRequest
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -46,7 +47,9 @@ private typealias ComponentWithInterface = Pair<DtmiContent.DtmiComponentContent

@HiltViewModel
class HighSpeedDataLogViewModel @Inject constructor(
private val blueManager: BlueManager, private val coroutineScope: CoroutineScope
private val blueManager: BlueManager,
private val stPreferences: StPreferences,
private val coroutineScope: CoroutineScope
) : ViewModel() {

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

val componentWithInterface =
blueManager.getDtmiModel(nodeId = nodeId)?.extractComponents(demoName = null)
blueManager.getDtmiModel(nodeId = nodeId, isBeta = stPreferences.isBetaApplication())?.extractComponents(demoName = null)
?: emptyList()

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

_acquisitionName.emit(datetime)
Expand Down
Expand Up @@ -6,10 +6,11 @@ object HsdlConfig {

var tags: List<String> = emptyList()

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

var showStopDialog: Boolean = false

var isLogging: Boolean = false

var datalogNameFormat: String? = null
}
Expand Up @@ -22,6 +22,7 @@ import kotlinx.serialization.json.JsonObject
@Composable
fun HsdlSensors(
modifier: Modifier = Modifier,
isLoading: Boolean,
sensors: List<Pair<DtmiContent.DtmiComponentContent, DtmiContent.DtmiInterfaceContent>> = emptyList(),
status: List<JsonObject>,
onValueChange: (String, Pair<String, Any>) -> Unit,
Expand All @@ -39,6 +40,7 @@ fun HsdlSensors(
Component(
name = name,
data = data,
enabled = isLoading.not(),
enableCollapse = true,
isOpen = isOpen == name,
componentModel = componentWithInterface.first,
Expand Down
Expand Up @@ -18,6 +18,7 @@ import kotlinx.serialization.json.JsonObject
@Composable
fun HsdlTags(
modifier: Modifier = Modifier,
isLoading: Boolean,
tags: List<Pair<DtmiContent.DtmiComponentContent, DtmiContent.DtmiInterfaceContent>> = emptyList(),
status: List<JsonObject>,
onValueChange: (String, Pair<String, Any>) -> Unit,
Expand All @@ -32,6 +33,7 @@ fun HsdlTags(
val name = componentWithInterface.first.name
val data = (status.find { it.containsKey(name) })?.get(name)
Component(
enabled = isLoading.not(),
name = name,
data = data,
enableCollapse = false,
Expand Down
Expand Up @@ -45,6 +45,7 @@ import com.st.ui.theme.PreviewBlueMSTheme
fun VespucciHsdlTags(
modifier: Modifier = Modifier,
acquisitionInfo: String,
isLoading: Boolean,
isLogging: Boolean,
vespucciTags: Map<String, Boolean>,
onTagChangeState: (String, Boolean) -> Unit = { _, _ -> /**NOOP**/ }
Expand All @@ -66,6 +67,7 @@ fun VespucciHsdlTags(
Spacer(modifier = Modifier.height(height = LocalDimensions.current.paddingMedium))

TagsInfo(
isLoading = isLoading,
isLogging = isLogging,
vespucciTags = vespucciTags,
onTagChangeState = onTagChangeState
Expand Down Expand Up @@ -168,6 +170,7 @@ fun AcquisitionInfo(
@Composable
fun TagsInfo(
modifier: Modifier = Modifier,
isLoading: Boolean,
isLogging: Boolean,
vespucciTags: Map<String, Boolean> = emptyMap(),
onTagChangeState: (String, Boolean) -> Unit = { _, _ -> /**NOOP**/ }
Expand Down Expand Up @@ -222,7 +225,7 @@ fun TagsInfo(
vespucciTags.forEach { tag ->
TagListItem(
tag = tag.key,
isEnabled = isLogging,
isEnabled = isLogging && isLoading.not(),
isChecked = tag.value,
onCheckChange = { checked ->
onTagChangeState(tag.key, checked)
Expand Down Expand Up @@ -293,6 +296,7 @@ private fun VespucciHsdlTagsPreview() {
VespucciHsdlTags(
acquisitionInfo = "Fri May 26 2023 13:47:27",
isLogging = false,
isLoading = false,
vespucciTags = mapOf("Prova" to true, "Test" to false, "Mock" to true)
)
}
Expand All @@ -305,6 +309,20 @@ private fun VespucciHsdlTagsLoggingPreview() {
VespucciHsdlTags(
acquisitionInfo = "Fri May 26 2023 13:47:27",
isLogging = true,
isLoading = false,
vespucciTags = mapOf("Prova" to true, "Test" to false, "Mock" to true)
)
}
}

@Preview(showBackground = true)
@Composable
private fun VespucciHsdlTagsLoadingPreview() {
PreviewBlueMSTheme {
VespucciHsdlTags(
acquisitionInfo = "Fri May 26 2023 13:47:27",
isLogging = false,
isLoading = true,
vespucciTags = mapOf("Prova" to true, "Test" to false, "Mock" to true)
)
}
Expand Down
Expand Up @@ -79,13 +79,8 @@ class LedControlFragment : Fragment() {

mLedImage.setOnClickListener {
if(mCurrentDevice!=null) {
mLedStatus = if (mLedStatus) {
mLedImage.setImageResource(R.drawable.stm32wb_led_off)
false
} else {
mLedImage.setImageResource(R.drawable.stm32wb_led_on)
true
}
mLedStatus = mLedStatus==false
changeLedStatusImage(mLedStatus)
viewModel.writeSwitchCommand(nodeId, mCurrentDevice!!,mLedStatus)
}
}
Expand All @@ -95,6 +90,13 @@ class LedControlFragment : Fragment() {
return binding.root
}

private fun changeLedStatusImage(newState: Boolean) {
when(newState) {
true -> mLedImage.setImageResource(R.drawable.stm32wb_led_on)
false -> mLedImage.setImageResource(R.drawable.stm32wb_led_off)
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

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

if(node!=null) {
mCurrentDevice =
node.advertiseInfo?.getDeviceId()
?.let { P2PConfiguration.getDeviceIdByBoardId(it.toInt()) }
mCurrentDevice = node.advertiseInfo?.let {
val deviceId = it.getDeviceId().toInt()
val sdkVersion = it.getProtocolVersion().toInt()
P2PConfiguration.getDeviceIdByBoardId(deviceId,sdkVersion)
}
// node.advertiseInfo?.getDeviceId()
// ?.let { P2PConfiguration.getDeviceIdByBoardId(it.toInt()) }
}

if (mCurrentDevice != null) {
showDeviceDetected(mCurrentDevice!!)
}

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

if(node.rssi!=null) {
mRssiText.text = getString(R.string.stm32wb_rssiFormat, node.rssi!!.rssi)
}
}

changeLedStatusImage(mLedStatus)
}

override fun onPause() {
Expand Down
2 changes: 1 addition & 1 deletion st_level/src/main/java/com/st/level/LevelDemoFragment.kt
Expand Up @@ -91,7 +91,7 @@ class LevelDemoFragment : Fragment() {
binding.levelSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
view: View?,
position: Int,
id: Long
) {
Expand Down
2 changes: 1 addition & 1 deletion st_login/build.gradle
Expand Up @@ -91,7 +91,7 @@ dependencies {
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

implementation 'com.auth0:java-jwt:4.0.0'
implementation 'com.auth0:java-jwt:4.4.0'
implementation 'net.openid:appauth:0.11.1'

// Tests
Expand Down
Expand Up @@ -81,7 +81,7 @@ class MotionAlgorithmsFragment : Fragment() {
mAlgoSelector.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
view: View?,
position: Int,
id: Long
) {
Expand Down
2 changes: 1 addition & 1 deletion st_neai_anomaly_detection/src/main/res/values/strings.xml
Expand Up @@ -38,7 +38,7 @@
<string name="st_neaiAnomalyDetection_aiengine_state_unknownError">UNKNOWN ERROR</string>
<string name="st_neaiAnomalyDetection_aiengine_state_null">NULL</string>
<string name="st_neaiAnomalyDetection_text_progressTitle">Progress:\u0020</string>
<string name="st_neaiAnomalyDetection_results_status_normal">ANOMALY</string>
<string name="st_neaiAnomalyDetection_results_status_normal">NORMAL</string>
<string name="st_neaiAnomalyDetection_results_status_anomaly">ANOMALY</string>
<string name="st_neaiAnomalyDetection_results_status_null">NULL</string>
<string name="st_neaiAnomalyDetection_text_resultsTitle">Results</string>
Expand Down
Expand Up @@ -180,7 +180,7 @@ class NfcWritingFragment : Fragment() {
authorizationSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
view: View?,
position: Int,
id: Long
) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class NfcWritingFragment : Fragment() {
encryptionSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
view: View?,
position: Int,
id: Long
) {
Expand Down Expand Up @@ -304,7 +304,7 @@ class NfcWritingFragment : Fragment() {
urlTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
view: View?,
position: Int,
id: Long
) {
Expand Down

0 comments on commit ea0904d

Please sign in to comment.