Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jones139 committed Dec 4, 2023
2 parents c1a033a + d12722d commit 7cf742f
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 46 deletions.
11 changes: 10 additions & 1 deletion apps/openseizure/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
0.02: Added battery level characteristic
0.01: New Widget!
0.02: Added battery level characteristic
0.03: Corrected service and characteristic UUIDs to match V4.2.x of OSD app.
0.04: Fixing issue with OSD JSON specification
0.05: Added heart rate characteristic
0.06: Changed heart rate characteristic to use the official UUIDs.
0.07: Removed OSD HR Char
0.08: Changed OSD UUIDs
0.09: Added watch ID char.
0.10: Added watch FW version char
0.11: Moved FW version to const to make it easier to change
6 changes: 3 additions & 3 deletions apps/openseizure/metadata.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"id": "openseizure",
"name": "OpenSeizureDetector Widget",
"shortName": "Short Name",
"version": "0.01",
"shortName": "OSD",
"version": "0.11",
"description": "[BETA!] A widget to work alongside [OpenSeizureDetector](https://www.openseizuredetector.org.uk/)",
"icon": "widget.png",
"type": "widget",
"tags": "widget",
"supports": ["BANGLEJS"],
"supports": ["BANGLEJS", "BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"openseizure.wid.js","url":"widget.js"}
Expand Down
168 changes: 126 additions & 42 deletions apps/openseizure/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,141 @@
*
* 07 August 2020 - Gordon Williams: Initial version providing an accelerometer data service.
* 12 August 2020 - Graham Jones: Added a battery percentage service.
*/
* 03 Oct 2023 - Graham Jones: Added heart rate data service
*/

const WATCH_FW = "0.11";
const WATCH_ID = "BangleJs";

const SERV_OSD = "000085e9-0000-1000-8000-00805f9b34fb";
const CHAR_OSD_ACC_DATA = "000085e9-0001-1000-8000-00805f9b34fb";
const CHAR_OSD_BAT_DATA = "000085e9-0002-1000-8000-00805f9b34fb";
const CHAR_OSD_WATCH_ID = "000085e9-0003-1000-8000-00805f9b34fb";
const CHAR_OSD_WATCH_FW = "000085e9-0004-1000-8000-00805f9b34fb";

// Official BLE UUIDs from https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned_Numbers.pdf
// Also based on bootgathrm bangle app.
const SERV_HRM = 0x180D; // Official BLE UUID
const CHAR_HRM = 0x2A37; // Official BLE UUID
const CHAR_HR_LOC = 0x2A38; // Official BLE Sensor Location UUID

(() => {
function draw() {
g.reset();
g.drawImage(E.toArrayBuffer(atob("GBiEBAAAAAABEREQAAAAAAAAAAAKmZkgAAAAAAAAAAAKmZkgAAAAAAAAAAAKkzkgAAAAAAACIQAKkzkgABIgAAAZmSAKPykgApmRAAApmZoqMjkiqZmSAAKZmZmZ8zmpmZmZIAKZmZmZMzmZmZmZIAEpmZmZkzqZmZmSEAACqZmZkjOZmZogAAAAApmZkjOZmSAAAAAAApmZn/mZmSAAAAACqZmZrymZmZogAAEpmZmZkzmZmZmSEAqZmZmZkjqZmZmZoAKZmZmamvmpmZmZIAApmZIan6mhKZmSAAAZmiAKkymgAqmRAAACIAAKkimgAAIgAAAAAAAKkimgAAAAAAAAAAAKmZmgAAAAAAAAAAAKmZmgAAAAAAAAAAABEREQAAAAAA==")), this.x, this.y);
}

var accelData = new Uint8Array(20);
var accelIdx = 0;
var batteryLevel = 0;
//http://kionixfs.kionix.com/en/datasheet/KX023-1025%20Specifications%20Rev%2012.0.pdf
Bangle.accelWr(0x1B,0x01 | 0x40); // 25hz output, ODR/2 filter
Bangle.setPollInterval(40); // 25hz input
Bangle.on('accel',function(a) {
accelData[accelIdx++] = E.clip(a.mag*64,0,255);
if (accelIdx>=accelData.length) {
accelIdx = 0;
batteryLevel = E.getBattery();
try { NRF.updateServices({
"000085e9-0000-1000-8000-00805f9b34fb" : {
"000085ea-0000-1000-8000-00805f9b34fb" : {
value : accelData, notify : true
},
"000085eb-0000-1000-8000-00805f9b34fb" : {
value : batteryLevel, notify : true
}
}
});} catch(e) {}
}
});

NRF.setServices({
"000085e9-0000-1000-8000-00805f9b34fb" : {
"000085ea-0000-1000-8000-00805f9b34fb" : {
var accelData = new Uint8Array(20);
var accelIdx = 0;
var batteryLevel = 0;
var hrVal = 0;

function draw() {
// Draw the OSD Icon
g.reset();
g.drawImage(E.toArrayBuffer(atob("GBiEBAAAAAABEREQAAAAAAAAAAAKmZkgAAAAAAAAAAAKmZkgAAAAAAAAAAAKkzkgAAAAAAACIQAKkzkgABIgAAAZmSAKPykgApmRAAApmZoqMjkiqZmSAAKZmZmZ8zmpmZmZIAKZmZmZMzmZmZmZIAEpmZmZkzqZmZmSEAACqZmZkjOZmZogAAAAApmZkjOZmSAAAAAAApmZn/mZmSAAAAACqZmZrymZmZogAAEpmZmZkzmZmZmSEAqZmZmZkjqZmZmZoAKZmZmamvmpmZmZIAApmZIan6mhKZmSAAAZmiAKkymgAqmRAAACIAAKkimgAAIgAAAAAAAKkimgAAAAAAAAAAAKmZmgAAAAAAAAAAAKmZmgAAAAAAAAAAABEREQAAAAAA==")), this.x, this.y);
}


// accelerometer data callback.
Bangle.on('accel',function(a) {
accelData[accelIdx++] = E.clip(a.mag*64,0,255);
if (accelIdx>=accelData.length) {
accelIdx = 0;
batteryLevel = E.getBattery();
try {
var charOsdAccData = {
value : accelData,
notify : true
};
var charOsdBatData = {
value : batteryLevel,
notify : true
};
var charOsdHrData = {
value : hrVal,
notify : true
};
var charBleHrm = {
value : [0x06, hrVal], // Check what 0x06 is?
notify : true
};


var servOsd = {};
servOsd[CHAR_OSD_ACC_DATA] = charOsdAccData;
servOsd[CHAR_OSD_BAT_DATA] = charOsdBatData;
servOsd[CHAR_OSD_HR_DATA] = charOsdHrData;
var servHrm = {};
servHrm[CHAR_HRM] = charBleHrm;

var servicesCfg = {};
servicesCfg[SERV_OSD] = servOsd;
servicesCfg[SERV_HRM] = servHrm;

NRF.updateServices(servicesCfg);
} catch(e) {}
}
});


Bangle.on('HRM', function(hrm) {
hrVal = hrm['bpm'];
});


// Initialise accelerometer
//http://kionixfs.kionix.com/en/datasheet/KX023-1025%20Specifications%20Rev%2012.0.pdf
Bangle.accelWr(0x1B,0x01 | 0x40); // 25hz output, ODR/2 filter
Bangle.setPollInterval(40); // 25hz input

// Switch on the heart rate monitor
Bangle.setHRMPower(1);


var charOsdAccData = {
value : accelData,
maxLen : 20,
readable : true,
notify : true
},
"000085eb-0000-1000-8000-00805f9b34fb" : {
};
var charOsdBatData = {
value : batteryLevel,
maxLen : 20,
readable : true,
notify : true
}
}
});
};
var charOsdWatchId = {
value : WATCH_ID,
maxLen : 10,
readable : true
};
var charOsdWatchFw = {
value : WATCH_FW,
maxLen : 8,
readable : true
};
var charBleHrm = {
value : [0x06, 0], // Check what 0x06 is?
maxLen : 2,
readable : true,
notify : true
};
var charBleHrLoc = { // Sensor Location: Wrist
value : 0x02,
};
var servOsd = {};
servOsd[CHAR_OSD_ACC_DATA] = charOsdAccData;
servOsd[CHAR_OSD_BAT_DATA] = charOsdBatData;
servOsd[CHAR_OSD_WATCH_ID] = charOsdWatchId;
servOsd[CHAR_OSD_WATCH_FW] = charOsdWatchFw;
var servHrm = {};
servHrm[CHAR_HRM] = charBleHrm;
servHrm[CHAR_HR_LOC] = charBleHrLoc;
var servicesCfg = {};
servicesCfg[SERV_OSD] = servOsd;
servicesCfg[SERV_HRM] = servHrm;

// add your widget
WIDGETS["openseizure"]={
area:"tl", width: 24, draw:draw
};
NRF.setServices(servicesCfg);

// add your widget
WIDGETS["openseizure"]={
area:"tl", width: 24, draw:draw
};
})();

0 comments on commit 7cf742f

Please sign in to comment.