mirror of https://github.com/espruino/BangleApps
Merge pull request #2396 from pebl-hank/master
0.31: Tweaking the swipe option; Added mylocation as a dependency.pull/2397/head
commit
cecf8c5177
|
@ -14,4 +14,5 @@
|
||||||
0.28: Reverted changes to implementation of 0.25
|
0.28: Reverted changes to implementation of 0.25
|
||||||
0.29: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps
|
0.29: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps
|
||||||
0.30: BJS2: swipe seems to be working now
|
0.30: BJS2: swipe seems to be working now
|
||||||
0.31: Remove calls to Bangle.loadWidgets as they are not needed and create warnings
|
0.31: Tweaking the swipe option; Added mylocation as a dependency.
|
||||||
|
Remove calls to Bangle.loadWidgets as they are not needed and create warnings
|
|
@ -1,8 +1,16 @@
|
||||||
|
|
||||||
# Hanks World Clock - See the time in four locations
|
# Hanks World Clock - See the time in four locations
|
||||||
|
|
||||||
In addition to the main clock and date in your current location, you can add up to three other locations. Great for travel or remote working.
|
In addition to the main clock and date in your current location, you can add up to three other locations. Great for travel or remote working.
|
||||||
Additionally we show the sunset/sunrise and seconds for the current location and the day name is shown in your locale.
|
Additionally we show the sunset/sunrise and seconds for the current location. The day name is shown in your locale.
|
||||||
If watch is locked, seconds get refreshed every 10 seconds.
|
Also, you can swipe up to show the current time to a friend.
|
||||||
|
|
||||||
|
All this is configurable:
|
||||||
|
|
||||||
|
- Show seconds only when unlocked (saves battery) / always / do not show seconds
|
||||||
|
- Green color on dark mode (on/off)
|
||||||
|
- Show sun info (on/off) (set your location in the mylocation app)
|
||||||
|
- Rotation degree on swipe (off / 90 / 180 / 270)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -10,11 +18,11 @@ If watch is locked, seconds get refreshed every 10 seconds.
|
||||||
|
|
||||||
Location for sun set / rise set with mylocation app.
|
Location for sun set / rise set with mylocation app.
|
||||||
|
|
||||||
Provide names and the UTC offsets for up to three other timezones in the app store. These are stored in a json file on your watch. UTC offsets can be decimal (e.g., 5.5 for India).
|
Provide names and the UTC offsets for up to three other timezones in the App Loader before uploading. These are stored in a json file on your watch. UTC offsets can be decimal (e.g., 5.5 for India).
|
||||||
|
|
||||||
The clock does not handle summer time / daylight saving time changes automatically. If one of your three locations changes its UTC offset, you can simply change the setting in the app store and update. Currently the clock only supports 24 hour time format for the additional time zones.
|
The clock does not handle summer time / daylight saving time changes automatically. If one of your three locations changes its UTC offset, you can simply change the setting in the App Launcher and update. Currently the clock only supports 24 hour time format for the additional time zones.
|
||||||
|
|
||||||
BangleJS2: Swipe up to rotate screen. So you can show the time to a friend real quick.
|
BangleJS2: Swipe up to rotate screen (Target rotation can be set in the settings). Swipe up again to go back to the default rotation. So you can show the time to a friend real quick or temporarily change orientation for sports etc.
|
||||||
|
|
||||||
## Requests
|
## Requests
|
||||||
|
|
||||||
|
@ -24,5 +32,4 @@ Please use [the Espruino Forum](http://forum.espruino.com/microcosms/1424/) if y
|
||||||
|
|
||||||
Created by Hank.
|
Created by Hank.
|
||||||
|
|
||||||
Based on the great work of "World Clock - 4 time zones". Made by [Scott Hale](https://www.github.com/computermacgyver), based upon the [Simple Clock](https://github.com/espruino/BangleApps/tree/master/apps/sclock).
|
Based on the great work of "World Clock - 4 time zones". Made by [Scott Hale](https://www.github.com/computermacgyver)
|
||||||
And Sun Clock [Sun Clock](https://github.com/espruino/BangleApps/tree/master/apps/sunclock)
|
|
||||||
|
|
|
@ -2,18 +2,19 @@
|
||||||
|
|
||||||
// ------- Settings file
|
// ------- Settings file
|
||||||
const SETTINGSFILE = "hworldclock.json";
|
const SETTINGSFILE = "hworldclock.json";
|
||||||
var secondsMode;
|
let secondsMode;
|
||||||
var showSunInfo;
|
let showSunInfo;
|
||||||
var colorWhenDark;
|
let colorWhenDark;
|
||||||
|
let rotationTarget;
|
||||||
// ------- Settings file
|
// ------- Settings file
|
||||||
|
|
||||||
const BANGLEJS2 = process.env.HWVERSION == 2;
|
//const BANGLEJS2 = process.env.HWVERSION == 2;
|
||||||
const big = g.getWidth()>200;
|
const big = g.getWidth()>200;
|
||||||
// Font for primary time and date
|
// Font for primary time and date
|
||||||
const primaryTimeFontSize = big?6:5;
|
const primaryTimeFontSize = big?6:5;
|
||||||
const primaryDateFontSize = big?3:2;
|
const primaryDateFontSize = big?3:2;
|
||||||
require("Font5x9Numeric7Seg").add(Graphics);
|
let font5x9 = require("Font5x9Numeric7Seg").add(Graphics);
|
||||||
require("FontTeletext10x18Ascii").add(Graphics);
|
let font10x18 = require("FontTeletext10x18Ascii").add(Graphics);
|
||||||
|
|
||||||
// Font for single secondary time
|
// Font for single secondary time
|
||||||
const secondaryTimeFontSize = 4;
|
const secondaryTimeFontSize = 4;
|
||||||
|
@ -27,8 +28,6 @@ const xcol2 = g.getWidth() - xcol1;
|
||||||
const font = "6x8";
|
const font = "6x8";
|
||||||
let drag;
|
let drag;
|
||||||
|
|
||||||
/* TODO: we could totally use 'Layout' here and
|
|
||||||
avoid a whole bunch of hard-coded offsets */
|
|
||||||
|
|
||||||
const xyCenter = g.getWidth() / 2;
|
const xyCenter = g.getWidth() / 2;
|
||||||
const xyCenterSeconds = xyCenter + (big ? 85 : 68);
|
const xyCenterSeconds = xyCenter + (big ? 85 : 68);
|
||||||
|
@ -41,22 +40,27 @@ const yposWorld = big ? 170 : 120;
|
||||||
const OFFSET_TIME_ZONE = 0;
|
const OFFSET_TIME_ZONE = 0;
|
||||||
const OFFSET_HOURS = 1;
|
const OFFSET_HOURS = 1;
|
||||||
|
|
||||||
var PosInterval = 0;
|
let PosInterval = 0;
|
||||||
|
|
||||||
var offsets = require("Storage").readJSON("hworldclock.settings.json") || [];
|
let offsets = require("Storage").readJSON("hworldclock.settings.json") || [];
|
||||||
|
|
||||||
//=======Sun
|
//=======Sun
|
||||||
setting = require("Storage").readJSON("setting.json",1);
|
let setting = require("Storage").readJSON("setting.json",1);
|
||||||
E.setTimeZone(setting.timezone); // timezone = 1 for MEZ, = 2 for MESZ
|
E.setTimeZone(setting.timezone); // timezone = 1 for MEZ, = 2 for MESZ
|
||||||
SunCalc = require("suncalc"); // from modules folder
|
//https://raw.githubusercontent.com/pebl-hank/BangleApps/master/modules/suncalc.js
|
||||||
|
let SunCalc = require("suncalc"); // from modules folder
|
||||||
const LOCATION_FILE = "mylocation.json";
|
const LOCATION_FILE = "mylocation.json";
|
||||||
var rise = "read";
|
let rise = "read";
|
||||||
var set = "...";
|
let set = "...";
|
||||||
//var pos = {altitude: 20, azimuth: 135};
|
//var pos = {altitude: 20, azimuth: 135};
|
||||||
//var noonpos = {altitude: 37, azimuth: 180};
|
//var noonpos = {altitude: 37, azimuth: 180};
|
||||||
//=======Sun
|
//=======Sun
|
||||||
|
|
||||||
var ampm = "AM";
|
let ampm = "AM";
|
||||||
|
|
||||||
|
let defaultRotation = setting.rotate || 0;
|
||||||
|
let currentRotation = defaultRotation;
|
||||||
|
|
||||||
|
|
||||||
// TESTING CODE
|
// TESTING CODE
|
||||||
// Used to test offset array values during development.
|
// Used to test offset array values during development.
|
||||||
|
@ -91,30 +95,36 @@ const mockOffsets = {
|
||||||
// END TESTING CODE
|
// END TESTING CODE
|
||||||
|
|
||||||
|
|
||||||
// Load settings
|
// ================ Load settings
|
||||||
function loadMySettings() {
|
// Helper function default setting
|
||||||
// Helper function default setting
|
let def = function(value, def) {
|
||||||
function def (value, def) {return value !== undefined ? value : def;}
|
return value !== undefined ? value : def;
|
||||||
|
|
||||||
var settings = require('Storage').readJSON(SETTINGSFILE, true) || {};
|
|
||||||
secondsMode = def(settings.secondsMode, "when unlocked");
|
|
||||||
showSunInfo = def(settings.showSunInfo, true);
|
|
||||||
colorWhenDark = def(settings.colorWhenDark, "green");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let settings = require('Storage').readJSON(SETTINGSFILE, true) || {};
|
||||||
|
secondsMode = def(settings.secondsMode, "when unlocked");
|
||||||
|
showSunInfo = def(settings.showSunInfo, true);
|
||||||
|
colorWhenDark = def(settings.colorWhenDark, "green");
|
||||||
|
rotationTarget = def(settings.rotationTarget, "90");
|
||||||
|
rotationTarget = parseInt(rotationTarget) || 0;
|
||||||
|
if (rotationTarget == 90) rotationTarget = 1; // very lame, but works for now.
|
||||||
|
if (rotationTarget == 180) rotationTarget = 2;
|
||||||
|
if (rotationTarget == 270) rotationTarget = 3;
|
||||||
|
// ================ Load settings
|
||||||
|
|
||||||
|
|
||||||
// Check settings for what type our clock should be
|
// Check settings for what type our clock should be
|
||||||
var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false;
|
let _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false;
|
||||||
|
|
||||||
// timeout used to update every minute
|
// timeout used to update every minute
|
||||||
var drawTimeout;
|
let drawTimeout;
|
||||||
var drawTimeoutSeconds;
|
let drawTimeoutSeconds;
|
||||||
var secondsTimeout;
|
let secondsTimeout;
|
||||||
|
|
||||||
g.setBgColor(g.theme.bg);
|
g.setBgColor(g.theme.bg);
|
||||||
|
|
||||||
// schedule a draw for the next minute
|
// schedule a draw for the next minute
|
||||||
function queueDraw() {
|
let queueDraw = function() {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = setTimeout(function() {
|
drawTimeout = setTimeout(function() {
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
|
@ -123,7 +133,7 @@ function queueDraw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// schedule a draw for the next second
|
// schedule a draw for the next second
|
||||||
function queueDrawSeconds() {
|
let queueDrawSeconds = function() {
|
||||||
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
||||||
drawTimeoutSeconds = setTimeout(function() {
|
drawTimeoutSeconds = setTimeout(function() {
|
||||||
drawTimeoutSeconds = undefined;
|
drawTimeoutSeconds = undefined;
|
||||||
|
@ -132,16 +142,16 @@ function queueDrawSeconds() {
|
||||||
}, secondsTimeout - (Date.now() % secondsTimeout));
|
}, secondsTimeout - (Date.now() % secondsTimeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
function doublenum(x) {
|
let doublenum = function(x) {
|
||||||
return x < 10 ? "0" + x : "" + x;
|
return x < 10 ? "0" + x : "" + x;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentTimeFromOffset(dt, offset) {
|
let getCurrentTimeFromOffset = function(dt, offset) {
|
||||||
return new Date(dt.getTime() + offset * 60 * 60 * 1000);
|
return new Date(dt.getTime() + offset * 60 * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePos() {
|
let updatePos = function() {
|
||||||
coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":0,"lon":0,"location":"-"}; //{"lat":53.3,"lon":10.1,"location":"Pattensen"};
|
let coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":0,"lon":0,"location":"-"}; //{"lat":53.3,"lon":10.1,"location":"Pattensen"};
|
||||||
if (coord.lat != 0 && coord.lon != 0) {
|
if (coord.lat != 0 && coord.lon != 0) {
|
||||||
//pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon);
|
//pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon);
|
||||||
times = SunCalc.getTimes(Date.now(), coord.lat, coord.lon);
|
times = SunCalc.getTimes(Date.now(), coord.lat, coord.lon);
|
||||||
|
@ -154,8 +164,7 @@ function updatePos() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let drawSeconds = function() {
|
||||||
function drawSeconds() {
|
|
||||||
// get date
|
// get date
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
let da = d.toString().split(" ");
|
let da = d.toString().split(" ");
|
||||||
|
@ -177,16 +186,13 @@ function drawSeconds() {
|
||||||
} else {
|
} else {
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
}
|
}
|
||||||
//console.log("---");
|
|
||||||
//console.log(seconds);
|
|
||||||
if (Bangle.isLocked() && secondsMode != "always") seconds = seconds.slice(0, -1) + ':::'; // we use :: as the font does not have an x
|
if (Bangle.isLocked() && secondsMode != "always") seconds = seconds.slice(0, -1) + ':::'; // we use :: as the font does not have an x
|
||||||
//console.log(seconds);
|
|
||||||
g.drawString(`${seconds}`, xyCenterSeconds, yposTime+14, true);
|
g.drawString(`${seconds}`, xyCenterSeconds, yposTime+14, true);
|
||||||
queueDrawSeconds();
|
queueDrawSeconds();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
let draw = function() {
|
||||||
// get date
|
// get date
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
let da = d.toString().split(" ");
|
let da = d.toString().split(" ");
|
||||||
|
@ -211,7 +217,6 @@ function draw() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//g.setFont(font, primaryTimeFontSize);
|
|
||||||
g.setFont("5x9Numeric7Seg",primaryTimeFontSize);
|
g.setFont("5x9Numeric7Seg",primaryTimeFontSize);
|
||||||
if (g.theme.dark) {
|
if (g.theme.dark) {
|
||||||
if (colorWhenDark == "green") {
|
if (colorWhenDark == "green") {
|
||||||
|
@ -293,24 +298,10 @@ function draw() {
|
||||||
if (secondsMode != "none") queueDrawSeconds();
|
if (secondsMode != "none") queueDrawSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean app screen
|
|
||||||
g.clear();
|
|
||||||
|
|
||||||
// Init the settings of the app
|
|
||||||
loadMySettings();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// draw immediately at first, queue update
|
|
||||||
draw();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if (BANGLEJS2) {
|
//if (BANGLEJS2) {
|
||||||
//Bangle.on("drag", e => {
|
|
||||||
let onDrag = e => {
|
let onDrag = e => {
|
||||||
if (!drag) { // start dragging
|
if (!drag) { // start dragging
|
||||||
drag = {x: e.x, y: e.y};
|
drag = {x: e.x, y: e.y};
|
||||||
|
@ -327,11 +318,19 @@ draw();
|
||||||
} else if (Math.abs(dy)>Math.abs(dx)+10) {
|
} else if (Math.abs(dy)>Math.abs(dx)+10) {
|
||||||
// vertical
|
// vertical
|
||||||
if (dx < dy) { //down
|
if (dx < dy) { //down
|
||||||
g.clear().setRotation(0);
|
//g.clear().setRotation(defaultRotation);
|
||||||
draw();
|
//currentRotation = defaultRotation;
|
||||||
Bangle.drawWidgets();
|
//draw();
|
||||||
|
//Bangle.drawWidgets();
|
||||||
} else {
|
} else {
|
||||||
g.clear().setRotation(2);
|
if (currentRotation == rotationTarget) {
|
||||||
|
g.clear().setRotation(defaultRotation);
|
||||||
|
currentRotation = defaultRotation;
|
||||||
|
} else {
|
||||||
|
g.clear().setRotation(rotationTarget);
|
||||||
|
currentRotation = rotationTarget;
|
||||||
|
}
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
}
|
}
|
||||||
|
@ -344,13 +343,12 @@ draw();
|
||||||
}
|
}
|
||||||
}; //);
|
}; //);
|
||||||
Bangle.on("drag", onDrag);
|
Bangle.on("drag", onDrag);
|
||||||
//} else {
|
//} <-- BJS2 only } else {
|
||||||
//setWatch(xxx, BTN1, { repeat: true, debounce:50 }); // maybe adding this later
|
//setWatch(xxx, BTN1, { repeat: true, debounce:50 }); // maybe adding this later
|
||||||
//setWatch(xxx, BTN3, { repeat: true, debounce:50 });
|
//setWatch(xxx, BTN3, { repeat: true, debounce:50 });
|
||||||
//setWatch(xxx, BTN4, { repeat: true, debounce:50 });
|
//setWatch(xxx, BTN4, { repeat: true, debounce:50 });
|
||||||
//setWatch(xxx, BTN5, { repeat: true, debounce:50 });
|
//setWatch(xxx, BTN5, { repeat: true, debounce:50 });
|
||||||
// }
|
// }
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -390,7 +388,6 @@ if (!Bangle.isLocked()) { // Initial state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Bangle.on('lock',on=>{
|
|
||||||
let onLock = on => {
|
let onLock = on => {
|
||||||
if (!on) { // UNlocked
|
if (!on) { // UNlocked
|
||||||
if (showSunInfo) {
|
if (showSunInfo) {
|
||||||
|
@ -430,11 +427,13 @@ let onLock = on => {
|
||||||
};
|
};
|
||||||
Bangle.on('lock', onLock);
|
Bangle.on('lock', onLock);
|
||||||
|
|
||||||
|
|
||||||
// Show launcher when middle button pressed
|
// Show launcher when middle button pressed
|
||||||
Bangle.setUI({
|
Bangle.setUI({
|
||||||
mode : "custom",clock:true,
|
mode : "custom",clock:true,
|
||||||
remove : function() {
|
remove : function() {
|
||||||
// Called to unload all of the clock app
|
// Called to unload all of the clock app
|
||||||
|
g.setRotation(defaultRotation); // bring back default rotation
|
||||||
if (typeof PosInterval === "undefined") {
|
if (typeof PosInterval === "undefined") {
|
||||||
console.log("PosInterval is undefined");
|
console.log("PosInterval is undefined");
|
||||||
} else {
|
} else {
|
||||||
|
@ -445,9 +444,15 @@ Bangle.setUI({
|
||||||
drawTimeoutSeconds = undefined;
|
drawTimeoutSeconds = undefined;
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
if (BANGLEJS2) Bangle.removeListener("drag",onDrag);
|
//if (BANGLEJS2)
|
||||||
|
Bangle.removeListener("drag",onDrag);
|
||||||
Bangle.removeListener("onLock",onLock);
|
Bangle.removeListener("onLock",onLock);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
|
||||||
|
g.clear().setRotation(defaultRotation); // clean app screen and make sure the default rotation is set
|
||||||
|
draw(); // draw immediately at first, queue update
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"custom": "custom.html",
|
"custom": "custom.html",
|
||||||
|
"dependencies": {"mylocation":"app"},
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"hworldclock.app.js","url":"app.js"},
|
{"name":"hworldclock.app.js","url":"app.js"},
|
||||||
{"name":"hworldclock.img","url":"hworldclock-icon.js","evaluate":true},
|
{"name":"hworldclock.img","url":"hworldclock-icon.js","evaluate":true},
|
||||||
|
@ -19,6 +20,6 @@
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
{"name":"hworldclock.settings.json"},
|
{"name":"hworldclock.settings.json"},
|
||||||
{"name":"hworldclock.json"}
|
{"name":"hworldclock.json"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
settings.showSunInfo = v;
|
settings.showSunInfo = v;
|
||||||
writeSettings();
|
writeSettings();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"Rotation": stringInSettings("rotationTarget", ["off", "90", "180", "270"]),
|
||||||
};
|
};
|
||||||
|
|
||||||
E.showMenu(mainmenu);
|
E.showMenu(mainmenu);
|
||||||
|
|
Loading…
Reference in New Issue