Merge branch 'master' of github.com:espruino/BangleApps

pull/563/head
Gordon Williams 2020-09-22 09:08:08 +01:00
commit 80dc05bc3c
4 changed files with 128 additions and 51 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ package-lock.json
*.js.bak
appdates.csv
.vscode
.idea/

View File

@ -1421,7 +1421,7 @@
"name": "Digital Assistant, not EDITH",
"shortName": "DANE",
"icon": "app.png",
"version": "0.07",
"version": "0.10",
"description": "A Watchface inspired by Tony Stark's EDITH",
"tags": "clock",
"type": "clock",

View File

@ -2,4 +2,7 @@
0.04: Added Icon to watchface
0.05: bugfix
0.06: moved and resized icon
0.07: Added Description
0.07: Added Description
0.08: Removed Image, Reduced RAM usage
0.09: Added Unix Time
0.10: Added Counter, Added Battery Display

View File

@ -1,66 +1,81 @@
const font = "6x8";
const timeFontSize = 4;
const unixTimeFontSize = 2;
const dateFontSize = 3;
const smallFontSize = 2;
const yOffset = 23;
const xyCenter = g.getWidth()/2;
const width = g.getWidth();
const height = g.getHeight();
const xyCenter = width/2+4;
const cornerSize = 14;
const cornerOffset = 3;
const borderWidth = 1;
const yposTime = 27+yOffset;
const yposDate = 65+yOffset;
const yposDate = 65+yOffset+12;
const yposCounter = 58+yOffset+35+40;
const mainColor = "#26dafd";
const mainColorDark = "#029dbb";
const mainColorLight = "#8bebfe";
// const mainColorLight = "#8bebfe";
const secondaryColor = "#df9527";
const secondaryColorDark = "#8b5c15";
const secondaryColorLight = "#ecc180";
// const secondaryColorLight = "#ecc180";
const success = "#00ff00";
const successDark = "#000900";
const successLight = "#060f06";
// const successDark = "#000900";
// const successLight = "#060f06";
const alert = "#ff0000";
const alertDark = "#090000";
const alertLight = "#0f0606";
// const alertDark = "#090000";
// const alertLight = "#0f0606";
let count = 100;
// function getImg() {
// return atob("/wA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AAdCABhN/OFM8ABU2P35zkM4U2hkAABwSBCwJ6/OjZx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Img() {
// return {
// width : 120, height : 120, bpp : 8,
// transparent : 254,
// buffer : require("heatshrink").decompress(getImg())
// }
// }
var img = {
width : 120, height : 120, bpp : 8,
transparent : 254,
buffer : require("heatshrink").decompress(atob("/wA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AAdCABhN/OFM8ABU2P35zkM4U2hkAABwSBCwJ6/OjZxBgxyPABAZBPgJ6/OqbnBOg8rAAJyNCBEGhk2PX51PmBhHOhEGmwACPRQXFCoL1DOP51HdIh0IhkwnhcDAAoKBm0wDwYdEDwp5/Oo8MKxjQEABwiEkp5/Oxs2OpBTDOgwjOEyEMPHrJFJwxPCmx0QPRM8PIQpJFQjs8JZLEDJa55EUYMGFpMwPG5ICgzsQUrimCkryKnh40OyYxfPAQxIGQMGPGZ2EIZJ2iPCLxyOwRBMO0Z4/IIp2yPH4/Dhg9JHwJ2nPAg5Mgx3sFgMwgEqHhMMO1B4EeBQ7EO1U8HZSzBni0rHh0AmyzqHPB4FmDwLgC1BHGsMB4J3uWxY/Ed2ivBO1h4DmxAOG00MV2jwYmBBld354DmB3LeEo0Bgzu9eCMGIcYzOm1DoZ3wPAUMeF4yNg8Bnp3zGYM3gEHO5U2eEIhBdxcHg52zO4U9gJ3JPAMMO8U2O5k3odEO+VEPAKxBO5UAnh3tHgM9oh30AAMNO4tWO4s2O79CoUGdxcHn1EotFO+NFO4M3O5R4BgxXBO708dxR3BhB2Co1AO+J4BnCzBO/U4OwdAoIACN8goDAAVAow2Bnx3FAApTBnh3fmx3FljuFO4NGsmzAAWPxOJstlLpGJx4LGBIWJSIgIBCIVBsuPFYYsCsjwCO+ApEO5NlJAJ0BAAllegwRCPAwJC2YVEOIJ/BAAOJT4YoDeAVEhB3roVCdwsrqx3IJgJSDZYNlcoTbGNo53EDop3GBglBoB3KJAhUBmx3mmR3Fn53ILYjlDA4LQCMwYKDO4SCCDYQkEFQILDO40yd5h3nAAkHhx3Bo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gAEGgoAHlZ3bDgQAWlYaCO8QmDH7B3WmAcCGyoXCO9AAZgEMICdCoUMGrh3DPDp3iICR3/d+42BO8J2cO/53/IDU8GykGO/88O+g1ggB2dIIgAdO64AeO/cwmwACGyoZDADU8VqhBPEoIADoQATG7IuUGsBCjHswA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A1"))
}
function drawTopLeftCorner(x,y) {
g.setColor(mainColor);
var x1 = x-cornerOffset;
var y1 = y-cornerOffset;
const x1 = x - cornerOffset;
const y1 = y - cornerOffset;
g.fillRect(x1,y1,x1+cornerSize,y1+cornerSize);
g.setColor("#000000");
g.fillRect(x,y,x+cornerSize-cornerOffset,y+cornerSize-cornerOffset);
}
function drawTopRightCorner(x,y) {
g.setColor(mainColor);
var x1 = x+cornerOffset;
var y1 = y-cornerOffset;
const x1 = x + cornerOffset;
const y1 = y - cornerOffset;
g.fillRect(x1,y1,x1-cornerSize,y1+cornerSize);
g.setColor("#000000");
g.fillRect(x,y,x-cornerSize-cornerOffset,y+cornerSize-cornerOffset);
}
function drawBottomLeftCorner(x,y) {
g.setColor(mainColor);
var x1 = x-cornerOffset;
var y1 = y+cornerOffset;
const x1 = x - cornerOffset;
const y1 = y + cornerOffset;
g.fillRect(x1,y1,x1+cornerSize,y1-cornerSize);
g.setColor("#000000");
g.fillRect(x,y,x+cornerSize-cornerOffset,y-cornerSize+cornerOffset);
}
function drawBottomRightCorner(x,y) {
g.setColor(mainColor);
var x1 = x+cornerOffset;
var y1 = y+cornerOffset;
const x1 = x + cornerOffset;
const y1 = y + cornerOffset;
g.fillRect(x1,y1,x1-cornerSize,y1-cornerSize);
g.setColor("#000000");
g.fillRect(x,y,x-cornerSize+cornerOffset,y-cornerSize+cornerOffset);
@ -85,79 +100,137 @@ function drawTopFrame(x1,y1,x2,y2) {
g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth);
}
function drawBottomFrame(x1,y1,x2,y2) {
drawTopLeftCorner(x1,y1);
drawTopRightCorner(x2,y1);
function drawFrameNoCorners(x1,y1,x2,y2) {
g.setColor(mainColorDark);
g.drawRect(x1,y1,x2,y2);
g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth);
}
// function drawBottomFrame(x1,y1,x2,y2) {
// drawTopLeftCorner(x1,y1);
// drawTopRightCorner(x2,y1);
// g.setColor(mainColorDark);
// g.drawRect(x1,y1,x2,y2);
// g.setColor("#000000");
// g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth);
// }
function getUTCTime(d) {
return d.toUTCString().split(' ')[4].split(':').map(function(d){return Number(d);});
}
// function getUTCTime(d) {
// return d.toUTCString().split(' ')[4].split(':').map(function(d){return Number(d);});
// }
function drawTimeText(d) {
const da = d.toString().split(" ");
// var dutc = getUTCTime(d);
function drawTimeText() {
g.setFontAlign(0, 0);
var d = new Date();
var da = d.toString().split(" ");
var dutc = getUTCTime(d);
var time = da[4].split(":");
var hours = time[0],
const time = da[4].split(":");
const hours = time[0],
minutes = time[1],
seconds = time[2];
g.setColor(mainColor);
g.setFont(font, timeFontSize);
g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true);
const unix = Math.round(d.getTime());
g.setFont(font, unixTimeFontSize);
g.setColor(secondaryColor);
g.drawString(`${unix}`, xyCenter, yposTime +22, true);
g.setFont(font, smallFontSize);
}
function drawDateText() {
g.setFontAlign(0, 0);
var d = new Date();
function drawDateText(d) {
g.setColor(mainColor);
g.setFont(font, dateFontSize);
g.drawString(`${d.getDate()}.${d.getMonth()+1}.${d.getFullYear()}`, xyCenter, yposDate, true);
}
function drawCounterText() {
if(count>999) count = 999;
if(count<0) count = 0;
g.setColor("#000000");
g.fillRect(37,58+yOffset+36,203,58+80+yOffset+34);
g.setFontAlign(0, 0);
g.setColor(alert);
g.setFont(font, 8);
g.drawString(`${count}`, xyCenter, yposCounter, true);
}
function levelColor(l) {
// no icon -> brightest green to indicate charging, even when showing percentage
if (Bangle.isCharging()) return success;
if (l >= 50) return success;
if (l >= 15) return secondaryColorDark;
return alert;
}
function drawBattery() {
const l = E.getBattery(), c = levelColor(l);
const xl = 45+l*(194-46)/100;
g.setColor(c).fillRect(46,58+80+yOffset+37,xl, height-5);
}
function drawClock() {
// main frame
drawFrame(3,10+yOffset,g.getWidth()-3,g.getHeight()-3);
drawFrame(3,10+yOffset,width-3,height-3);
// time frame
drawTopFrame(20,10+yOffset,220,46+yOffset);
drawTopFrame(20,10+yOffset,220,58+yOffset);
// date frame
drawTopFrame(28,46+yOffset,212,46+yOffset+35);
drawTopFrame(28,58+yOffset,212,58+yOffset+35);
// texts
drawTimeText();
drawDateText();
g.drawImage(img,g.getWidth()/2-(img.width/2),g.getHeight()/2);
// counter frame
drawTopFrame(36,58+yOffset+35,204,58+80+yOffset+35);
// battery frame
drawFrameNoCorners(44,58+80+yOffset+35,196, height-3);
updateClock();
// const img = makeImg();
// g.drawImage(img,width/2-(img.width/2),height/2);
}
function updateClock() {
drawTimeText();
drawDateText();
g.setFontAlign(0, 0);
const date = new Date();
drawTimeText(date);
drawDateText(date);
drawCounterText();
drawBattery();
}
Bangle.on('lcdPower', function(on) {
if (on) drawClock();
});
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
drawClock();
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
setWatch(function() {
count+=1;
drawCounterText();
}, BTN1, {repeat:true,edge:"falling"});
setWatch(function() {
count--;
drawCounterText();
}, BTN3, {repeat:true,edge:"falling"});
// refesh every 100 milliseconds
setInterval(updateClock, 100);
setInterval(updateClock, 500);