Quantcast
Jump to content

Sign in to follow this  
STF News

Use Tizen Web To Measure Heart Rate With Galaxy Watches

Recommended Posts

Health monitoring is a very popular feature in smart watches, and Tizen provides various APIs for this purpose. One API is HumanActivityMonitor, which allows users to monitor health by providing metrics such as heart rate, step count, and stress level.

This blog describes how to measure heart rate using this API. A sample web app combined with a widget is attached. This sample app measures heart rate and stores data by timestamp, and the widget shows the last measured heart rate. This blog focuses on how to measure heart rate using the device sensor, stored data, and communication between an app and a widget.

Create and run a Tizen project

1. Create a project in Tizen Studio. Because our target is an app that is combined with a widget, select the Widget template to create this project.

1.png

2. Add the Tizen Advanced UI (TAU) framework library to your project. You can create and manage various UI functionalities using the TAU library as an alternative to designing a UI with HTML and CSS components.

3. Link the tau.circle.min.css and tau.min.js in the app’s index.html file.

<link rel="stylesheet"
href="lib/tau/wearable/theme/default/tau.min.css"> 
<link rel="stylesheet" media="all and (-tizen-geometric-shape: circle)"
href="lib/tau/wearable/theme/default/tau.circle.min.css">
<script src="lib/tau/wearable/js/tau.min.js"> </script>

Measure heart rate and manage data

To measure heart rate using the HumanActivityMonitor API, add the following feature and privilege to the config.xml file:

<feature name="http://tizen.org/feature/humanactivitymonitor"/>
<tizen:privilege name="http://tizen.org/privilege/healthinfo"/>

Applications must request a user’s permission for privacy-related features. The tizen.ppm.requestPermission() method invokes the permission pop-up. When users give permission through the pop-up, they can then use the app features related to that privilege.

To measure heart rate, users must give permission to access the sensor using the following code snippet:

function onSuccess() {

    function onchangedCB(hrmInfo) {
        console.log(‘heart rate:’ + hrmInfo.heartRate);
        tizen.humanactivitymonitor.stop('HRM');
    }
    tizen.humanactivitymonitor.start('HRM', onchangedCB);
}

function onError(e) {
    console.log("error " + JSON.stringify(e));
}
tizen.ppm.requestPermission("http://tizen.org/privilege/healthinfo",onSuccess, onError);

Note that the HumanActivityMonitor API provides heart rate data directly in BPM (beats per minute). If you need the raw data of the sensor, you can use SensorHRMRawData.

The following screenshots show how to measure heart rate using the sample app:

2.png

The Web Storage API stores data in key-value format. This API offers two types of storage – Local and Session. In the sample, we use local storage, along with Date as key and heartRate as value. The Date key retrieves data according to date, week, and month. If you do not want to retrieve history according to date, you can use a different key, such as an integer value; just make sure there is no repetition in key value.

Create a Date object to get the current time stamp. localStorage.setItem() puts the key (Date)-value (heartRate) pair in local storage.

var date_key = new Date();
localStorage.setItem(date_key, hrmInfo.heartRate);

To retrieve data, filter according to the key. Date and month are retrieved from the Date object and filter data using localStorage.getItem(localStorage.key(i)).

var date = new Date();
var lastdate = new Date(localStorage.key(i));
if (lastdate.getDate() == date.getDate() 
&& lastdate.getMonth() == date.getMonth()) {
              console.log(localStorage.key(i)+ " :" + localStorage.getItem(localStorage.key(i)));

The following screenshots show how the history is categorized by day, week, and month:

31.png

Communication between the app and a widget

The sample widget shows the last measured heart rate value, and heart rate history is stored in the local storage of the web app. To establish communication between the app and widget, we’ll use the Preference API. The Preference API stores key-pair values, allowing web widgets to communicate with their parent apps.
In the app, data is stored with ‘KEY’:

tizen.preference.setValue('KEY', hrmInfo.heartRate);

In the widget, data is retrieved using the same ‘KEY’:

if (tizen.preference.exists('KEY')) {
    console.log(‘Last Measured: ‘ + tizen.preference.getValue('KEY'));
} 

The following screenshot of the sample widget shows the last measured heart rate:

4.png

Launch the app from a widget

To launch an app from widget, add the following privilege to config.xml:

<tizen:privilege 
name="http://tizen.org/privilege/application.launch"/>

To launch an app, provide your app ID in tizen.application.launch().

tizen.application.launch(YourAppID);

In the sample widget, the user taps Measure to launch the heart-rate measuring page or History to launch the heart-rate history page, and Preference can be used to determine which one is clicked. To implement, a different key-value pair is set for each page in the widget, and in the web app, key values are checked to detect which page is clicked.

5.png

For example, in the widget, the open_measure key is set to 1 to link to the Measure Page. The app then launches.

tizen.preference.setValue(‘open_measure’, 1);
tizen.application.launch(YourAppID);

The app checks for the open_measure key. If the key exists, the user is redirected to the Measure Page with tau.changePage().

window.onload = function() {
    if (tizen.preference.exists(' open_measure ')) {
        tau.changePage(YourPageID);
    }
}

You can also use the HumanActivityMonitor API to implement a step counter, stress level reading, GPS, and other features in your wearable device. Because enabling other features is similar to implementing the heart rate monitor, you can use this blog as a guide and the attached sampleHeartRateMonitor to enable a full range of health monitoring metrics to your Galaxy Watch.

View the full blog at its source

Share this post


Link to post
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...
Sign in to follow this  

  • Similar Topics

    • By Alex
      At the World Nuclear Exhibition 2016 (WNE 2016) that takes place in a Parisian suburb Le Bourget from June, 28 to June, 30 Samsung Electronics and Intersoft Eurasia OJSC – a Skolkovo Technopark resident – showcased the core for personal radiation monitoring device DO-RA. Core based on the proprietary technologies. This innovative device measures background radiation level of the environment and by synchronizing with a smartphone shows this information on a display using a specialized mobile app. The new product was made on the basis of Tizen secure mobile platform with the application of personal environment and food radiation monitoring technology.
      DO-RA is an affordable and compact dosimeter-radiometer, equipped with solid silicon detector DoRaSi, reading electronics and energy-efficient components. In its standard configuration the device measures MED of ionizing radiation and provides broadcast data transmission over Bluetooth Low Energy profile (BLE). The first version of DO-RA allows to exchange data between smartphones based on OS Tizen over a sound channel with data integrity and adequacy check. In perspective it is planned to increase measuring capabilities of the DO-RA.Core base version by adding specific sensors and expanding data communication channel to Bluetooth 2.0 by means of hybrid Bluetooth.
      The showcased DO-RA device functions on the basis of Tizen mobile platform and Samsung Z3 smartphone. The mobile platform enables effective use of a hi tech pack – DO-RA measuring device and a smartphone for solving any  monitoring and analytical issues.
      “Recently we presented a corporate version of Samsung Z3 smartphone based on Tizen, which was a very important step for us in the OS extension in Russia. Today we are happy to start the new phase of our work and demonstrate DO-RA technology as yet another innovative solution made in cooperation with a Russian company. I am sure, that the new device is going to become common use in our country and will provide Russian consumers with additional benefits,” –commented Alexander Terekhov, Head of B2B Mobile at Samsung Electronics in Russia.
      The World Nuclear Exhibition is being held since 2014 and is one of the most significant events in the area of nuclear solutions and innovations harnessed for peaceful uses. The main theme of WNE 2016 is The role of nuclear industry in the global energy mix. As expected more that 10 000 people from 71 countries will visit the exhibition of nearly 700 innovative solutions. The event is organized by the Association of French Nuclear Export Industries (AIFEN).
      “The Intersoft Eurasia’s project is a vivid example of Skolkovo Foundation commitment to supporting commercialization of radiotechnology solutions and solutions in B2C segment,” – said Igor Karavaev, Vice-president and CEO of Cluster Nuclear Technologies at Skolkovo Foundation.
      About DO-RA project:
      The primary idea of DO-RA project dates from June, 2011 and is protected by Russian licence №109625. It also has licenses of foreign jurisdiction: USA, Japan, China, Korea, India, EU, Belorussia, Ukraine.
      In 2013 Dow Jones estimated the plow-back of Intersoft Eurasia OJSC – the DO-RA project provider – as $10 mln. Thereafter within its innovative activities the company received 55 patents in various fields of IT industry.
      The name DO-RA was created from the first letter combinations of the words dozimeter-radiometer – DO-RA. The abbreviations coincide both in Russian and English languages which increases awareness of the device.  
      The DO-RA project’s website: www.do-ra.ru , www.intersofteurasia.ru
      About Samsung Electronics Co., Ltd.
      Samsung Electronics Co., Ltd. inspires the world and shapes the future with transformative ideas and technologies, opening new possibilities for people everywhere through relentless innovation and discovery. For the latest news, please visit the Samsung Newsroom at news.samsung.com.
        Tags:  Tizen View the full article
    • By Alex
      WhatsApp’s voice calling feature is available for Android users, and it looks like customers who purchased the Samsung Z1 have something to rejoice about as WhatsApp for Tizen has been updated with voice calling support as well. If you’re the owner of the Samsung Z1, you’ll just need to launch the WhatsApp app and you will see the new feature available for your use.
       
      At this point in time Samsung Z1 owners will only be able to call Android devices who has the updated feature, or other Samsung Z1 owners. This effectively brings the voice calling feature to two platforms – Android and Tizen, with iOS users left having to wait for their update which has been scheduled for a rollout in the coming weeks.
       
      As pointed out by SamMobile, the reason why the Tizen version of WhatsApp managed to get this feature ahead of a more “prominent” platform like iOS is because the Tizen version of WhatsApp is an emulated version of the Android app. This means that it is possible for Tizen users to receive the same updates and features as its Android counterpart without too much fuss or hassle.
       
      Like we said iOS users will still have to wait a couple of weeks for their feature, and there’s still no word on when voice calling will be rolled out to users of BlackBerry or Windows Phone platforms.
       
      Source: http://www.ubergizmo.com/2015/04/whatsapp-for-tizen-updated-with-voice-calling-feature/


×
×
  • Create New...