forked from FOSS/BangleApps
commit
374b4bbae1
|
@ -59,13 +59,6 @@ module.exports = {
|
|||
"no-unused-vars"
|
||||
]
|
||||
},
|
||||
"sleeplog/settings.js": {
|
||||
"hash": "bd5e3e1382321df6682ef1cb718b0e15ab355422bef77278eb086f213f643021",
|
||||
"rules": [
|
||||
"no-unused-vars",
|
||||
"no-undef"
|
||||
]
|
||||
},
|
||||
"showimg/app.js": {
|
||||
"hash": "71cbbaa488e2d08c5bf28f7d56178d5e7694eb9761cd4752bbc9733e825d4bcf",
|
||||
"rules": [
|
||||
|
@ -276,13 +269,6 @@ module.exports = {
|
|||
"no-undef"
|
||||
]
|
||||
},
|
||||
"sleeplog/app.js": {
|
||||
"hash": "336da552e4b04677447cf76a253b40bc259a597ea11d455121933f93afe99794",
|
||||
"rules": [
|
||||
"no-unused-vars",
|
||||
"no-undef"
|
||||
]
|
||||
},
|
||||
"qmsched/app.js": {
|
||||
"hash": "4b7dbabed6c252021531d6b0449c16a3adc2e405f2ddda33ca0a65f5fa42c663",
|
||||
"rules": [
|
||||
|
@ -562,13 +548,6 @@ module.exports = {
|
|||
"no-undef"
|
||||
]
|
||||
},
|
||||
"sleeplog/lib.js": {
|
||||
"hash": "755e0d4c02b92181281fd6990df39c9446c73ff896b50b64d7e14cb1c0188556",
|
||||
"rules": [
|
||||
"no-unused-vars",
|
||||
"no-undef"
|
||||
]
|
||||
},
|
||||
"doztime/app-bangle1.js": {
|
||||
"hash": "1e9598c201175180ae77d1c3bc47e8138b339b72eb58782b5057fb7aefdc88a1",
|
||||
"rules": [
|
||||
|
@ -756,12 +735,6 @@ module.exports = {
|
|||
"no-undef"
|
||||
]
|
||||
},
|
||||
"sleeplog/boot.js": {
|
||||
"hash": "b4c9d8e3c3e7cdf44ea10e29a9e3b53f958b86c21ca91d88e4efb85901c3bde9",
|
||||
"rules": [
|
||||
"no-undef"
|
||||
]
|
||||
},
|
||||
"scicalc/app.js": {
|
||||
"hash": "416c7b2eb12a5d10bcc3a99d89d8f6f54ecd2b47cce2d1f4d55c3e3bc602b31a",
|
||||
"rules": [
|
||||
|
|
|
@ -12,3 +12,4 @@
|
|||
0.14: Add "Delete all logfiles before" to interface.html, display all logfiles in the interface
|
||||
0.15: Issue newline before GB commands (solves issue with console.log and ignored commands)
|
||||
0.16: Only write logs if we have a non-empty log to write
|
||||
0.17: Minor code improvements
|
||||
|
|
|
@ -245,13 +245,13 @@ function draw() {
|
|||
g.reset();
|
||||
var imgStr = "";
|
||||
// check which icon to set
|
||||
if (!global.sleeplog || sleeplog.conf.enabled !== true) {
|
||||
if (!global.sleeplog || global.sleeplog.conf.enabled !== true) {
|
||||
// set color and disabled service icon
|
||||
g.setColor(1, 0, 0);
|
||||
imgStr = "FBSBAOAAfwAP+AH3wD4+B8Hw+A+fAH/gA/wAH4AB+AA/wAf+APnwHw+D4Hx8A++AH/AA/gAH";
|
||||
} else if (sleeplog.debug) {
|
||||
} else if (global.sleeplog.debug) {
|
||||
// set debugging icon
|
||||
imgStr = typeof sleeplog.debug === "object" ?
|
||||
imgStr = typeof global.sleeplog.debug === "object" ?
|
||||
"FBSBAB/4AQDAF+4BfvAX74F+CBf+gX/oFJKBf+gUkoF/6BSSgX/oFJ6Bf+gX/oF/6BAAgf/4" : // file
|
||||
"FBSBAP//+f/V///4AAGAABkAAZgAGcABjgAYcAGDgBhwAY4AGcABmH+ZB/mAABgAAYAAH///"; // console
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ var ATID; // analysis timeout ID
|
|||
var drawingID = 0; // drawing ID for ongoing process
|
||||
// get screen width and center (zero based)
|
||||
var width = g.getWidth() - 1;
|
||||
var center = width / 2 - 1;
|
||||
//var center = width / 2 - 1;
|
||||
|
||||
// set areas and actions array
|
||||
var aaa = [
|
||||
|
|
|
@ -18,14 +18,14 @@ global.sleeplog = {
|
|||
};
|
||||
|
||||
// check if service is enabled
|
||||
if (sleeplog.conf.enabled) {
|
||||
if (global.sleeplog.conf.enabled) {
|
||||
// assign functions to global object
|
||||
global.sleeplog = Object.assign({
|
||||
// define function to initialy start or restart the service
|
||||
start: function() {
|
||||
// add kill and health listener
|
||||
E.on('kill', sleeplog.saveStatus);
|
||||
Bangle.on('health', sleeplog.health);
|
||||
E.on('kill', global.sleeplog.saveStatus);
|
||||
Bangle.on('health', global.sleeplog.health);
|
||||
|
||||
// restore saved status
|
||||
this.restoreStatus();
|
||||
|
@ -34,8 +34,8 @@ if (sleeplog.conf.enabled) {
|
|||
// define function to stop the service, it will be restarted on reload if enabled
|
||||
stop: function() {
|
||||
// remove all listeners
|
||||
Bangle.removeListener('health', sleeplog.health);
|
||||
E.removeListener('kill', sleeplog.saveStatus);
|
||||
Bangle.removeListener('health', global.sleeplog.health);
|
||||
E.removeListener('kill', global.sleeplog.saveStatus);
|
||||
|
||||
// save active values
|
||||
this.saveStatus();
|
||||
|
@ -122,11 +122,11 @@ if (sleeplog.conf.enabled) {
|
|||
if (!global.sleeplog) return new Error("sleeplog: Can't save status, global object missing!");
|
||||
|
||||
// check saveUpToDate is not set or forced
|
||||
if (!sleeplog.info.saveUpToDate || force) {
|
||||
if (!global.sleeplog.info.saveUpToDate || force) {
|
||||
// save status, consecutive status and info timestamps to restore on reload
|
||||
var save = [sleeplog.info.lastCheck, sleeplog.info.awakeSince, sleeplog.info.asleepSince];
|
||||
var save = [global.sleeplog.info.lastCheck, global.sleeplog.info.awakeSince, global.sleeplog.info.asleepSince];
|
||||
// add debuging status if active
|
||||
if (sleeplog.debug) save.push(sleeplog.debug.writeUntil, sleeplog.debug.fileid);
|
||||
if (global.sleeplog.debug) save.push(global.sleeplog.debug.writeUntil, global.sleeplog.debug.fileid);
|
||||
|
||||
// stringify entries
|
||||
save = "," + save.map((entry, index) => {
|
||||
|
@ -135,8 +135,8 @@ if (sleeplog.conf.enabled) {
|
|||
}).join(",") + "\n";
|
||||
|
||||
// add present status if forced
|
||||
if (force) save = (sleeplog.info.lastChange / 6E5) + "," +
|
||||
sleeplog.status + "," + sleeplog.consecutive + "\n" + save;
|
||||
if (force) save = (global.sleeplog.info.lastChange / 6E5) + "," +
|
||||
global.sleeplog.status + "," + global.sleeplog.consecutive + "\n" + save;
|
||||
|
||||
// append saved data to StorageFile
|
||||
require("Storage").open("sleeplog.log", "a").write(save);
|
||||
|
@ -161,20 +161,20 @@ if (sleeplog.conf.enabled) {
|
|||
// add preliminary status depending on charging and movement thresholds
|
||||
// 1 = not worn, 2 = awake, 3 = light sleep, 4 = deep sleep
|
||||
data.status = Bangle.isCharging() ? 1 :
|
||||
data.movement <= sleeplog.conf.deepTh ? 4 :
|
||||
data.movement <= sleeplog.conf.lightTh ? 3 : 2;
|
||||
data.movement <= global.sleeplog.conf.deepTh ? 4 :
|
||||
data.movement <= global.sleeplog.conf.lightTh ? 3 : 2;
|
||||
|
||||
// check if changing to deep sleep from non sleeping
|
||||
if (data.status === 4 && sleeplog.status <= 2) {
|
||||
sleeplog.checkIsWearing((isWearing, data) => {
|
||||
if (data.status === 4 && global.sleeplog.status <= 2) {
|
||||
global.sleeplog.checkIsWearing((isWearing, data) => {
|
||||
// correct status
|
||||
if (!isWearing) data.status = 1;
|
||||
// set status
|
||||
sleeplog.setStatus(data);
|
||||
global.sleeplog.setStatus(data);
|
||||
}, data);
|
||||
} else {
|
||||
// set status
|
||||
sleeplog.setStatus(data);
|
||||
global.sleeplog.setStatus(data);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -185,7 +185,7 @@ if (sleeplog.conf.enabled) {
|
|||
}
|
||||
|
||||
// create a temporary object to store data and functions
|
||||
global.tmpWearingCheck = {
|
||||
const tmpWearingCheck = {
|
||||
// define temporary hrm listener function to read the wearing status
|
||||
hrmListener: hrm => tmpWearingCheck.isWearing = hrm.isWearing,
|
||||
// set default wearing status
|
||||
|
@ -195,22 +195,18 @@ if (sleeplog.conf.enabled) {
|
|||
// enable HRM
|
||||
Bangle.setHRMPower(true, "wearingCheck");
|
||||
// wait until HRM is initialised
|
||||
setTimeout((returnFn, data) => {
|
||||
setTimeout((returnFn, data, tmpWearingCheck) => {
|
||||
// add HRM listener
|
||||
Bangle.on('HRM-raw', tmpWearingCheck.hrmListener);
|
||||
// wait for two cycles (HRM working on 60Hz)
|
||||
setTimeout((returnFn, data) => {
|
||||
setTimeout((returnFn, data, tmpWearingCheck) => {
|
||||
// remove listener and disable HRM
|
||||
Bangle.removeListener('HRM-raw', tmpWearingCheck.hrmListener);
|
||||
Bangle.setHRMPower(false, "wearingCheck");
|
||||
// cache wearing status
|
||||
var isWearing = tmpWearingCheck.isWearing;
|
||||
// clear temporary object
|
||||
delete global.tmpWearingCheck;
|
||||
// call return function with status
|
||||
returnFn(isWearing, data);
|
||||
}, 34, returnFn, data);
|
||||
}, 2500, returnFn, data);
|
||||
returnFn(tmpWearingCheck.isWearing, data);
|
||||
}, 34, returnFn, data, tmpWearingCheck);
|
||||
}, 2500, returnFn, data, tmpWearingCheck);
|
||||
},
|
||||
|
||||
// define function to set the status
|
||||
|
@ -361,7 +357,7 @@ if (sleeplog.conf.enabled) {
|
|||
|
||||
// define trigger object
|
||||
trigger: {}
|
||||
}, sleeplog);
|
||||
}, global.sleeplog);
|
||||
|
||||
// initial starting
|
||||
global.sleeplog.start();
|
||||
|
|
|
@ -3,7 +3,7 @@ exports = {
|
|||
// define en-/disable function, restarts the service to make changes take effect
|
||||
setEnabled: function(enable) {
|
||||
// stop if enabled
|
||||
if (global.sleeplog && sleeplog.enabled) sleeplog.stop();
|
||||
if (global.sleeplog && global.sleeplog.enabled) global.sleeplog.stop();
|
||||
|
||||
// define settings filename
|
||||
var settings = "sleeplog.json";
|
||||
|
@ -138,7 +138,7 @@ exports = {
|
|||
}
|
||||
|
||||
// define last index
|
||||
var lastIndex = log.length - 1;
|
||||
//var lastIndex = log.length - 1;
|
||||
// set timestamp of first entry to since if first entry before since
|
||||
if (log[0] && log[0][0] < since) log[0][0] = since;
|
||||
// add timestamp at now with unknown status if until after now
|
||||
|
@ -251,7 +251,7 @@ exports = {
|
|||
// set default date or correct date type if needed
|
||||
if (!date || !date.getDay) date = date ? new Date(date) : new Date();
|
||||
// set default ToD as set in sleeplog.conf or settings if available
|
||||
if (ToD === undefined) ToD = (global.sleeplog && sleeplog.conf ? sleeplog.conf.breakToD :
|
||||
if (ToD === undefined) ToD = (global.sleeplog && global.sleeplog.conf ? global.sleeplog.conf.breakToD :
|
||||
(require("Storage").readJSON("sleeplog.json", true) || {}).breakToD) || 12;
|
||||
// calculate last break time and return
|
||||
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), ToD);
|
||||
|
@ -274,24 +274,24 @@ exports = {
|
|||
|
||||
// check if nothing has to be changed
|
||||
if (!duration &&
|
||||
(enable && sleeplog.debug === true) ||
|
||||
(!enable && !sleeplog.debug)) return;
|
||||
(enable && global.sleeplog.debug === true) ||
|
||||
(!enable && !global.sleeplog.debug)) return;
|
||||
|
||||
// check if en- or disable debugging
|
||||
if (enable) {
|
||||
// define debug object
|
||||
sleeplog.debug = {};
|
||||
global.sleeplog.debug = {};
|
||||
|
||||
// check if a file should be generated
|
||||
if (typeof duration === "number") {
|
||||
// check duration boundaries, 0 => 8
|
||||
duration = duration > 96 ? 96 : duration || 12;
|
||||
// calculate and set writeUntil in 10min steps
|
||||
sleeplog.debug.writeUntil = ((Date.now() / 6E5 | 0) + duration * 6) * 6E5;
|
||||
global.sleeplog.debug.writeUntil = ((Date.now() / 6E5 | 0) + duration * 6) * 6E5;
|
||||
// set fileid to "{hours since 1970}"
|
||||
sleeplog.debug.fileid = Date.now() / 36E5 | 0;
|
||||
global.sleeplog.debug.fileid = Date.now() / 36E5 | 0;
|
||||
// write csv header on empty file
|
||||
var file = require("Storage").open("sleeplog_" + sleeplog.debug.fileid + ".csv", "a");
|
||||
var file = require("Storage").open("sleeplog_" + global.sleeplog.debug.fileid + ".csv", "a");
|
||||
if (!file.getLength()) file.write(
|
||||
"timestamp,movement,status,consecutive,asleepSince,awakeSince,bpm,bpmConfidence\n"
|
||||
);
|
||||
|
@ -299,21 +299,21 @@ exports = {
|
|||
file = undefined;
|
||||
} else {
|
||||
// set debug as active
|
||||
sleeplog.debug = true;
|
||||
global.sleeplog.debug = true;
|
||||
}
|
||||
} else {
|
||||
// disable debugging
|
||||
delete sleeplog.debug;
|
||||
delete global.sleeplog.debug;
|
||||
}
|
||||
|
||||
// save status forced
|
||||
sleeplog.saveStatus(true);
|
||||
global.sleeplog.saveStatus(true);
|
||||
},
|
||||
|
||||
// define debugging function, called after logging if debug is set
|
||||
debug: function(data) {
|
||||
// check if global variable accessable and debug active
|
||||
if (!global.sleeplog || !sleeplog.debug) return;
|
||||
if (!global.sleeplog || !global.sleeplog.debug) return;
|
||||
|
||||
// set functions to convert timestamps
|
||||
function localTime(timestamp) {
|
||||
|
@ -328,10 +328,10 @@ exports = {
|
|||
var console = "sleeplog: " +
|
||||
localTime(data.timestamp) + " > " +
|
||||
"movement: " + ("" + data.movement).padStart(4) + ", " +
|
||||
"unknown ,non consec.,consecutive".split(",")[sleeplog.consecutive] + " " +
|
||||
"unknown ,non consec.,consecutive".split(",")[global.sleeplog.consecutive] + " " +
|
||||
"unknown,not worn,awake,light sleep,deep sleep".split(",")[data.status].padEnd(12) + ", " +
|
||||
"asleep since: " + localTime(sleeplog.info.asleepSince) + ", " +
|
||||
"awake since: " + localTime(sleeplog.info.awakeSince);
|
||||
"asleep since: " + localTime(global.sleeplog.info.asleepSince) + ", " +
|
||||
"awake since: " + localTime(global.sleeplog.info.awakeSince);
|
||||
// add bpm if set
|
||||
if (data.bpm) console += ", " +
|
||||
"bpm: " + ("" + data.bpm).padStart(3) + ", " +
|
||||
|
@ -340,24 +340,24 @@ exports = {
|
|||
print(console);
|
||||
|
||||
// check if debug is set as object with a file id and it is not past writeUntil
|
||||
if (typeof sleeplog.debug === "object" && sleeplog.debug.fileid &&
|
||||
Date.now() < sleeplog.debug.writeUntil) {
|
||||
if (typeof global.sleeplog.debug === "object" && global.sleeplog.debug.fileid &&
|
||||
Date.now() < global.sleeplog.debug.writeUntil) {
|
||||
// generate next csv line
|
||||
var csv = [
|
||||
officeTime(data.timestamp),
|
||||
data.movement,
|
||||
data.status,
|
||||
sleeplog.consecutive,
|
||||
sleeplog.info.asleepSince ? officeTime(sleeplog.info.asleepSince) : "",
|
||||
sleeplog.info.awakeSince ? officeTime(sleeplog.info.awakeSince) : "",
|
||||
global.sleeplog.consecutive,
|
||||
global.sleeplog.info.asleepSince ? officeTime(global.sleeplog.info.asleepSince) : "",
|
||||
global.sleeplog.info.awakeSince ? officeTime(global.sleeplog.info.awakeSince) : "",
|
||||
data.bpm || "",
|
||||
data.bpmConfidence || ""
|
||||
].join(",");
|
||||
// write next line to log if set
|
||||
require("Storage").open("sleeplog_" + sleeplog.debug.fileid + ".csv", "a").write(csv + "\n");
|
||||
require("Storage").open("sleeplog_" + global.sleeplog.debug.fileid + ".csv", "a").write(csv + "\n");
|
||||
} else {
|
||||
// clear file setting in debug
|
||||
sleeplog.debug = true;
|
||||
global.sleeplog.debug = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"id":"sleeplog",
|
||||
"name":"Sleep Log",
|
||||
"shortName": "SleepLog",
|
||||
"version": "0.16",
|
||||
"version": "0.17",
|
||||
"description": "Log and view your sleeping habits. This app is using the built in movement calculation.",
|
||||
"icon": "app.png",
|
||||
"type": "app",
|
||||
|
|
|
@ -174,8 +174,8 @@
|
|||
}
|
||||
|
||||
// get thresholds
|
||||
var deepTh = global.sleeplog ? sleeplog.conf.deepTh : defaults.deepTh;
|
||||
var lightTh = global.sleeplog ? sleeplog.conf.lightTh : defaults.lightTh;
|
||||
var deepTh = global.sleeplog ? global.sleeplog.conf.deepTh : defaults.deepTh;
|
||||
var lightTh = global.sleeplog ? global.sleeplog.conf.lightTh : defaults.lightTh;
|
||||
// set lowest movement displayed
|
||||
var minMove = deepTh - 20;
|
||||
// set start point
|
||||
|
@ -240,8 +240,8 @@
|
|||
// check if sleeplog is available
|
||||
if (global.sleeplog) {
|
||||
// get debug status, file and duration
|
||||
var enabled = !!sleeplog.debug;
|
||||
var file = typeof sleeplog.debug === "object";
|
||||
var enabled = !!global.sleeplog.debug;
|
||||
var file = typeof global.sleeplog.debug === "object";
|
||||
var duration = 0;
|
||||
// setup debugging menu
|
||||
var debugMenu = {
|
||||
|
@ -250,7 +250,7 @@
|
|||
},
|
||||
/*LANG*/"< Back": () => {
|
||||
// check if some value has changed
|
||||
if (enabled !== !!sleeplog.debug || file !== (typeof sleeplog.debug === "object") || duration)
|
||||
if (enabled !== !!global.sleeplog.debug || file !== (typeof global.sleeplog.debug === "object") || duration)
|
||||
require("sleeplog").setDebug(enabled, file ? duration || 12 : undefined);
|
||||
// redraw main menu
|
||||
showMain(7);
|
||||
|
@ -265,7 +265,7 @@
|
|||
onchange: v => file = v
|
||||
},
|
||||
/*LANG*/"Duration": {
|
||||
value: file ? (sleeplog.debug.writeUntil - Date.now()) / 36E5 | 0 : 12,
|
||||
value: file ? (global.sleeplog.debug.writeUntil - Date.now()) / 36E5 | 0 : 12,
|
||||
min: 1,
|
||||
max: 96,
|
||||
wrap: true,
|
||||
|
@ -275,7 +275,7 @@
|
|||
/*LANG*/"Cancel": () => showMain(7),
|
||||
};
|
||||
// show menu
|
||||
var menu = E.showMenu(debugMenu);
|
||||
/*var menu =*/ E.showMenu(debugMenu);
|
||||
} else {
|
||||
// show error prompt
|
||||
E.showPrompt("Sleeplog" + /*LANG*/"not enabled!", {
|
||||
|
@ -290,7 +290,7 @@
|
|||
// show menu to change thresholds
|
||||
function showThresholds() {
|
||||
// setup logging menu
|
||||
var menu;
|
||||
//var menu;
|
||||
var thresholdsMenu = {
|
||||
"": {
|
||||
title: /*LANG*/"Thresholds"
|
||||
|
@ -377,9 +377,9 @@
|
|||
buttons: {
|
||||
/*LANG*/"Ok": 0
|
||||
}
|
||||
}).then(() => menu = E.showMenu(thresholdsMenu));
|
||||
}).then(() => /*menu =*/ E.showMenu(thresholdsMenu));
|
||||
} else {
|
||||
menu = E.showMenu(thresholdsMenu);
|
||||
/*menu =*/ E.showMenu(thresholdsMenu);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,9 +388,9 @@
|
|||
// set debug image
|
||||
var debugImg = !global.sleeplog ?
|
||||
"FBSBAOAAfwAP+AH3wD4+B8Hw+A+fAH/gA/wAH4AB+AA/wAf+APnwHw+D4Hx8A++AH/AA/gAH" : // X
|
||||
typeof sleeplog.debug === "object" ?
|
||||
typeof global.sleeplog.debug === "object" ?
|
||||
"FBSBAB/4AQDAF+4BfvAX74F+CBf+gX/oFJKBf+gUkoF/6BSSgX/oFJ6Bf+gX/oF/6BAAgf/4" : // file
|
||||
sleeplog.debug ?
|
||||
global.sleeplog.debug ?
|
||||
"FBSBAP//+f/V///4AAGAABkAAZgAGcABjgAYcAGDgBhwAY4AGcABmH+ZB/mAABgAAYAAH///" : // console
|
||||
0; // off
|
||||
debugImg = debugImg ? "\0" + atob(debugImg) : false;
|
||||
|
@ -440,7 +440,7 @@
|
|||
onchange: () => setTimeout(showDebug, 10)
|
||||
}
|
||||
};
|
||||
var menu = E.showMenu(mainMenu);
|
||||
/*var menu =*/ E.showMenu(mainMenu);
|
||||
}
|
||||
|
||||
// draw main menu
|
||||
|
|
Loading…
Reference in New Issue