ClockFace: add `is12Hour` property, document `paused`
parent
0684e378da
commit
f7efc338f1
|
|
@ -32,6 +32,8 @@ function ClockFace(options) {
|
||||||
if (dir>0 && options.down) options.down.apply(this);
|
if (dir>0 && options.down) options.down.apply(this);
|
||||||
};
|
};
|
||||||
if (options.upDown) this._upDown = options.upDown;
|
if (options.upDown) this._upDown = options.upDown;
|
||||||
|
|
||||||
|
this.is12Hour = !!(require("Storage").readJSON("setting.json", 1) || {})["12hour"];
|
||||||
}
|
}
|
||||||
|
|
||||||
ClockFace.prototype.tick = function() {
|
ClockFace.prototype.tick = function() {
|
||||||
|
|
@ -69,6 +71,7 @@ ClockFace.prototype.start = function() {
|
||||||
if (this._upDown) Bangle.setUI("clockupdown", d=>this._upDown.apply(this,[d]));
|
if (this._upDown) Bangle.setUI("clockupdown", d=>this._upDown.apply(this,[d]));
|
||||||
else Bangle.setUI("clock");
|
else Bangle.setUI("clock");
|
||||||
delete this._last;
|
delete this._last;
|
||||||
|
this.paused = false;
|
||||||
this.tick();
|
this.tick();
|
||||||
|
|
||||||
Bangle.on("lcdPower", on => {
|
Bangle.on("lcdPower", on => {
|
||||||
|
|
@ -87,7 +90,7 @@ ClockFace.prototype.pause = function() {
|
||||||
ClockFace.prototype.resume = function() {
|
ClockFace.prototype.resume = function() {
|
||||||
if (this._timeout) return; // not paused
|
if (this._timeout) return; // not paused
|
||||||
delete this._last;
|
delete this._last;
|
||||||
delete this.paused;
|
this.paused = false;
|
||||||
if (this._resume) this._resume.apply(this);
|
if (this._resume) this._resume.apply(this);
|
||||||
this.tick(true);
|
this.tick(true);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ var clock = new ClockFace({
|
||||||
draw: function(time, changed) { // at least draw or update is required
|
draw: function(time, changed) { // at least draw or update is required
|
||||||
// (re)draw entire clockface, time is a Date object
|
// (re)draw entire clockface, time is a Date object
|
||||||
// `changed` is the same format as for update() below, but always all true
|
// `changed` is the same format as for update() below, but always all true
|
||||||
|
// You can use `this.is12Hour` to test if the 'Time Format' setting is set to "12h" or "24h"
|
||||||
},
|
},
|
||||||
// The difference between draw() and update() is that the screen is cleared
|
// The difference between draw() and update() is that the screen is cleared
|
||||||
// before draw() is called, so it needs to always redraw the entire clock
|
// before draw() is called, so it needs to always redraw the entire clock
|
||||||
|
|
@ -108,3 +109,28 @@ var clock = new ClockFace(function(time) {
|
||||||
clock.start();
|
clock.start();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Properties
|
||||||
|
----------
|
||||||
|
The following properties are automatically set on the clock:
|
||||||
|
* `is12Hour`: `true` if the "Time Format" setting is set to "12h", `false` for "24h".
|
||||||
|
* `paused`: `true` while the clock is paused. (You don't need to check this inside your `draw()` code)
|
||||||
|
|
||||||
|
Inside the `draw()`/`update()` function you can access these using `this`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var ClockFace = require("ClockFace");
|
||||||
|
var clock = new ClockFace({
|
||||||
|
draw: function (time) {
|
||||||
|
if (this.is12Hour) // draw 12h time
|
||||||
|
else // use 24h format
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clock.start();
|
||||||
|
|
||||||
|
Bangle.on('step', function(steps) {
|
||||||
|
if (clock.paused === false) // draw step count
|
||||||
|
});
|
||||||
|
|
||||||
|
```
|
||||||
Loading…
Reference in New Issue