Hello, i'm trying to increase the precison of the heart rate values on a Samsung Gear S. I developed a web application that communicates with a PC thanks to a web socket.
I tried to use the function
parseFloat(interval).toPrecision(4)
or even
interval.toPrecision(4)
with no success. I used parseFloat because i need a Float data type for my communication.
Another strange and curious thing is that, apparently, the sensor can output only even values and not the odd ones. Is it possible that the precision cannot be increased (with the most accurate values something like 1.24 or 0.84)? How can i print also the odd numbers? Is it not possible for some reason?
I will post the entire Javascript source code below, thank you very much in advance.
Marco
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName === "back")
window.webapis.motion.stop("HRM");
tizen.application.getCurrentApplication().exit();
});
function Connect(){
var ip;
var connection=false;
var interval_screen = 0;
if (document.getElementById("ip").value==="")
{
ip="10.42.0.1";
}
else
{
ip=document.getElementById("ip").value;
}
var ros = new ROSLIB.Ros({
url : 'ws://' + ip +':9090'
});
ros.on('connection', function() {
connection=true;
document.getElementById("Connection_status").setAttribute("color","green");
document.getElementById("Connection_status").innerHTML = 'Connected';
tizen.power.request("SCREEN", "SCREEN_DIM");
});
ros.on('error', function(error) {
document.getElementById("Connection_status").setAttribute("color","orange");
document.getElementById("Connection_status").innerHTML = 'Error';
});
ros.on('close', function() {
document.getElementById("Connection_status").setAttribute("color","red");
document.getElementById("Connection_status").innerHTML = 'Unconnected';
connection=false;
tizen.power.release("SCREEN");
});
var RatePub = new ROSLIB.Topic({
ros : ros,
name : '/HeartRateData',
messageType : 'std_msgs/Float64'
});
var IntervalPub = new ROSLIB.Topic({
ros : ros,
name : '/HeartRateInterval',
messageType : 'std_msgs/Float64'
});
window.webapis.motion.start("HRM", onchangedCB);
function onchangedCB(hrmInfo)
{
var rate = hrmInfo.heartRate;
document.getElementById("mytext").innerHTML = 'Heart Rate= ' + rate + ' bpm';
var interval = hrmInfo.rRInterval/1000;
parseFloat(interval).toPrecision(4);
}
if (interval !== 0) {
interval_screen = interval;
}
document.getElementById("mytext1").innerHTML = 'RR Interval= ' + interval_screen + ' s';
var Float64 = new ROSLIB.Message({
data:rate
});
if(connection===true)
{
RatePub.publish(Float64);
}
else
{
document.getElementById("mytext").innerHTML = 'Heart Rate = 0 bpm';
}
var Float64 = new ROSLIB.Message({
data:interval
});
if(connection===true)
{ if (interval !== 0) {
IntervalPub.publish(Float64);
}
else {
}
}
else
{
document.getElementById("mytext1").innerHTML = 'RR Interval = 0 s';
}
}}