Working of setAccelOn function

I wanted to know how the following function, setAccelOn, works.

var Ruuvitag = require("Ruuvitag");

function onInit() {
  Ruuvitag.setAccelOn(true, function(xyz) {

Instead of printing the values, can this function return a value using “return xyz” statement??

The callback function is called by interrupt handling the data and returning values wouldn’t make sense. My approach would be to set a flag notifying main program there’s new data on callback and then read the data in main.

Could you please provide the code?


Here’s how I do it in C:

When interrupt from FIFO Full of LIS2DH12 triggers, event is placed in scheduler queue.

After interrupt program wakes up from yield in main loop and scheduled functions get executed.

Is the scheduled function which reads the FIFO and updates advertised data. After all scheduled functions are executed tag goes back to sleep to wait for the next event.

I do not have equivalent code for Espruino, but the approach I’d take is similar. Register event in callback, main loop wakes up to handle the event and tag goes back to sleep.