From 097a056778c449020a00eda7602ec57eb5bc3f2f Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Tue, 8 Oct 2024 14:21:06 +0200 Subject: [PATCH 1/2] ChangeLog: specify Bangle 2 for E.showScroller fix --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 97f6c6e20..d2177ec80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,7 +24,7 @@ Jolt.js: Increase Storage area from 40kb to 400kb nRF5x: Don't add BLE UART write events into the input buffer ESP32: Timers are now turned off when requested - digitalPulse/soft pwm/writeAtTime more accurate - Bangle.js: Remove debug log messages from E.showScroller + Bangle.js2: Remove debug log messages from E.showScroller STM32F4: Update stm32f4xx_ll_usb to fix over-buffered USB CDC tx after being woken from deep sleep Waveform: Add 'npin' option to allow +/- output on two pins Waveform: Add ability to play directly from Storage From 54f631d7eac3396dbae07f717d3d575c4f139ed0 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com> Date: Sun, 6 Oct 2024 23:46:54 +0200 Subject: [PATCH 2/2] E_showMenu_/E_showScroller_Q3: forward touch event The goal was to make it possible for menus to distinguish between short and long touches when the entry maps to a function. With this alarms in the `alarm` app could be made togglable by longpressing corresponding menu entries. --- ChangeLog | 1 + libs/banglejs/jswrap_bangle.c | 5 +++++ libs/js/banglejs/E_showMenu_Q3.js | 8 ++++---- libs/js/banglejs/E_showScroller_Q3.js | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2177ec80..e491903ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ jsvObjectIterator is now safe even if not called on something iterable X.on now always allocates an array - tidies up code (fix #2559) Bangle.js: E.showMenu no longer sends the internal `l` menu object as argument when running the callback function. + Bangle.js2: Pass the modified touch event on through both E.showScroller and E.showMenu (to enable more complex interaction with menus). 2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()' Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off) diff --git a/libs/banglejs/jswrap_bangle.c b/libs/banglejs/jswrap_bangle.c index 3369dc5dc..356fafb20 100644 --- a/libs/banglejs/jswrap_bangle.c +++ b/libs/banglejs/jswrap_bangle.c @@ -5904,6 +5904,10 @@ On Bangle.js there are a few additions over the standard `graphical_menu`: menu is removed * (Bangle.js 2) `scroll : int` - an integer specifying how much the initial menu should be scrolled by +* (Bangle.js 2) The mapped functions can consider the touch event that interacted with the entry: + `"Entry" : function(touch) { ... }` + * This is also true of `onchange` mapped functions in entry objects: + `onchange : (value, touch) => { ... }` * The object returned by `E.showMenu` contains: * (Bangle.js 2) `scroller` - the object returned by `E.showScroller` - `scroller.scroll` returns the amount the menu is currently scrolled by @@ -6046,6 +6050,7 @@ Supply an object containing: draw : function(idx, rect) { ... } // a function to call when the item is selected, touch parameter is only relevant // for Bangle.js 2 and contains the coordinates touched inside the selected item + // as well as the type of the touch - see `Bangle.touch`. select : function(idx, touch) { ... } // optional function to be called when 'back' is tapped back : function() { ...} diff --git a/libs/js/banglejs/E_showMenu_Q3.js b/libs/js/banglejs/E_showMenu_Q3.js index 6bda1fb29..63c30d391 100644 --- a/libs/js/banglejs/E_showMenu_Q3.js +++ b/libs/js/banglejs/E_showMenu_Q3.js @@ -133,19 +133,19 @@ l = g.setFont("6x15").wrapString(title,r.w-pad); g.setFontAlign(-1,0).drawString(l.join("\n"), r.x+12, r.y+H/2); }, - select : function(idx) { + select : function(idx, touch) { if (idx<0) return back&&back(); // title var item = menu[keys[idx]]; Bangle.buzz(20); - if ("function" == typeof item) item(); + if ("function" == typeof item) item(touch); else if ("object" == typeof item) { - // if a bool, just toggle it if ("number" == typeof item.value) { showSubMenu(item, keys[idx]); } else { + // if a bool, just toggle it if ("boolean"==typeof item.value) item.value=!item.value; - if (item.onchange) item.onchange(item.value); + if (item.onchange) item.onchange(item.value, touch); if (l.scroller.isActive()) l.scroller.drawItem(idx); } } diff --git a/libs/js/banglejs/E_showScroller_Q3.js b/libs/js/banglejs/E_showScroller_Q3.js index f2d0c207a..4a7897c57 100644 --- a/libs/js/banglejs/E_showScroller_Q3.js +++ b/libs/js/banglejs/E_showScroller_Q3.js @@ -82,7 +82,7 @@ Bangle.setUI({ } if ((menuScrollMin<0 || i>=0) && i