Week12
Week 12 Progress: BLE Control, Reset Commands, and Exporting Graphs
Objective:
To finalize app interaction logic by adding BLE-based command sending (RESET), exporting chart visuals to the gallery, and refining the feedback interface.
Implementation:
This week focused on expanding interactivity, BLE write operations, and implementing advanced features such as exporting graph images. These additions greatly enhanced the app’s practicality and user-friendliness.
Reset Command via BLE Write:
The reset function allows users to instruct the microcontroller to restart all monitoring. The code sends a "RESET" string to a writable BLE characteristic (19B10003...) using:
commandCharacteristic.value = "RESET".toByteArray()
gatt.writeCharacteristic(commandCharacteristic)
dataList.clear()
This command clears chart history and resets backend data processing, with confirmation shown via a Toast.
Image Export of Chart View:
A bitmap of the chart is captured from the Compose surface using drawing cache logic. The captured image is saved using the Android MediaStore API:
val bitmap = Bitmap.createBitmap(view.drawingCache)
saveBitmapToGallery(bitmap)
Support is included for both Android 10+ and legacy directory structures, making it future-proof. A success/failure message is displayed after each export operation.
Descriptor Configuration for Notifications:
BLE notification setup is handled during service discovery. A CCCD descriptor is written to ensure that the app is notified whenever the BLE peripheral updates a characteristic:
val descriptor = stateCharacteristic.getDescriptor(UUID.fromString("00002902-..."))
descriptor?.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
gatt.writeDescriptor(descriptor)
Without this step, BLE callbacks like onCharacteristicChanged wouldn’t trigger.
UI Enhancements and Command Buttons:
UI buttons for Disconnect, Reset, and Export were added and tested. Conditional display logic ensures that only relevant controls are visible based on connection state. Every action provides immediate feedback through Toast.makeText.
Results:
BLE command writing works reliably across test cases.
Users can reset the monitoring system from the app without restarting hardware.
Real-time BLE updates now support notification-based architecture.
Exported chart images verify app completeness and readiness for demo.


Comments
Post a Comment