Deepblu Cosmiq+: stop downloading once we've seen the dives already

.. and also support cancellation of dive downloading in the middle.

The Cosmiq+ doesn't remember all that many dives, but BLE is slow and
there's no point in downloading more than necessary.

I'll look at fingerprinting next, so that we can avoid downloading the
profile data if we have already seen the header.  That's a further small
optimization.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2019-08-27 12:19:32 -07:00
parent df7aeeef01
commit d532be187a

View File

@ -431,8 +431,10 @@ deepblu_download_dive(deepblu_device_t *device, unsigned char nr, dc_dive_callba
if (status != DC_STATUS_SUCCESS)
return status;
if (callback)
callback(profile, profile_len+256, header, header_len, userdata);
if (callback) {
if (!callback(profile, profile_len+256, header, header_len, userdata))
return DC_STATUS_DONE;
}
return DC_STATUS_SUCCESS;
}
@ -459,9 +461,21 @@ deepblu_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void
device_event_emit(abstract, DC_EVENT_PROGRESS, &progress);
for (i = 1; i <= nrdives; i++) {
if (device_is_cancelled(abstract)) {
dc_status_set_error(&status, DC_STATUS_CANCELLED);
break;
}
status = deepblu_download_dive(device, i, callback, userdata);
if (status != DC_STATUS_SUCCESS)
switch (status) {
case DC_STATUS_DONE:
i = nrdives;
break;
case DC_STATUS_SUCCESS:
break;
default:
return status;
}
progress.current = i;
device_event_emit(abstract, DC_EVENT_PROGRESS, &progress);
}