minor tweaks
parent
ce48309568
commit
f6184f0fd1
|
|
@ -1,9 +1,10 @@
|
||||||
(function() {
|
(function() {
|
||||||
var log = function() {};//print
|
var log = function() {};//print
|
||||||
var gatt;
|
var gatt;
|
||||||
|
var status;
|
||||||
|
|
||||||
Bangle.isHRMOn = function() {
|
Bangle.isHRMOn = function() {
|
||||||
return gatt!==undefined;
|
return (status=="searching" || status=="connecting") || (gatt!==undefined);
|
||||||
}
|
}
|
||||||
Bangle.setHRMPower = function(isOn, app) {
|
Bangle.setHRMPower = function(isOn, app) {
|
||||||
// Do app power handling
|
// Do app power handling
|
||||||
|
|
@ -17,10 +18,12 @@
|
||||||
// so now we know if we're really on
|
// so now we know if we're really on
|
||||||
if (isOn) {
|
if (isOn) {
|
||||||
log("setHRMPower on", app);
|
log("setHRMPower on", app);
|
||||||
if (!gatt) {
|
if (!Bangle.isHRMOn()) {
|
||||||
log("HRM not already on");
|
log("HRM not already on");
|
||||||
|
status = "searching";
|
||||||
NRF.requestDevice({ filters: [{ services: ['180D'] }] }).then(function(device) {
|
NRF.requestDevice({ filters: [{ services: ['180D'] }] }).then(function(device) {
|
||||||
log("Found device "+device.id);
|
log("Found device "+device.id);
|
||||||
|
status = "connecting";
|
||||||
device.on('gattserverdisconnected', function(reason) {
|
device.on('gattserverdisconnected', function(reason) {
|
||||||
gatt = undefined;
|
gatt = undefined;
|
||||||
});
|
});
|
||||||
|
|
@ -54,16 +57,18 @@
|
||||||
return characteristic.startNotifications();
|
return characteristic.startNotifications();
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
log("Ready");
|
log("Ready");
|
||||||
console.log("Done!");
|
status = "ok";
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
console.log("Error",err);
|
log("Error",err);
|
||||||
gatt = undefined;
|
gatt = undefined;
|
||||||
|
status = "error";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else { // not on
|
} else { // not on
|
||||||
log("setHRMPower off", app);
|
log("setHRMPower off", app);
|
||||||
if (gatt) {
|
if (gatt) {
|
||||||
log("HRM connected - disconnecting");
|
log("HRM connected - disconnecting");
|
||||||
|
status = undefined;
|
||||||
try {gatt.disconnect();}catch(e) {
|
try {gatt.disconnect();}catch(e) {
|
||||||
log("HRM disconnect error", e);
|
log("HRM disconnect error", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue