# Events

During a measurement, the SDK emits events to inform the application of the progress of the PPG measurement.  Events will only be emitted after a measurement is started using the `startMeasurement`  SDK Method.

<figure><img src="https://550842036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1VHmKXYQVUzvBkU504K0%2Fuploads%2FFs1oXCobvoIhqkAVuuwD%2Fdocs.fibricheck.com%20-%20SDK%20Events%20Sunny%20Day%20Scenario.png?alt=media&#x26;token=c62d2736-c389-477b-adbf-c0e9d5d3b45b" alt=""><figcaption><p>Overview of relevant SDK events during a measurement</p></figcaption></figure>

## Subscribe to events

The following code examples demonstrate how to listen for events on each platform. The examples feature the `onFingerDetected` events. Subscribing to other events is similar.

{% tabs %}
{% tab title="Flutter" %}

```dart
FibriCheckView(
    ...
    onFingerDetected: () => { ...your code here...},
    ...
),
```

{% endtab %}

{% tab title="React Native" %}

```jsx
<RNFibriCheckView
    ...
    onFingerDetected={() => ...your code here...}
    ...
/>
```

{% endtab %}

{% tab title="Cordova" %}

```typescript
const { FibriCheckCordovaSDK: fc } = cordova.plugins;

fc.onFingerDetected(() => {
    /** Your Code Here **/
});

```

{% endtab %}

{% tab title="iOS" %}

```swift
import FibriCheckCameraSDK

func handleFingerDetected() -> Void {
    // Your Code Here
}

fc.onFingerDetected = handleFingerDetected
```

{% endtab %}

{% tab title="Android" %}

```java
import com.qompium.fibricheck_camera_sdk.FibriCheck;

ViewGroup viewGroup = binding.getRoot();

fibriChecker = new FibriChecker.FibriBuilder(viewGroup.getContext(), viewGroup).build();

fibriChecker.setFibriListener(new FibriListener() {
    @Override public void onFingerDetected() {
        Log.i(TAG, "Callback: onFingerDetected");
    }
});
```

{% endtab %}
{% endtabs %}

## Available events

### onFingerDetected

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>The user's finger is correctly placed on the smartphone camera.</td></tr><tr><td><strong>Frequency</strong></td><td>Can be emitted multiple times if a user moves their finger.</td></tr><tr><td><strong>When</strong></td><td>Before measurement, during measurement, after measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr></tbody></table>

###

### onFingerRemoved

<table data-header-hidden><thead><tr><th width="157"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>The user's finger is no longer present on the camera.<br><br>When the finger is removed, the measurement is <strong>paused</strong> until the finger is detected again.</td></tr><tr><td><strong>Frequency</strong></td><td>Can be emitted multiple times if a user moves their finger placement on the camera. Happens after a <code>onFingerDetected</code> event.</td></tr><tr><td><strong>When</strong></td><td>Before measurement, during measurement, after measurement</td></tr><tr><td><strong>Data</strong></td><td><code>y[number]</code> - Luminance<br><code>v[number]</code> - Red chrominance<br><code>stdDevY[number]</code> -  Luminance standard deviation</td></tr></tbody></table>

###

### onFingerDetectionTimeExpired

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>The user's finger has not been detected within the set time. This event is disabled by default.</td></tr><tr><td><strong>Frequency</strong></td><td>Once per measurement</td></tr><tr><td><strong>When</strong></td><td>Before measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr></tbody></table>

###

### onPulseDetected

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when a pulse has been detected. The pulse detection is only active after the finger detection has been completed.</td></tr><tr><td><strong>Frequency</strong></td><td>Once per measurement</td></tr><tr><td><strong>When</strong></td><td>Before the measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr></tbody></table>

###

### onPulseDetectionTimeExpired

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when no pulse has been detected after 10 seconds.</td></tr><tr><td><strong>Frequency</strong></td><td>once per measurement</td></tr><tr><td><strong>When</strong></td><td>Before the measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr><tr><td><strong>Info</strong></td><td>This is an <strong>informational event</strong>, it's not required to implement this event. <br>The measurement process will continue independent of a pulse being detected.</td></tr></tbody></table>

###

### onCalibrationReady

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>When performing a measurement, a baseline needs to be calculated. When this baseline has been calculated, the calibration is ready and the SDK will emit this event.</td></tr><tr><td><strong>Frequency</strong></td><td>Once per measurement</td></tr><tr><td><strong>When</strong></td><td>Before measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr></tbody></table>

###

### onMeasurementStart

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when the PPG measurement has successfully started started.</td></tr><tr><td><strong>Frequency</strong></td><td>Once per measurement</td></tr><tr><td><strong>When</strong></td><td>Before the measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr></tbody></table>

###

### onHeartBeat

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when a heartbeat is detected. Returns the heart rate as a number.</td></tr><tr><td><strong>Frequency</strong></td><td>Multiple times per measurement, emitted on every change in heart rate</td></tr><tr><td><strong>When</strong></td><td>During the measurement</td></tr><tr><td><strong>Data</strong></td><td><code>heartrate[number]</code></td></tr></tbody></table>

###

### onSampleReady

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted every time when a PPG signal has been successfully extracted from a camera image. It can be used to draw a graph or analyse the data during the measurement.</td></tr><tr><td><strong>Frequency</strong></td><td>Multiple times per measurement, typically around 30 times per second during the measurement.</td></tr><tr><td><strong>When</strong></td><td>Before and during the measurement.</td></tr><tr><td><strong>Data</strong></td><td><code>ppg[number]</code> - filtered PPG value<br><code>raw[number]</code> - raw PPG value<br><br>Use the <code>ppg</code> value when you want to visualise a chart to the user</td></tr></tbody></table>

{% hint style="warning" %}
When acting on this event it's important to measure the **performance** of the application while measuring. Especially in cross-platform environments (Flutter, React Native, Cordova) it's possible that the bridging layer is not fast enough to handle the amount of data that this event generates.
{% endhint %}

{% hint style="info" %}
The range of PPG values reported by this event can vary greatly between different devices and depends on ambient lightning conditions. If you want to plot the PPG values, keep these recommendations:

* Only plot the latest x samples
* Use dynamic ranges for the y-axis of the visualization to account for differences in device specifications and conditions.
  {% endhint %}

### onMovementDetected

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when the SDK detects movement of the phone. <br>Depends on the value of <code>movementDetectionEnabled</code>, which is <code>true</code> by default</td></tr><tr><td><strong>Frequency</strong></td><td>Multiple times per measurement</td></tr><tr><td><strong>When</strong></td><td>During the measurement</td></tr><tr><td><strong>Data</strong></td><td>/</td></tr></tbody></table>

###

### onTimeRemaining

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted to update the application on the time remaining in seconds for the measurement to complete.</td></tr><tr><td><strong>Frequency</strong></td><td>Every second during the measurement</td></tr><tr><td><strong>When</strong></td><td>During the measurement</td></tr><tr><td><strong>Data</strong></td><td><code>timeRemaining[number]</code></td></tr></tbody></table>

###

### onMeasurementFinished

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when the measurement has finished. After this event, the SDK starts processing the measurement.</td></tr><tr><td><strong>Frequency</strong></td><td>Once</td></tr><tr><td><strong>When</strong></td><td>After the measurement</td></tr><tr><td><strong>Data</strong></td><td></td></tr></tbody></table>

###

### onMeasurementError

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when a measurement error occurs. The measurement wil stop.<br><br>Possible errors:<br><code>BROKEN_ACC_SENSOR</code> - Can happen on iOS devices, ask the user to reboot the device if this happens.</td></tr><tr><td><strong>Frequency</strong></td><td>Once</td></tr><tr><td><strong>When</strong></td><td>During the measurement</td></tr><tr><td><strong>Data</strong></td><td><code>Error[string]</code></td></tr></tbody></table>

###

### onMeasurementProcessed

<table data-header-hidden><thead><tr><th width="153"></th><th></th></tr></thead><tbody><tr><td><strong>Description</strong></td><td>Emitted when the measurement has been processed. The output of this event should be forwarded to the FibriCheck Cloud for further analysis by the FibriCheck Algorithm.</td></tr><tr><td><strong>Frequency</strong></td><td>Once</td></tr><tr><td><strong>When</strong></td><td>After the measurement</td></tr><tr><td><strong>Data</strong></td><td><code>Measurement</code> - details of the returned data can be found in <a href="measurements">Measurements</a></td></tr></tbody></table>
