From f7efc338f172ccc3a0468ce8ffcacb4a6e44d702 Mon Sep 17 00:00:00 2001 From: Richard de Boer Date: Mon, 16 May 2022 20:21:24 +0200 Subject: [PATCH] ClockFace: add `is12Hour` property, document `paused` --- modules/ClockFace.js | 5 ++++- modules/ClockFace.md | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/ClockFace.js b/modules/ClockFace.js index 9818ae4e3..25e2430bf 100644 --- a/modules/ClockFace.js +++ b/modules/ClockFace.js @@ -32,6 +32,8 @@ function ClockFace(options) { if (dir>0 && options.down) options.down.apply(this); }; if (options.upDown) this._upDown = options.upDown; + + this.is12Hour = !!(require("Storage").readJSON("setting.json", 1) || {})["12hour"]; } ClockFace.prototype.tick = function() { @@ -69,6 +71,7 @@ ClockFace.prototype.start = function() { if (this._upDown) Bangle.setUI("clockupdown", d=>this._upDown.apply(this,[d])); else Bangle.setUI("clock"); delete this._last; + this.paused = false; this.tick(); Bangle.on("lcdPower", on => { @@ -87,7 +90,7 @@ ClockFace.prototype.pause = function() { ClockFace.prototype.resume = function() { if (this._timeout) return; // not paused delete this._last; - delete this.paused; + this.paused = false; if (this._resume) this._resume.apply(this); this.tick(true); }; diff --git a/modules/ClockFace.md b/modules/ClockFace.md index 1da6e6020..e760c3e74 100644 --- a/modules/ClockFace.md +++ b/modules/ClockFace.md @@ -59,6 +59,7 @@ var clock = new ClockFace({ draw: function(time, changed) { // at least draw or update is required // (re)draw entire clockface, time is a Date object // `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 // before draw() is called, so it needs to always redraw the entire clock @@ -107,4 +108,29 @@ var clock = new ClockFace(function(time) { }); 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 +}); + ``` \ No newline at end of file