mirror of https://github.com/espruino/BangleApps
Adding alarm.vibrate and menu
parent
771950f51b
commit
5c33cad685
|
@ -32,13 +32,17 @@ Alarms are stored in an array in `alarm.json`, and take the form:
|
|||
msg : "Eat chocolate", // message to display
|
||||
last : 0, // last day of the month we alarmed on - so we don't alarm twice in one day!
|
||||
rp : true, // repeat
|
||||
vibrate : "...", // pattern of '.', '-' and ' ' to use for when buzzing out this alarm (defaults to '..' if not set)
|
||||
as : false, // auto snooze
|
||||
timer : 5*60*1000, // OPTIONAL - if set, this is a timer and it's the time in ms
|
||||
js : "load('myapp.js')" // OPTIONAL - a JS command to execute when the alarm activates (*instead* of loading 'alarm.js')
|
||||
// when this code is run, you're responsible for setting alarm.on=false (or removing the alarm)
|
||||
data : { ... } // OPTIONAL - your app can store custom data in here if needed
|
||||
}
|
||||
```
|
||||
|
||||
You app
|
||||
|
||||
The [`alarm` library](https://github.com/espruino/BangleApps/blob/master/apps/alarm/lib.js) contains
|
||||
a few helpful functions for getting/setting alarms, but is intentionally sparse so as not to
|
||||
use too much RAM.
|
||||
|
|
|
@ -58,10 +58,7 @@ function showAlarm(alarm) {
|
|||
load();
|
||||
});
|
||||
function buzz() {
|
||||
if ((require('Storage').readJSON('setting.json',1)||{}).quiet>1) return; // total silence
|
||||
Bangle.buzz(100).then(()=>{
|
||||
setTimeout(()=>{
|
||||
Bangle.buzz(100).then(function() {
|
||||
require("buzz").pattern(alarm.vibrate===undefined?"..":alarm.vibrate).then(function() {
|
||||
if (buzzCount--)
|
||||
setTimeout(buzz, 3000);
|
||||
else if(alarm.as) { // auto-snooze
|
||||
|
@ -69,9 +66,8 @@ function showAlarm(alarm) {
|
|||
setTimeout(buzz, 600000);
|
||||
}
|
||||
});
|
||||
},100);
|
||||
});
|
||||
}
|
||||
if ((require('Storage').readJSON('setting.json',1)||{}).quiet>1) return;
|
||||
buzz();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,8 @@ function editAlarm(alarmIndex, alarm) {
|
|||
rp : true,
|
||||
as : false,
|
||||
dow : 0b1111111,
|
||||
last : 0
|
||||
last : 0,
|
||||
vibrate : ".."
|
||||
}
|
||||
if (!newAlarm) Object.assign(a, alarms[alarmIndex]);
|
||||
if (alarm) Object.assign(a,alarm);
|
||||
|
@ -118,6 +119,7 @@ function editAlarm(alarmIndex, alarm) {
|
|||
value: "SMTWTFS".split("").map((d,n)=>a.dow&(1<<n)?d:".").join(""),
|
||||
onchange: () => editDOW(a.dow, d=>{a.dow=d;editAlarm(alarmIndex,a)})
|
||||
},
|
||||
/*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ),
|
||||
/*LANG*/'Auto snooze': {
|
||||
value: a.as,
|
||||
format: v=>v?"Yes":"No",
|
||||
|
@ -151,7 +153,8 @@ function editTimer(alarmIndex, alarm) {
|
|||
rp : false,
|
||||
as : false,
|
||||
dow : 0b1111111,
|
||||
last : 0
|
||||
last : 0,
|
||||
vibrate : ".."
|
||||
}
|
||||
if (!newAlarm) Object.assign(a, alarms[alarmIndex]);
|
||||
if (alarm) Object.assign(a,alarm);
|
||||
|
@ -172,7 +175,8 @@ function editTimer(alarmIndex, alarm) {
|
|||
value: a.on,
|
||||
format: v=>v?"On":"Off",
|
||||
onchange: v=>a.on=v
|
||||
}
|
||||
},
|
||||
/*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ),
|
||||
};
|
||||
menu[/*LANG*/"Save"] = function() {
|
||||
a.timer = encodeTime(t);
|
||||
|
|
|
@ -15,18 +15,10 @@
|
|||
require('Storage').writeJSON("messages.settings.json", settings);
|
||||
}
|
||||
|
||||
var vibPatterns = [/*LANG*/"Off", ".", "-", "--", "-.-", "---"];
|
||||
var mainmenu = {
|
||||
"" : { "title" : /*LANG*/"Messages" },
|
||||
"< Back" : back,
|
||||
/*LANG*/'Vibrate': {
|
||||
value: Math.max(0,vibPatterns.indexOf(settings().vibrate)),
|
||||
min: 0, max: vibPatterns.length,
|
||||
format: v => vibPatterns[v]||"Off",
|
||||
onchange: v => {
|
||||
updateSetting("vibrate", vibPatterns[v]);
|
||||
}
|
||||
},
|
||||
/*LANG*/'Vibrate': require("buzz_menu").pattern(settings().vibrate, v => updateSetting("vibrate", v) }),
|
||||
/*LANG*/'Repeat': {
|
||||
value: settings().repeat,
|
||||
min: 0, max: 10,
|
||||
|
|
|
@ -32,14 +32,7 @@ draw:function() {
|
|||
Bangle.drawWidgets();
|
||||
},buzz:function() {
|
||||
if ((require('Storage').readJSON('setting.json',1)||{}).quiet) return; // never buzz during Quiet Mode
|
||||
let v = (require('Storage').readJSON("messages.settings.json", true) || {}).vibrate || ".";
|
||||
function b() {
|
||||
var c = v[0];
|
||||
v = v.substr(1);
|
||||
if (c==".") Bangle.buzz().then(()=>setTimeout(b,100));
|
||||
if (c=="-") Bangle.buzz(500).then(()=>setTimeout(b,100));
|
||||
}
|
||||
b();
|
||||
require("buzz").pattern((require('Storage').readJSON("messages.settings.json", true) || {}).vibrate || ".");
|
||||
},touch:function(b,c) {
|
||||
var w=WIDGETS["messages"];
|
||||
if (!w||!w.width||c.x<w.x||c.x>w.x+w.width||c.y<w.y||c.y>w.y+w.iconwidth) return;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
/* Call this with a pattern like '.-.', '.. .' or '..' to buzz that pattern
|
||||
out on the internal vibration motor. use buzz_menu to display a menu
|
||||
where the patterns can be chosen. */
|
||||
exports.pattern = pattern => new Promise(resolve => {
|
||||
function b() {
|
||||
if (pattern=="") resolve();
|
||||
var c = pattern[0];
|
||||
pattern = pattern.substr(1);
|
||||
if (c==".") Bangle.buzz().then(()=>setTimeout(b,100));
|
||||
else if (c=="-") Bangle.buzz(500).then(()=>setTimeout(b,100));
|
||||
else setTimeout(b,100);
|
||||
}
|
||||
b();
|
||||
});
|
|
@ -0,0 +1,13 @@
|
|||
/* Display a menu to select from various vibration patterns for use with buzz.js */
|
||||
|
||||
exports.pattern = function(value, callback) {
|
||||
var vibPatterns = ["", ".", "..", "-", "--", "-.-", "---"];
|
||||
return {
|
||||
value: Math.max(0,vibPatterns.indexOf(value)),
|
||||
min: 0, max: vibPatterns.length,
|
||||
format: v => vibPatterns[v]||/*LANG*/"Off",
|
||||
onchange: v => {
|
||||
callback(vibPatterns[v]);
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue