Merge pull request #1343 from storm64/master

sleepphasealarm: Compatibility to Bangle.js 2 and new firmware
master
Gordon Williams 2022-01-25 09:17:37 +00:00 committed by GitHub
commit 3dac14d07d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 18 deletions

View File

@ -1,2 +1,3 @@
0.01: New App! 0.01: New App!
0.02: Respect Quiet Mode 0.02: Respect Quiet Mode
0.03: Add compatibility for Bangle.js 2 and new firmware, added "Alarm at " for the alarm time

View File

@ -1,3 +1,4 @@
const BANGLEJS2 = process.env.HWVERSION == 2; //# check for bangle 2
const alarms = require("Storage").readJSON("alarm.json",1)||[]; const alarms = require("Storage").readJSON("alarm.json",1)||[];
const active = alarms.filter(a=>a.on); const active = alarms.filter(a=>a.on);
@ -52,21 +53,21 @@ active.forEach(alarm => {
} }
}); });
function drawString(s, x, y) { function drawString(s, y) { //# replaced x: always centered
g.clearRect(0,y-15,239,y+15); g.reset(); //# moved up to prevent blue background
g.reset(); g.clearRect(0, y - 12, 239, y + 8); //# minimized upper+lower clearing
g.setFont("Vector", 20); g.setFont("Vector", 20);
g.setFontAlign(0,0); // align right bottom g.setFontAlign(0, 0); // align centered
g.drawString(s, x, y); g.drawString(s, g.getWidth() / 2, y); //# set x to center
} }
function drawApp() { function drawApp() {
g.clearRect(0,24,239,215); g.clearRect(0,24,239,215); //# no problem
var alarmHour = nextAlarm.getHours(); var alarmHour = nextAlarm.getHours();
var alarmMinute = nextAlarm.getMinutes(); var alarmMinute = nextAlarm.getMinutes();
if (alarmHour < 10) alarmHour = "0" + alarmHour; if (alarmHour < 10) alarmHour = "0" + alarmHour;
if (alarmMinute < 10) alarmMinute = "0" + alarmMinute; if (alarmMinute < 10) alarmMinute = "0" + alarmMinute;
const s = alarmHour + ":" + alarmMinute + "\n\n"; const s = "Alarm at " + alarmHour + ":" + alarmMinute + "\n\n"; //# make distinct to time
E.showMessage(s, "Sleep Phase Alarm"); E.showMessage(s, "Sleep Phase Alarm");
function drawTime() { function drawTime() {
@ -78,13 +79,21 @@ function drawApp() {
if (nowHour < 10) nowHour = "0" + nowHour; if (nowHour < 10) nowHour = "0" + nowHour;
if (nowMinute < 10) nowMinute = "0" + nowMinute; if (nowMinute < 10) nowMinute = "0" + nowMinute;
if (nowSecond < 10) nowSecond = "0" + nowSecond; if (nowSecond < 10) nowSecond = "0" + nowSecond;
const time = nowHour + ":" + nowMinute + ":" + nowSecond; const time = nowHour + ":" + nowMinute + (BANGLEJS2 ? "" : ":" + nowSecond); //# hide seconds on bangle 2
drawString(time, 120, 140); drawString(time, BANGLEJS2 ? 85 : 105); //# remove x, adjust height for bangle 2 an newer firmware
} }
} }
if (BANGLEJS2) {
drawTime();
setTimeout(_ => {
drawTime();
setInterval(drawTime, 60000);
}, 60000 - Date.now() % 60000); //# every new minute on bangle 2
} else {
setInterval(drawTime, 500); // 2Hz setInterval(drawTime, 500); // 2Hz
} }
}
var buzzCount = 19; var buzzCount = 19;
function buzz() { function buzz() {
@ -104,8 +113,8 @@ function buzz() {
var minAlarm = new Date(); var minAlarm = new Date();
var measure = true; var measure = true;
if (nextAlarm !== undefined) { if (nextAlarm !== undefined) {
Bangle.loadWidgets(); //# correct widget load draw order
Bangle.drawWidgets(); Bangle.drawWidgets();
Bangle.loadWidgets();
// minimum alert 30 minutes early // minimum alert 30 minutes early
minAlarm.setTime(nextAlarm.getTime() - (30*60*1000)); minAlarm.setTime(nextAlarm.getTime() - (30*60*1000));
@ -116,7 +125,7 @@ if (nextAlarm !== undefined) {
if (swest !== undefined) { if (swest !== undefined) {
if (Bangle.isLCDOn()) { if (Bangle.isLCDOn()) {
drawString(swest ? "Sleep" : "Awake", 120, 180); drawString(swest ? "Sleep" : "Awake", BANGLEJS2 ? 150 : 180); //# remove x, adjust height
} }
} }
@ -133,6 +142,6 @@ if (nextAlarm !== undefined) {
E.showMessage('No Alarm'); E.showMessage('No Alarm');
setTimeout(load, 1000); setTimeout(load, 1000);
} }
// BTN2 to menu, BTN3 to main // BTN2 to menu, BTN3 to main # on bangle 2 only BTN to main
setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" }); if (!BANGLEJS2) setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" });
setWatch(() => load(), BTN3, { repeat: false, edge: "falling" }); setWatch(() => load(), BANGLEJS2 ? BTN : BTN3, { repeat: false, edge: "falling" });

View File

@ -2,11 +2,11 @@
"id": "sleepphasealarm", "id": "sleepphasealarm",
"name": "SleepPhaseAlarm", "name": "SleepPhaseAlarm",
"shortName": "SleepPhaseAlarm", "shortName": "SleepPhaseAlarm",
"version": "0.02", "version": "0.03",
"description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.", "description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.",
"icon": "app.png", "icon": "app.png",
"tags": "alarm", "tags": "alarm",
"supports": ["BANGLEJS"], "supports": ["BANGLEJS","BANGLEJS2"],
"storage": [ "storage": [
{"name":"sleepphasealarm.app.js","url":"app.js"}, {"name":"sleepphasealarm.app.js","url":"app.js"},
{"name":"sleepphasealarm.img","url":"app-icon.js","evaluate":true} {"name":"sleepphasealarm.img","url":"app-icon.js","evaluate":true}