Skip to content

Commit

Permalink
Bangle.js: If screen is rotated, also rotate accelerometer and magnet…
Browse files Browse the repository at this point in the history
…ometer values

Fixes espruino/BangleApps#2999
  • Loading branch information
gfwilliams committed Sep 8, 2023
1 parent 032fbc2 commit a4ffbdc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Allow E.pipe to pipe from Strings, remove pipe's internal `position` counter (fix #2352)
Bangle.js 1: remove OneWire and JIT as it uses too much flash space to exist alongside UTF8+Tensorflow on nRF52
ARM: Apply -fmerge-all-constants to the build (saves ~1kb)
Bangle.js: If screen is rotated, also rotate accelerometer and magnetometer values

2v18 : Fix drawString with setClipRect with 90/270-degree rotation (fix #2343)
Pico/Wifi: Enabled JIT compiler
Expand Down
18 changes: 18 additions & 0 deletions libs/banglejs/jswrap_bangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,15 @@ void peripheralPollHandler() {
}
#endif
if (newReading) {
// if the graphics instance is rotated, also rotate magnetometer values
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_SWAP_XY) {
short t = mag.x;
mag.x = mag.y;
mag.y = t;
}
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_INVERT_X) mag.x = -mag.x;
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_INVERT_Y) mag.y = -mag.y;
// Work out min and max values for auto-calibration
if (mag.x<magmin.x) {
magmin.x=mag.x;
if (magmax.x-magmin.x > MAG_MAX_RANGE)
Expand Down Expand Up @@ -1429,6 +1438,15 @@ void peripheralPollHandler() {
#ifdef ACCEL_DEVICE_KX126
newy = -newy;
#endif
// if the graphics instance is rotated, also rotate accelerometer values
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_INVERT_X) newx = -newx;
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_INVERT_Y) newy = -newy;
if (graphicsInternal.data.flags & JSGRAPHICSFLAGS_SWAP_XY) {
short t = newx;
newx = newy;
newy = t;
}

int dx = newx-acc.x;
int dy = newy-acc.y;
int dz = newz-acc.z;
Expand Down

0 comments on commit a4ffbdc

Please sign in to comment.