as you can see from my previous question, i'm very new to the world of coding. I tried to develop an app for a Tizen device (Samsung Gear S) that read the heart rate and shows it. I used templates and i tried to write data in the filesystem but i encountered some problems and i started to develop a simple app that will show the heart rate on the screen. I used some code snippets from the dev site of Tizen and i was able to console log the data. Now i want to stream these data to a "textbox like thing" (sorry for this words :) ) that will eventually show in the app screen when running. I tried first with a super simple app that showed the hello world string in the textbox and it worked. Now i'm trying to tuning the code for my purpose. What i want is a stream of data that will show on the box continuosly, not only once, and maybe i have to use a different type of code. Below there's my code, sorry for the stupid question, but i was assigned to a thing totally far away from knowledge. Thanks in advance for the help! The Tizen sdk has the Javascript language for the main files and the HTML and CSS language for the graphic interface of the web app.
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="A single-page template generated by Tizen Wearable Web IDE"/>
<title>Tizen Wearable Web IDE - Tizen Wearable - jQuery</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class=contents>
<div style='margin:auto;'>
<span class=content_text id=textbox>Basic</span>
<input type="text" id="mytext">
</div>
</div>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
JAVASCRIPT:
var counter = 0;
function onchangedCB(hrmInfo)
{
console.log("Heart Rate: " + hrmInfo.heartRate);
console.log("Peak-to-peak interval: " + hrmInfo.rRInterval + " milliseconds");
counter++;
if (counter > 10)
{
/* Stop the sensor after detecting a few changes */
tizen.humanactivitymonitor.stop("HRM");
}
}
tizen.humanactivitymonitor.start("HRM", onchangedCB);
function onsuccessCB(hrmInfo)
{
console.log("Heart rate: " + hrmInfo.heartRate);
}
function onerrorCB(error)
{
console.log("Error occurred: " + error.message);
}
tizen.humanactivitymonitor.getHumanActivityData("HRM", onsuccessCB, onerrorCB);
var data = hrmInfo.heartRate;
document.getElementById("mytext").value = data;
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName === "back") {
try {
tizen.humanactivitymonitor.stop("HRM");
tizen.application.getCurrentApplication().exit();
} catch (error) {
console.error("getCurrentApplication(): " + error.message);
}
}
});
I think the problem is that document.getElementById("mytext").value = data;
and the previous line are not at the right place. I recommend to add these lines to onchangedCB
, above or below the console-lines. This is the place where hrmInfo
is expected to be defined because it is passed as parameter to onchangedCB
.