[Scheduler] Export new functions
- newDefaultAlarm - newDefaultTimer - get/setSettingsmaster
parent
810624d1f8
commit
b0a43413c8
|
|
@ -53,21 +53,27 @@ use too much RAM.
|
||||||
It can be used as follows:
|
It can be used as follows:
|
||||||
|
|
||||||
```
|
```
|
||||||
// add/update an existing alarm
|
// Get a new alarm with default values
|
||||||
|
let alarm = require("sched").newDefaultAlarm();
|
||||||
|
|
||||||
|
// Get a new timer with default values
|
||||||
|
let timer = require("sched").newDefaultTimer();
|
||||||
|
|
||||||
|
// Add/update an existing alarm
|
||||||
require("sched").setAlarm("mytimer", {
|
require("sched").setAlarm("mytimer", {
|
||||||
msg : "Wake up",
|
msg : "Wake up",
|
||||||
timer : 10*60*1000, // 10 Minutes
|
timer : 10 * 60 * 1000 // 10 minutes
|
||||||
});
|
});
|
||||||
// Ensure the widget and alarm timer updates to schedule the new alarm properly
|
// Ensure the widget and alarm timer updates to schedule the new alarm properly
|
||||||
require("sched").reload();
|
require("sched").reload();
|
||||||
|
|
||||||
// Get the time to the next alarm for us
|
// Get the time to the next alarm for us
|
||||||
var timeToNext = require("sched").getTimeToAlarm(require("sched").getAlarm("mytimer"));
|
let timeToNext = require("sched").getTimeToAlarm(require("sched").getAlarm("mytimer"));
|
||||||
// timeToNext===undefined if no alarm or alarm disabled
|
// timeToNext === undefined if no alarm or alarm disabled
|
||||||
|
|
||||||
// delete an alarm
|
// Delete an alarm
|
||||||
require("sched").setAlarm("mytimer", undefined);
|
require("sched").setAlarm("mytimer", undefined);
|
||||||
// reload after deleting...
|
// Reload after deleting
|
||||||
require("sched").reload();
|
require("sched").reload();
|
||||||
|
|
||||||
// Or add an alarm that runs your own code - in this case
|
// Or add an alarm that runs your own code - in this case
|
||||||
|
|
@ -76,12 +82,15 @@ require("sched").reload();
|
||||||
require("sched").setAlarm("customrunner", {
|
require("sched").setAlarm("customrunner", {
|
||||||
appid : "myapp",
|
appid : "myapp",
|
||||||
js : "load('setting.app.js')",
|
js : "load('setting.app.js')",
|
||||||
timer : 1*60*1000, // 1 Minute
|
timer : 1 * 60 * 1000 // 1 minute
|
||||||
});
|
});
|
||||||
|
|
||||||
// If you have been specifying `appid` you can also find any alarms that
|
// If you have been specifying `appid` you can also find any alarms that
|
||||||
// your app has created with the following:
|
// your app has created with the following:
|
||||||
require("sched").getAlarms().filter(a=>a.appid=="myapp");
|
require("sched").getAlarms().filter(a => a.appid == "myapp");
|
||||||
|
|
||||||
|
// Get the scheduler settings
|
||||||
|
let settings = require("sched").getSettings();
|
||||||
```
|
```
|
||||||
|
|
||||||
If your app requires alarms, you can specify that the alarms app needs to
|
If your app requires alarms, you can specify that the alarms app needs to
|
||||||
|
|
|
||||||
|
|
@ -52,3 +52,58 @@ exports.reload = function() {
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Factory that creates a new alarm with default values
|
||||||
|
exports.newDefaultAlarm = function () {
|
||||||
|
const settings = exports.getSettings();
|
||||||
|
|
||||||
|
let alarm = {
|
||||||
|
t: 12 * 3600000, // Default to 12:00
|
||||||
|
on: true,
|
||||||
|
rp: false, // repeat not the default
|
||||||
|
as: settings.defaultAutoSnooze || false,
|
||||||
|
dow: 0b1111111,
|
||||||
|
last: 0,
|
||||||
|
vibrate: settings.defaultAlarmPattern,
|
||||||
|
};
|
||||||
|
|
||||||
|
delete settings;
|
||||||
|
|
||||||
|
return alarm;
|
||||||
|
}
|
||||||
|
// Factory that creates a new timer with default values
|
||||||
|
exports.newDefaultTimer = function () {
|
||||||
|
const settings = exports.getSettings();
|
||||||
|
|
||||||
|
let timer = {
|
||||||
|
timer: 5 * 60 * 1000, // 5 minutes
|
||||||
|
on: true,
|
||||||
|
rp: false,
|
||||||
|
as: false,
|
||||||
|
dow: 0b1111111,
|
||||||
|
last: 0,
|
||||||
|
vibrate: settings.defaultTimerPattern
|
||||||
|
}
|
||||||
|
|
||||||
|
delete settings;
|
||||||
|
|
||||||
|
return timer;
|
||||||
|
};
|
||||||
|
// Return the scheduler settings
|
||||||
|
exports.getSettings = function () {
|
||||||
|
return Object.assign(
|
||||||
|
{
|
||||||
|
unlockAtBuzz: false,
|
||||||
|
defaultSnoozeMillis: 600000, // 10 minutes
|
||||||
|
defaultAutoSnooze: false,
|
||||||
|
buzzCount: 10,
|
||||||
|
buzzIntervalMillis: 3000, // 3 seconds
|
||||||
|
defaultAlarmPattern: "..",
|
||||||
|
defaultTimerPattern: ".."
|
||||||
|
},
|
||||||
|
require("Storage").readJSON("sched.settings.json", true) || {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Write the updated settings back to storage
|
||||||
|
exports.setSettings = function(settings) {
|
||||||
|
require("Storage").writeJSON("sched.settings.json", settings);
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue