Add files via upload

master
jla-42 2024-03-13 22:29:28 +01:00 committed by GitHub
parent e068ba789a
commit 29933cb4e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 178 additions and 1 deletions

View File

@ -1 +1 @@
0.01: New App!

27
apps/slpquiet/README.md Normal file
View File

@ -0,0 +1,27 @@
# Sleep Quiet
Set Quiet mode (or alarms only mode), when the sleep tracking app detects sleep (each 10 min evaluated)
## Usage
When activated, app disables all notifications / all except alarms when sleep detected.
## Controls
In the app you can activate / deactivate the functionality and define if all notifications / all except alarms are to be silenced.
## Creator
[jla-42](https://github.com/jla-42)
## Note
The app is based upon the [sleeplog](https://github.com/espruino/BangleApps/tree/master/apps/sleeplog) app.
It reuses the widget from [Quiet Mode Schedule and Widget](https://github.com/espruino/BangleApps/tree/master/apps/qmsched), as it does exactly what I needed, so why reinvent the wheel.
## ToDos
-further code clean up
-optimization of code (and check if needed)
-feedback is always welcome

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEw4UA///jc+tfUvk+Jf8AhWoBhUoBZWgBRMCwAvKHa5bTG5UqJ4OqBY+qBYJpIBYRpIBYRRIBYQAIBbJhJBYIBBktVAAVoBYmoj//AAXWBYsdC4d1BZVdGwILO0ALIAAWdBY+vIQILI04LBrojKAAoLyX40CBeUqBZD1HAH8AA="))

45
apps/slpquiet/app.js Normal file
View File

@ -0,0 +1,45 @@
const SETTINGS_FILE = "quietSwitch.json";
const storage = require("Storage");
let settings = storage.readJSON('setting.json', 1);
let saved = storage.readJSON(SETTINGS_FILE, 1) || {};
// Main menu
var mainmenu = {
"" : {
"title" : "Quiet Switch"
},
"Quiet Switch" : {
value : saved.quietWhenSleep,
format : v => v?"On":"Off",
min:0,max:1,step:1,
onchange :v=>{
saved.quietWhenSleep = v;
storage.writeJSON(SETTINGS_FILE,saved);
}
},
"Quiet Mode" : {
value : saved.quietMode,
format : v => v?"Alerts":"Silent",
min:0,max:1,step:1,
onchange :v=>{
saved.quietMode = v;
storage.writeJSON(SETTINGS_FILE,saved);
}
},
"Exit" : function() {load();},
};
// Actually display the menu
E.showMenu(mainmenu);
// Function to fix time format
function fixTime(h, m) {
if (h.toString().length <2) {
h = "0" + h.toString();
}
if (m.toString().length <2) {
m = "0" + m.toString();
}
return h.toString() +":" + m.toString();
}

BIN
apps/slpquiet/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

52
apps/slpquiet/boot.js Normal file
View File

@ -0,0 +1,52 @@
// first ensure that the sleeplog trigger object is available (sleeplog is enabled)
if (typeof (global.sleeplog || {}).trigger === "object") {
// then add your parameters with the function to call as object into the trigger object
sleeplog.trigger["quietMode"] = {
onChange: true, // false as default, if true call fn only on a status change
from: 0, // 0 as default, in ms, first time fn will be called
// to: 24*60*60*1000, // 24h as default, in ms, last time fn will be called
to: 0,
// reference time to from & to is rounded to full minutes
fn: function(data, thisTriggerEntry) {
aSettings = require('Storage').readJSON('quietSwitch.json', 1) || {};
const DEFAULTS = {
'quietWhenSleep': false,
'quietMode': 1
};
Object.keys(DEFAULTS).forEach(k => {
if (aSettings[k] === undefined) aSettings[k] = DEFAULTS[k];
});
if (aSettings && aSettings['quietWhenSleep']){
console.log("the sleep status is: "+data.status);
quietMode = aSettings['quietMode'];
delete aSettings;
if ((data.status === 3 || data.status === 4)
&& (data.prevStatus !== 3 && data.prevStatus !== 4 )) {
bSettings = require("Storage").readJSON('setting.json',true)||{};
current = 0|bSettings.quiet;
console.log("quiet mode is:" + current);
if (current !== quietMode ){
console.log("fallen asleep");
bSettings.quiet = quietMode;
require("Storage").writeJSON("setting.json", bSettings);
}
delete bSettings;
}
if ((data.status === 2 || data.status === 1)
&& (data.prevStatus !== 2 && data.prevStatus !== 1 )) {
bSettings = require("Storage").readJSON('setting.json',true)||{};
current = 0|bSettings.quiet;
console.log("quiet mode is:" + current);
if (current !== 0 ){
console.log("woken up");
bSettings.quiet = 0;
require("Storage").writeJSON("setting.json", bSettings);
}
delete bSettings;
}
}
}
};
}

View File

@ -0,0 +1,16 @@
{ "id": "slpquiet",
"name": "Sleep Quiet (activate quiet mode when asleep)",
"shortName":"Sleep Quiet",
"version":"0.01",
"description": "Set Quiet mode (or alarms only mode), when the sleep tracking app detects sleep (each 10 min evaluated)",
"icon": "app.png",
"tags": "tool,widget",
"supports" : ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"slpquiet.app.js","url":"app.js"},
{"name":"slpquiet.boot.js","url":"boot.js"},
{"name":"slpquiet.img","url":"app-icon.js","evaluate":true},
{"name":"slpquiet.wid.js","url":"widget.js"}
]
}

36
apps/slpquiet/widget.js Normal file
View File

@ -0,0 +1,36 @@
(function() {
WIDGETS["qmsched"] = {
area: "tl",
width: ((require("Storage").readJSON("setting.json", 1) || {}).quiet|0) ? 24 : 0,
draw: function() {
const mode = (require("Storage").readJSON("setting.json", 1) || {}).quiet|0;
if (mode===0) { // Off
if (this.width!==0) {
this.width = 0;
Bangle.drawWidgets();
}
return;
}
// not Off: make sure width is correct
if (this.width!==24) {
this.width = 24;
Bangle.drawWidgets();
return; // drawWidgets will call draw again
}
let x = this.x, y = this.y;
g.reset().clearRect(x, y, x+23, y+23);
// quiet mode: draw red one-way-street sign (dim red on Bangle.js 1)
x = this.x+11;y = this.y+11; // center of widget
g.setColor(process.env.HWVERSION===2 ? 1 : 0.8, 0, 0).fillCircle(x, y, 8);
g.setColor(g.theme.bg).fillRect(x-6, y-2, x+6, y+2);
if (mode>1) {return;} // no alarms
// alarms still on: draw alarm icon in bottom-right corner
x = this.x+18;y = this.y+17; // center of alarm
g.setColor(1, 1, 0)
.fillCircle(x, y, 3) // alarm body
.fillRect(x-5, y+2, x+5, y+3) // bottom ridge
.fillRect(x-1, y-5, x+1, y+5).drawLine(x, y-6, x, y+6) // top+bottom
.drawLine(x+5, y-3, x+3, y-5).drawLine(x-5, y-3, x-3, y-5); // wriggles
},
};
})();