Update alarm.js

master
frigis1 2022-05-15 07:40:13 -07:00 committed by GitHub
parent cfe8887b6a
commit 117b52cc08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 96 additions and 21 deletions

View File

@ -6,6 +6,73 @@ if (Bangle.SCHED) {
delete Bangle.SCHED;
}
function hardMode(tries, max) {
var R = Bangle.appRect;
function adv() {
tries++;
hardMode(tries, max);
}
function random(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
if (tries < max) {
g.clear();
g.reset();
g.setClipRect(R.x,R.y,R.x2,R.y2);
var code = Math.abs(E.hwRand()%4);
if (code == 0) dir = "up";
else if (code == 1) dir = "right";
else if (code == 2) dir = "down";
else dir = "left";
g.setFont("6x8:2").setFontAlign(0,0).drawString(tries+"/"+max+"\nSwipe "+dir, (R.x2-R.x)/2, (R.y2-R.y)/2);
var drag;
Bangle.setUI({
mode : "custom",
drag : e=>{
if (!drag) { // start dragging
drag = {x: e.x, y: e.y};
} else if (!e.b) { // released
const dx = e.x-drag.x, dy = e.y-drag.y;
drag = null;
//horizontal swipes
if (Math.abs(dx)>Math.abs(dy)+10) {
//left
if (dx<0 && code == 3) adv();
//right
else if (dx>0 && code == 1) adv();
//wrong swipe - reset
else startHM();
}
//vertical swipes
else if (Math.abs(dy)>Math.abs(dx)+10) {
//up
if (dy<0 && code == 0) adv();
//down
else if (dy>0 && code == 2) adv();
//wrong swipe - reset
else startHM();
}
}
}
});
}
else {
if (!active[0].timer) active[0].last = (new Date()).getDate();
if (!active[0].rp) active[0].on = false;
if (active[0].timer) active[0].timer = active[0].data.ot;
require("sched").setAlarms(alarms);
load();
}
}
function startHM() {
//between 5-8 random swipes
hardMode(0, Math.abs(E.hwRand()%4)+5);
}
function showAlarm(alarm) {
const settings = require("sched").getSettings();
@ -21,6 +88,13 @@ function showAlarm(alarm) {
let buzzCount = settings.buzzCount;
if (alarm.data.hm && alarm.data.hm == true) {
//hard mode extends auto-snooze time
buzzCount = buzzCount * 2;
startHM();
}
else {
E.showPrompt(msg,{
title: "TIMER!",
buttons : {"Snooze":true,"Ok":false} // default is sleep so it'll come back in 10 mins
@ -38,11 +112,12 @@ function showAlarm(alarm) {
if (!alarm.rp) alarm.on = false;
}
//reset timer value
alarm.timer = alarm.data.ot;
if (alarm.timer) alarm.timer = alarm.data.ot;
// alarm is still a member of 'alarms', so writing to array writes changes back directly
require("sched").setAlarms(alarms);
load();
});
}
function buzz() {
if (settings.unlockAtBuzz) {