Added simplestpp, basic clock with fast load and clock_info support

pull/2377/head
Hugh Barney 2022-12-06 23:12:14 +00:00
parent 22b97ac962
commit b29a2c4d0b
8 changed files with 179 additions and 0 deletions

54
apps/simplestpp/README.md Normal file
View File

@ -0,0 +1,54 @@
# Simplest++ Clock
The simplest working clock, with fast load and clock_info
![](screenshot1.png)
![](screenshot2.png)
![](screenshot3.png)
Simplest++ has 1 clock info menu that is displayed as a single line at the bottom of the screen.
This provides a working demo of how to use the clock_info modules.
## Usage
* When the screen is unlocked, tap at the bottom of the csreen on the information text.
It should change color showing it is selected.
* Swipe up or down to cycle through the info screens that can be displayed
when you have finished tap again towards the centre of the screen to unselect.
* Swipe left or right to change the type of info screens displayed (by default
there is only one type of data so this will have no effect)
* Settings are saved automatically and reloaded along with the clock.
## About Clock Info's
* The clock info modules enable all clocks to add the display of information to the clock face.
* The default clock_info module provides a display of battery %, Steps, Heart Rate and Altitude.
* Installing the [Sunrise ClockInfo](https://banglejs.com/apps/?id=clkinfosunrise) adds Sunrise and Sunset times into the list of info's.
## References
* [What is Fast Load and how does it work](http://www.espruino.com/Bangle.js+Fast+Load)
* [Clock Info Tutorial](http://www.espruino.com/Bangle.js+Clock+Info)
* [How to load modules through the IDE](https://github.com/espruino/BangleApps/blob/master/modules/README.md)
## With Thanks
* Gordon for support
* David Peer for his work on BW Clock
Written by: [Hugh Barney](https://github.com/hughbarney) For support
and discussion please post in the [Bangle JS
Forum](http://forum.espruino.com/microcosms/1424/)

108
apps/simplestpp/app.js Normal file
View File

@ -0,0 +1,108 @@
/**
*
* Simplestpp Clock
*
* The entire clock code is contained within the block below this
* supports 'fast load'
*
* To add support for clock_info_supprt we add the code marked at [1] and [2]
*
*/
{
// must be inside our own scope here so that when we are unloaded everything disappears
// we also define functions using 'let fn = function() {..}' for the same reason. function decls are global
let draw = function() {
var date = new Date();
var timeStr = require("locale").time(date,1);
var h = g.getHeight();
var w = g.getWidth();
g.reset();
g.setColor(g.theme.bg);
g.fillRect(Bangle.appRect);
g.setFont('Vector', w/3);
g.setFontAlign(0, 0);
g.setColor(g.theme.fg);
g.drawString(timeStr, w/2, h/2);
clockInfoMenu.redraw(); // clock_info_support
// schedule a draw for the next minute
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = setTimeout(function() {
drawTimeout = undefined;
draw();
}, 60000 - (Date.now() % 60000));
};
/**
* clock_info_support
* this is the callback function that get invoked by clockInfoMenu.redraw();
*
* We will display the image and text on the same line and centre the combined
* length of the image+text
*
*
*/
let clockInfoDraw = (itm, info, options) => {
g.reset().setFont('Vector',24).setBgColor(options.bg).setColor(options.fg);
//use info.text.toString(), steps does not have length defined
var text_w = g.stringWidth(info.text.toString());
// gap between image and text
var gap = 10;
// width of the image and text combined
var w = gap + (info.img ? 24 :0) + text_w;
// different fg color if we tapped on the menu
if (options.focus) g.setColor(options.hl);
// clear the whole info line
g.clearRect(0, options.y -1, g.getWidth(), options.y+24);
// draw the image if we have one
if (info.img) {
// image start
var x = (g.getWidth() / 2) - (w/2);
g.drawImage(info.img, x, options.y);
// draw the text to the side of the image (left/centre alignment)
g.setFontAlign(-1,0).drawString(info.text, x + 23 + gap, options.y+12);
} else {
// text only option, not tested yet
g.setFontAlign(0,0).drawString(info.text, g.getWidth() / 2, options.y+12);
}
};
// clock_info_support
// retrieve all the clock_info modules that are installed
let clockInfoItems = require("clock_info").load();
// clock_info_support
// setup the way we wish to interact with the menu
// the hl property defines the color the of the info when the menu is selected after tapping on it
let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { x:64, y:132, w:50, h:40, draw : clockInfoDraw, bg : g.theme.bg, fg : g.theme.fg, hl : "#0ff"} );
// timeout used to update every minute
var drawTimeout;
g.clear();
// Show launcher when middle button pressed, add updown button handlers
Bangle.setUI({
mode : "clock",
remove : function() {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
// remove info menu
clockInfoMenu.remove();
delete clockInfoMenu;
}
});
// Load widgets
Bangle.loadWidgets();
draw();
setTimeout(Bangle.drawWidgets,0);
} // end of clock

BIN
apps/simplestpp/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 994 B

1
apps/simplestpp/icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEw4UA///E8MBqtVoALHBQIABBQ0FqgDBitQCwwEIFoISEgoxEiodFFAQEGCQoiFEgsBLQwHDgplHD4UUCYwIDBZY6DBYgsCBZQGEAgwLXLwhvFqALmirvDXIQLPI9ibja677MBZZgELwhnHA4sBHgY6DCYatCAAcVAhASGEgoiEAANVAhASCDwUVIIwTBAARlHgIKBMgwAV"))

View File

@ -0,0 +1,16 @@
{
"id": "simplestpp",
"name": "Simplest++ Clock",
"version": "0.01",
"description": "The simplest working clock, with fast load and clock_info, acts as a tutorial piece",
"readme": "README.md",
"icon": "app.png",
"screenshots": [{"url":"screenshot3.png"}],
"type": "clock",
"tags": "clock",
"supports": ["BANGLEJS2"],
"storage": [
{"name":"simplestpp.app.js","url":"app.js"},
{"name":"simplestpp.img","url":"icon.js","evaluate":true}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB