Avatar for malaire

malaire

Member since Oct 2021 • Last active Sep 2022
  • 15 conversations
  • 208 comments

Most recent activity

  • in Bangle.js
    Avatar for malaire

    Some code for an example. If you define your widget as

    WIDGETS.mywidget = {
        area: ...,
        draw: ...,
        width: ...,
        someVariable: 123,
        someFunction: () => { ... },
      };
    

    Then in your clock, after calling Bangle.loadWidgets(), you can use WIDGETS.mywidget.someVariable and WIDGETS.mywidget.someFunction().

  • in Bangle.js
    Avatar for malaire

    All properties/functions of a widget are globally available as WIDGETS.widgetname.property, for example my widget has function setClockError which is available as WIDGETS.adjust.setClockError(x).

    The reason is that certain processes should not be interrupted when the user presses the button to go to the setting screen.

    All widgets are stopped and restarted when user goes to settings screen, just like when user changes to any other app. (Settings is just one of the apps.)

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

Actions