adding support for slower devices

This commit is contained in:
Felix 2025-05-22 21:46:39 +02:00 committed by Xelef2000
parent 181e068751
commit 01b9e19c40

View file

@ -320,7 +320,8 @@
const char *context, GError **error) {
struct crfpmoc_ec_params_fp_context_v1 p;
gboolean rv = FALSE;
gint tries = 20; // Wait at most 2 seconds (20 * 100ms)
gint tries = 40;
const guint base_sleep_us = 80000; // 80ms
fp_dbg("Setting context to '%s'", context);
@ -338,30 +339,47 @@
if (!rv) {
g_prefix_error(error, "Initiating context setting failed: ");
fp_dbg("Initiating context setting failed. Error: %s", (*error)->message);
fp_warn("Initiating context setting failed. Error: %s", (*error)->message);
return FALSE;
}
for (int i = 0; i < tries; i++) {
g_usleep(80000); // Sleep for 80ms
guint sleep_us;
if (i < 10) {
sleep_us = base_sleep_us;
} else if (i < 20) {
// Linear increase from 80ms to 800ms
double factor = 1.0 + 9.0 * (i - 10) / 9.0;
sleep_us = (guint)(base_sleep_us * factor);
} else {
sleep_us = base_sleep_us * 10;
}
if (i >= 10) {
fp_warn("Context setting is taking longer than expected. Attempt %d of %d",
(i + 1), tries);
}
g_usleep(sleep_us);
p.action = CRFPMOC_FP_CONTEXT_GET_RESULT;
rv = crfpmoc_ec_command(self, CRFPMOC_EC_CMD_FP_CONTEXT, 1, &p, sizeof(p),
NULL, 0, error);
if (rv) {
fp_dbg("Context set successfully.");
fp_dbg("Context set successfully.");
return TRUE;
}
if (strcmp((*error)->message, "BUSY") != 0) {
g_prefix_error(error, "Setting context failed: ");
fp_dbg("Setting context failed. Error: %s", (*error)->message);
fp_warn("Setting context failed. Error: %s", (*error)->message);
return FALSE;
}
fp_dbg("Context setting is still in progress. Attempt %d of %d", (i + 1),
tries);
tries);
g_clear_error(error);
*error = NULL;
}