From c622998fb1c813fb91cec3e812f86a29a467f229 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 9 Dec 2018 10:43:40 +0100 Subject: [PATCH] Fix the Cobalt 2 memory size The Cobalt 2 has a bit more flash memory available for storing dives compared to the original Cobalt 1. This larger amount of memory can cause the progress events to exceed past 100% if there are many dives present. This will trigger the assert in the event code and crash the application. --- src/atomics_cobalt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/atomics_cobalt.c b/src/atomics_cobalt.c index 21d5896..e907b77 100644 --- a/src/atomics_cobalt.c +++ b/src/atomics_cobalt.c @@ -43,13 +43,17 @@ #define EXITCODE(rc) (rc == LIBUSB_ERROR_TIMEOUT ? DC_STATUS_TIMEOUT : DC_STATUS_IO) +#define COBALT1 0 +#define COBALT2 2 + #define VID 0x0471 #define PID 0x0888 #define TIMEOUT 2000 #define FP_OFFSET 20 -#define SZ_MEMORY (29 * 64 * 1024) +#define SZ_MEMORY1 (29 * 64 * 1024) // Cobalt 1 +#define SZ_MEMORY2 (41 * 64 * 1024) // Cobalt 2 #define SZ_VERSION 14 typedef struct atomics_cobalt_device_t { @@ -350,9 +354,12 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac { atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract; + // Get the model number. + unsigned int model = array_uint16_le (device->version + 12); + // Enable progress notifications. dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; - progress.maximum = SZ_MEMORY + 2; + progress.maximum = (model == COBALT2 ? SZ_MEMORY2 : SZ_MEMORY1) + 2; device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); // Emit a vendor event.