Skip to content

Commit 0f9139c

Browse files
authored
Merge pull request #3978 from RKBoss6/schedSnoozeUpdates
[Sched] Add snooze menu
2 parents 51d0261 + 5003ff5 commit 0f9139c

File tree

4 files changed

+74
-13
lines changed

4 files changed

+74
-13
lines changed

apps/sched/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535
0.32: clkinfo ensures an alarm won't trigger immediately (copying `alarm`'s behaviour)
3636
0.33: Ensure default vibration pattern is longer
3737
0.34: Ensure ClockInfo updates if it's used to start a timer
38+
0.35: If you use 2v28 (or above) firmware, you can long-press on the snooze button to gain finer control over snooze lengths.

apps/sched/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
Sched: Scheduling library for alarms and timers
2-
====================================
1+
# Sched: Scheduling library for alarms and timers
2+
33

44
This provides boot code, a library and tools for alarms and timers.
55

66
Other apps can use this to provide alarm functionality.
77

8-
App
9-
---
8+
## App
9+
10+
11+
The `Alarms & Timers` app allows you to add/modify any running alarms and timers.
12+
1013

11-
The **Alarms & Timers** app allows you to add/modify any running alarms and timers.
14+
### Snooze Menu
15+
16+
With sched version 0.35 or later, when an alarm or timer is triggered, and you have the latest cutting-edge firmware (or 2v28 when released), you can long press on the snooze button that pops up to go to a snooze menu, for finer control over snooze amounts. If you do not have the latest firmware, you will not notice any changes.
17+
18+
## Global Settings
1219

13-
Global Settings
14-
---------------
1520

1621
- `Unlock at Buzz` - If `Yes` the alarm/timer will unlock the watch
1722
- `Delete Expired Timers` - Default for whether expired timers are removed after firing.
@@ -21,8 +26,8 @@ Global Settings
2126
- `Buzz Interval` - The interval between one buzz and the next
2227
- `Default Alarm/Timer Pattern` - Default vibration pattern for newly created alarms/timers
2328

24-
Internals / Library
25-
-------------------
29+
## Internals / Library
30+
2631

2732
Alarms are stored in an array in `sched.json`, and take the form:
2833

apps/sched/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "sched",
33
"name": "Scheduler",
4-
"version": "0.34",
4+
"version": "0.35",
55
"description": "Scheduling library for alarms and timers",
66
"icon": "app.png",
77
"type": "scheduler",

apps/sched/sched.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,60 @@
1+
12
// Chances are boot0.js got run already and scheduled *another*
23
// 'load(sched.js)' - so let's remove it first!
34
if (Bangle.SCHED) {
45
clearInterval(Bangle.SCHED);
56
delete Bangle.SCHED;
67
}
78

9+
function formatMS(ms) {
10+
if (ms < 60000) {
11+
// less than a minute → show seconds
12+
return Math.round(ms / 1000) + "s";
13+
} else {
14+
// one minute or more → show minutes
15+
return Math.round(ms / 60000) + "m";
16+
}
17+
}
18+
19+
function showSnoozeMenu(alarm){
20+
21+
Bangle.buzz(40);
22+
23+
function onSnooze(snoozeTime) {
24+
if (alarm.ot === undefined) {
25+
alarm.ot = alarm.t;
26+
}
27+
let time = new Date();
28+
let currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000);
29+
alarm.t = currentTime + snoozeTime;
30+
alarm.t %= 86400000;
31+
Bangle.emit("alarmSnooze", alarm);
32+
33+
// The updated alarm is still a member of 'alarms'
34+
// so writing to array writes changes back directly
35+
require("sched").setAlarms(alarms);
36+
load();
37+
}
38+
39+
if(alarm.timer){
40+
41+
let timerLength=alarm.timer
42+
let buttons={ "15s": 15, "30s":30,"1m":60 ,"2m":120,"5m":360};
43+
let formattedLength = formatMS(timerLength)+"*";
44+
buttons[formattedLength] = Math.round(timerLength/1000);
45+
//different button lengths
46+
E.showPrompt("Choose snooze length", {
47+
title: "Snooze Options",
48+
buttons
49+
}).then(snoozeTime => onSnooze(snoozeTime * 1000));
50+
}else{
51+
E.showPrompt("Choose snooze length", {
52+
title: "Snooze Options",
53+
buttons: { "1m": 1, "2m":2,"5m": 5,"10m":10 }
54+
}).then(snoozeTime => onSnooze(snoozeTime * 60000));
55+
}
56+
}
57+
858
function showAlarm(alarm) {
959
const alarmIndex = alarms.indexOf(alarm);
1060
const settings = require("sched").getSettings();
@@ -27,11 +77,16 @@ function showAlarm(alarm) {
2777

2878
E.showPrompt(message, {
2979
title: alarm.timer ? /*LANG*/"TIMER!" : /*LANG*/"ALARM!",
30-
buttons: { /*LANG*/"Snooze": true, /*LANG*/"Stop": false } // default is sleep so it'll come back in some mins
80+
buttons: { /*LANG*/"Snooze": 1, /*LANG*/"Stop": 2 }, // default is sleep so it'll come back in some mins
81+
buttonsLong:{/*LANG*/"Snooze":3},
3182
}).then(function (sleep) {
3283
buzzCount = 0;
33-
34-
if (sleep) {
84+
//long press triggered
85+
if(sleep==3){
86+
showSnoozeMenu(alarm);
87+
return;
88+
}
89+
if (sleep==1) {
3590
if (alarm.ot === undefined) {
3691
alarm.ot = alarm.t;
3792
}

0 commit comments

Comments
 (0)