Intro - A4100 Sample Health App Using PPG Sensor
Background
This document covers the foundational technical details of PPG Sensors utilized in Heart Rate, Breathing Rate, and Blood Oxygen Monitoring on Mason A4100. This document provides code snippets and navigational data flows and the public GitHub codebase source is shared in the below sections.
PPG - “Photoplethysmography” is a technique that can be applied to various aspects of cardiovascular monitoring, including the detection of blood oxygen saturation, heart rate, etc
The A4100 is not a medical device and should not be used for medical purposes. The A4100 is not intended to diagnose, treat, cure or prevent any medical condition. This sample Health app using PPG sensor should not be used for medical purposes. If you are experiencing symptoms of a medical condition or have concerns about your health, you should seek the advice of a medical professional immediately.
Each section is explained in detail in below sections:
Getting Started - Listening to Sensor
To get the reading use SensorManager Class. Different devices have a variety of sensors that can be accessed via the sensor framework. Possible tasks related to sensors include:
- List available sensors
- Determine sensor capabilities (range, resolution, etc)
- Acquire raw sensor data
- Register sensor event listeners
It's also important to note that this example uses the onResume() and onPause() callback methods to register and unregister the sensor event listener. As a best practice, you should disable sensors you don't need, especially when your activity is paused. This will help reduce battery consumption.
// Add Uses Feature to AndroidManifest
<uses-feature android:name="android.hardware.type.watch" />
// Declare SensorManage and Sensor variable
private SensorManager sensorManager; private Sensor sensor;<br>
// Get sensor manager
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);<br>
// Get the default sensor of the specified type
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
//Start Sensor
private void startMeasure() { boolean sensorRegistered = sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST, null); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_LOW_LATENCY_OFFBODY_DETECT), SensorManager.SENSOR_DELAY_FASTEST); Log.d("Sensor Status:", " Sensor registered: " + (sensorRegistered ? "yes" : "no")); }
//Stop Sensor
// Stop Sensor private void stopMeasure() { sensorManager.unregisterListener(this); }<br>
//Register and Unregister Sensor
@Override protected void onResume() { super.onResume(); startMeasure(); } @Override protected void onPause() { super.onPause(); stopMeasure(); }
Data collection for new sensor event
For SensorManager to get notified of new sensor data, one should utilize the public interface SensorEventListener. This has two callback methods:
Callback method | Parameters |
public abstract void onAccuracyChanged (Sensor sensor, int accuracy) | Sensor: Sensor accuracy: int: The new accuracy of this sensor, one of SensorManager.SENSOR_STATUS |
public abstract void onSensorChanged (SensorEvent event) | event: SensorEvent: the SensorEvent. |
Please Note: onAccuracyChanged() is called when the accuracy of the registered sensor has changed. Unlike onSensorChanged(), this is only called when this accuracy value is changed.
Enable Health in App Launcher
To initiate a measurement, wear the watch on your wrist and go to the Launcher Screen. There we can see the Health Option on the Launcher app list.
// To enable Health in launcher list Below is the code snippet in AndroidManifest.xml
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
Upon clicking the health item from the list it will take you to the submenu in the health category.