Merge branch 'master' into master

master
Gordon Williams 2021-01-11 10:57:06 +00:00 committed by GitHub
commit dd398dca24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 300 additions and 11 deletions

View File

@ -2139,12 +2139,12 @@
{ "id": "multiclock",
"name": "Multi Clock",
"icon": "multiclock.png",
"version":"0.07",
"version":"0.08",
"description": "Clock with multiple faces - Big, Analogue, Digital, Text, Time-Date.\n Switch between faces with BTN1 & BTN3",
"readme": "README.md",
"tags": "clock",
"type":"clock",
"allow_emulator":false,
"allow_emulator":true,
"storage": [
{"name":"multiclock.app.js","url":"clock.js"},
{"name":"big.face.js","url":"big.js"},
@ -2483,7 +2483,7 @@
{ "id": "dtlaunch",
"name": "Desktop Launcher",
"icon": "icon.png",
"version":"0.02",
"version":"0.03",
"description": "Desktop style App Launcher with six apps per page - fast access if you have lots of apps installed.",
"readme": "README.md",
"tags": "tool,system,launcher",
@ -2564,5 +2564,19 @@
{"name":"breath.settings.json","url":"settings.json"},
{"name":"breath.img","url":"app-icon.js","evaluate":true}
]
},
{ "id": "lazyclock",
"name": "Lazy Clock",
"icon": "lazyclock.png",
"version":"0.01",
"readme": "README.md",
"description": "Tells the time, roughly",
"tags": "clock",
"type":"clock",
"allow_emulator":true,
"storage": [
{"name":"lazyclock.app.js","url":"lazyclock-app.js"},
{"name":"lazyclock.img","url":"lazyclock-icon.js","evaluate":true}
]
}
]

View File

@ -1,2 +1,4 @@
0.01: Initial version
0.02: Multiple pages
0.03: cycle thru pages

View File

@ -15,7 +15,7 @@ apps.sort((a,b)=>{
var Napps = apps.length;
var Npages = Math.ceil(Napps/6);
var maxPage = Npages-1;
var selected = -1;
var selected = 0;
var oldselected = -1;
var page = 0;
@ -45,10 +45,10 @@ Bangle.on("swipe",(dir)=>{
selected = 0;
oldselected=-1;
if (dir<0){
++page; if (page>maxPage) page=maxPage;
++page; if (page>maxPage) page=0;
drawPage(page);
} else {
--page; if (page<0) page=0;
--page; if (page<0) page=maxPage;
drawPage(page);
}
});

1
apps/lazyclock/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Launch app

26
apps/lazyclock/README.md Normal file
View File

@ -0,0 +1,26 @@
# Lazy clock
This clock gives you the time (roughly).
* 11:05 becomes 'About eleven'
* 15:34 becomes 'Just gone half three'
* 04:12 becomes 'Around quarter past four'
Phrases have a 10 min 'resolution':
* 10:00 - 10:09: past the hour,
* 10:10 - 10:19: about quarter past
* 10:20 - 10:29: nearly half past
* 10:30 - 10:39: just gone half past
* 10:40 - 10:49: about quarter to
* 10:50 - 10:59: almost the hour
Various phrases and combinations for each time chunk are provided.
## Usage
* Press BTN-1 to see the actual time and date
* Press BTN-3 to cycle through lazy descriptions
## Attributions
Icon from https://icons8.com

View File

@ -0,0 +1,236 @@
let secondInterval;
let showRealTime = false;
const utils = {
random: function(items) {
return items[~~(items.length * Math.random())];
},
oneIn: function(chance) {
return Math.floor(Math.random() * Math.floor(chance + 1)) === chance;
},
hours2Word: function(hours, minutes) {
const numbers = [
'twelve',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
'eleven',
'twelve',
];
let adjustedHours = hours;
if (minutes > 40) {
adjustedHours += 1;
}
if (adjustedHours > 12) {
adjustedHours -= 12;
}
return numbers[adjustedHours];
},
print: function(str) {
let fontSize = 4;
const width = g.getWidth();
const height = g.getHeight() - 48;
const lines = str.split(`\n`).length;
let totalHeight;
do {
g.setFont("6x8", fontSize);
totalHeight = g.getFontHeight() * lines;
if (fontSize === 1 || (g.stringWidth(str) < width && totalHeight < height)) {
break;
}
fontSize--;
} while (true);
const x = width / 2;
const y = (g.getHeight() / 2) - (g.getFontHeight() * ((lines - 1) / 2));
g.drawString(str, x, y < 25 ? 24 : y);
}
};
const words = {
approx: ['\'Bout', 'About', 'Around', `Summat\nlike`, 'Near', 'Close to'],
approach: ['Nearly', `Coming\nup to`, 'Approaching', `A touch\nbefore`],
past: [`A shade\nafter`, `A whisker\nafter`, 'Just gone'],
quarter: ['Quarter', `Fifteen\nminutes`],
half: ['Half', 'Half past'],
exactly: ['exactly', 'on the dot', 'o\' clock'],
ish: ['-ish', `\n(ish)`]
};
function switchMode() {
showRealTime = !showRealTime;
refreshTime();
}
function drawRealTime(date) {
const pad = (number) => `0${number}`.substr(-2);
const hours = pad(date.getHours());
const minutes = pad(date.getMinutes());
g.setFontAlign(0,1);
g.setFont("6x8", 8);
g.drawString(`${hours}:${minutes}`, g.getWidth() / 2, g.getHeight() / 2);
g.setFont("6x8", 3);
g.setFontAlign(0, -1);
g.drawString(date.toISOString().split('T')[0], g.getWidth() / 2, g.getHeight() / 2);
}
function drawDumbTime(time) {
const hours = time.getHours();
const minutes = time.getMinutes();
function formatTime(hours, minutes) {
const makeApprox = (str, template) => {
let _template = template || 'approx';
if (utils.oneIn(2)) {
_template = 'approx';
if (utils.oneIn(words.approx.length)) {
const ish = utils.random(words.ish);
return `${str}${ish}`;
}
}
const approx = `${utils.random(words[_template])} `;
return `${approx}\n${str.toLowerCase()}`;
};
const formatters = {
'onTheHour': (hoursAsWord) => {
const exactly = utils.random(words.exactly);
return `${hoursAsWord}\n${exactly}`;
},
'nearTheHour': (hoursAsWord) => {
const template = (minutes < 10) ? 'past' : 'approach';
return makeApprox(hoursAsWord, template);
},
'nearQuarter': (hoursAsWord, minutes) => {
const direction = (minutes > 30) ? 'to' : 'past';
const quarter = utils.random(words.quarter);
const formatted = `${quarter} ${direction}\n${hoursAsWord}`;
return (minutes === 15 || minutes === 45) ? formatted : makeApprox(formatted);
},
'nearHalf': (hoursAsWord, minutes) => {
const half = utils.random(words.half);
const formatted = `${half}\n${hoursAsWord}`;
const template = (minutes > 30) ? 'past' : 'approach';
return (minutes === 30) ? formatted : makeApprox(formatted, template);
},
};
function getFormatter(hours, minutes) {
if (minutes === 0) {
return formatters.onTheHour;
} else if (minutes > 50 || minutes < 10) {
return formatters.nearTheHour;
} else if (minutes > 40|| minutes < 20) {
return formatters.nearQuarter;
} else {
return formatters.nearHalf;
}
}
const hoursAsWord = utils.hours2Word(hours, minutes);
const formatter = getFormatter(hours, minutes);
return formatter(hoursAsWord, minutes);
}
utils.print(formatTime(hours, minutes));
}
function cancelTimeout() {
if (secondInterval) {
clearTimeout(secondInterval);
}
secondInterval = undefined;
}
function refreshTime() {
cancelTimeout();
g.clearRect(0, 24, g.getWidth(), g.getHeight()-24);
g.reset();
g.setFontAlign(0,0);
const time = new Date();
const method = showRealTime ? drawRealTime : drawDumbTime;
method(time);
const secondsTillRefresh = 60 - time.getSeconds();
secondInterval = setTimeout(refreshTime, secondsTillRefresh * 1000);
}
function startClock() {
const secondsToRefresh = refreshTime();
}
function addEvents() {
Bangle.on('lcdPower', (on) => {
cancelTimeout();
if (on) {
startClock();
}
});
setWatch(switchMode, BTN1, {
repeat: true,
edge: "falling"
});
setWatch(Bangle.showLauncher, BTN2, {
repeat: false,
edge: "falling"
});
setWatch(refreshTime, BTN3, {
repeat: true,
edge: "falling"
});
}
function init() {
g.clear();
startClock();
Bangle.loadWidgets();
Bangle.drawWidgets();
addEvents();
}
init();

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwhC/AH4A1iIXXDCwXYF1kBIzEQXlfdC9sNC6oWB6BFVFy5dWIqoXV93u8ArThwXB9wLHhGIAAeAFwwwJCwgABC54uFC5XoHQoXQnBTFCwwkFlwXClAjFFhI7CwYWB8YOFRpYMCkfjFwQPDLpYMHABQwFC6IwETQ4TIGAwXOCQIQDIyIRFGARyRGAQXQRIwXCDoTGGXJAKBeQwA/AH4A6A"))

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -5,6 +5,8 @@
0.05: Add README
0.06: Add txt clock
0.07: Add Time Date clock and fix font sizes
0.08: Add pinned clock face

View File

@ -1,2 +0,0 @@
(function(){return function(){function e(a,d,b,c){a*=k;g.fillPoly([120+Math.sin(a)*d,134-Math.cos(a)*d,120+Math.sin(a+h)*c,134-Math.cos(a+h)*c,120+Math.sin(a)*b,134-Math.cos(a)*b,120+Math.sin(a-h)*c,134-Math.cos(a-h)*c])}function l(){g.setColor(0,0,0);e(360*f.getSeconds()/60,-5,90,3);0===f.getSeconds()&&(e(360*(d.getHours()+d.getMinutes()/60)/12,-16,60,7),e(360*d.getMinutes()/60,-16,86,7),d=new Date);g.setColor(1,1,1);e(360*(d.getHours()+d.getMinutes()/60)/12,-16,60,7);e(360*d.getMinutes()/60,-16,
86,7);g.setColor(0,1,1);f=new Date;e(360*f.getSeconds()/60,-5,90,3);g.setColor(0,0,0);g.fillCircle(120,134,2)}var h=Math.PI/2,k=Math.PI/180,d,f;return{init:function(){f=d=new Date;g.setColor(1,1,1);for(var a=0;60>a;a++){var e=360*a/60,b=e*k,c=120+100*Math.sin(b);b=134-100*Math.cos(b);0==e%90?(g.setColor(0,1,1),g.fillRect(c-6,b-6,c+6,b+6)):0==e%30?(g.setColor(0,1,1),g.fillRect(c-4,b-4,c+4,b+4)):(g.setColor(1,1,1),g.fillRect(c-1,b-1,c+1,b+1))}l()},tick:l}}})();

View File

@ -1,6 +1,8 @@
var FACES = [];
var iface = 0;
require("Storage").list(/\.face\.js$/).forEach(face=>FACES.push(eval(require("Storage").read(face))));
var STOR = require("Storage");
STOR.list(/\.face\.js$/).forEach(face=>FACES.push(eval(require("Storage").read(face))));
var lastface = STOR.readJSON("multiclock.json")||{pinned:0};
var iface = lastface.pinned;
var face = FACES[iface]();
var intervalRefSec;
@ -25,7 +27,14 @@ function setButtons(){
face = FACES[iface]();
startdraw();
}
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
function finish(){
if (lastface.pinned!=iface){
lastface.pinned=iface;
STOR.write("multiclock.json",lastface);
}
Bangle.showLauncher();
}
setWatch(finish, BTN2, {repeat:false,edge:"falling"});
setWatch(newFace.bind(null,1), BTN1, {repeat:true,edge:"rising"});
setWatch(newFace.bind(null,-1), BTN3, {repeat:true,edge:"rising"});
}