Check for pending events before updating the config
Small optimisation that significantly reduces number of config updates.
This commit is contained in:
13
api.cpp
13
api.cpp
@@ -60,6 +60,16 @@ class Context {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasPendingEvent() {
|
||||||
|
return gpp_rethrow([=]() {
|
||||||
|
CameraEventType event_type = GP_EVENT_UNKNOWN;
|
||||||
|
gpp_unique_ptr<void, free> event_data(GPP_CALL(
|
||||||
|
void *, gp_camera_wait_for_event(camera.get(), 0, &event_type, _,
|
||||||
|
context.get())));
|
||||||
|
return event_type != GP_EVENT_TIMEOUT;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
val configToJS() {
|
val configToJS() {
|
||||||
return gpp_rethrow([=]() {
|
return gpp_rethrow([=]() {
|
||||||
GPPWidget config(
|
GPPWidget config(
|
||||||
@@ -277,5 +287,6 @@ EMSCRIPTEN_BINDINGS(gphoto2_js_api) {
|
|||||||
.function("configToJS", &Context::configToJS)
|
.function("configToJS", &Context::configToJS)
|
||||||
.function("setConfigValue", &Context::setConfigValue)
|
.function("setConfigValue", &Context::setConfigValue)
|
||||||
.function("capturePreviewAsBlob", &Context::capturePreviewAsBlob)
|
.function("capturePreviewAsBlob", &Context::capturePreviewAsBlob)
|
||||||
.function("captureImageAsFile", &Context::captureImageAsFile);
|
.function("captureImageAsFile", &Context::captureImageAsFile)
|
||||||
|
.function("hasPendingEvent", &Context::hasPendingEvent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,12 @@ class App extends Component {
|
|||||||
type: 'Config',
|
type: 'Config',
|
||||||
config
|
config
|
||||||
});
|
});
|
||||||
|
do {
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
|
} while (
|
||||||
|
!(await this.connection.schedule(context => context.hasPendingEvent()))
|
||||||
|
);
|
||||||
|
console.log('Event!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user