Week11
Week 11 Progress: Building the App Interface and State Management
Objective:
To design and implement the primary interface for the smart sock Android application using Jetpack Compose. This included setting up the BLE device list screen, live data display components, and the infrastructure for real-time state management.
Implementation:
During this week, focus was placed on two major components: the connection logic in MainActivity.kt and the UI construction within ConnectedDeviceScreen.kt. The goal was to build a responsive, functional layout that could reflect live BLE data and display relevant health status indicators.
Connection Flow and UI Switching:
A reactive architecture was adopted using mutableStateOf variables such as isConnected, connectedDeviceData, and alarmStatusState. These were used to dynamically swap between the scanning screen and the connected device screen:
setContent {
if (isConnected) {
ConnectedDeviceScreen(...)
} else {
BleDeviceListScreen(...)
}
}
BLE Callbacks and Data Parsing:
In onCharacteristicChanged, composite BLE data (e.g., "MOVING,NORMAL,6380") was split into parts and stored in state variables:
val parts = compositeValue.split(",")
deviceStatusState = parts[0]
alarmStatusState = parts[1]
connectedDeviceData = (parts[2].toInt() / 100.0).toString()
This mechanism ensured that state variables instantly reflected new incoming data, triggering automatic UI updates due to Compose’s recomposition model.
Chart Integration and Dynamic Plotting:
The application incorporates MPAndroidChart through the custom LineChartComponent, which reads from the reactive dataList. As connectedDeviceData changes, its value is appended to dataList, which the chart component observes to redraw the line in real-time:
Interface Composition:
The app’s screen was built using vertical Column structures, embedding Text views for status indicators and buttons for user interaction. Components were spaced with padding and aligned to maximize clarity and accessibility on small screens.
Results:
A fully functional and clean Compose interface was completed.
BLE data parsing and live status tracking were tested successfully.
Charts displayed historical ADC values with accurate rendering.
A robust architecture is now in place for integrating BLE controls and user interactions in the next phase.
A fully functional and clean Compose interface was completed.
BLE data parsing and live status tracking were tested successfully.
Charts displayed historical ADC values with accurate rendering.
A robust architecture is now in place for integrating BLE controls and user interactions in the next phase.

Comments
Post a Comment