Skip to content

Commit

Permalink
Bangle.getPressure() redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
d3nd3 committed Jan 13, 2024
1 parent c1824f0 commit d091112
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions libs/banglejs/jswrap_bangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -4243,6 +4243,16 @@ bool jswrap_banglejs_idle() {
if (o) {
jsiQueueObjectCallbacks(bangle, JS_EVENT_PREFIX"pressure", &o, 1);
jsvUnLock(o);
if ( promisePressure ) {
// disable sensor now we have a result
JsVar *id = jsvNewFromString("getPressure");
jswrap_banglejs_setBarometerPower(0, id);
jsvUnLock(id);
// resolve the promise
jspromise_resolve(promisePressure, o);
jsvUnLock(promisePressure);
promisePressure = 0;
}
}
}
#endif
Expand Down Expand Up @@ -5031,21 +5041,6 @@ JsVar *jswrap_banglejs_getBarometerObject() {
}
return o;
}

void jswrap_banglejs_getPressure_callback() {
JsVar *o = 0;
if (jswrap_banglejs_barometerPoll()) {
o = jswrap_banglejs_getBarometerObject();
}
// disable sensor now we have a result
JsVar *id = jsvNewFromString("getPressure");
jswrap_banglejs_setBarometerPower(0, id);
jsvUnLock(id);
// resolve the promise
jspromise_resolve(promisePressure, o);
jsvUnLock2(promisePressure,o);
promisePressure = 0;
}
#endif // PRESSURE_DEVICE


Expand Down Expand Up @@ -5103,7 +5098,6 @@ JsVar *jswrap_banglejs_getPressure() {
if (PRESSURE_DEVICE_SPL06_007_EN)
powerOnTimeout = 400; // on SPL06 we may actually be leaving it *too long* before requesting data, and it starts to do another reading
#endif
jsvUnLock(jsiSetTimeout(jswrap_banglejs_getPressure_callback, powerOnTimeout));
return jsvLockAgain(promisePressure);
#endif
}
Expand Down

0 comments on commit d091112

Please sign in to comment.