Skip to content

Commit

Permalink
Puck.js: On v2.1 ensure Puck.mag behaves like other variants - just r…
Browse files Browse the repository at this point in the history
…eturning the last reading (avoids glitches when used with Puck.magOn)
  • Loading branch information
gfwilliams committed Jan 9, 2025
1 parent d55ac84 commit 5627e89
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
: nRF5x: ensure TIMER1_IRQHandler doesn't always wake idle loop up (fix #1900)
Puck.js: On v2.1 ensure Puck.mag behaves like other variants - just returning the last reading (avoids glitches when used with Puck.magOn)

2v25 : ESP32C3: Get analogRead working correctly
Graphics: Adjust image alignment when rotating images to avoid cropping (fix #2535)
Expand Down
12 changes: 4 additions & 8 deletions libs/puckjs/jswrap_puck.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ outputs.
"return" : ["JsVar", "An Object `{x,y,z}` of magnetometer readings as integers" ]
}
Turn on the magnetometer, take a single reading, and then turn it off again.
If the magnetometer is already on (with `Puck.magOn()`) then the last reading
is returned.
An object of the form `{x,y,z}` is returned containing magnetometer readings.
Due to residual magnetism in the Puck and magnetometer itself, with no magnetic
Expand Down Expand Up @@ -652,14 +654,8 @@ JsVar *jswrap_puck_mag() {
if (!mag_enabled) {
mag_on(0, true /*instant*/); // takes a reading right away
mag_off();
} else if (puckVersion == PUCKJS_2V1) { // MMC5603NJ
// magnetometer is on, but let's poll it quickly
// to see if we have any new data
unsigned char buf[1];
mag_rd(0x18, buf, 1); // Status
if (buf[0]&0x40) // check for Meas_m_done
mag_read();
}
} // else magnetometer is on, just return the last reading

return to_xyz(mag_reading, 1);
}

Expand Down

0 comments on commit 5627e89

Please sign in to comment.