From dd847c5cf65b5b88364b77c5c2796806fdf58dd8 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 19 Aug 2008 10:17:13 +0000 Subject: [PATCH] Implemented progress notifications for the Suunto D9 and Vyper2. --- src/suunto_d9.c | 28 ++++++++++++++++++++++++---- src/suunto_vyper2.c | 28 ++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/suunto_d9.c b/src/suunto_d9.c index f374823..db59821 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -263,7 +263,7 @@ suunto_d9_device_reset_maxdepth (device_t *abstract) static device_status_t -suunto_d9_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size) +suunto_d9_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_state_t *progress) { suunto_d9_device_t *device = (suunto_d9_device_t*) abstract; @@ -300,6 +300,8 @@ suunto_d9_device_read (device_t *abstract, unsigned int address, unsigned char d message("\"\n"); #endif + progress_event (progress, DEVICE_EVENT_PROGRESS, len); + nbytes += len; address += len; data += len; @@ -309,6 +311,13 @@ suunto_d9_device_read (device_t *abstract, unsigned int address, unsigned char d } +static device_status_t +suunto_d9_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size) +{ + return suunto_d9_read (abstract, address, data, size, NULL); +} + + static device_status_t suunto_d9_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size) { @@ -364,7 +373,11 @@ suunto_d9_device_dump (device_t *abstract, unsigned char data[], unsigned int si if (size < SUUNTO_D9_MEMORY_SIZE) return DEVICE_STATUS_ERROR; - int rc = suunto_d9_device_read (abstract, 0x00, data, SUUNTO_D9_MEMORY_SIZE); + // Enable progress notifications. + device_progress_state_t progress; + progress_init (&progress, abstract, SUUNTO_D9_MEMORY_SIZE); + + int rc = suunto_d9_read (abstract, 0x00, data, SUUNTO_D9_MEMORY_SIZE, &progress); if (rc != DEVICE_STATUS_SUCCESS) return rc; @@ -378,9 +391,13 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us if (! device_is_suunto_d9 (abstract)) return DEVICE_STATUS_TYPE_MISMATCH; + // Enable progress notifications. + device_progress_state_t progress; + progress_init (&progress, abstract, RB_PROFILE_END - RB_PROFILE_BEGIN + 8); + // Read the header bytes. unsigned char header[8] = {0}; - int rc = suunto_d9_device_read (abstract, 0x0190, header, sizeof (header)); + int rc = suunto_d9_read (abstract, 0x0190, header, sizeof (header), NULL); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory header."); return rc; @@ -401,6 +418,9 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us unsigned int remaining = RB_PROFILE_DISTANCE (begin, end); + progress_set_maximum (&progress, remaining + 8); + progress_event (&progress, DEVICE_EVENT_PROGRESS, 8); + // To reduce the number of read operations, we always try to read // packages with the largest possible size. As a consequence, the // last package of a dive can contain data from more than one dive. @@ -444,7 +464,7 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us // Read the package. unsigned char *p = data + remaining - nbytes; - rc = suunto_d9_device_read (abstract, address - len, p - len, len); + rc = suunto_d9_read (abstract, address - len, p - len, len, &progress); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); return rc; diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index a3e38af..1b9bfef 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -250,7 +250,7 @@ suunto_vyper2_device_reset_maxdepth (device_t *abstract) static device_status_t -suunto_vyper2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size) +suunto_vyper2_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_state_t *progress) { suunto_vyper2_device_t *device = (suunto_vyper2_device_t*) abstract; @@ -287,6 +287,8 @@ suunto_vyper2_device_read (device_t *abstract, unsigned int address, unsigned ch message("\"\n"); #endif + progress_event (progress, DEVICE_EVENT_PROGRESS, len); + nbytes += len; address += len; data += len; @@ -296,6 +298,13 @@ suunto_vyper2_device_read (device_t *abstract, unsigned int address, unsigned ch } +static device_status_t +suunto_vyper2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size) +{ + return suunto_vyper2_read (abstract, address, data, size, NULL); +} + + static device_status_t suunto_vyper2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size) { @@ -351,7 +360,11 @@ suunto_vyper2_device_dump (device_t *abstract, unsigned char data[], unsigned in if (size < SUUNTO_VYPER2_MEMORY_SIZE) return DEVICE_STATUS_ERROR; - int rc = suunto_vyper2_device_read (abstract, 0x00, data, SUUNTO_VYPER2_MEMORY_SIZE); + // Enable progress notifications. + device_progress_state_t progress; + progress_init (&progress, abstract, SUUNTO_VYPER2_MEMORY_SIZE); + + int rc = suunto_vyper2_read (abstract, 0x00, data, SUUNTO_VYPER2_MEMORY_SIZE, &progress); if (rc != DEVICE_STATUS_SUCCESS) return rc; @@ -365,9 +378,13 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void if (! device_is_suunto_vyper2 (abstract)) return DEVICE_STATUS_TYPE_MISMATCH; + // Enable progress notifications. + device_progress_state_t progress; + progress_init (&progress, abstract, RB_PROFILE_END - RB_PROFILE_BEGIN + 8); + // Read the header bytes. unsigned char header[8] = {0}; - int rc = suunto_vyper2_device_read (abstract, 0x0190, header, sizeof (header)); + int rc = suunto_vyper2_read (abstract, 0x0190, header, sizeof (header), NULL); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory header."); return rc; @@ -388,6 +405,9 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void unsigned int remaining = RB_PROFILE_DISTANCE (begin, end); + progress_set_maximum (&progress, remaining + 8); + progress_event (&progress, DEVICE_EVENT_PROGRESS, 8); + // To reduce the number of read operations, we always try to read // packages with the largest possible size. As a consequence, the // last package of a dive can contain data from more than one dive. @@ -431,7 +451,7 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void // Read the package. unsigned char *p = data + remaining - nbytes; - rc = suunto_vyper2_device_read (abstract, address - len, p - len, len); + rc = suunto_vyper2_read (abstract, address - len, p - len, len, &progress); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); return rc;