Bangle.setUI({mode:"custom",
back: function() {
// Bangle.js 2 also calls this for button presses
Bangle.showClock();
},
btn: global.BTN2 ? function(b) {
if (b==2) Bangle.showClock(); // only needed for Bangle.js 1
} : undefined
});
Bangle.js 2 setUIchecks if there are any button listeners, and assigns the back function otherwise, Bangle.js 1 doesn't :-(
Maybe we could add similar code to the Bangle.js 1 setUI:
Bangle.on("touch", touchHandler);
if (Bangle.btnWatches===undefined) // only add back button handler if there are no existing watches
btnWatch = setWatch(function() {
btnWatch = undefined;
options.back();
}, BTN2, {edge:"falling"});
...
// and in widget.remove:
if (btnWatch) clearWatch(btnWatch);
But I suppose that would lead to the same problem of it not working in older firmware... (On the other hand: it doesn't work now either, so apps that already assign their own BTN2 listeners should be fine?)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Right, I can see why we want to avoid changing Bangle.setUI.
But as far as I can tell on Bangle.js 1:
opens the launcher (instead of the clock) when you press the middle button.
And
does nothing for button presses.
So we end up needing something like this:
Bangle.js 2
setUI
checks if there are any button listeners, and assigns theback
function otherwise, Bangle.js 1 doesn't :-(Maybe we could add similar code to the Bangle.js 1
setUI
:But I suppose that would lead to the same problem of it not working in older firmware... (On the other hand: it doesn't work now either, so apps that already assign their own BTN2 listeners should be fine?)