Intro - A4100 Sample Health App Using ECG Sensor

Background

This document covers the foundational technical details of the ECG Sensor utilized in Heart Rate, Stress level and State of Stress, Total Energy, and Energy Progress on Mason smartwatch.  This document provides code snippets and navigational data flows shared in the below sections.

ECG - “Electrocardiogram” is a technique used to monitor heart activity.

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 ECG 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 - Working With ECGSensor

To get the reading use SensorManager Class and MasonHardwareFramework. 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 sensor data
  • Register sensor event listeners

The MasonHardwareFramework provides an interface for control/data exchange with device-specific sensors not already supported by the Android Sensor Framework (currently the A4100 supports ECG).

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 Android Manifest
<uses-feature android:name="android.hardware.type.watch" /><br>
// Declare SensorManger and Sensor variable
private SensorManager mSensorManager;
private ECGSensorManager  ecgManager;
private Sensor sensorData;
private Sensor userControl;
private Sensor sampleData;
// Get Different Sensor Type
sensorData=mSensorManager.getDefaultSensor(ECGSensorManager.SensorType.ECG_SENSORS_DATA);
userControl=mSensorManager.getDefaultSensor(ECGSensorManager.SensorType.ECG_USER_CONTROL);
sampleData=mSensorManager.getDefaultSensor(ECGSensorManager.SensorType.ECG_SAMPLES_DATA);
// Retrieve an instance of the given MasonHardwareFramework API.
     * @param targetClass Typed interface for the given MasonHardwareFramework
 ecgManager = MasonHardwareFramework.get(getContext(), ECGSensorManager.class);<br>
// Register and Unregister Sensor
@Override
protected void onResume() {
   super.onResume();
   //mHeartKeySensorEventListener is ECGEventListener type  
   ecgManager.registerEventListener(mHeartKeySensorEventListener);
   mSensorManager.registerListener(mUserControlEventListener, userControl, SensorManager.SENSOR_DEL AY_NORMAL);
   mSensorManager.registerListener(mECGSensorDataEventListener, sensorData, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
   super.onPause();
   mSensorManager.unregisterListener(mUserControlEventListener);
   mSensorManager.unregisterListener(mECGSensorDataEventListener);
   mSensorManager.unregisterListener(mECGSampleDataEventListener);
}<br>

Data Collection for new Sensor Event

For an ECGSensor Event to get notified of new sensor data, one should utilize the public interface ECGEventListener. This has some callback methods:

Callback method  Parameters 
public void HandleHeartRate (ECGHeartRate event) event: ECGHeartRate
public void HandleStress (ECGStress event) event: ECGStress
public void HandleEnergy (ECGEnergy event) event: ECGEnergy
public void HandleUserId (ECGEnergy event) event: ECGUserID
public void HandleHeartRateVariability (ECGHeartRateVariability event) event : ECGHeartRateVariability
public void HandleStress (ECGEnergy event) event: ECGEnergy
public void HandleUserId (ECGUserID event) event: ECGUserID
public void HandleECGSamples (ECGSamples event) event: ECGSamples
public void HandleUserPresence (ECGUserPresence event) event: ECGUserPresence
public void ECGExecuteResponse (ECGExecuteResponse event) event: ECGExecuteResponse
public void HandleGetVersion (ECGFwVersion event) event: ECGFwVersion
public void HandleGetUserMetadata (ECGUserMetadata event) event: ECGUserMetadata
public void HandleGetLibConfig (ECGLibConfig event) event: ECGLibConfig

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
<intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
</intent-filter><br>
// Integrate mason library in Manifest file
<uses-library android:name="masonamerica.platform" />
<uses-library android:name="mason.hardware.platform" />

Next Up:

ECG Data - A4100 Sample Health App ECG Sensor

Still need help? Contact Us Contact Us