diff --git a/ChangeLog b/ChangeLog index 03d7567ca1..cd4a91858a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/libs/banglejs/jswrap_bangle.c b/libs/banglejs/jswrap_bangle.c index 1e7cffbc3e..03c83eb528 100644 --- a/libs/banglejs/jswrap_bangle.c +++ b/libs/banglejs/jswrap_bangle.c @@ -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 MAG_MAX_RANGE) @@ -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;