From d09111209750e2b5487c46e44e290f6bd34c8d3c Mon Sep 17 00:00:00 2001 From: Graham Fenner Date: Sat, 13 Jan 2024 19:54:06 +0000 Subject: [PATCH] Bangle.getPressure() redesign --- libs/banglejs/jswrap_bangle.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/libs/banglejs/jswrap_bangle.c b/libs/banglejs/jswrap_bangle.c index 58fbe9f35a..8fcf30a612 100644 --- a/libs/banglejs/jswrap_bangle.c +++ b/libs/banglejs/jswrap_bangle.c @@ -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 @@ -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 @@ -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 }