Most recent activity
-
-
-
Not necessarily. For example 8x8 bitmap font needs 8 bytes per character and as of Unicode 14.0 there are 144 697 characters, so full font would take about 1.1 MB and would easily fit into Bangle.js 2
(This ignores the fact that you shouldn't just render each character as-is as there are complex rules of how some Unicode characters should be rendered.)
-
-
Actually documentation of
require("Storage").read
says that it does NOT use RAM. It returns some kind of reference to the file data.https://www.espruino.com/Reference#l_Storage_read
(But in general using more RAM can be a downside of creating variables outside functions.)
-
Ah, so does naming the variables at the beginning only load them once?
Any code outside functions is only executed once - when app starts.
Would I be better off naming '''var d = new Date();''' and such at the beginning, outside of my draw functions?
Usually it's better to keep variable inside function if that is possible, i.e.
var d = new Date();
should be inside function.But those images might be an exception if loading them from storage is too slow.
-
That code looks correct except for
setTimeout(0);
which does nothing I think.I havn't used images so I wonder if reading them is too slow here. You could try code like this instead so you read images once when app starts and not every time it's drawn (this code is replacement for your
daylight
function):var faceDaylight = require("Storage").read("FaceDaylight.gif"); var hourHandDay = require("Storage").read("HourHandDay.gif"); var minHandDay = require("Storage").read("MinHandDay.gif"); var secHandDay = require("Storage").read("SecHandDay.gif"); function daylight() { var d = new Date(); var h = d.getHours() % 12 || 12; //var time = (""+h).substr(-2) + ":" + ("0"+m).substr(-2); var HoursAngle = (d.getHours()+(d.getMinutes()/60))/12 * twoPi - Pi; var MinutesAngle = (d.getMinutes()/60) * twoPi - Pi; //var SecondsAngle = (d.getSeconds()/60) * twoPi - Pi; var SecondsAngle = (d.getSeconds()/60+d.getMilliseconds()/60000) * twoPi - Pi; g.reset(); g.clear(); g.drawImage(faceDaylight); //DateWindow g.setFont("6x8"); g.setFontAlign(0,0); g.setColor(0,0,0); g.drawString(d.toISOString().substr(8,2), 138, 88, 0); g.drawString(d.toISOString().substr(8,2), 139, 88, 0); g.drawImage(hourHandDay,xc,yc,{scale:1,rotate:HoursAngle}); g.drawImage(minHandDay,xc,yc,{scale:1,rotate:MinutesAngle}); g.drawImage(secHandDay,xc,yc,{scale:1,rotate:SecondsAngle}); queueDraw(); }
And similar change for
nightglow
function. -
-
One thing I don't fully understand is why we need Bangle.on('lock', on => { draw(); });
That creates an event which calls
draw
every time lock state changes, i.e. when watch is locked or unlocked. This is used so that draw is done immediately after state change. Without this draw would happen at next queued draw, i.e. with up to 250 ms delay with your current 250ms interval.... if we're going to call the draw function right afterward anyway.
That
draw();
at end is so that first draw when app starts is immediate. This also starts queued draws whenqueueDraw
is called during that draw.I'm still seeing the lag when changing images
I don't understand why that would happen. Can you show your
daylight()
andnightglow()
functions? -
https://github.com/malaire