How please ensure that the output from the sensors is always a positive number? In the simulator I have no problem with a single sensor, but in ERA I see a lot of errors on line 31 in the sample code: Error Name: Invalid Value
It's hard for me to identify the problem, because I don't have a real watch and I have no way to find out what real data is coming from the sensors. Does anyone have experience with how to ensure only positive numbers, as output?
function getHistoryIterator() {
if ((Toybox has :SensorHistory) && (SensorHistory has :getHeartRateHistory)) {
return SensorHistory.getHeartRateHistory({:period => 60, :order => true});
}
return null;
}
var dataIterator = getHistoryIterator();
var historyData = null;
var historyMax = 0;
var graphBarHeight = 45;
if (dataIterator != null) {
var historyVal = dataIterator.next();
historyData = [];
while (historyVal != null) {
if (historyVal.data instanceof Lang.String || historyVal.data == null || historyVal.data == false || historyVal.data < 0) {
historyData.add(0);
} else {
historyData.add(historyVal.data);
}
historyVal = dataIterator.next();
}
} else {
historyData = null;
}
if (historyData != null) {
historyMax = arrayMax(historyData);
for (var i = 0; i < historyData.size(); i ++) {
var graphBarH = Math.ceil(historyData[i].toNumber() * (graphBarHeight.toFloat() / historyMax.toFloat())).toNumber();
// code continue
// ...
}
} else {
// no data; unsupported sensor
}