mirror of https://github.com/espruino/BangleApps
Resolve conflict in merge
commit
960efeff8e
|
@ -1,3 +1,8 @@
|
|||
0.01: Initial version
|
||||
0.02: Add battery level
|
||||
<<<<<<< HEAD
|
||||
0.03: fix battery level displaying
|
||||
=======
|
||||
0.03: Fix battery display when full
|
||||
0.04: Add support for settings
|
||||
>>>>>>> feature/introduce_settings
|
||||
|
|
|
@ -3,3 +3,21 @@
|
|||
Just a simple watch face for the Banglejs2.
|
||||
|
||||
It shows battery level in the upper left corner, date information in the upper right, and time information in the bottom.
|
||||
|
||||

|
||||
|
||||
## Settings
|
||||
|
||||
**Analog Clock:**
|
||||
|
||||
**Human Readable Date:** When the setting is on, the date is shown in a more human-friendly format (e.g. "Oct 2"), otherwise the date is shown in a standard format (e.g. "02/10"). Default is off.
|
||||
|
||||
**Show Week Info:** When the setting is on, the weekday and week number are shown in the upper right box. When the setting is off, the full year is shown instead. Default is off.
|
||||
|
||||
**Vector Font:** When the setting is on, the app uses Espruino's vector font, otherwise it uses the default font. Default is off.
|
||||
|
||||
## Using the app
|
||||
|
||||
Monogram Watch Face can be selected as the default clock or it can be run manually from the launcher. Its settings can be accessed and changed via the relevant menu.
|
||||
|
||||
Tapping on the "Alerts" area will replace the current time display with the time of the most immediate alert.
|
||||
|
|
|
@ -1,48 +1,81 @@
|
|||
const SETTINGSFILE = "smclock.json";
|
||||
const background = {
|
||||
width : 176, height : 176, bpp : 3,
|
||||
transparent : 1,
|
||||
buffer : require("heatshrink").decompress(atob("/4A/AH4ACUb8H9MkyVJAThB/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INP/AH4A/AAX8Yz4Afn5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INI="))
|
||||
width: 176,
|
||||
height: 176,
|
||||
bpp: 3,
|
||||
transparent: 1,
|
||||
buffer: require("heatshrink").decompress(
|
||||
atob(
|
||||
"/4A/AH4ACUb8H9MkyVJAThB/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INP/AH4A/AAX8Yz4Afn5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/IP5B/INI="
|
||||
)
|
||||
),
|
||||
};
|
||||
const monthName = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
|
||||
const weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
|
||||
const weekday = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
|
||||
var level = -1;
|
||||
// dynamic variables
|
||||
var batLevel = -1;
|
||||
var batColor = [0, 0, 0];
|
||||
|
||||
function ISO8601_week_no(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
|
||||
// settings variables
|
||||
var dateFormat;
|
||||
var drawInterval;
|
||||
var pollInterval;
|
||||
var showAnalogFace;
|
||||
var showWeekInfo;
|
||||
var useVectorFont;
|
||||
|
||||
// load settings
|
||||
function loadSettings() {
|
||||
// Helper function default setting
|
||||
function def(value, def) {return value !== undefined ? value : def;}
|
||||
var settings = require("Storage").readJSON(SETTINGSFILE, true) || {};
|
||||
|
||||
dateFormat = def(settings.dateFormat, "Short");
|
||||
drawInterval = def(settings.drawInterval, 10);
|
||||
pollInterval = def(settings.pollInterval, 60);
|
||||
showAnalogFace = def(settings.showAnalogFace, false);
|
||||
showWeekInfo = def(settings.showWeekInfo, false);
|
||||
useVectorFont = def(settings.useVectorFont, false);
|
||||
}
|
||||
|
||||
// copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
|
||||
function ISO8601_week_no(date) {
|
||||
var tdt = new Date(date.valueOf());
|
||||
var dayn = (date.getDay() + 6) % 7;
|
||||
tdt.setDate(tdt.getDate() - dayn + 3);
|
||||
var firstThursday = tdt.valueOf();
|
||||
tdt.setMonth(0, 1);
|
||||
if (tdt.getDay() !== 4) {
|
||||
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
|
||||
tdt.setMonth(0, 1 + ((4 - tdt.getDay() + 7) % 7));
|
||||
}
|
||||
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
|
||||
}
|
||||
|
||||
function d02(value) {
|
||||
return ('0' + value).substr(-2);
|
||||
return ("0" + value).substr(-2);
|
||||
}
|
||||
|
||||
function pollBattery() {
|
||||
level = E.getBattery();
|
||||
return level;
|
||||
batLevel = E.getBattery();
|
||||
}
|
||||
|
||||
function getBatteryColor(level) {
|
||||
var color;
|
||||
if (level < 0) {
|
||||
level = pollBattery();
|
||||
pollBattery();
|
||||
level = batLevel;
|
||||
}
|
||||
if(level>80) {
|
||||
color = [0,0,1];
|
||||
} else if(level>60) {
|
||||
color = [0,1,1];
|
||||
} else if(level>40) {
|
||||
color = [0,1,0];
|
||||
} else if(level>20) {
|
||||
color = [1,1,0];
|
||||
if (level > 80) {
|
||||
color = [0, 0, 1];
|
||||
} else if (level > 60) {
|
||||
color = [0, 1, 1];
|
||||
} else if (level > 40) {
|
||||
color = [0, 1, 0];
|
||||
} else if (level > 20) {
|
||||
color = [1, 1, 0];
|
||||
} else {
|
||||
color = [1,0,0];
|
||||
color = [1, 0, 0];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
@ -50,57 +83,119 @@ function getBatteryColor(level) {
|
|||
function draw() {
|
||||
g.drawImage(background);
|
||||
|
||||
<<<<<<< HEAD
|
||||
const color = getBatteryColor();
|
||||
const bat = E.getBattery() + "%";
|
||||
=======
|
||||
const color = getBatteryColor(batLevel);
|
||||
var bat = "";
|
||||
>>>>>>> feature/introduce_settings
|
||||
const d = new Date();
|
||||
const day = d.getDate();
|
||||
const month = (d.getMonth() + 1);
|
||||
const month = d.getMonth() + 1;
|
||||
const week = d02(ISO8601_week_no(d));
|
||||
const date1 = d02(day) + "/" + d02(month);
|
||||
const date2 = weekday[d.getDay()] + " " + d02(week);
|
||||
const date1 = "";
|
||||
const date2 = "";
|
||||
const h = d.getHours();
|
||||
const m = d.getMinutes();
|
||||
const time = d02(h) + ":" + d02(m);
|
||||
|
||||
if (E.getBattery() < 100) {
|
||||
bat = d02(E.getBattery()) + "%";
|
||||
} else {
|
||||
bat = E.getBattery() + "%";
|
||||
}
|
||||
|
||||
g.reset();
|
||||
|
||||
g.setColor(0, 0, 0);
|
||||
g.setFont("Vector", 20);
|
||||
g.drawString(date1, 105, 20, false);
|
||||
g.setFont("Vector", 16);
|
||||
g.drawString(date2, 105, 55, false);
|
||||
|
||||
g.setColor(1, 1, 1);
|
||||
g.setFont("Vector", 60);
|
||||
g.drawString(time, 10, 108, false);
|
||||
|
||||
// draw battery info
|
||||
g.setColor(1, 1, 1);
|
||||
if (useVectorFont == true) {
|
||||
g.setFont("Vector", 16);
|
||||
g.drawString("Bat:", 12, 22, false);
|
||||
} else {
|
||||
g.setFont("4x6", 2);
|
||||
g.drawString("Bat:", 10, 22, false);
|
||||
}
|
||||
g.setColor(color[0], color[1], color[2]);
|
||||
<<<<<<< HEAD
|
||||
g.drawString(bat, 46, 22, false);
|
||||
=======
|
||||
if (batLevel < 100) {
|
||||
g.drawString(bat, 52, 22, false);
|
||||
} else {
|
||||
g.drawString(bat, 46, 22, false);
|
||||
}
|
||||
|
||||
// draw date info
|
||||
g.setColor(0, 0, 0);
|
||||
if (useVectorFont == true) {
|
||||
g.setFont("Vector", 20);
|
||||
} else {
|
||||
g.setFont("6x8", 2);
|
||||
}
|
||||
if (dateFormat == "Short") {
|
||||
date1 = d02(day) + "/" + d02(month);
|
||||
g.drawString(date1, 105, 20, false);
|
||||
} else {
|
||||
date1 = monthName[month - 1] + d02(day);
|
||||
g.drawString(date1, 104, 20, false);
|
||||
}
|
||||
|
||||
// draw week info
|
||||
if (showWeekInfo == true) {
|
||||
date2 = weekday[d.getDay()] + " " + d02(week)
|
||||
if (useVectorFont == true) {
|
||||
g.setFont("Vector", 18);
|
||||
} else {
|
||||
g.setFont("6x8", 2);
|
||||
}
|
||||
g.drawString(date2, 105, 55, false);
|
||||
} else {
|
||||
date2 = d.getFullYear();
|
||||
if (useVectorFont == true) {
|
||||
g.setFont("Vector", 22);
|
||||
g.drawString(date2, 105, 55, false);
|
||||
} else {
|
||||
g.setFont("4x6", 3);
|
||||
g.drawString(date2, 108, 55, false);
|
||||
}
|
||||
}
|
||||
|
||||
// draw time
|
||||
g.setColor(1, 1, 1);
|
||||
if (useVectorFont == true) {
|
||||
g.setFont("Vector", 60);
|
||||
g.drawString(time, 10, 108, false);
|
||||
} else {
|
||||
g.setFont("6x8", 5);
|
||||
g.drawString(time, 14, 112, false);
|
||||
}
|
||||
>>>>>>> feature/introduce_settings
|
||||
}
|
||||
|
||||
loadSettings();
|
||||
|
||||
g.clear();
|
||||
|
||||
pollBattery();
|
||||
draw();
|
||||
|
||||
var batInterval = setInterval(pollBattery, 60000);
|
||||
var drawInterval = setInterval(draw, 10000);
|
||||
var batInterval = setInterval(pollBattery, pollInterval * 1000);
|
||||
var actualDrawInterval = setInterval(draw, drawInterval * 1000);
|
||||
|
||||
// Stop updates when LCD is off, restart when on
|
||||
Bangle.on('lcdPower',on=>{
|
||||
Bangle.on("lcdPower", (on) => {
|
||||
if (batInterval) clearInterval(batInterval);
|
||||
batInterval = undefined;
|
||||
if (drawInterval) clearInterval(drawInterval);
|
||||
drawInterval = undefined;
|
||||
if (actualDrawInterval) clearInterval(actualDrawInterval);
|
||||
actualDrawInterval = undefined;
|
||||
if (on) {
|
||||
batInterval = setInterval(pollBattery, 60000);
|
||||
drawInterval = setInterval(draw, 10000);
|
||||
batInterval = setInterval(pollBattery, pollInterval * 1000);
|
||||
actualDrawInterval = setInterval(draw, drawInterval * 1000);
|
||||
|
||||
pollBattery();
|
||||
draw(); // draw immediately
|
||||
draw();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
<<<<<<< HEAD
|
||||
"id":"smclock",
|
||||
"name":"Monogram Watch Face",
|
||||
"shortName":"MonoClock",
|
||||
|
@ -9,13 +10,24 @@
|
|||
"screenshots": [{"url":"screenshot.png"}],
|
||||
"version":"0.02",
|
||||
>>>>>>> 29432bb9 (Add screenshot)
|
||||
=======
|
||||
"id": "smclock",
|
||||
"name": "Monogram Watch Face",
|
||||
"shortName": "MonoClock",
|
||||
"icon": "app.png",
|
||||
"screenshots": [{ "url": "screenshot.png" }],
|
||||
"version": "0.04",
|
||||
>>>>>>> feature/introduce_settings
|
||||
"description": "A simple watchface based on my stylised monogram.",
|
||||
"tags":"clock",
|
||||
"readme":"README.md",
|
||||
"supports" : ["BANGLEJS2"],
|
||||
"type": "clock",
|
||||
"tags": "clock",
|
||||
"readme": "README.md",
|
||||
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||
"allow_emulator": true,
|
||||
"storage": [
|
||||
{"name":"smclock.app.js","url":"app.js"},
|
||||
{"name":"smclock.img","url":"app-icon.js","evaluate":true}
|
||||
]
|
||||
{ "name": "smclock.app.js", "url": "app.js" },
|
||||
{ "name": "smclock.settings.js", "url": "settings.js" },
|
||||
{ "name": "smclock.img", "url": "app-icon.js", "evaluate": true }
|
||||
],
|
||||
"data": [{ "name": "smclock.json" }]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
// settings menu for Monogram Watch Face
|
||||
// Anton Clock settings were used as template
|
||||
// helper functions taken from Anton Clock
|
||||
|
||||
(function (back) {
|
||||
var FILE = "smclock.json";
|
||||
// load settings from the file
|
||||
// assign default values if it doesn't exist
|
||||
var settings = Object.assign({
|
||||
dateFormat: "Short",
|
||||
drawInterval: 10,
|
||||
pollInterval: 60,
|
||||
showAnalogFace: false,
|
||||
showWeekInfo: false,
|
||||
useVectorFont: false,
|
||||
}, require("Storage").readJSON(FILE, true) || {});
|
||||
|
||||
// write the new settings to the file
|
||||
function writeSettings() {require("Storage").writeJSON(FILE, settings);}
|
||||
|
||||
// helper method which uses int-based menu item for set of string values
|
||||
function stringItems(startvalue, writer, values) {
|
||||
return {
|
||||
value: startvalue === undefined ? 0 : values.indexOf(startvalue),
|
||||
format: v => values[v],
|
||||
min: 0,
|
||||
max: values.length - 1,
|
||||
wrap: true,
|
||||
step: 1,
|
||||
onchange: v => {
|
||||
writer(values[v]);
|
||||
writeSettings();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// helper method which breaks string set settings down to local settings object
|
||||
function stringInSettings(name, values) {
|
||||
return stringItems(settings[name], (v) => (settings[name] = v), values);
|
||||
}
|
||||
|
||||
// settings menu
|
||||
var mainmenu = {
|
||||
"": {title: "Monogram Clock",},
|
||||
"< Back": () => back(),
|
||||
"Analog Face": {
|
||||
value:
|
||||
settings.showAnalogFace !== undefined ? settings.showAnalogFace : false,
|
||||
format: v => v ? "On" : "Off",
|
||||
onchange: v => {
|
||||
settings.showAnalogFace = v;
|
||||
writeSettings();
|
||||
},
|
||||
},
|
||||
Date: stringInSettings("dateFormat", ["Long", "Short"]),
|
||||
"Draw Interval": {
|
||||
value: settings.drawInterval,
|
||||
onchange: v => {
|
||||
settings.drawInterval = v;
|
||||
writeSettings();
|
||||
},
|
||||
},
|
||||
"Poll Interval": {
|
||||
value: settings.pollInterval,
|
||||
onchange: v => {
|
||||
settings.pollInterval = v;
|
||||
writeSettings();
|
||||
},
|
||||
},
|
||||
"Week Info": {
|
||||
value:
|
||||
settings.showWeekInfo !== undefined ? settings.showWeekInfo : false,
|
||||
format: v => v ? "On" : "Off",
|
||||
onchange: v => {
|
||||
settings.showWeekInfo = v;
|
||||
writeSettings();
|
||||
},
|
||||
},
|
||||
"Vector Font": {
|
||||
value:
|
||||
settings.useVectorFont !== undefined ? settings.useVectorFont : false,
|
||||
format: v => v ? "On" : "Off",
|
||||
onchange: v => {
|
||||
settings.useVectorFont = v;
|
||||
writeSettings();
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Actually display the menu
|
||||
E.showMenu(mainmenu);
|
||||
});
|
||||
|
||||
// end of file
|
Loading…
Reference in New Issue