Quantcast
Jump to content


Recommended Posts

Posted

workout-b2.png

This is the third blog in a series to introduce the sample application Workout, a Tizen example for monitoring health sensors on a wearable device.

The first blog, Workout -- A Tizen Sample App for Monitoring Health Sensors, presented the basic features of the application. The second blog, Adding Distance Traveled to the Tizen Workout Sample App, described how distance traveled is calculated.

In this blog, I will demonstrate another key feature of the app, Heart Rate Measurement (HRM), which shows the most recent heart rate intensity.

Intensity

Implementation

To start collecting data from the HRM sensor, first start Tizen.Sensor.HeartRateMonitor from TizenFX API.

HeartRateMonitorService.cs

public void Init()
{
    try
    {
        _hrm = new HRM
        {
            Interval = 1000,
            PausePolicy = SensorPausePolicy.None
        };
 
        _hrm.DataUpdated += OnDataUpdated;
    }
    catch (Exception)
    {
        NotSupported?.Invoke(this, EventArgs.Empty);
    }
}

Initiating HRM in this way invokes DataUpdated every one second and the sensor is not stopped even when the application is sent to the background. The data from the event is handled by the OnDataUpdated handler, which invokes the event with the single bpm value.

This event is listened to by the OnServiceDataUpdated handler in the HeartRateMonitorModel, where all information related to heart rate is calculated:

HeartRateMonitorModel.cs

private void OnServiceDataUpdated(object sender, int bpm)
{
    double normalizedBpm = Math.Clamp((bpm - _minBpm) / (double)(_maxBpm - _minBpm), 0, 1);
    int bpmRange = bpm < _minBpm ? 0 : Math.Min((int)((normalizedBpm * (_bpmRanges - 1)) + 1), _bpmRanges - 1);
 
    if (!_isMeasurementPaused)
    {
        _bpmRangeOccurrences[bpmRange]++;
    }
 
    Updated?.Invoke(this, new HeartRateMonitorUpdatedEventArgs(new HeartRateMonitorData
    {
        Bpm = bpm,
        BpmRange = bpmRange,
        BpmRangeOccurrences = _bpmRangeOccurrences,
        NormalizedBpm = normalizedBpm
    }));
}

However, let's start with the values that are used in the above method:

_maxBpm - this value is calculated during the class instantiation according to the formula: 220 - user age
_minBpm - this is half the value of _maxBpm

_minBpm and _maxBpm is used to calculate normalizedBpm, a value ranging from 0 to 1.

Next, the bpmRange to which the current HRM service value belongs is calculated: For bpm below _minBpm, bpmRange is set to 0. For bpm greater than or equal to _minBpm, bpmRange is set to either (_normalizedBpm * (_bpmRanges -1) + 1) or (_bpmRanges - 1), whichever value is smaller.

This calculated pulse interval is used as a position in an array, whose value is increased by 1. To obtain the most common pulse interval, find the index with the highest value associated with it.

DetailsPageViewModel.cs

Intensity = Array.LastIndexOf(bpmRangeOccurrences, bpmRangeOccurrences.Max()).ToString();

To display the range indication, Intensity is delivered to XAML and converted into text using a converter.

DetailsPageView.xaml.cs

<models:DetailsItemData Name="intensity"
                        Value="{Binding Intensity, Converter={StaticResource BpmRangeValueConverter}}"
                        Icon="images/details_intensity_icon.png"
                        IsActionButtonVisible="True">

Read more

To learn more about the implementation of the HRM sensor and the use of the data in the Workout app, see this tutorial

In the final blog of this series, you'll learn how CircleListView is used in the app.

View the full blog at its source



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By Samsung Newsroom
      View the full blog at its source
    • By Alex
      cnet is covering Samsung's CES press conference, the South Korean electronics giant will show off its latest crop of TVs and home appliances during its presentation at the Consumer Electronics Show in Las Vegas.
       
      Samsung's presentation starts at 2 p.m. PT on Monday, and we'll be bringing you all the news and commentary from inside the Mandalay Bay hotel on the Las Vegas Strip. I'll be live blogging along with David Katzmaier, and James Martin will provide photography from the event.
       
      Samsung's 2015 CES press conference: Join us Monday (live blog)





×
×
  • Create New...