DANE Watchface v0.08: Reduced RAM usage

master
OmegaRogue 2020-09-21 19:38:07 +02:00
parent 867fcf6c9b
commit de1bfb5ad0
3 changed files with 65 additions and 53 deletions

View File

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

View File

@ -3,3 +3,4 @@
0.05: bugfix 0.05: bugfix
0.06: moved and resized icon 0.06: moved and resized icon
0.07: Added Description 0.07: Added Description
0.08: Removed Image, Reduced RAM usage

View File

@ -3,7 +3,9 @@ const timeFontSize = 4;
const dateFontSize = 3; const dateFontSize = 3;
const smallFontSize = 2; const smallFontSize = 2;
const yOffset = 23; const yOffset = 23;
const xyCenter = g.getWidth()/2; const width = g.getWidth();
const height = g.getHeight();
const xyCenter = width/2;
const cornerSize = 14; const cornerSize = 14;
const cornerOffset = 3; const cornerOffset = 3;
const borderWidth = 1; const borderWidth = 1;
@ -12,55 +14,64 @@ const yposDate = 65+yOffset;
const mainColor = "#26dafd"; const mainColor = "#26dafd";
const mainColorDark = "#029dbb"; const mainColorDark = "#029dbb";
const mainColorLight = "#8bebfe"; // const mainColorLight = "#8bebfe";
const secondaryColor = "#df9527"; // const secondaryColor = "#df9527";
const secondaryColorDark = "#8b5c15"; // const secondaryColorDark = "#8b5c15";
const secondaryColorLight = "#ecc180"; const secondaryColorLight = "#ecc180";
const success = "#00ff00"; const success = "#00ff00";
const successDark = "#000900"; // const successDark = "#000900";
const successLight = "#060f06"; // const successLight = "#060f06";
const alert = "#ff0000"; const alert = "#ff0000";
const alertDark = "#090000"; // const alertDark = "#090000";
const alertLight = "#0f0606"; const alertLight = "#0f0606";
var img = {
width : 120, height : 120, bpp : 8, // function getImg() {
transparent : 254, // return atob("/wA/A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EhgAEGgoAHlZ3bDgQAWlYaCO8QmDH7B3WmAcCGyoXCO9AAZgEMICdCoUMGrh3DPDp3iICR3/d+42BO8J2cO/53/IDU8GykGO/88O+g1ggB2dIIgAdO64AeO/cwmwACGyoZDADU8VqhBPEoIADoQATG7IuUGsBCjHswA/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A/AH4A1")) // }
}
// function makeImg() {
// return {
// width : 120, height : 120, bpp : 8,
// transparent : 254,
// buffer : require("heatshrink").decompress(getImg())
// }
// }
function drawTopLeftCorner(x,y) { function drawTopLeftCorner(x,y) {
g.setColor(mainColor); g.setColor(mainColor);
var x1 = x-cornerOffset; const x1 = x - cornerOffset;
var y1 = y-cornerOffset; const y1 = y - cornerOffset;
g.fillRect(x1,y1,x1+cornerSize,y1+cornerSize); g.fillRect(x1,y1,x1+cornerSize,y1+cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x+cornerSize-cornerOffset,y+cornerSize-cornerOffset); g.fillRect(x,y,x+cornerSize-cornerOffset,y+cornerSize-cornerOffset);
} }
function drawTopRightCorner(x,y) { function drawTopRightCorner(x,y) {
g.setColor(mainColor); g.setColor(mainColor);
var x1 = x+cornerOffset; const x1 = x + cornerOffset;
var y1 = y-cornerOffset; const y1 = y - cornerOffset;
g.fillRect(x1,y1,x1-cornerSize,y1+cornerSize); g.fillRect(x1,y1,x1-cornerSize,y1+cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x-cornerSize-cornerOffset,y+cornerSize-cornerOffset); g.fillRect(x,y,x-cornerSize-cornerOffset,y+cornerSize-cornerOffset);
} }
function drawBottomLeftCorner(x,y) { function drawBottomLeftCorner(x,y) {
g.setColor(mainColor); g.setColor(mainColor);
var x1 = x-cornerOffset; const x1 = x - cornerOffset;
var y1 = y+cornerOffset; const y1 = y + cornerOffset;
g.fillRect(x1,y1,x1+cornerSize,y1-cornerSize); g.fillRect(x1,y1,x1+cornerSize,y1-cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x+cornerSize-cornerOffset,y-cornerSize+cornerOffset); g.fillRect(x,y,x+cornerSize-cornerOffset,y-cornerSize+cornerOffset);
} }
function drawBottomRightCorner(x,y) { function drawBottomRightCorner(x,y) {
g.setColor(mainColor); g.setColor(mainColor);
var x1 = x+cornerOffset; const x1 = x + cornerOffset;
var y1 = y+cornerOffset; const y1 = y + cornerOffset;
g.fillRect(x1,y1,x1-cornerSize,y1-cornerSize); g.fillRect(x1,y1,x1-cornerSize,y1-cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x-cornerSize+cornerOffset,y-cornerSize+cornerOffset); g.fillRect(x,y,x-cornerSize+cornerOffset,y-cornerSize+cornerOffset);
@ -85,31 +96,28 @@ function drawTopFrame(x1,y1,x2,y2) {
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth); g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth);
} }
function drawBottomFrame(x1,y1,x2,y2) { // function drawBottomFrame(x1,y1,x2,y2) {
drawTopLeftCorner(x1,y1); // drawTopLeftCorner(x1,y1);
drawTopRightCorner(x2,y1); // drawTopRightCorner(x2,y1);
g.setColor(mainColorDark); // g.setColor(mainColorDark);
g.drawRect(x1,y1,x2,y2); // g.drawRect(x1,y1,x2,y2);
g.setColor("#000000"); // g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth); // g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth);
} // }
function getUTCTime(d) { // function getUTCTime(d) {
return d.toUTCString().split(' ')[4].split(':').map(function(d){return Number(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() { const time = da[4].split(":");
g.setFontAlign(0, 0); const hours = time[0],
var d = new Date();
var da = d.toString().split(" ");
var dutc = getUTCTime(d);
var time = da[4].split(":");
var hours = time[0],
minutes = time[1], minutes = time[1],
seconds = time[2]; seconds = time[2];
g.setColor(mainColor); g.setColor(mainColor);
@ -117,9 +125,7 @@ function drawTimeText() {
g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true); g.drawString(`${hours}:${minutes}:${seconds}`, xyCenter, yposTime, true);
g.setFont(font, smallFontSize); g.setFont(font, smallFontSize);
} }
function drawDateText() { function drawDateText(d) {
g.setFontAlign(0, 0);
var d = new Date();
g.setFont(font, dateFontSize); g.setFont(font, dateFontSize);
g.drawString(`${d.getDate()}.${d.getMonth()+1}.${d.getFullYear()}`, xyCenter, yposDate, true); g.drawString(`${d.getDate()}.${d.getMonth()+1}.${d.getFullYear()}`, xyCenter, yposDate, true);
} }
@ -128,36 +134,41 @@ function drawDateText() {
function drawClock() { function drawClock() {
// main frame // main frame
drawFrame(3,10+yOffset,g.getWidth()-3,g.getHeight()-3); drawFrame(3,10+yOffset,width-3,height-3);
// time frame // time frame
drawTopFrame(20,10+yOffset,220,46+yOffset); drawTopFrame(20,10+yOffset,220,46+yOffset);
// date frame // date frame
drawTopFrame(28,46+yOffset,212,46+yOffset+35); drawTopFrame(28,46+yOffset,212,46+yOffset+35);
// texts updateClock();
drawTimeText();
drawDateText(); // const img = makeImg();
g.drawImage(img,g.getWidth()/2-(img.width/2),g.getHeight()/2); // g.drawImage(img,width/2-(img.width/2),height/2);
} }
function updateClock() { function updateClock() {
drawTimeText(); g.setFontAlign(0, 0);
drawDateText(); const date = new Date();
drawTimeText(date);
drawDateText(date);
} }
Bangle.on('lcdPower', function(on) { Bangle.on('lcdPower', function(on) {
if (on) drawClock(); if (on) drawClock();
}); });
g.clear(); g.clear();
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
drawClock(); drawClock();
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"}); setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
// refesh every 100 milliseconds // refesh every 100 milliseconds
setInterval(updateClock, 100); setInterval(updateClock, 500);