public interface

ECGSensorManager

mason.hardware.platform.ECGSensorManager

Class Overview

ECGSensorManager lets you access the device ECG sensor. A set of commands is available for support of multiple sensor specific functionalities.

Summary

Nested Classes
class ECGSensorManager.Command Available ECG Sensor commands  
class ECGSensorManager.GenericSensorType ECG sensor types, device agnostic. 
Public Methods
abstract void dispatch(SensorEvent event)
Parsing and dispatch to the specific callback previously registered with registerEventListener(ECGEventListener) depending on the event type.
abstract int execute(int command)
Send a specific command for execution.
abstract int executeWithParameter(int command, CommandParameter data)
Send a specific command that requires aditional input parameters for execution.
abstract int getSensorType(int type)
Get the device specific sensor type from generic sensor type ECGSensorManager.GenericSensorType
abstract void registerEventListener(ECGEventListener listener)
Register callbacks for all available events from ECG.

Public Methods

public abstract void dispatch (SensorEvent event)

Parsing and dispatch to the specific callback previously registered with registerEventListener(ECGEventListener) depending on the event type.

public abstract int execute (int command)

Send a specific command for execution. Used for commands that do not required aditional input parameters. On success, the result information would be sent through onSensorChanged() of SensorEventListener registered by ECG_USER_CONTROL sensor

Parameters
command int: command to be executed, ECGSensorManager.Command
Returns
int return the seqid on success or -1 on failure.

public abstract int executeWithParameter (int command, CommandParameter data)

Send a specific command that requires aditional input parameters for execution. On success, the result information would be sent through onSensorChanged() of SensorEventListener registered by ECG_USER_CONTROL sensor

Parameters
command int: command to be executed, ECGSensorManager.Command
data CommandParameter: additional data to be added to the execution, see CommandParameter
Returns
int return the seqid on success or -1 on failure.

public abstract int getSensorType (int type)

Get the device specific sensor type from generic sensor type ECGSensorManager.GenericSensorType

Parameters
type int: One of ECGSensorManager.GenericSensorType constans describing the ECG sensors.
Returns
int device specific sensor type.

public abstract void registerEventListener (ECGEventListener listener)

Register callbacks for all available events from ECG. By register this listener the dispatch and parsing for different events is simplified for the user. This is the recomended way of using the Mason Hardware framework:

  • Create and register with the ECGSensorManager an ECGEventListener in order to process all data comming from the ECG sensor
  • On the specific OnSensorChanged event call the dispatch(SensorEvent) in order to obtain the parsed data.

     ECGEventListener mSensorEventListener = new ECGEventListener () {
         ...
         @Override
         public void HandleHeartRate(ECGHeartRate ecgHeartRate) {
             // Process ECGHeartRate data here
         }
    
         @Override
         public void HandleUserPresence(ECGUserPresence ecgUserPresence) {
             // Process ECGUserPresence data here
         }
    
         @Override
         public void HandleGetVersion(ECGFwVersion ecgFwVersion) {
             // Process ECGFwVersion data here
         }
         ...
     };
     ...
     private SensorEventListener mECGSensorDataEventListener = new SensorEventListener() {
         @Override
         public void onSensorChanged(SensorEvent event) {
             ecgManager.dispatch(event);
         }
    
         @Override
         public void onAccuracyChanged(Sensor sensor, int accuracy) {}
     };
     ...
     SensorManager mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
     Sensor sensorData = mSensorManager.getDefaultSensor(ecgManager.getSensorType(ECGSensorManager.GenericSensorType.ECG_SENSORS_DATA));
    
     mSensorManager.registerListener(mECGSensorDataEventListener, sensorData, SensorManager.SENSOR_DELAY_NORMAL);
     ECGSensorManager ecgManager = MasonHardwareFramework.get(getContext(), ECGSensorManager.class);
     ecgManager.registerEventListener(mSensorEventListener);
     ...
     

    Parameters
    listener ECGEventListener: The object containing callbacks to process all ECG data events when available