Simplestpp, removed fast load so that we have the simplest clock with clock_info support
parent
8425f0b50a
commit
a6e2207b4a
|
|
@ -0,0 +1,2 @@
|
||||||
|
0.01: first release
|
||||||
|
0.02: removed fast load, minimalism is useful for narrowing down on issues
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Simplest++ Clock
|
# Simplest++ Clock
|
||||||
|
|
||||||
The simplest working clock, with fast load and clock_info
|
The simplest working clock, with clock_info
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
@ -36,8 +36,6 @@ This provides a working demo of how to use the clock_info modules.
|
||||||
|
|
||||||
## References
|
## 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)
|
* [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)
|
* [How to load modules through the IDE](https://github.com/espruino/BangleApps/blob/master/modules/README.md)
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,6 @@
|
||||||
/**
|
// Simplestpp Clock, see comments 'clock_info_support'
|
||||||
*
|
|
||||||
* 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]
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
{
|
function draw() {
|
||||||
// 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 date = new Date();
|
||||||
var timeStr = require("locale").time(date,1);
|
var timeStr = require("locale").time(date,1);
|
||||||
var h = g.getHeight();
|
var h = g.getHeight();
|
||||||
|
|
@ -27,27 +14,33 @@
|
||||||
g.setFontAlign(0, 0);
|
g.setFontAlign(0, 0);
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
g.drawString(timeStr, w/2, h/2);
|
g.drawString(timeStr, w/2, h/2);
|
||||||
clockInfoMenu.redraw(); // clock_info_support
|
|
||||||
|
|
||||||
// schedule a draw for the next minute
|
clockInfoMenu.redraw(); // clock_info_support
|
||||||
|
queueDraw(); // queue draw in one minute
|
||||||
|
};
|
||||||
|
|
||||||
|
// timeout used to update every minute
|
||||||
|
var drawTimeout;
|
||||||
|
|
||||||
|
// schedule a draw for the next minute
|
||||||
|
function queueDraw() {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = setTimeout(function() {
|
drawTimeout = setTimeout(function() {
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
draw();
|
draw();
|
||||||
}, 60000 - (Date.now() % 60000));
|
}, 60000 - (Date.now() % 60000));
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clock_info_support
|
* clock_info_support
|
||||||
* this is the callback function that get invoked by clockInfoMenu.redraw();
|
* 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
|
* We will display the image and text on the same line and centre the combined
|
||||||
* length of the image+text
|
* length of the image+text
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
let clockInfoDraw = (itm, info, options) => {
|
function clockInfoDraw(itm, info, options)
|
||||||
|
{
|
||||||
g.reset().setFont('Vector',24).setBgColor(options.bg).setColor(options.fg);
|
g.reset().setFont('Vector',24).setBgColor(options.bg).setColor(options.fg);
|
||||||
|
|
||||||
//use info.text.toString(), steps does not have length defined
|
//use info.text.toString(), steps does not have length defined
|
||||||
|
|
@ -74,35 +67,29 @@
|
||||||
g.setFontAlign(0,0).drawString(info.text, g.getWidth() / 2, options.y+12);
|
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
|
* clock_info_support: retrieve all the clock_info modules that are
|
||||||
let clockInfoItems = require("clock_info").load();
|
* installed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
let clockInfoItems = require("clock_info").load();
|
||||||
|
|
||||||
// clock_info_support
|
/**
|
||||||
// setup the way we wish to interact with the menu
|
* 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
|
* the hl property defines the color the of the info when the menu is
|
||||||
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"} );
|
* 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
|
// Clear the screen once, at startup
|
||||||
var drawTimeout;
|
g.clear();
|
||||||
g.clear();
|
|
||||||
|
|
||||||
// Show launcher when middle button pressed, add updown button handlers
|
// Show launcher when middle button pressed
|
||||||
Bangle.setUI({
|
Bangle.setUI("clock");
|
||||||
mode : "clock",
|
// Load widgets
|
||||||
remove : function() {
|
Bangle.loadWidgets();
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
Bangle.drawWidgets();
|
||||||
drawTimeout = undefined;
|
draw();
|
||||||
// remove info menu
|
|
||||||
clockInfoMenu.remove();
|
|
||||||
delete clockInfoMenu;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load widgets
|
|
||||||
Bangle.loadWidgets();
|
|
||||||
draw();
|
|
||||||
setTimeout(Bangle.drawWidgets,0);
|
|
||||||
} // end of clock
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
"id": "simplestpp",
|
"id": "simplestpp",
|
||||||
"name": "Simplest++ Clock",
|
"name": "Simplest++ Clock",
|
||||||
"shortName": "Simplest++",
|
"shortName": "Simplest++",
|
||||||
"version": "0.01",
|
"version": "0.02",
|
||||||
"description": "The simplest working clock, with fast load and clock_info, acts as a tutorial piece",
|
"description": "The simplest working clock, with clock_info, acts as a tutorial piece",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"screenshots": [{"url":"screenshot3.png"}],
|
"screenshots": [{"url":"screenshot3.png"}],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue