Avatar for malaire

malaire

Member since Oct 2021 • Last active Jul 2022
  • 15 conversations
  • 206 comments

Most recent activity

  • in Bangle.js
    Avatar for malaire

    hmm, how setInterval works if watch time is changed with setTime while setInterval is going?

  • in Bangle.js
    Avatar for malaire

    That's only accurate for first draw. It's better to use this at end of each draw so that every draw will be accurate:

    setTimeout(()=>{
      draw();
    }, 1000 - (Date.now() % 1000));
    
  • in Bangle.js
    Avatar for malaire

    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.)

  • in Bangle.js
    Avatar for malaire

    I think it would make more sense for Espruino to support UTF-8 strings, and then support fonts which include some parts of UTF-8, instead of having codepages.

  • in Bangle.js
    Avatar for malaire

    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_Sto­rage_read

    (But in general using more RAM can be a downside of creating variables outside functions.)

  • in Bangle.js
    Avatar for malaire

    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.

  • in Bangle.js
    Avatar for malaire

    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.gi­f");
    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()/6­0000) * 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,r­otate:HoursAngle});
      g.drawImage(minHandDay,xc,yc,{scale:1,ro­tate:MinutesAngle});
      g.drawImage(secHandDay,xc,yc,{scale:1,ro­tate:SecondsAngle});
      queueDraw();
    }
    

    And similar change for nightglow function.

  • in Bangle.js
    Avatar for malaire

    ... deleted ...

  • in Bangle.js
    Avatar for malaire

    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 when queueDraw 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() and nightglow() functions?

  • in Bangle.js
    Avatar for malaire

    As Gordon said, don't use Bangle.isLocked() in queueDraw but in draw (btw that was also what I meant in my post with "draw using isLocked" comment, but I guess I should've spelled that more clearly).

    Also having Bangle.on('lock', off => { makes no sense - just use single event.

Actions