Skip to content

Commit

Permalink
Changed int(x) to Math.round(x). Did I mention how much I like javasc…
Browse files Browse the repository at this point in the history
…ript...
  • Loading branch information
jones139 committed Dec 13, 2023
1 parent aa7d61b commit 4311eb1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/openseizure/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
0.14: Added 3d acceleration data option and test data option
0.15: Converted 3d data to integer milli-g
0.16: I hate Javascript - it looks like saying if (variablename) is true, even if the variable is false...
0.17: Changed int(x) to Math.round(x).
2 changes: 1 addition & 1 deletion apps/openseizure/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "openseizure",
"name": "OpenSeizureDetector Widget",
"shortName": "OSD",
"version": "0.16",
"version": "0.17",
"description": "[BETA!] A widget to work alongside [OpenSeizureDetector](https://www.openseizuredetector.org.uk/)",
"icon": "widget.png",
"type": "widget",
Expand Down
17 changes: 9 additions & 8 deletions apps/openseizure/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ACC_FMT_3D = 3;

/////////////////////////////////
// Build Configuration
const WATCH_FW = "0.16";
const WATCH_FW = "0.17";
const WATCH_ID = "BangleJs";
const ACC_FMT = ACC_FMT_3D;
const USE_TEST_ACC_DATA = false; // FIXME - does not send real data when set to true
Expand Down Expand Up @@ -49,16 +49,16 @@ function getTestVal() {
// From 'sensible.js' example app
function encodeAccel3DData(a) {
let x = 0; let y = 0; let z = 0;
x = toByteArray(int(1000*a.x), 2, true);
y = toByteArray(int(1000*a.y), 2, true);
z = toByteArray(int(1000*a.z), 2, true);
x = toByteArray(Math.round(1000*a.x), 2, true);
y = toByteArray(Math.round(1000*a.y), 2, true);
z = toByteArray(Math.round(1000*a.z), 2, true);
return [
x[0], x[1], y[0], y[1], z[0], z[1] // Accel 3D
];
}

function encodeAccel16bitData(a) {
let x = toByteArray(int(1000*a.mag), 2, false);
let x = toByteArray(Math.round(1000*a.mag), 2, false);
return [
x[0], x[1]
];
Expand Down Expand Up @@ -98,7 +98,8 @@ function toByteArray(value, numberOfBytes, isSigned) {

// accelerometer data callback.
Bangle.on('accel',function(a) {
let accArr = []
let accArr = [];
let n = 0;
switch (ACC_FMT) {
case ACC_FMT_8BIT: // 8 bit vector magnitude scaled so 1g=64
// Calculate vector magnitude of acceleration measurement, and scale it so 1g is value 64 (so we cover 0 to 4g)
Expand All @@ -108,7 +109,7 @@ function toByteArray(value, numberOfBytes, isSigned) {
break;
case ACC_FMT_16BIT: // 16 bit vector magnitude in milli-g
accArr = encodeAccel16bitData(a);
for (let n=0; n<accArr.length;n++) {
for (n=0; n<accArr.length;n++) {
accelData[accelIdx] = accArr[n];
accelIdx += 1
}
Expand All @@ -117,7 +118,7 @@ function toByteArray(value, numberOfBytes, isSigned) {
break;
case ACC_FMT_3D: // 16 bit acceleration components in milli-g (x, y, z)
accArr = encodeAccel3DData(a);
for (let n=0; n<accArr.length;n++) {
for (n=0; n<accArr.length;n++) {
accelData[accelIdx] = accArr[n];
accelIdx += 1
}
Expand Down

0 comments on commit 4311eb1

Please sign in to comment.