Skip to content

Commit

Permalink
Bangle.js2: Swipe direction is now modified based on g.setRotation
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Oct 21, 2022
1 parent 9286ecc commit 5345b5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Bangle.js2: Add built-in touchscreen calibration
Bangle.js2: Add fast-path for all-white or all-black full-width graphics fill/clear (24ms -> 2ms)
Bangle.js2: LCD background flip (send to LCD while returning to execute other code)
Bangle.js2: Swipe direction is now modified based on g.setRotation

2v15 : Fix issue where `E.toJS("\0"+"0") == '"\00"'` which is just `"\0"`
Fix issue accessing `arguments` after/inside 'let/const' keyword (fix #2224)
Expand Down
29 changes: 25 additions & 4 deletions libs/banglejs/jswrap_bangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,27 @@ void btn4Handler(bool state, IOEventFlags flags) {
#endif

#ifdef TOUCH_DEVICE // so it's available even in emulator

// Convert Touchscreen gesture based on graphics orientation
TouchGestureType touchSwipeRotate(TouchGestureType g) {
// gesture is the value that comes straight from the touchscreen
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_INVERT_X) {
if (g==TG_SWIPE_LEFT) g=TG_SWIPE_RIGHT;
else if (g==TG_SWIPE_RIGHT) g=TG_SWIPE_LEFT;
}
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_INVERT_Y) {
if (g==TG_SWIPE_UP) g=TG_SWIPE_DOWN;
else if (g==TG_SWIPE_DOWN) g=TG_SWIPE_UP;
}
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_SWAP_XY) {
if (g==TG_SWIPE_LEFT) g=TG_SWIPE_UP;
else if (g==TG_SWIPE_RIGHT) g=TG_SWIPE_DOWN;
else if (g==TG_SWIPE_UP) g=TG_SWIPE_LEFT;
else if (g==TG_SWIPE_DOWN) g=TG_SWIPE_RIGHT;
}
return g;
}

void touchHandlerInternal(int tx, int ty, int pts, int gesture) {
// ignore if locked
if (bangleFlags & JSBF_LOCKED) return;
Expand All @@ -1674,19 +1695,19 @@ void touchHandlerInternal(int tx, int ty, int pts, int gesture) {
switch (gesture) { // gesture
case 0:break; // no gesture
case 1: // slide down
touchGesture = TG_SWIPE_DOWN;
touchGesture = touchSwipeRotate(TG_SWIPE_DOWN);
bangleTasks |= JSBT_SWIPE;
break;
case 2: // slide up
touchGesture = TG_SWIPE_UP;
touchGesture = touchSwipeRotate(TG_SWIPE_UP);
bangleTasks |= JSBT_SWIPE;
break;
case 3: // slide left
touchGesture = TG_SWIPE_LEFT;
touchGesture = touchSwipeRotate(TG_SWIPE_LEFT);
bangleTasks |= JSBT_SWIPE;
break;
case 4: // slide right
touchGesture = TG_SWIPE_RIGHT;
touchGesture = touchSwipeRotate(TG_SWIPE_RIGHT);
bangleTasks |= JSBT_SWIPE;
break;
case 5: // single click
Expand Down

0 comments on commit 5345b5f

Please sign in to comment.