Layout module - BTN2 undefined (?)

Posted on
  • Hi Al,
    it seems that the Layout module has a problem, perhaps related to new handling of let/const of v14 firmware.
    When rendering on a Bangle2 a layout with more than one button, the following message is diplayed:

    Uncaught ReferenceError: "BTN2" is not defined
     at line 115 col 79 in Layout
    ...pressHandler.bind(this,1), BTN2, {repeat:true,edge:-1}));
                                  ^
    in function "setUI" called from line 65 col 14 in Layout
      this.setUI();
                 ^
    in function "Layout" called from line 373 col 14 in Layout
    ], lazy:true});
                 ^
    

    This happens even running the sample code available in the tutorial, e.g.:

    var Layout = require("Layout");
    var layout = new Layout( {
      type:"v", c: [
        {type:"txt", font:"6x8:2", label:"A Test", id:"label" }
      ]
    }, {btns:[
      {label:"One", cb: l=>print("One"),  cbl: l=>print("One long press")},
      {label:"Two", cb: l=>print("Two")},
      {label:"Three", cb: l=>print("Three")}
    ], lazy:true});
    
    function setLabel(x) {
      layout.label.label = x;
      layout.render();
    }
    g.clear();
    layout.render();
    

    I'm pretty sure that it worked on v13.
    g-

  • @GRikell the problem is not let/const. So far I broke down the issue to a specific commit in the layout library itself by @Gordon.

    The issue was introduced here https://github.com/espruino/BangleApps/c­ommit/43a3d70571d35896a24fb1364e9fb0f066­391807

    It tries to use a physical button 2 for this example instead of a virtual one. The BangleJS2 only has one physical button.

    Reverting that commit it is using correctly virtual buttons on the BangleJs2

  • Ok, thanks a lot.
    So we have to wait for Gordon to fix this commit.
    Actually, it is not just for the sample, but it also broke "Interval Timer".

  • Ok, thanks - it looks like I just got one line in the wrong place: https://github.com/espruino/BangleApps/c­ommit/6ad485c6287f15fb1f00f01859d2542e76­77f50f

    Now fixed I hope (in the development app loader) but please let me know!

  • Hi Gordon,
    unfortunately Interval Timer app still crashes (blank screen) and the following appears on the web IDE

    Uncaught ReferenceError: "a" is not defined
     at line 1 col 787 in intervalTimer.app.js
    ...1,h.width=32,h.r=1,h))}]},a&&a.push.a­pply(a,this._l.c[1].c);this.se...
                                         ^
    in function "Layout" called from line 63 col 355 in intervalTimer.app.js
    ...{decrementActiveTime();}}]});menuLayo­ut.render();const incrementA...
                                       ^
    in function "setActiveTime" called from line 77 col 50 in intervalTimer.app.js
    }Bangle.setUI();timerMode='active';setAc­tiveTime();
                                                     ^
    in function "setup" called from line 77 col 81 in intervalTimer.app.js
    ...angle.setLCDPower(1);setup();
                                  ^
    > 
    

    Running in the emulator and disabling minified module uploads, this is the message:

    >Uncaught Error: Cannot read property 'bind' of undefined
     at line 1 col 709
    ....btnWatches.push(setWatch(a.bind(this­,0),BTN1,{repeat:!0,edg...
                                  ^
    in function "setUI" called from line 1 col 916
    ...this._l.c[1].c)}this.setUI();var e=this;d(this._l),this.upda...
                                  ^
    in function "Layout" called from line 16 col 5
      ]});
        ^
    in function "setActiveTime" called from line 8 col 17
      setActiveTime();
                    ^
    in function "setup" called from line 1 col 7
    setup();
    

    Thanks!
    g

  • Ok, thanks - so it looks like this is another separate issue due to the minification (it works fine with the unminified Layout). I'm looking into it now

  • Ok, fixed!

  • Yes!
    Thanks a lot (my trainings will improve for sure)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Layout module - BTN2 undefined (?)

Posted by Avatar for GRikell @GRikell

Actions