From 845e6442f6af586e96e5ed58475062ea4a9d0d0d Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 20 Feb 2009 12:11:52 +0000 Subject: [PATCH] Port the Suunto Eon, Vyper, Vyper2 and D9 to the new event code. --- src/suunto_d9.c | 29 ++++++++++++++++++++--------- src/suunto_eon.c | 9 ++++++--- src/suunto_vyper.c | 26 ++++++++++++++++++-------- src/suunto_vyper2.c | 29 ++++++++++++++++++++--------- 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/suunto_d9.c b/src/suunto_d9.c index 52a2446..a3752db 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -304,7 +304,7 @@ suunto_d9_device_reset_maxdepth (device_t *abstract) static device_status_t -suunto_d9_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_state_t *progress) +suunto_d9_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_t *progress) { suunto_d9_device_t *device = (suunto_d9_device_t*) abstract; @@ -341,7 +341,11 @@ suunto_d9_read (device_t *abstract, unsigned int address, unsigned char data[], message("\"\n"); #endif - progress_event (progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + if (progress) { + progress->current += len; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, progress); + } nbytes += len; address += len; @@ -417,8 +421,9 @@ suunto_d9_device_dump (device_t *abstract, unsigned char data[], unsigned int si } // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, SUUNTO_D9_MEMORY_SIZE); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = SUUNTO_D9_MEMORY_SIZE; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); device_status_t rc = suunto_d9_read (abstract, 0x00, data, SUUNTO_D9_MEMORY_SIZE, &progress); if (rc != DEVICE_STATUS_SUCCESS) @@ -438,8 +443,9 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us return DEVICE_STATUS_TYPE_MISMATCH; // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, RB_PROFILE_END - RB_PROFILE_BEGIN + 8); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = RB_PROFILE_END - RB_PROFILE_BEGIN + 8; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Read the header bytes. unsigned char header[8] = {0}; @@ -464,8 +470,11 @@ 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); + // Update and emit a progress event. + + progress.maximum = remaining + 8; + progress.current += 8; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // To reduce the number of read operations, we always try to read // packages with the largest possible size. As a consequence, the @@ -526,7 +535,9 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us return rc; } - progress_event (&progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + progress.current += len; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Next package. nbytes += len; diff --git a/src/suunto_eon.c b/src/suunto_eon.c index ff576b9..76e5b8d 100644 --- a/src/suunto_eon.c +++ b/src/suunto_eon.c @@ -165,8 +165,9 @@ suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int s } // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, SUUNTO_EON_MEMORY_SIZE + 1); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = SUUNTO_EON_MEMORY_SIZE + 1; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Send the command. unsigned char command[1] = {'P'}; @@ -184,7 +185,9 @@ suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int s return EXITCODE (rc); } - progress_event (&progress, DEVICE_EVENT_PROGRESS, sizeof (answer)); + // Update and emit a progress event. + progress.current += sizeof (answer); + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Verify the checksum of the package. unsigned char crc = answer[sizeof (answer) - 1]; diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 17e8e69..934bc51 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -248,7 +248,7 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman static device_status_t -suunto_vyper_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_state_t *progress) +suunto_vyper_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_t *progress) { suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract; @@ -285,7 +285,11 @@ suunto_vyper_read (device_t *abstract, unsigned int address, unsigned char data[ message("\"\n"); #endif - progress_event (progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + if (progress) { + progress->current += len; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, progress); + } nbytes += len; address += len; @@ -361,7 +365,7 @@ suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsig static device_status_t -suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result, int init, device_progress_state_t *progress) +suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result, int init, device_progress_t *progress) { suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract; @@ -456,7 +460,11 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s return DEVICE_STATUS_SUCCESS; } - progress_event (progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + if (progress) { + progress->current += len; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, progress); + } // If a package is smaller than $SUUNTO_VYPER_PACKET_SIZE bytes, // we assume it's the last packet and the transmission can be @@ -508,8 +516,9 @@ suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int } // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, SUUNTO_VYPER_MEMORY_SIZE); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = SUUNTO_VYPER_MEMORY_SIZE; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); device_status_t rc = suunto_vyper_read (abstract, 0x00, data, SUUNTO_VYPER_MEMORY_SIZE, &progress); if (rc != DEVICE_STATUS_SUCCESS) @@ -529,8 +538,9 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void return DEVICE_STATUS_TYPE_MISMATCH; // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, SUUNTO_VYPER_MEMORY_SIZE - 0x4C); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = SUUNTO_VYPER_MEMORY_SIZE - 0x4C; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // The memory layout of the Spyder is different from the Vyper // (and all other compatible dive computers). The Spyder has diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index 97d956c..62e8054 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -291,7 +291,7 @@ suunto_vyper2_device_reset_maxdepth (device_t *abstract) static device_status_t -suunto_vyper2_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_state_t *progress) +suunto_vyper2_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size, device_progress_t *progress) { suunto_vyper2_device_t *device = (suunto_vyper2_device_t*) abstract; @@ -328,7 +328,11 @@ suunto_vyper2_read (device_t *abstract, unsigned int address, unsigned char data message("\"\n"); #endif - progress_event (progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + if (progress) { + progress->current += len; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, progress); + } nbytes += len; address += len; @@ -404,8 +408,9 @@ suunto_vyper2_device_dump (device_t *abstract, unsigned char data[], unsigned in } // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, SUUNTO_VYPER2_MEMORY_SIZE); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = SUUNTO_VYPER2_MEMORY_SIZE; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); device_status_t rc = suunto_vyper2_read (abstract, 0x00, data, SUUNTO_VYPER2_MEMORY_SIZE, &progress); if (rc != DEVICE_STATUS_SUCCESS) @@ -425,8 +430,9 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void return DEVICE_STATUS_TYPE_MISMATCH; // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, RB_PROFILE_END - RB_PROFILE_BEGIN + 8); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = RB_PROFILE_END - RB_PROFILE_BEGIN + 8; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Read the header bytes. unsigned char header[8] = {0}; @@ -451,8 +457,11 @@ 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); + // Update and emit a progress event. + + progress.maximum = remaining + 8; + progress.current += 8; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // To reduce the number of read operations, we always try to read // packages with the largest possible size. As a consequence, the @@ -513,7 +522,9 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void return rc; } - progress_event (&progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + progress.current += len; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Next package. nbytes += len;