How does Accel.on work with Pebble js?

94 views Asked by At

How does Accel.on work with Pebble js? I know that for Pebble C SDK, you unsubscribe to the accel service, but there doesn't seem to be anything like that for Pebble js. I have a boolean called shake; in a function, while shake is false, I have Vibe.vibrate('long') to make the watch vibrate

In my Accel.on anonymous function, I set 'shake' to true

How does Accel.on actually work? In the C sdk, it seems to continuously call the handler. Is it the same for Javascript? the lines of code in question is this:

while (!shake){
     Vibe.vibrate('long');
      startAccelCheck();
  }

startAccelCheck changes shake to true when acceleration is over a certain point

It currently does not work; I'm wondering if it's possible to change the value of shake to true in Accel.On while the loop is ongoing

1

There are 1 answers

0
mlb406 On

Accel.on is a way of listening to an "accelTap" no matter what window is being displayed. The alternative is:

wind.on("accelTap", function(e) {

});

where wind is the active window in the stack. If the second method is used, the watch will only trigger the event if the selected window is active; whereas Accel.on is global and will pick up every "tap" of the watch.

The startAccelCheck is not specifically required, if all it does is set a global boolean value to true. Another way of doing this would be to put the changing of that value to true inside function(e) of the Accel.on etc.

E.G.

Accel.on("tap", function(e) {
    shake = False;
});
//and then continue to run the loop

Is there a GitHub repo or somewhere I can find your code to better help you?

Sourced from the Pebble developer docs.

Hope this helps.