2020-12-09 13:19:57 +00:00
|
|
|
var d = require("https://raw.githubusercontent.com/OmegaVoid/EspruinoDocs/master/modules/dane_arwes.js");
|
2020-12-08 17:53:24 +00:00
|
|
|
var Arwes = d.default();
|
|
|
|
|
|
|
|
|
2020-12-03 21:03:56 +00:00
|
|
|
const font = "6x8";
|
|
|
|
const timeFontSize = 4;
|
|
|
|
const unixTimeFontSize = 2;
|
|
|
|
const dateFontSize = 3;
|
2020-04-15 12:00:01 +00:00
|
|
|
const smallFontSize = 2;
|
2020-12-03 21:03:56 +00:00
|
|
|
const yOffset = 23;
|
2020-09-21 17:38:07 +00:00
|
|
|
const width = g.getWidth();
|
|
|
|
const height = g.getHeight();
|
2020-12-03 21:03:56 +00:00
|
|
|
const xyCenter = width / 2 + 4;
|
|
|
|
const yposTime = 27 + yOffset;
|
|
|
|
const yposDate = 65 + yOffset + 12;
|
|
|
|
const yposCounter = 58 + yOffset + 35 + 40;
|
|
|
|
|
2020-09-21 21:21:41 +00:00
|
|
|
let count = 100;
|
2020-04-15 12:00:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-21 17:38:07 +00:00
|
|
|
function drawTimeText(d) {
|
|
|
|
const da = d.toString().split(" ");
|
|
|
|
// var dutc = getUTCTime(d);
|
2020-04-15 12:00:01 +00:00
|
|
|
|
2020-09-21 17:38:07 +00:00
|
|
|
const time = da[4].split(":");
|
|
|
|
const hours = time[0],
|
2020-12-03 21:03:56 +00:00
|
|
|
minutes = time[1],
|
|
|
|
seconds = time[2];
|
2020-12-08 17:53:24 +00:00
|
|
|
g.setColor(Arwes.C.color.primary.base);
|
2020-04-15 12:00:01 +00:00
|
|
|
g.setFont(font, timeFontSize);
|
|
|
|
g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true);
|
2020-09-21 20:25:33 +00:00
|
|
|
const unix = Math.round(d.getTime());
|
|
|
|
|
|
|
|
g.setFont(font, unixTimeFontSize);
|
2020-12-08 17:53:24 +00:00
|
|
|
g.setColor(Arwes.C.color.secondary.base);
|
2020-12-03 21:03:56 +00:00
|
|
|
g.drawString(`${unix}`, xyCenter, yposTime + 22, true);
|
2020-04-15 12:00:01 +00:00
|
|
|
g.setFont(font, smallFontSize);
|
|
|
|
}
|
2020-12-03 21:03:56 +00:00
|
|
|
|
2020-09-21 17:38:07 +00:00
|
|
|
function drawDateText(d) {
|
2020-12-08 17:53:24 +00:00
|
|
|
g.setColor(Arwes.C.color.primary.base);
|
2020-04-15 12:00:01 +00:00
|
|
|
g.setFont(font, dateFontSize);
|
2020-12-03 21:03:56 +00:00
|
|
|
g.drawString(`${d.getDate()}.${d.getMonth() + 1}.${d.getFullYear()}`, xyCenter, yposDate, true);
|
2020-04-15 12:00:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 21:21:41 +00:00
|
|
|
function drawCounterText() {
|
2020-12-03 21:03:56 +00:00
|
|
|
if (count > 255) count = 255;
|
|
|
|
if (count < 0) count = 0;
|
2020-09-21 21:21:41 +00:00
|
|
|
g.setColor("#000000");
|
2020-12-03 21:03:56 +00:00
|
|
|
g.fillRect(37, 58 + yOffset + 36, 203, 58 + 80 + yOffset + 34);
|
2020-09-21 21:21:41 +00:00
|
|
|
g.setFontAlign(0, 0);
|
2020-12-08 17:53:24 +00:00
|
|
|
g.setColor(Arwes.C.color.alert.base);
|
2020-09-21 21:21:41 +00:00
|
|
|
g.setFont(font, 8);
|
|
|
|
g.drawString(`${count}`, xyCenter, yposCounter, true);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function levelColor(l) {
|
|
|
|
// no icon -> brightest green to indicate charging, even when showing percentage
|
2020-12-08 17:53:24 +00:00
|
|
|
if (Bangle.isCharging()) return Arwes.C.color.success.base;
|
|
|
|
if (l >= 50) return Arwes.C.color.success.base;
|
|
|
|
if (l >= 15) return Arwes.C.color.secondary.dark;
|
|
|
|
return Arwes.C.color.alert.base;
|
2020-09-21 21:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawBattery() {
|
|
|
|
const l = E.getBattery(), c = levelColor(l);
|
2020-12-03 21:03:56 +00:00
|
|
|
count = l;
|
|
|
|
const xl = 45 + l * (194 - 46) / 100;
|
2020-12-09 13:19:57 +00:00
|
|
|
g.clearRect(46, 58 + 80 + yOffset + 37, 193, height - 5);
|
2020-12-03 21:03:56 +00:00
|
|
|
g.setColor(c).fillRect(46, 58 + 80 + yOffset + 37, xl, height - 5);
|
2020-09-21 21:21:41 +00:00
|
|
|
}
|
2020-04-15 12:00:01 +00:00
|
|
|
|
2020-12-09 13:24:02 +00:00
|
|
|
function updateCounter() {
|
|
|
|
drawBattery();
|
|
|
|
drawCounterText();
|
|
|
|
}
|
2020-04-15 12:00:01 +00:00
|
|
|
|
|
|
|
function drawClock() {
|
|
|
|
// main frame
|
2020-12-08 17:53:24 +00:00
|
|
|
Arwes.drawFrame(3, 10 + yOffset, width - 3, height - 3);
|
2020-04-15 12:00:01 +00:00
|
|
|
// time frame
|
2020-12-08 17:53:24 +00:00
|
|
|
Arwes.drawFrameBottomCorners(20, 10 + yOffset, 220, 58 + yOffset);
|
2020-04-15 12:00:01 +00:00
|
|
|
// date frame
|
2020-12-08 17:53:24 +00:00
|
|
|
Arwes.drawFrameBottomCorners(28, 58 + yOffset, 212, 58 + yOffset + 35);
|
2020-09-21 21:21:41 +00:00
|
|
|
|
|
|
|
// counter frame
|
2020-12-08 17:53:24 +00:00
|
|
|
Arwes.drawFrameBottomCorners(36, 58 + yOffset + 35, 204, 58 + 80 + yOffset + 35);
|
2020-09-21 21:21:41 +00:00
|
|
|
|
|
|
|
// battery frame
|
2020-12-08 17:53:24 +00:00
|
|
|
Arwes.drawFrameNoCorners(44, 58 + 80 + yOffset + 35, 196, height - 3);
|
2020-09-21 21:21:41 +00:00
|
|
|
|
2020-04-15 12:00:01 +00:00
|
|
|
|
2020-12-09 13:24:02 +00:00
|
|
|
updateCounter()
|
2020-09-21 17:38:07 +00:00
|
|
|
updateClock();
|
|
|
|
|
|
|
|
// const img = makeImg();
|
|
|
|
// g.drawImage(img,width/2-(img.width/2),height/2);
|
2020-04-15 12:00:01 +00:00
|
|
|
}
|
2020-12-03 21:03:56 +00:00
|
|
|
|
2020-04-15 12:00:01 +00:00
|
|
|
function updateClock() {
|
2020-09-21 17:38:07 +00:00
|
|
|
g.setFontAlign(0, 0);
|
|
|
|
const date = new Date();
|
|
|
|
drawTimeText(date);
|
|
|
|
drawDateText(date);
|
2020-12-09 13:24:02 +00:00
|
|
|
|
2020-04-15 12:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 21:03:56 +00:00
|
|
|
Bangle.on('lcdPower', function (on) {
|
2020-04-15 12:00:01 +00:00
|
|
|
if (on) drawClock();
|
2020-09-21 17:38:07 +00:00
|
|
|
|
2020-04-15 12:00:01 +00:00
|
|
|
});
|
2020-09-21 17:38:07 +00:00
|
|
|
|
2020-04-15 12:00:01 +00:00
|
|
|
g.clear();
|
|
|
|
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
|
|
|
|
drawClock();
|
|
|
|
|
|
|
|
|
2020-12-03 21:03:56 +00:00
|
|
|
setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: "falling"});
|
2020-09-21 17:38:07 +00:00
|
|
|
|
2020-12-03 21:03:56 +00:00
|
|
|
// setWatch(function () {
|
|
|
|
// count++;
|
|
|
|
// drawCounterText();
|
|
|
|
// }, BTN1, {repeat: true, edge: "falling"});
|
|
|
|
// setWatch(function () {
|
|
|
|
// count--;
|
|
|
|
// drawCounterText();
|
|
|
|
// }, BTN3, {repeat: true, edge: "falling"});
|
2020-09-21 21:21:41 +00:00
|
|
|
|
2020-04-15 12:00:01 +00:00
|
|
|
// refesh every 100 milliseconds
|
2020-09-21 17:38:07 +00:00
|
|
|
setInterval(updateClock, 500);
|
2020-12-09 13:24:02 +00:00
|
|
|
setInterval(updateCounter, 1000);
|
2020-12-03 21:03:56 +00:00
|
|
|
|
|
|
|
|