Hi!
The code for the Pixl's menu implementation is at https://github.com/espruino/Espruino/blob/master/libs/js/pixljs/E_showMenu.js
It does exactly as you have above:
Pixl.btnWatches = [ setWatch(function() { m.move(-1); }, BTN1, {repeat:1}), setWatch(function() { m.move(1); }, BTN4, {repeat:1}), setWatch(function() { m.select(); }, BTN3, {repeat:1}) ];
So really I'd have thought you could just do:
Pixl.btnWatches.forEach(clearWatch); Pixl.btnWatches = [ setWatch(function() { m.move(-1); }, BTN1, {repeat:1}), setWatch(function() { m.move(1); }, BTN4, {repeat:1}), setWatch(function() { m.select(); }, BTN3, {repeat:1}) ];
Immediately after calling E.showMenu and it would have exactly the same effect? If that doesn't work could you explain what's not working?
E.showMenu
One other option is to just overwrite the Pixl's default showMenu implementation:
E.showMenu = (function(menudata) { if (Pixl.btnWatches) { Pixl.btnWatches.forEach(clearWatch); Pixl.btnWatches = undefined; } g.clear();g.flip(); // clear screen if no menu supplied if (!menudata) return; if (!menudata[""]) menudata[""]={}; g.setFontBitmap();g.setFontAlign(-1,-1,0); var w = g.getWidth()-9; var h = g.getHeight(); menudata[""].x=9; menudata[""].x2=w-2; menudata[""].preflip=function() { g.drawImage(E.toString(8,8,1, 0b00010000, 0b00111000, 0b01111100, 0b11111110, 0b00010000, 0b00010000, 0b00010000, 0b00010000, ),0,4); g.drawImage(E.toString(8,8,1, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b11111110, 0b01111100, 0b00111000, 0b00010000, ),0,h-12); g.drawImage(E.toString(8,8,1, 0b00000000, 0b00001000, 0b00001100, 0b00001110, 0b11111111, 0b00001110, 0b00001100, 0b00001000, ),w+1,h-12); //g.drawLine(7,0,7,h); //g.drawLine(w,0,w,h); }; var m = require("graphical_menu").list(g, menudata); Pixl.btnWatches = [ setWatch(function() { m.move(-1); }, D1, {repeat:1}), // <------------ change these setWatch(function() { m.move(1); }, D2, {repeat:1}), // <------------ change these setWatch(function() { m.select(); }, D3, {repeat:1}) // <------------ change these ]; return m; });
And now every time E.showMenu is called, it'll use the right button inputs
edit: also, just moving this to the Pixl.js section of the forum
@Gordon started
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.
Hi!
The code for the Pixl's menu implementation is at https://github.com/espruino/Espruino/blob/master/libs/js/pixljs/E_showMenu.js
It does exactly as you have above:
So really I'd have thought you could just do:
Immediately after calling
E.showMenu
and it would have exactly the same effect? If that doesn't work could you explain what's not working?One other option is to just overwrite the Pixl's default showMenu implementation:
And now every time
E.showMenu
is called, it'll use the right button inputsedit: also, just moving this to the Pixl.js section of the forum