From db3bee9b75ca6ebd8b5cda516004b5edefdd63de Mon Sep 17 00:00:00 2001 From: Lutz Mueller Date: Tue, 28 Nov 2000 21:30:15 +0000 Subject: [PATCH] Enhanced error reporting. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@1352 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/konica/konica.c | 1044 ++++++++++++++++--------------------- camlibs/konica/konica.h | 91 +--- camlibs/konica/library.c | 596 +++++++++------------ camlibs/konica/library.h | 40 +- camlibs/konica/lowlevel.c | 214 ++++---- camlibs/konica/lowlevel.h | 44 +- 6 files changed, 889 insertions(+), 1140 deletions(-) diff --git a/camlibs/konica/konica.c b/camlibs/konica/konica.c index 6cbd01fa5..efe4d9dd9 100644 --- a/camlibs/konica/konica.c +++ b/camlibs/konica/konica.c @@ -10,6 +10,7 @@ #include #include #include +#include "library.h" #include "lowlevel.h" #include "konica.h" @@ -17,85 +18,70 @@ /**************/ /* Prototypes */ /**************/ -k_return_status_t K_RETURN_STATUS (l_return_status_t l_return_status); - - -k_return_status_t return_status_translation (guchar byte1, guchar byte2); +gint GP_RESULT (guchar byte1, guchar byte2); /*************/ /* Functions */ /*************/ -k_return_status_t K_RETURN_STATUS (l_return_status_t l_return_status) -{ - switch (l_return_status) { - case L_IO_ERROR: - return (K_L_IO_ERROR); - case L_TRANSMISSION_ERROR: - return (K_L_TRANSMISSION_ERROR); - default: - return (K_SUCCESS); - } -} - - -k_return_status_t return_status_translation (guchar byte1, guchar byte2) +gint +GP_RESULT (guchar byte1, guchar byte2) { gchar buffer[1024]; switch ((byte2 << 8 ) | byte1) { case 0x0000: - return (K_SUCCESS); + return (GP_OK); case 0x0101: - return (K_ERROR_FOCUSING_ERROR); + return (KONICA_ERROR_FOCUSING_ERROR); case 0x0102: - return (K_ERROR_IRIS_ERROR); + return (KONICA_ERROR_IRIS_ERROR); case 0x0201: - return (K_ERROR_STROBE_ERROR); + return (KONICA_ERROR_STROBE_ERROR); case 0x0203: - return (K_ERROR_EEPROM_CHECKSUM_ERROR); + return (KONICA_ERROR_EEPROM_CHECKSUM_ERROR); case 0x0205: - return (K_ERROR_INTERNAL_ERROR1); + return (KONICA_ERROR_INTERNAL_ERROR1); case 0x0206: - return (K_ERROR_INTERNAL_ERROR2); + return (KONICA_ERROR_INTERNAL_ERROR2); case 0x0301: - return (K_ERROR_NO_CARD_PRESENT); + return (KONICA_ERROR_NO_CARD_PRESENT); case 0x0311: - return (K_ERROR_CARD_NOT_SUPPORTED); + return (KONICA_ERROR_CARD_NOT_SUPPORTED); case 0x0321: - return (K_ERROR_CARD_REMOVED_DURING_ACCESS); + return (KONICA_ERROR_CARD_REMOVED_DURING_ACCESS); case 0x0340: - return (K_ERROR_IMAGE_NUMBER_NOT_VALID); + return (KONICA_ERROR_IMAGE_NUMBER_NOT_VALID); case 0x0341: - return (K_ERROR_CARD_CAN_NOT_BE_WRITTEN); + return (KONICA_ERROR_CARD_CAN_NOT_BE_WRITTEN); case 0x0381: - return (K_ERROR_CARD_IS_WRITE_PROTECTED); + return (KONICA_ERROR_CARD_IS_WRITE_PROTECTED); case 0x0382: - return (K_ERROR_NO_SPACE_LEFT_ON_CARD); + return (KONICA_ERROR_NO_SPACE_LEFT_ON_CARD); case 0x0390: - return (K_ERROR_NO_PICTURE_ERASED_AS_IMAGE_PROTECTED); + return (KONICA_ERROR_NO_IMAGE_ERASED_AS_IMAGE_PROTECTED); case 0x0401: - return (K_ERROR_LIGHT_TOO_DARK); + return (KONICA_ERROR_LIGHT_TOO_DARK); case 0x0402: - return (K_ERROR_AUTOFOCUS_ERROR); + return (KONICA_ERROR_AUTOFOCUS_ERROR); case 0x0501: - return (K_ERROR_SYSTEM_ERROR); + return (KONICA_ERROR_SYSTEM_ERROR); case 0x0800: - return (K_ERROR_ILLEGAL_PARAMETER); + return (KONICA_ERROR_ILLEGAL_PARAMETER); case 0x0801: - return (K_ERROR_COMMAND_CANNOT_BE_CANCELLED); + return (KONICA_ERROR_COMMAND_CANNOT_BE_CANCELLED); case 0x0b00: - return (K_ERROR_LOCALIZATION_DATA_EXCESS); + return (KONICA_ERROR_LOCALIZATION_DATA_EXCESS); case 0x0bff: - return (K_ERROR_LOCALIZATION_DATA_CORRUPT); + return (KONICA_ERROR_LOCALIZATION_DATA_CORRUPT); case 0x0c01: - return (K_ERROR_UNSUPPORTED_COMMAND); + return (KONICA_ERROR_UNSUPPORTED_COMMAND); case 0x0c02: - return (K_ERROR_OTHER_COMMAND_EXECUTING); + return (KONICA_ERROR_OTHER_COMMAND_EXECUTING); case 0x0c03: - return (K_ERROR_COMMAND_ORDER_ERROR); + return (KONICA_ERROR_COMMAND_ORDER_ERROR); case 0x0fff: - return (K_ERROR_UNKNOWN_ERROR); + return (KONICA_ERROR_UNKNOWN_ERROR); default: sprintf ( buffer, @@ -109,24 +95,27 @@ k_return_status_t return_status_translation (guchar byte1, guchar byte2) byte1, byte2); gp_frontend_message (NULL, buffer); - return (K_PROGRAM_ERROR); + return (GP_ERROR); } } -k_return_status_t k_init (gpio_device *device) +gint +k_init (gpio_device* device) { - return (K_RETURN_STATUS (l_init (device))); + return (l_init (device)); } -k_return_status_t k_exit (gpio_device *device) +gint +k_exit (gpio_device* device) { - return (K_RETURN_STATUS (l_exit (device))); + return (l_exit (device)); } -k_return_status_t k_erase_image (gpio_device *device, gboolean image_id_long, gulong image_id) +gint +k_erase_image (gpio_device* device, gboolean image_id_long, gulong image_id) { /************************************************/ /* Command to erase one image. */ @@ -152,35 +141,29 @@ k_return_status_t k_erase_image (gpio_device *device, gboolean image_id_long, gu /************************************************/ guchar sb[] = {0x00, 0x80, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); if (!image_id_long) { sb[6] = image_id; sb[7] = image_id >> 8; - l_return_status = l_send_receive (device, sb, 8, &rb, &rbs); + result = l_send_receive (device, sb, 8, &rb, &rbs); } else { sb[6] = image_id >> 16; sb[7] = image_id >> 24; sb[8] = image_id; sb[9] = image_id >> 8; - l_return_status = l_send_receive (device, sb, 10, &rb, &rbs); - } - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return k_return_status; + result = l_send_receive (device, sb, 10, &rb, &rbs); } + if (result == GP_OK) result = GP_RESULT (rb [2], rb [3]); + g_free (rb); + return (result); } -k_return_status_t k_format_memory_card (gpio_device *device) +gint +k_format_memory_card (gpio_device* device) { /************************************************/ /* Command to format the memory card. */ @@ -200,25 +183,19 @@ k_return_status_t k_format_memory_card (gpio_device *device) /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x10, 0x80, 0x00, 0x00, 0x02, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x10, 0x80, 0x00, 0x00, 0x02, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - l_return_status = l_send_receive (device, sb, 6, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return k_return_status; - } + result = l_send_receive (device, sb, 6, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_erase_all (gpio_device *device, guint *number_of_images_not_erased) +gint k_erase_all (gpio_device* device, guint* number_of_images_not_erased) { /************************************************/ /* Command to erase all images in the camera, */ @@ -242,30 +219,24 @@ k_return_status_t k_erase_all (gpio_device *device, guint *number_of_images_not_ /* 0xXX: Byte 0 of number of images not erased */ /* 0xXX: Byte 1 of number of images not erased */ /************************************************/ - unsigned char sb[] = {0x20, 0x80, 0x00, 0x00, 0x02, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x20, 0x80, 0x00, 0x00, 0x02, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (number_of_images_not_erased != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (number_of_images_not_erased, GP_ERROR_BAD_PARAMETERS); - l_return_status = l_send_receive (device, sb, 6, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) - *number_of_images_not_erased = (rb[5] << 8) | rb[4]; - g_free (rb); - return k_return_status; + result = l_send_receive (device, sb, 6, &rb, &rbs); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) *number_of_images_not_erased = (rb[5] << 8) | rb[4]; } + g_free (rb); + return (result); } -k_return_status_t k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected) +gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected) { /************************************************/ /* Command to set the protect status of one */ @@ -294,45 +265,39 @@ k_return_status_t k_set_protect_status (gpio_device *device, gboolean image_id_l /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x30, 0x80, 0x00, 0x00, 0x02, 0x00, + guchar sb[] = {0x30, 0x80, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); if (!image_id_long) { if (protected) sb[8] = 0x01; sb[6] = image_id; sb[7] = image_id >> 8; - l_return_status = l_send_receive (device, sb, 10, &rb, &rbs); + result = l_send_receive (device, sb, 10, &rb, &rbs); } else { if (protected) sb[10] = 0x01; sb[6] = image_id >> 16; sb[7] = image_id >> 24; sb[8] = image_id; sb[9] = image_id >> 8; - l_return_status = l_send_receive (device, sb, 12, &rb, &rbs); - } - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return k_return_status; + result = l_send_receive (device, sb, 12, &rb, &rbs); } + if (result == GP_OK) result = GP_RESULT (rb [2], rb [3]); + g_free (rb); + return (result); } -k_return_status_t k_get_image ( - gpio_device *device, - gboolean image_id_long, - gulong image_id, - k_image_type_t image_type, - guchar **image_buffer, - guint *image_buffer_size) +gint +k_get_image ( + gpio_device* device, + gboolean image_id_long, + gulong image_id, + k_image_type_t image_type, + guchar** image_buffer, + guint* image_buffer_size) { /************************************************/ /* Commands to get an image from the camera. */ @@ -367,15 +332,13 @@ k_return_status_t k_get_image ( /************************************************/ guchar sb[] = {0x00, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; + gint result; guchar *rb = NULL; guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (image_buffer != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*image_buffer == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (image_buffer_size != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (image_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*image_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (image_buffer_size, GP_ERROR_BAD_PARAMETERS); switch (image_type) { case K_THUMBNAIL: @@ -391,34 +354,30 @@ k_return_status_t k_get_image ( if (!image_id_long) { sb[6] = image_id; sb[7] = image_id >> 8; - l_return_status = l_send_receive_receive (device, sb, 8, image_buffer, image_buffer_size, &rb, &rbs, 2000); + result = l_send_receive_receive (device, sb, 8, image_buffer, image_buffer_size, &rb, &rbs, 5000); } else { sb[6] = image_id >> 16; sb[7] = image_id >> 24; sb[8] = image_id; sb[9] = image_id >> 8; - l_return_status = l_send_receive_receive (device, sb, 10, image_buffer, image_buffer_size, &rb, &rbs, 2000); - } - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return (k_return_status); + result = l_send_receive_receive (device, sb, 10, image_buffer, image_buffer_size, &rb, &rbs, 5000); } + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_get_image_information ( - gpio_device *device, - gboolean image_id_long, - gulong image_number, - gulong *image_id, - guint *exif_size, - gboolean *protected, - guchar **information_buffer, - guint *information_buffer_size) +gint +k_get_image_information ( + gpio_device* device, + gboolean image_id_long, + gulong image_number, + gulong* image_id, + guint* exif_size, + gboolean* protected, + guchar** information_buffer, + guint* information_buffer_size) { /************************************************/ /* Command to get the information about an */ @@ -457,53 +416,52 @@ k_return_status_t k_get_image_information ( /* 0x01: protected */ /* 0x00: Byte 1 of protect status */ /************************************************/ - guchar sb[] = {0x20, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x20, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (image_id != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (exif_size != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (protected != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (information_buffer != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*information_buffer == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (information_buffer_size != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (image_id, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (exif_size, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (protected, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (information_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*information_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (information_buffer_size, GP_ERROR_BAD_PARAMETERS); if (!image_id_long) { sb[6] = image_number; sb[7] = image_number >> 8; - l_return_status = l_send_receive_receive (device, sb, 8, information_buffer, information_buffer_size, &rb, &rbs, 1000); - if (l_return_status != L_SUCCESS) - return K_RETURN_STATUS (l_return_status); - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { - *image_id = (gulong) ((rb[5] << 8) | rb[4]); - *exif_size = (rb[7] << 8) | rb[6]; - *protected = (rb[8] != 0x00); + result = l_send_receive_receive (device, sb, 8, information_buffer, information_buffer_size, &rb, &rbs, 1000); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { + *image_id = (gulong) ((rb[5] << 8) | rb[4]); + *exif_size = (rb[7] << 8) | rb[6]; + *protected = (rb[8] != 0x00); + } } } else { sb[6] = image_number >> 16; sb[7] = image_number >> 24; sb[8] = image_number; sb[9] = image_number >> 8; - l_return_status = l_send_receive_receive (device, sb, 10, information_buffer, information_buffer_size, &rb, &rbs, 1000); - if (l_return_status != L_SUCCESS) - return K_RETURN_STATUS (l_return_status); - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { - *image_id = (rb[5] << 24) | (rb[4] << 16) | (rb[7] << 8) | rb[6]; - *exif_size = (rb[9] << 8) | rb[8]; - *protected = (rb[10] != 0x00); + result = l_send_receive_receive (device, sb, 10, information_buffer, information_buffer_size, &rb, &rbs, 1000); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { + *image_id = (rb[5] << 24) | (rb[4] << 16) | (rb[7] << 8) | rb[6]; + *exif_size = (rb[9] << 8) | rb[8]; + *protected = (rb[10] != 0x00); + } } } g_free (rb); - return (k_return_status); + return (result); } -k_return_status_t k_get_preview (gpio_device *device, gboolean thumbnail, guchar **image_buffer, guint *image_buffer_size) +gint +k_get_preview (gpio_device* device, gboolean thumbnail, guchar** image_buffer, guint* image_buffer_size) { /************************************************/ /* Command to get the preview from the camera. */ @@ -526,46 +484,40 @@ k_return_status_t k_get_preview (gpio_device *device, gboolean thumbnail, guchar /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x40, 0x88, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x40, 0x88, 0x00, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (image_buffer != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*image_buffer == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (image_buffer_size != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (image_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*image_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (image_buffer_size, GP_ERROR_BAD_PARAMETERS); + if (thumbnail) sb[4] = 0x01; - l_return_status = l_send_receive_receive (device, sb, 6, image_buffer, image_buffer_size, &rb, &rbs, 5000); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return k_return_status; - } + result = l_send_receive_receive (device, sb, 6, image_buffer, image_buffer_size, &rb, &rbs, 5000); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_get_io_capability ( - gpio_device *device, - gboolean *bit_rate_300, - gboolean *bit_rate_600, - gboolean *bit_rate_1200, - gboolean *bit_rate_2400, - gboolean *bit_rate_4800, - gboolean *bit_rate_9600, - gboolean *bit_rate_19200, - gboolean *bit_rate_38400, - gboolean *bit_rate_57600, - gboolean *bit_rate_115200, - gboolean *bit_flag_8_bits, - gboolean *bit_flag_stop_2_bits, - gboolean *bit_flag_parity_on, - gboolean *bit_flag_parity_odd, - gboolean *bit_flag_hw_flow_control) +gint k_get_io_capability ( + gpio_device* device, + gboolean* bit_rate_300, + gboolean* bit_rate_600, + gboolean* bit_rate_1200, + gboolean* bit_rate_2400, + gboolean* bit_rate_4800, + gboolean* bit_rate_9600, + gboolean* bit_rate_19200, + gboolean* bit_rate_38400, + gboolean* bit_rate_57600, + gboolean* bit_rate_115200, + gboolean* bit_flag_8_bits, + gboolean* bit_flag_stop_2_bits, + gboolean* bit_flag_parity_on, + gboolean* bit_flag_parity_odd, + gboolean* bit_flag_hw_flow_control) { /************************************************/ /* Command to get the IO capability from the */ @@ -587,35 +539,31 @@ k_return_status_t k_get_io_capability ( /* 0xXX: Byte 0 of supported flags */ /* 0xXX: Byte 1 of supported flags */ /************************************************/ - guchar sb[] = {0x00, 0x90, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x00, 0x90, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_300 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_600 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_1200 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_2400 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_4800 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_9600 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_19200 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_38400 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_57600 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_rate_115200 != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_flag_8_bits != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_flag_stop_2_bits != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_flag_parity_on != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_flag_parity_odd != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (bit_flag_hw_flow_control != NULL, K_PROGRAM_ERROR); - l_return_status = (l_send_receive (device, sb, 4, &rb, &rbs)); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { + g_return_val_if_fail (bit_rate_300, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_600, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_1200, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_2400, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_4800, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_9600, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_19200, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_38400, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_57600, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_rate_115200, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_flag_8_bits, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_flag_stop_2_bits, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_flag_parity_on, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_flag_parity_odd, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (bit_flag_hw_flow_control, GP_ERROR_BAD_PARAMETERS); + + result = (l_send_receive (device, sb, 4, &rb, &rbs)); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { *bit_rate_300 = ((rb[4] ^ (1 << 0)) && ~rb[4]); *bit_rate_600 = ((rb[4] ^ (1 << 1)) && ~rb[4]); *bit_rate_1200 = ((rb[4] ^ (1 << 2)) && ~rb[4]); @@ -632,24 +580,25 @@ k_return_status_t k_get_io_capability ( *bit_flag_parity_odd = ((rb[6] ^ (1 << 3)) && ~rb[6]); *bit_flag_hw_flow_control= ((rb[6] ^ (1 << 4)) && ~rb[6]); } - g_free (rb); - return k_return_status; } + g_free (rb); + return result; } -k_return_status_t k_get_information ( - gpio_device *device, - gchar **model, - gchar **serial_number, - guchar *hardware_version_major, - guchar *hardware_version_minor, - guchar *software_version_major, - guchar *software_version_minor, - guchar *testing_software_version_major, - guchar *testing_software_version_minor, - gchar **name, - gchar **manufacturer) +gint +k_get_information ( + gpio_device* device, + gchar** model, + gchar** serial_number, + guchar* hardware_version_major, + guchar* hardware_version_minor, + guchar* software_version_major, + guchar* software_version_minor, + guchar* testing_software_version_major, + guchar* testing_software_version_minor, + gchar** name, + gchar** manufacturer) { /************************************************/ /* Command to get some information about the */ @@ -747,35 +696,31 @@ k_return_status_t k_get_information ( /* 0xXX: Byte 28 of manufacturer */ /* 0xXX: Byte 29 of manufacturer */ /************************************************/ - guchar sb[] = {0x10, 0x90, 0x00, 0x00}; - guint i, j; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x10, 0x90, 0x00, 0x00}; + guint i, j; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (model != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*model == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (serial_number != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*serial_number == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (hardware_version_major != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (hardware_version_minor != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (software_version_major != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (software_version_minor != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (testing_software_version_major != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (testing_software_version_minor != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (name != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*name == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (manufacturer != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*manufacturer == NULL, K_PROGRAM_ERROR); - l_return_status = l_send_receive (device, sb, 4, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { + g_return_val_if_fail (model, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*model, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (serial_number, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*serial_number, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (hardware_version_major, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (hardware_version_minor, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (software_version_major, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (software_version_minor, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (testing_software_version_major, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (testing_software_version_minor, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (name, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*name, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (manufacturer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*manufacturer, GP_ERROR_BAD_PARAMETERS); + + result = l_send_receive (device, sb, 4, &rb, &rbs); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { /****************/ /* Model */ /****************/ @@ -811,36 +756,37 @@ k_return_status_t k_get_information ( *manufacturer = g_new0 (gchar, i + 1); for (j = 0; j < i; j++) (*manufacturer)[j] = rb[50 + j]; } - g_free (rb); - return k_return_status; } + g_free (rb); + return result; } -k_return_status_t k_get_status ( - gpio_device *device, - guint *self_test_result, - k_power_level_t *power_level, - k_power_source_t *power_source, - k_card_status_t *card_status, - k_display_t *display, - guint *card_size, - guint *pictures, - guint *pictures_left, - guchar *year, - guchar *month, - guchar *day, - guchar *hour, - guchar *minute, - guchar *second, - guint *io_setting_bit_rate, - guint *io_setting_flags, - guchar *flash, - guchar *resolution, - guchar *focus, - guchar *exposure, - guint *total_pictures, - guint *total_strobes) +gint +k_get_status ( + gpio_device* device, + guint* self_test_result, + k_power_level_t* power_level, + k_power_source_t* power_source, + k_card_status_t* card_status, + k_display_t* display, + guint* card_size, + guint* pictures, + guint* pictures_left, + guchar* year, + guchar* month, + guchar* day, + guchar* hour, + guchar* minute, + guchar* second, + guint* io_setting_bit_rate, + guint* io_setting_flags, + guchar* flash, + guchar* resolution, + guchar* focus, + guchar* exposure, + guint* total_pictures, + guint* total_strobes) { /************************************************/ /* Command to get the status of the camera. */ @@ -902,43 +848,38 @@ k_return_status_t k_get_status ( /* 0xXX: Byte 0 of total strobes */ /* 0xXX: Byte 1 of total strobes */ /************************************************/ - guchar sb[] = {0x20, 0x90, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x20, 0x90, 0x00, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (self_test_result != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (power_level != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (power_source != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (card_status != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (display != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (card_size != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (pictures != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (pictures_left != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (year != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (month != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (day != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (hour != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (minute != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (second != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (io_setting_bit_rate != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (io_setting_flags != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (flash != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (resolution != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (focus != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (exposure != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (total_pictures != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (total_strobes != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (self_test_result, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (power_level, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (power_source, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (card_status, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (display, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (card_size, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (pictures, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (pictures_left, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (year, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (month, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (day, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (hour, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (minute, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (second, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (io_setting_bit_rate, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (io_setting_flags, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (flash, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (resolution, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (focus, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (exposure, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (total_pictures, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (total_strobes, GP_ERROR_BAD_PARAMETERS); - l_return_status = l_send_receive (device, sb, 6, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { + result = l_send_receive (device, sb, 6, &rb, &rbs); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { *self_test_result = (rb[5] << 8) | rb[4]; switch (rb[6]) { case 0x00: @@ -1005,20 +946,21 @@ k_return_status_t k_get_status ( *total_pictures = (rb[31] << 8) | rb[30]; *total_strobes = (rb[33] << 8) | rb[32]; } - g_free (rb); - return (k_return_status); } + g_free (rb); + return (result); } -k_return_status_t k_get_date_and_time ( - gpio_device *device, - guchar *year, - guchar *month, - guchar *day, - guchar *hour, - guchar *minute, - guchar *second) +gint +k_get_date_and_time ( + gpio_device* device, + guchar* year, + guchar* month, + guchar* day, + guchar* hour, + guchar* minute, + guchar* second) { /************************************************/ /* Command to get the date and time from the */ @@ -1042,27 +984,22 @@ k_return_status_t k_get_date_and_time ( /* 0xXX: Minute */ /* 0xXX: Second */ /************************************************/ - guchar sb[] = {0x30, 0x90, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x30, 0x90, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (year != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (month != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (day != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (hour != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (minute != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (second != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (year, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (month, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (day, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (hour, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (minute, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (second, GP_ERROR_BAD_PARAMETERS); - l_return_status = l_send_receive (device, sb, 4, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { + result = l_send_receive (device, sb, 4, &rb, &rbs); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { *year = rb[4]; *month = rb[5]; *day = rb[6]; @@ -1070,18 +1007,19 @@ k_return_status_t k_get_date_and_time ( *minute = rb[8]; *second = rb[9]; } - g_free (rb); - return (k_return_status); } + g_free (rb); + return (result); }; -k_return_status_t k_get_preferences ( - gpio_device *device, - guint *shutoff_time, - guint *self_timer_time, - guint *beep, - guint *slide_show_interval) +gint +k_get_preferences ( + gpio_device* device, + guint* shutoff_time, + guint* self_timer_time, + guint* beep, + guint* slide_show_interval) { /************************************************/ /* Command to get the preferences from the */ @@ -1107,43 +1045,40 @@ k_return_status_t k_get_preferences ( /* 0xXX: Byte 0 of slide show interval */ /* 0xXX: Byte 1 of slide show interval */ /************************************************/ - unsigned char sb[] = {0x40, 0x90, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x40, 0x90, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (shutoff_time != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (self_timer_time != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (beep != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (slide_show_interval != NULL, K_PROGRAM_ERROR); - l_return_status = l_send_receive (device, sb, 4, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { + g_return_val_if_fail (shutoff_time, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (self_timer_time, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (beep, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (slide_show_interval, GP_ERROR_BAD_PARAMETERS); + + result = l_send_receive (device, sb, 4, &rb, &rbs); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { *shutoff_time = rb[4]; *self_timer_time = rb[5]; *beep = rb[6]; *slide_show_interval = rb[7]; } - g_free (rb); - return k_return_status; } + g_free (rb); + return (result); } -k_return_status_t k_set_io_capability ( - gpio_device *device, - guint bit_rate, - gboolean bit_flag_7_or_8_bits, - gboolean bit_flag_stop_2_bits, - gboolean bit_flag_parity_on, - gboolean bit_flag_parity_odd, - gboolean bit_flag_use_hw_flow_control) +gint +k_set_io_capability ( + gpio_device* device, + guint bit_rate, + gboolean bit_flag_7_or_8_bits, + gboolean bit_flag_stop_2_bits, + gboolean bit_flag_parity_on, + gboolean bit_flag_parity_odd, + gboolean bit_flag_use_hw_flow_control) { /************************************************/ /* Command to set the IO capability of the */ @@ -1164,13 +1099,11 @@ k_return_status_t k_set_io_capability ( /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x80, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x80, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); switch (bit_rate) { case 300: sb[4] = (1 << 0); @@ -1203,31 +1136,19 @@ k_return_status_t k_set_io_capability ( sb[5] = (1 << 1); break; default: - return (K_UNSUPPORTED_BITRATE); + return (GP_ERROR); break; } - sb[6] = (bit_flag_7_or_8_bits | (bit_flag_stop_2_bits << 1) | (bit_flag_parity_on << 2) | (bit_flag_parity_odd << 3) | - (bit_flag_use_hw_flow_control << 4)); - l_return_status = l_send_receive (device, sb, 8, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return k_return_status; - } + sb[6] = (bit_flag_7_or_8_bits | (bit_flag_stop_2_bits << 1) | (bit_flag_parity_on << 2) | (bit_flag_parity_odd << 3) | (bit_flag_use_hw_flow_control << 4)); + result = l_send_receive (device, sb, 8, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_set_date_and_time ( - gpio_device *device, - guchar year, - guchar month, - guchar day, - guchar hour, - guchar minute, - guchar second) +gint +k_set_date_and_time (gpio_device* device, guchar year, guchar month, guchar day, guchar hour, guchar minute, guchar second) { /************************************************/ /* Command to set date and time of the camera. */ @@ -1249,12 +1170,10 @@ k_return_status_t k_set_date_and_time ( /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0xb0, 0x90, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0xb0, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; sb[4] = year; sb[5] = month; @@ -1262,21 +1181,15 @@ k_return_status_t k_set_date_and_time ( sb[7] = hour; sb[8] = minute; sb[9] = second; - l_return_status = l_send_receive (device, sb, 10, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return k_return_status; - } + result = l_send_receive (device, sb, 10, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_set_preference ( - gpio_device *device, - k_preference_t preference, guint value) +gint +k_set_preference (gpio_device* device, k_preference_t preference, guint value) { /************************************************/ /* Command to set a preference of the camera. */ @@ -1294,13 +1207,11 @@ k_return_status_t k_set_preference ( /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0xc0, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0xc0, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); switch (preference) { case K_PREFERENCE_RESOLUTION: sb[4] = 0x00; @@ -1336,19 +1247,15 @@ k_return_status_t k_set_preference ( } sb[6] = value; sb[7] = value >> 8; - l_return_status = l_send_receive (device, sb, 8, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return (k_return_status); - } + result = l_send_receive (device, sb, 8, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_reset_preferences (gpio_device *device) +gint +k_reset_preferences (gpio_device* device) { /************************************************/ /* Command to reset the preferences of the */ @@ -1365,33 +1272,27 @@ k_return_status_t k_reset_preferences (gpio_device *device) /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0xc1, 0x90, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0xc1, 0x90, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - l_return_status = l_send_receive (device, sb, 4, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - g_free (rb); - return (k_return_status); - } + result = l_send_receive (device, sb, 4, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); + return (result); } -k_return_status_t k_take_picture ( - gpio_device *device, - gboolean image_id_long, - gulong *image_id, - guint *exif_size, - unsigned char **information_buffer, - unsigned int *information_buffer_size, - gboolean *protected) +gint +k_take_picture ( + gpio_device* device, + gboolean image_id_long, + gulong* image_id, + guint* exif_size, + guchar** information_buffer, + guint* information_buffer_size, + gboolean* protected) { /************************************************/ /* Command to take a picture. */ @@ -1423,26 +1324,22 @@ k_return_status_t k_take_picture ( /* 0x01: protected */ /* 0x00: Byte 1 of protect status */ /************************************************/ - guchar sb[] = {0x00, 0x91, 0x00, 0x00, 0x02, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x00, 0x91, 0x00, 0x00, 0x02, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (image_id != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (exif_size != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (protected != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (information_buffer != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (*information_buffer == NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (information_buffer_size != NULL, K_PROGRAM_ERROR); - l_return_status = l_send_receive_receive (device, sb, 6, information_buffer, information_buffer_size, &rb, &rbs, 60000); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) { + g_return_val_if_fail (image_id, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (exif_size, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (protected, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (information_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*information_buffer, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (information_buffer_size, GP_ERROR_BAD_PARAMETERS); + + result = l_send_receive_receive (device, sb, 6, information_buffer, information_buffer_size, &rb, &rbs, 60000); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) { if (!image_id_long) { *image_id = 0x00 | 0x00 | (rb[5] << 8) | rb[4]; *exif_size = (rb[7] << 8) | rb[6]; @@ -1453,13 +1350,14 @@ k_return_status_t k_take_picture ( *protected = (rb[10] != 0x00); } } - g_free (rb); - return (k_return_status); - } + } + g_free (rb); + return (result); } -k_return_status_t k_localization_tv_output_format_set (gpio_device *device, k_tv_output_format_t tv_output_format) +gint +k_localization_tv_output_format_set (gpio_device* device, k_tv_output_format_t tv_output_format) { /************************************************/ /* Command for various localization issues. */ @@ -1488,13 +1386,11 @@ k_return_status_t k_localization_tv_output_format_set (gpio_device *device, k_tv /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x00, 0x92, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x00, 0x92, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); switch (tv_output_format) { case K_TV_OUTPUT_FORMAT_NTSC: sb[6] = 0x00; @@ -1506,20 +1402,17 @@ k_return_status_t k_localization_tv_output_format_set (gpio_device *device, k_tv sb[6] = 0x02; break; default: - return (K_PROGRAM_ERROR); + return (GP_ERROR_BAD_PARAMETERS); } - l_return_status = l_send_receive (device, sb, 8, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } - k_return_status = return_status_translation (rb[2], rb[3]); + result = l_send_receive (device, sb, 8, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); g_free (rb); - return (k_return_status); + return (result); } -k_return_status_t k_localization_date_format_set (gpio_device *device, k_date_format_t date_format) +gint +k_localization_date_format_set (gpio_device* device, k_date_format_t date_format) { /************************************************/ /* Command for various localization issues. */ @@ -1548,13 +1441,11 @@ k_return_status_t k_localization_date_format_set (gpio_device *device, k_date_fo /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x00, 0x92, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x00, 0x92, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); switch (date_format) { case K_DATE_FORMAT_MONTH_DAY_YEAR: sb[6] = 0x00; @@ -1566,20 +1457,17 @@ k_return_status_t k_localization_date_format_set (gpio_device *device, k_date_fo sb[6] = 0x02; break; default: - return (K_PROGRAM_ERROR); + return (GP_ERROR_BAD_PARAMETERS); } - l_return_status = l_send_receive (device, sb, 8, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } - k_return_status = return_status_translation (rb[2], rb[3]); + result = l_send_receive (device, sb, 8, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); g_free (rb); - return (k_return_status); + return (result); } -k_return_status_t k_localization_data_put (gpio_device *device, guchar *data, gulong data_size) +gint +k_localization_data_put (gpio_device* device, guchar* data, gulong data_size) { /************************************************/ /* Command for various localization issues. */ @@ -1619,17 +1507,16 @@ k_return_status_t k_localization_data_put (gpio_device *device, guchar *data, gu /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; - gulong i, j; - guint packet_size = 1024; - guchar sb[16 + packet_size]; + gint result; + guchar* rb = NULL; + guint rbs; + gulong i, j; + static guint packet_size = 1024; + guchar sb[16 + packet_size]; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (data_size >= 512, K_PROGRAM_ERROR); - g_return_val_if_fail (data != NULL, K_PROGRAM_ERROR); + g_return_val_if_fail (data_size >= 512, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (data, GP_ERROR_BAD_PARAMETERS); + sb[0] = 0x00; sb[1] = 0x92; sb[2] = 0x00; @@ -1667,31 +1554,28 @@ k_return_status_t k_localization_data_put (gpio_device *device, guchar *data, gu /* camera reports K_ERROR_LOCALIZATION_DATA_CORRUPT. */ /********************************************************/ if (i + packet_size > 65536) sb[14] = 0x01; - l_return_status = l_send_receive (device, sb, packet_size + 16, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return (K_RETURN_STATUS (l_return_status)); - } - k_return_status = return_status_translation (rb[2], rb[3]); + result = l_send_receive (device, sb, packet_size + 16, &rb, &rbs); + if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); g_free (rb); - switch (k_return_status) { - case K_SUCCESS: + switch (result) { + case GP_OK: /* Everything is fine. Continue sending packets. However, make sure we don't loop forever. */ - if (i > 131072) return (K_PROGRAM_ERROR); + if (i > 131072) return (GP_ERROR_BAD_PARAMETERS); break; - case K_ERROR_LOCALIZATION_DATA_EXCESS: + case KONICA_ERROR_LOCALIZATION_DATA_EXCESS: /* The camera does no longer want to receive localization data. We are done. */ - return (K_SUCCESS); + return (GP_OK); default: /* Something went wrong. */ - return (k_return_status); + return (result); } i += packet_size; } } -k_return_status_t k_cancel (gpio_device *device, k_command_t *command) +gint +k_cancel (gpio_device* device, k_command_t* command) { /************************************************/ /* Command to cancel a command. */ @@ -1710,22 +1594,18 @@ k_return_status_t k_cancel (gpio_device *device, k_command_t *command) /* 0xXX: Byte 0 of cancelled command */ /* 0xXX: Byte 1 of cancelled command */ /************************************************/ - guchar sb[] = {0x00, 0x9e, 0x00, 0x00}; - l_return_status_t l_return_status; - k_return_status_t k_return_status; - guchar *rb = NULL; - guint rbs; + guchar sb[] = {0x00, 0x9e, 0x00, 0x00}; + gint result; + guchar* rb = NULL; + guint rbs; - g_return_val_if_fail (device != NULL, K_PROGRAM_ERROR); - g_return_val_if_fail (command != NULL, K_PROGRAM_ERROR); - l_return_status = l_send_receive (device, sb, 4, &rb, &rbs); - if (l_return_status != L_SUCCESS) { - g_free (rb); - return K_RETURN_STATUS (l_return_status); - } else { - k_return_status = return_status_translation (rb[2], rb[3]); - if (k_return_status == K_SUCCESS) - *command = (rb[5] << 8) | rb[4]; - return (k_return_status); + g_return_val_if_fail (command, GP_ERROR_BAD_PARAMETERS); + + result = l_send_receive (device, sb, 4, &rb, &rbs); + if (result == GP_OK) { + result = GP_RESULT (rb[2], rb[3]); + if (result == GP_OK) *command = (rb[5] << 8) | rb[4]; } + g_free (rb); + return (result); } diff --git a/camlibs/konica/konica.h b/camlibs/konica/konica.h index 2be378f35..8f3966a2b 100644 --- a/camlibs/konica/konica.h +++ b/camlibs/konica/konica.h @@ -196,49 +196,6 @@ typedef enum { } k_preference_t; -/****************************************************************/ -/* The following is a list of return states that the camera */ -/* will send (third and fourth byte, see above). The ones */ -/* before K_SUCCESS have been added to make programming */ -/* easier - they are _not_ sent by the camera. */ -/* */ -/* The list is by no means complete - I added an item each time */ -/* I discovered a new return state. */ -/****************************************************************/ -typedef enum { - K_L_IO_ERROR, - K_L_TRANSMISSION_ERROR, - K_UNSUPPORTED_BITRATE, - K_PROGRAM_ERROR, - K_SUCCESS, - K_ERROR_FOCUSING_ERROR, - K_ERROR_IRIS_ERROR, - K_ERROR_STROBE_ERROR, - K_ERROR_EEPROM_CHECKSUM_ERROR, - K_ERROR_INTERNAL_ERROR1, - K_ERROR_INTERNAL_ERROR2, - K_ERROR_NO_CARD_PRESENT, - K_ERROR_CARD_NOT_SUPPORTED, - K_ERROR_CARD_REMOVED_DURING_ACCESS, - K_ERROR_IMAGE_NUMBER_NOT_VALID, - K_ERROR_CARD_CAN_NOT_BE_WRITTEN, - K_ERROR_CARD_IS_WRITE_PROTECTED, - K_ERROR_NO_SPACE_LEFT_ON_CARD, - K_ERROR_NO_PICTURE_ERASED_AS_IMAGE_PROTECTED, - K_ERROR_LIGHT_TOO_DARK, - K_ERROR_AUTOFOCUS_ERROR, - K_ERROR_SYSTEM_ERROR, - K_ERROR_ILLEGAL_PARAMETER, - K_ERROR_COMMAND_CANNOT_BE_CANCELLED, - K_ERROR_LOCALIZATION_DATA_EXCESS, - K_ERROR_LOCALIZATION_DATA_CORRUPT, - K_ERROR_UNSUPPORTED_COMMAND, - K_ERROR_OTHER_COMMAND_EXECUTING, - K_ERROR_COMMAND_ORDER_ERROR, - K_ERROR_UNKNOWN_ERROR -} k_return_status_t; - - typedef enum { K_POWER_LEVEL_LOW, K_POWER_LEVEL_NORMAL, @@ -295,13 +252,13 @@ typedef enum { /* for image IDs (qm100, unsigned int), the other one uses four */ /* (qm200, unsigned long). */ /****************************************************************/ -k_return_status_t k_init (gpio_device *device); +gint k_init (gpio_device *device); -k_return_status_t k_exit (gpio_device *device); +gint k_exit (gpio_device *device); -k_return_status_t k_get_io_capability ( +gint k_get_io_capability ( gpio_device *device, gboolean *bit_rate_300, gboolean *bit_rate_600, @@ -320,7 +277,7 @@ k_return_status_t k_get_io_capability ( gboolean *bit_flag_hw_flow_control); -k_return_status_t k_set_io_capability ( +gint k_set_io_capability ( gpio_device *device, guint bit_rate, gboolean bit_flag_7_or_8_bits, @@ -330,13 +287,13 @@ k_return_status_t k_set_io_capability ( gboolean bit_flag_use_hw_flow_control); -k_return_status_t k_erase_all (gpio_device *device, guint *number_of_images_not_erased); +gint k_erase_all (gpio_device *device, guint *number_of_images_not_erased); -k_return_status_t k_format_memory_card (gpio_device *device); +gint k_format_memory_card (gpio_device *device); -k_return_status_t k_take_picture ( +gint k_take_picture ( gpio_device *device, gboolean image_id_long, gulong *image_id, @@ -346,22 +303,22 @@ k_return_status_t k_take_picture ( gboolean *protected); -k_return_status_t k_get_preview (gpio_device *device, gboolean thumbnail, guchar **image_buffer, guint *image_buffer_size); +gint k_get_preview (gpio_device *device, gboolean thumbnail, guchar **image_buffer, guint *image_buffer_size); -k_return_status_t k_set_preference (gpio_device *device, k_preference_t preference, guint value); +gint k_set_preference (gpio_device *device, k_preference_t preference, guint value); -k_return_status_t k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected); +gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected); -k_return_status_t k_erase_image (gpio_device *device, gboolean image_id_long, gulong image_id); +gint k_erase_image (gpio_device *device, gboolean image_id_long, gulong image_id); -k_return_status_t k_reset_preferences (gpio_device *device); +gint k_reset_preferences (gpio_device *device); -k_return_status_t k_get_date_and_time ( +gint k_get_date_and_time ( gpio_device *device, guchar *year, guchar *month, @@ -371,7 +328,7 @@ k_return_status_t k_get_date_and_time ( guchar *second); -k_return_status_t k_set_date_and_time ( +gint k_set_date_and_time ( gpio_device *device, guchar year, guchar month, @@ -381,7 +338,7 @@ k_return_status_t k_set_date_and_time ( guchar second); -k_return_status_t k_get_preferences ( +gint k_get_preferences ( gpio_device *device, guint *shutoff_time, guint *self_timer_time, @@ -389,7 +346,7 @@ k_return_status_t k_get_preferences ( guint *slide_show_interval); -k_return_status_t k_get_status ( +gint k_get_status ( gpio_device *device, guint *self_test_result, k_power_level_t *power_level, @@ -415,7 +372,7 @@ k_return_status_t k_get_status ( guint *total_strobes); -k_return_status_t k_get_information ( +gint k_get_information ( gpio_device *device, gchar **model, gchar **serial_number, @@ -429,7 +386,7 @@ k_return_status_t k_get_information ( gchar **manufacturer); -k_return_status_t k_get_image_information ( +gint k_get_image_information ( gpio_device *device, gboolean image_id_long, gulong image_number, @@ -440,7 +397,7 @@ k_return_status_t k_get_image_information ( guint *information_buffer_size); -k_return_status_t k_get_image ( +gint k_get_image ( gpio_device *device, gboolean image_id_long, gulong image_id, @@ -449,17 +406,17 @@ k_return_status_t k_get_image ( guint *image_buffer_size); -k_return_status_t k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected); +gint k_set_protect_status (gpio_device *device, gboolean image_id_long, gulong image_id, gboolean protected); -k_return_status_t k_localization_tv_output_format_set (gpio_device *device, k_tv_output_format_t tv_output_format); +gint k_localization_tv_output_format_set (gpio_device *device, k_tv_output_format_t tv_output_format); -k_return_status_t k_localization_date_format_set (gpio_device *device, k_date_format_t date_format); +gint k_localization_date_format_set (gpio_device *device, k_date_format_t date_format); -k_return_status_t k_localization_data_put (gpio_device *device, guchar *data, gulong data_size); +gint k_localization_data_put (gpio_device *device, guchar *data, gulong data_size); -k_return_status_t k_cancel (gpio_device *device, k_command_t *command); +gint k_cancel (gpio_device *device, k_command_t *command); diff --git a/camlibs/konica/library.c b/camlibs/konica/library.c index 974ce7672..2e3cfbdfe 100644 --- a/camlibs/konica/library.c +++ b/camlibs/konica/library.c @@ -8,6 +8,20 @@ #include #include #include +#ifdef ENABLE_NLS +# include +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define _(String) (String) +# define N_(String) (String) +# endif +#else +# define _(String) (String) +# define N_(String) (String) +#endif #include "library.h" #include "konica.h" @@ -15,144 +29,70 @@ /*************/ /* Variables */ /*************/ -char *models_qm100[] = { - "Konica Q-EZ", - "Konica Q-M100", - "Konica Q-M100V", - "HP PhotoSmart C20", - "HP PhotoSmart C30", - NULL}; +static gchar* konica_results[] = { + /* KONICA_ERROR_FOCUSING_ERROR */ N_("Focusing error"), + /* KONICA_ERROR_IRIS_ERROR */ N_("Iris error"), + /* KONICA_ERROR_STROBE_ERROR */ N_("Strobe error"), + /* KONICA_ERROR_EEPROM_CHECKSUM_ERROR */ N_("EEPROM checksum error"), + /* KONICA_ERROR_INTERNAL_ERROR1 */ N_("Internal error (1)"), + /* KONICA_ERROR_INTERNAL_ERROR2 */ N_("Internal error (2)"), + /* KONICA_ERROR_NO_CARD_PRESENT */ N_("No card present"), + /* KONICA_ERROR_CARD_NOT_SUPPORTED */ N_("Card not supported"), + /* KONICA_ERROR_CARD_REMOVED_DURING_ACCESS */ N_("Card removed during access"), + /* KONICA_ERROR_IMAGE_NUMBER_NOT_VALID */ N_("Image number not valid"), + /* KONICA_ERROR_CARD_CAN_NOT_BE_WRITTEN */ N_("Card cannot be written"), + /* KONICA_ERROR_CARD_IS_WRITE_PROTECTED */ N_("Card is write protected"), + /* KONICA_ERROR_NO_SPACE_LEFT_ON_CARD */ N_("No space left on card"), + /* KONICA_ERROR_NO_IMAGE_ERASED_AS_IMAGE_PROTECTED */ N_("No image erased as image protected"), + /* KONICA_ERROR_LIGHT_TOO_DARK */ N_("Light too dark"), + /* KONICA_ERROR_AUTOFOCUS_ERROR */ N_("Autofocus error"), + /* KONICA_ERROR_SYSTEM_ERROR */ N_("System error"), + /* KONICA_ERROR_ILLEGAL_PARAMETER */ N_("Illegal parameter"), + /* KONICA_ERROR_COMMAND_CANNOT_BE_CANCELLED */ N_("Command cannot be cancelled"), + /* KONICA_ERROR_LOCALIZATION_DATA_EXCESS */ N_("Localization data excess"), + /* KONICA_ERROR_LOCALIZATION_DATA_CORRUPT */ N_("Localization data corrupt"), + /* KONICA_ERROR_UNSUPPORTED_COMMAND */ N_("Unsupported command"), + /* KONICA_ERROR_OTHER_COMMAND_EXECUTING */ N_("Other command executing"), + /* KONICA_ERROR_COMMAND_ORDER_ERROR */ N_("Command order error"), + /* KONICA_ERROR_UNKNOWN_ERROR */ N_("Unknown error") +}; -char *models_qm200[] = { - "Konica Q-M200", - "HP PhotoSmart C200", - NULL}; + +gchar* models_qm100[] = {"Konica Q-EZ", "Konica Q-M100", "Konica Q-M100V", "HP PhotoSmart C20", "HP PhotoSmart C30", NULL}; -char **models[2] = {models_qm100, models_qm200}; +gchar* models_qm200[] = {"Konica Q-M200", "HP PhotoSmart C200", NULL}; + + +gchar** models[2] = {models_qm100, models_qm200}; /**************/ /* Prototypes */ /**************/ -gboolean error_happened (Camera *camera, k_return_status_t return_status); gboolean localization_file_read (Camera *camera, gchar *file_name, guchar **data, gulong *data_size); /*************/ /* Functions */ /*************/ -gboolean error_happened (Camera *camera, k_return_status_t return_status) +int +camera_id (CameraText *id) { - g_return_val_if_fail (camera != NULL, GP_ERROR); - switch (return_status) { - case K_PROGRAM_ERROR: - gp_frontend_message (camera, "Program error!"); - return (TRUE); - case K_L_IO_ERROR: - gp_frontend_message (camera, "IO error!"); - return (TRUE); - case K_L_TRANSMISSION_ERROR: - gp_frontend_message (camera, "Transmission error!\n"); - return (TRUE); - case K_SUCCESS: - return (FALSE); - case K_ERROR_FOCUSING_ERROR: - gp_frontend_message (camera, "Focussing error!"); - return (TRUE); - case K_ERROR_IRIS_ERROR: - gp_frontend_message (camera, "Iris error!"); - return (TRUE); - case K_ERROR_STROBE_ERROR: - gp_frontend_message (camera, "Strobe error!"); - return (TRUE); - case K_ERROR_EEPROM_CHECKSUM_ERROR: - gp_frontend_message (camera, "Eeprom checksum error!"); - return (TRUE); - case K_ERROR_INTERNAL_ERROR1: - gp_frontend_message (camera, "Internal error (1)!"); - return (TRUE); - case K_ERROR_INTERNAL_ERROR2: - gp_frontend_message (camera, "Internal error (2)!"); - return (TRUE); - case K_ERROR_NO_CARD_PRESENT: - gp_frontend_message (camera, "No card present!"); - return (TRUE); - case K_ERROR_CARD_NOT_SUPPORTED: - gp_frontend_message (camera, "Card not supported!"); - return (TRUE); - case K_ERROR_CARD_REMOVED_DURING_ACCESS: - gp_frontend_message (camera, "Card removed during access!"); - return (TRUE); - case K_ERROR_IMAGE_NUMBER_NOT_VALID: - gp_frontend_message (camera, "Image number not valid!"); - return (TRUE); - case K_ERROR_CARD_CAN_NOT_BE_WRITTEN: - gp_frontend_message (camera, "Card can not be written!"); - return (TRUE); - case K_ERROR_CARD_IS_WRITE_PROTECTED: - gp_frontend_message (camera, "Card is write protected!"); - return (TRUE); - case K_ERROR_NO_SPACE_LEFT_ON_CARD: - gp_frontend_message (camera, "ERROR!\n"); - return (TRUE); - case K_ERROR_NO_PICTURE_ERASED_AS_IMAGE_PROTECTED: - gp_frontend_message (camera, "No picture erased as image protected!"); - return (TRUE); - case K_ERROR_LIGHT_TOO_DARK: - gp_frontend_message (camera, "Light too dark!"); - return (TRUE); - case K_ERROR_AUTOFOCUS_ERROR: - gp_frontend_message (camera, "Autofocus error!"); - return (TRUE); - case K_ERROR_SYSTEM_ERROR: - gp_frontend_message (camera, "System Error!"); - return (TRUE); - case K_ERROR_ILLEGAL_PARAMETER: - gp_frontend_message (camera, "Illegal parameter!"); - return (TRUE); - case K_ERROR_COMMAND_CANNOT_BE_CANCELLED: - gp_frontend_message (camera, "Command cannot be cancelled!"); - return (TRUE); - case K_ERROR_LOCALIZATION_DATA_EXCESS: - gp_frontend_message (camera, "Too much localization data!\n"); - return (TRUE); - case K_ERROR_LOCALIZATION_DATA_CORRUPT: - gp_frontend_message (camera, "Localization data corrupt!\n"); - return (TRUE); - case K_ERROR_UNSUPPORTED_COMMAND: - gp_frontend_message (camera, "Unsupported command!"); - return (TRUE); - case K_ERROR_OTHER_COMMAND_EXECUTING: - gp_frontend_message (camera, "Other command executing!"); - return (TRUE); - case K_ERROR_COMMAND_ORDER_ERROR: - gp_frontend_message (camera, "Command order error!"); - return (TRUE); - case K_ERROR_UNKNOWN_ERROR: - gp_frontend_message (camera, "Unknown error!"); - return (TRUE); - default: - return (TRUE); - } -} - - -int camera_id (CameraText *id) -{ - g_return_val_if_fail (id != NULL, GP_ERROR); + g_return_val_if_fail (id != NULL, GP_ERROR_BAD_PARAMETERS); strcpy (id->text, "konica"); return (GP_OK); } -int camera_abilities (CameraAbilitiesList *list) +int +camera_abilities (CameraAbilitiesList* list) { - gint i, j; - CameraAbilities *a; + gint i, j; + CameraAbilities* a; - g_return_val_if_fail (list != NULL, GP_ERROR); + g_return_val_if_fail (list != NULL, GP_ERROR_BAD_PARAMETERS); for (i = 0; i < 2; i++) { for (j = 0; ; j++) { if (models[i][j] == NULL) break; @@ -182,25 +122,26 @@ int camera_abilities (CameraAbilitiesList *list) } -int camera_init (Camera *camera, CameraInit *init) +int +camera_init (Camera* camera, CameraInit* init) { - gint i, j; - guint test_bit_rate[10] = {9600, 115200, 57600, 38400, 19200, 4800, 2400, 1200, 600, 300}; - guint bit_rate[10] = {300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200}; - gboolean bit_rate_supported[10] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; - gboolean bit_flag_8_bits; - gboolean bit_flag_stop_2_bits; - gboolean bit_flag_parity_on; - gboolean bit_flag_parity_odd; - gboolean bit_flag_use_hw_flow_control; - guint speed; - konica_data_t *konica_data; - gpio_device_settings device_settings; - gpio_device *device; + gint i, j; + guint test_bit_rate[10] = { 9600, 115200, 57600, 38400, 19200, 4800, 2400, 1200, 600, 300}; + guint bit_rate[10] = { 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200}; + gboolean bit_rate_supported[10] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE}; + gboolean bit_flag_8_bits; + gboolean bit_flag_stop_2_bits; + gboolean bit_flag_parity_on; + gboolean bit_flag_parity_odd; + gboolean bit_flag_use_hw_flow_control; + gint result; + guint speed; + konica_data_t* konica_data; + gpio_device_settings device_settings; + gpio_device* device; - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_init ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (init != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (init, GP_ERROR_BAD_PARAMETERS); /* First, set up all the function pointers. */ camera->functions->id = camera_id; @@ -218,6 +159,7 @@ int camera_init (Camera *camera, CameraInit *init) camera->functions->summary = camera_summary; camera->functions->manual = camera_manual; camera->functions->about = camera_about; + camera->functions->result_as_string = camera_result_as_string; /* Create device. */ device = gpio_new (GPIO_DEVICE_SERIAL); @@ -257,7 +199,7 @@ int camera_init (Camera *camera, CameraInit *init) if (init->port.speed != 0) { device_settings.serial.speed = init->port.speed; gpio_set_settings (device, device_settings); - if (k_init (device) == K_SUCCESS) return (GP_OK); + if (k_init (device) == GP_OK) return (GP_OK); } /* We either do have a speed of 0 or are not */ @@ -267,7 +209,7 @@ int camera_init (Camera *camera, CameraInit *init) gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Testing speed %i.\n", test_bit_rate[i]); device_settings.serial.speed = test_bit_rate[i]; gpio_set_settings (device, device_settings); - if (k_init (device) == K_SUCCESS) break; + if (k_init (device) == GP_OK) break; } if ((i == 1) && (init->port.speed == 0)) { @@ -284,7 +226,7 @@ int camera_init (Camera *camera, CameraInit *init) /* ... and what speed it is able to handle. */ gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Getting IO capabilities.\n"); - if (error_happened (camera, k_get_io_capability ( + result = k_get_io_capability ( device, &bit_rate_supported[0], &bit_rate_supported[1], @@ -300,9 +242,10 @@ int camera_init (Camera *camera, CameraInit *init) &bit_flag_stop_2_bits, &bit_flag_parity_on, &bit_flag_parity_odd, - &bit_flag_use_hw_flow_control))) { + &bit_flag_use_hw_flow_control); + if (result != GP_OK) { gpio_free (device); - return (GP_ERROR); + return (result); } if (init->port.speed == 0) { @@ -313,19 +256,19 @@ int camera_init (Camera *camera, CameraInit *init) return (GP_ERROR); } gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Setting speed to %i.\n", bit_rate[i]); - if (error_happened (camera, k_set_io_capability (device, bit_rate[i], TRUE, FALSE, FALSE, FALSE, FALSE))) { + if ((result = k_set_io_capability (device, bit_rate[i], TRUE, FALSE, FALSE, FALSE, FALSE)) != GP_OK) { gpio_free (device); - return (GP_ERROR); + return (result); } - if (error_happened (camera, k_exit (device))) { + if ((result = k_exit (device)) != GP_OK) { gpio_free (device); - return (GP_ERROR); + return (result); } device_settings.serial.speed = bit_rate[i]; gpio_set_settings (device, device_settings); - if (error_happened (camera, k_init (device))) { + if ((result = k_init (device)) != GP_OK) { gpio_free (device); - return (GP_ERROR); + return (result); } /* We were successful! */ @@ -359,15 +302,15 @@ int camera_init (Camera *camera, CameraInit *init) return (GP_ERROR); } /* Now we can set the given speed. */ - if (error_happened (camera, k_set_io_capability (device, init->port.speed, TRUE, FALSE, FALSE, FALSE, FALSE))) { + if ((result = k_set_io_capability (device, init->port.speed, TRUE, FALSE, FALSE, FALSE, FALSE)) != GP_OK) { gpio_free (device); return (GP_ERROR); } - if (error_happened (camera, k_exit (device))) { + if ((result = k_exit (device)) != GP_OK) { gpio_free (device); return (GP_ERROR); } - if (error_happened (camera, k_init (device))) { + if ((result = k_init (device)) != GP_OK) { gpio_free (device); return (GP_ERROR); } @@ -378,26 +321,28 @@ int camera_init (Camera *camera, CameraInit *init) } -int camera_exit (Camera *camera) +gint +camera_exit (Camera* camera) { - konica_data_t *konica_data; + gint result; + konica_data_t* konica_data; - g_return_val_if_fail (camera != NULL, GP_ERROR); - - konica_data = (konica_data_t *) camera->camlib_data; - g_return_val_if_fail (!error_happened (camera, k_exit (konica_data->device)), GP_ERROR); - g_return_val_if_fail (gp_filesystem_free (konica_data->filesystem) == GP_OK, GP_ERROR); - g_return_val_if_fail (gpio_free (konica_data->device) == GP_OK, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (konica_data = (konica_data_t *) camera->camlib_data, GP_ERROR_BAD_PARAMETERS); + + if ((result = k_exit (konica_data->device)) != GP_OK) return (result); + if ((result = gp_filesystem_free (konica_data->filesystem)) != GP_OK) return (result); + if ((result = gpio_free (konica_data->device)) != GPIO_OK) return (GP_ERROR); return (GP_OK); } -int +gint camera_folder_list (Camera* camera, CameraList* list, gchar* folder) { - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (list != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (list, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (folder, GP_ERROR_BAD_PARAMETERS); /* The camera does not support folders. */ return (GP_OK); @@ -437,14 +382,15 @@ camera_file_list (Camera* camera, CameraList* list, gchar* folder) gulong image_id; konica_data_t* konica_data; gchar* filename; + gint result; gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_file_list ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (list != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (list, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (folder, GP_ERROR_BAD_PARAMETERS); konica_data = (konica_data_t *) camera->camlib_data; - if (error_happened (camera, k_get_status ( + if ((result = k_get_status ( konica_data->device, &self_test_result, &power_level, @@ -467,7 +413,7 @@ camera_file_list (Camera* camera, CameraList* list, gchar* folder) &focus, &exposure, &total_pictures, - &total_strobes))) return (GP_ERROR); + &total_strobes)) != GP_OK) return (result); /* We can't get the filename from the camera. */ /* But we decide to call the images */ @@ -475,7 +421,7 @@ camera_file_list (Camera* camera, CameraList* list, gchar* folder) /* parameter. Therefore, let's get the image */ /* ids. */ for (i = 0; i < pictures; i++) { - if (!error_happened (camera, k_get_image_information ( + if (k_get_image_information ( konica_data->device, konica_data->image_id_long, i + 1, @@ -483,11 +429,11 @@ camera_file_list (Camera* camera, CameraList* list, gchar* folder) &exif_size, &protected, &information_buffer, - &information_buffer_size))) filename = g_strdup_printf ("%06i.jpeg", (int) image_id); + &information_buffer_size) == GP_OK) filename = g_strdup_printf ("%06i.jpeg", (int) image_id); else filename = g_strdup ("??????.jpg"); g_free (information_buffer); information_buffer = NULL; - g_return_val_if_fail (gp_list_append (list, filename, GP_LIST_FILE) == GP_OK, GP_ERROR); + if ((result = gp_list_append (list, filename, GP_LIST_FILE)) != GP_OK) return (result); gp_filesystem_append (konica_data->filesystem, "/", filename); g_free (filename); } @@ -503,11 +449,12 @@ camera_file_get_generic (Camera* camera, CameraFile* file, gchar* folder, gchar* gchar image_id_string[] = {0, 0, 0, 0, 0, 0, 0}; konica_data_t* konica_data; gchar* tmp; + gint result; - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (file != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); - g_return_val_if_fail (filename != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (file, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (folder, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (filename, GP_ERROR_BAD_PARAMETERS); konica_data = (konica_data_t *) camera->camlib_data; @@ -517,35 +464,31 @@ camera_file_get_generic (Camera* camera, CameraFile* file, gchar* folder, gchar* image_id = atol (image_id_string); /* Get the image. */ - g_return_val_if_fail (!error_happened (camera, k_get_image ( + result = k_get_image ( konica_data->device, konica_data->image_id_long, image_id, image_type, (guchar **) &file->data, - (guint *) &file->size)), GP_ERROR); + (guint *) &file->size); - strcpy (file->type, "image/jpg"); - if (image_type == K_THUMBNAIL) { - tmp = g_strdup_printf ("%06i-thumbnail.jpg", (int) image_id); - strcpy (file->name, tmp); - g_free (tmp); - } else { - strcpy (file->name, filename); + if (result == GP_OK) { + strcpy (file->type, "image/jpg"); + if (image_type == K_THUMBNAIL) { + tmp = g_strdup_printf ("%06i-thumbnail.jpg", (int) image_id); + strcpy (file->name, tmp); + g_free (tmp); + } else { + strcpy (file->name, filename); + } } - return (GP_OK); + return (result); } int camera_file_get (Camera* camera, CameraFile* file, gchar* folder, gchar* filename) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_file_get ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (file != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); - g_return_val_if_fail (filename != NULL, GP_ERROR); - return (camera_file_get_generic (camera, file, folder, filename, K_IMAGE_EXIF)); } @@ -553,30 +496,24 @@ camera_file_get (Camera* camera, CameraFile* file, gchar* folder, gchar* filenam int camera_file_get_preview (Camera* camera, CameraFile* file, gchar* folder, gchar* filename) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_file_get_preview ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (file != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); - g_return_val_if_fail (filename != NULL, GP_ERROR); - return (camera_file_get_generic (camera, file, folder, filename, K_THUMBNAIL)); } -int +gint camera_file_put (Camera* camera, CameraFile* file, char* folder) { gp_debug_printf (GP_DEBUG_LOW, "konica", "*** camera_file_put ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (file != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (file, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (folder, GP_ERROR_BAD_PARAMETERS); /* The camera does not support putting files. */ return (GP_ERROR); } -int +gint camera_file_delete (Camera* camera, gchar* folder, gchar* filename) { gulong image_id; @@ -584,9 +521,9 @@ camera_file_delete (Camera* camera, gchar* folder, gchar* filename) konica_data_t* konica_data; gp_debug_printf (GP_DEBUG_LOW, "konica", "*** camera_file_delete ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (folder != NULL, GP_ERROR); - g_return_val_if_fail (filename != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (folder, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (filename, GP_ERROR_BAD_PARAMETERS); konica_data = (konica_data_t *) camera->camlib_data; @@ -595,36 +532,31 @@ camera_file_delete (Camera* camera, gchar* folder, gchar* filename) memcpy (image_id_string, filename, 6); image_id = atol (image_id_string); - g_return_val_if_fail (!error_happened (camera, k_erase_image (konica_data->device, konica_data->image_id_long, image_id)), GP_ERROR); - return (GP_OK); + return (k_erase_image (konica_data->device, konica_data->image_id_long, image_id)); } -int camera_summary (Camera *camera, CameraText *summary) +gint +camera_summary (Camera* camera, CameraText* summary) { - gchar *model = NULL; - gchar *serial_number = NULL; - guchar hardware_version_major; - guchar hardware_version_minor; - guchar software_version_major; - guchar software_version_minor; - guchar testing_software_version_major; - guchar testing_software_version_minor; - gchar *name = NULL; - gchar *manufacturer = NULL; - guint shutoff_time; - guint self_timer_time; - guint beep; - guint slide_show_interval; - guchar year, month, day, hour, minute, second; - konica_data_t *konica_data; + gchar* model = NULL; + gchar* serial_number = NULL; + guchar hardware_version_major; + guchar hardware_version_minor; + guchar software_version_major; + guchar software_version_minor; + guchar testing_software_version_major; + guchar testing_software_version_minor; + gchar* name = NULL; + gchar* manufacturer = NULL; + konica_data_t* konica_data; + gint result; - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** camera_summary ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (summary != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (summary, GP_ERROR_BAD_PARAMETERS); konica_data = (konica_data_t *) camera->camlib_data; - if (error_happened (camera, k_get_information ( + result = k_get_information ( konica_data->device, &model, &serial_number, @@ -635,22 +567,9 @@ int camera_summary (Camera *camera, CameraText *summary) &testing_software_version_major, &testing_software_version_minor, &name, - &manufacturer))) return (GP_ERROR); - else if (error_happened (camera, k_get_preferences ( - konica_data->device, - &shutoff_time, - &self_timer_time, - &beep, - &slide_show_interval))) return (GP_ERROR); - else if (error_happened (camera, k_get_date_and_time ( - konica_data->device, - &year, - &month, - &day, - &hour, - &minute, - &second))) return (GP_ERROR); - else { + &manufacturer); + + if (result == GP_OK) sprintf (summary->text, "About the camera:\n" " Model: %s\n" @@ -659,19 +578,7 @@ int camera_summary (Camera *camera, CameraText *summary) " Software Version: %i.%i\n" " Testing Software Version: %i.%i\n" " Name: %s,\n" - " Manufacturer: %s\n" - "Current settings:\n" - " Shutoff time: %i (min)\n" - " Self timer time: %i (sec)\n" - " Beep: %i\n" - " Slide show interval: %i (sec)\n" - "Date and time:\n" - " Year: %i\n" - " Month: %i\n" - " Day: %i\n" - " Hour: %i\n" - " Minute: %i\n" - " Second: %i\n", + " Manufacturer: %s\n", model, serial_number, hardware_version_major, @@ -681,35 +588,27 @@ int camera_summary (Camera *camera, CameraText *summary) testing_software_version_major, testing_software_version_minor, name, - manufacturer, - shutoff_time, - self_timer_time, - beep, - slide_show_interval, - year, - month, - day, - hour, - minute, - second); - return (GP_OK); - } + manufacturer); + + return (result); } -int camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) +gint +camera_capture (Camera* camera, CameraFile* file, CameraCaptureInfo* info) { - konica_data_t *konica_data; - gulong image_id; - gint exif_size; - guchar *information_buffer = NULL; - guint information_buffer_size; - gboolean protected; + konica_data_t* konica_data; + gulong image_id; + gint exif_size; + guchar* information_buffer = NULL; + guint information_buffer_size; + gboolean protected; + gint result; gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_capture ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (file != NULL, GP_ERROR); - g_return_val_if_fail (info != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (file, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (info, GP_ERROR_BAD_PARAMETERS); konica_data = (konica_data_t *) camera->camlib_data; @@ -718,29 +617,27 @@ int camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) case GP_CAPTURE_IMAGE: /* Take the picture. */ - if (error_happened (camera, k_take_picture ( + result = k_take_picture ( konica_data->device, konica_data->image_id_long, &image_id, &exif_size, &information_buffer, &information_buffer_size, - &protected))) - return (GP_ERROR); + &protected); g_free (information_buffer); + if (result != GP_OK) return (result); /* Get the image. */ - if (error_happened (camera, k_get_image ( + result = k_get_image ( konica_data->device, konica_data->image_id_long, image_id, K_IMAGE_JPEG, (guchar **) &file->data, - (guint *) &file->size))) - return (GP_ERROR); - strcpy (file->type, "image/jpg"); - - return (GP_OK); + (guint *) &file->size); + if (result == GP_OK) strcpy (file->type, "image/jpg"); + return (result); case GP_CAPTURE_VIDEO: @@ -751,26 +648,20 @@ int camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info) case GP_CAPTURE_PREVIEW: /* Get the preview. */ - if (error_happened (camera, k_get_preview ( - konica_data->device, - TRUE, - (guchar**) &file->data, - (guint*) &file->size))) return (GP_ERROR); - strcpy (file->type, "image/jpg"); - strcpy (file->name, "preview.jpg"); - - return (GP_OK); + if ((result = k_get_preview (konica_data->device, TRUE, (guchar**) &file->data, (guint*) &file->size)) == GP_OK) { + strcpy (file->type, "image/jpg"); + strcpy (file->name, "preview.jpg"); + } + return (result); default: - return (GP_ERROR); + return (GP_ERROR_BAD_PARAMETERS); } } int camera_manual (Camera *camera, CameraText *manual) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_manual ***"); - strcpy(manual->text, "No manual available."); return (GP_OK); @@ -779,9 +670,8 @@ int camera_manual (Camera *camera, CameraText *manual) int camera_about (Camera *camera, CameraText *about) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_about ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (about != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (about, GP_ERROR_BAD_PARAMETERS); strcpy (about->text, "Konica library\n" @@ -818,15 +708,16 @@ int camera_config_get (Camera *camera, CameraWidget **window) gint year_4_digits; struct tm tm_struct; time_t t; + gint result; gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_config_get ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (window != NULL, GP_ERROR); - g_return_val_if_fail (*window == NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (window, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (!*window, GP_ERROR_BAD_PARAMETERS); /* Get the current settings. */ konica_data = (konica_data_t *) camera->camlib_data; - if (error_happened (camera, k_get_status ( + if ((result = k_get_status ( konica_data->device, &self_test_result, &power_level, @@ -849,13 +740,13 @@ int camera_config_get (Camera *camera, CameraWidget **window) &focus_self_timer, &exposure, &total_pictures, - &total_strobes))) return (GP_ERROR); - if (error_happened (camera, k_get_preferences ( + &total_strobes)) != GP_OK) return (result); + if ((result = k_get_preferences ( konica_data->device, &shutoff_time, &self_timer_time, &beep, - &slide_show_interval))) return (GP_ERROR); + &slide_show_interval)) != GP_OK) return (result); /* Create the window. */ *window = gp_widget_new (GP_WIDGET_WINDOW, "Konica Configuration"); @@ -1056,10 +947,11 @@ int camera_config_set (Camera *camera, CameraWidget *window) gfloat f; gchar* c; struct tm* tm_struct; + gint result; gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_config_set ***"); - g_return_val_if_fail (camera != NULL, GP_ERROR); - g_return_val_if_fail (window != NULL, GP_ERROR); + g_return_val_if_fail (camera, GP_ERROR_BAD_PARAMETERS); + g_return_val_if_fail (window, GP_ERROR_BAD_PARAMETERS); c = g_new0 (gchar, 256); @@ -1075,17 +967,14 @@ int camera_config_set (Camera *camera, CameraWidget *window) if (gp_widget_changed (widget)) { gp_widget_value_get (widget, &i); tm_struct = localtime ((time_t*) &i); - if (error_happened (camera, k_set_date_and_time ( + if ((result = k_set_date_and_time ( konica_data->device, tm_struct->tm_year - 100, tm_struct->tm_mon, tm_struct->tm_mday, tm_struct->tm_hour, tm_struct->tm_min, - tm_struct->tm_sec))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the date and time."); - return (GP_ERROR); - } + tm_struct->tm_sec)) != GP_OK) return (result); } /* Beep */ @@ -1095,40 +984,28 @@ int camera_config_set (Camera *camera, CameraWidget *window) if (strcmp (c, "Off") == 0) beep = 0; else if (strcmp (c, "On") == 0) beep = 1; else g_assert_not_reached (); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_BEEP, beep))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the beep."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_BEEP, beep)) != GP_OK) return (result); } /* Self Timer Time */ g_assert ((widget = gp_widget_child_by_label (section, "Self Timer Time")) != NULL); if (gp_widget_changed (widget)) { gp_widget_value_get (widget, &f); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_SELF_TIMER_TIME, (gint) f))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the self timer time."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_SELF_TIMER_TIME, (gint) f)) != GP_OK) return (result); } /* Auto Off Time */ g_assert ((widget = gp_widget_child_by_label (section, "Auto Off Time")) != NULL); if (gp_widget_changed (widget)) { gp_widget_value_get (widget, &f); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_AUTO_OFF_TIME, (gint) f))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the auto off time."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_AUTO_OFF_TIME, (gint) f)) != GP_OK) return (result); } /* Slide Show Interval */ g_assert ((widget = gp_widget_child_by_label (section, "Slide Show Interval")) != NULL); if (gp_widget_changed (widget)) { gp_widget_value_get (widget, &f); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_SLIDE_SHOW_INTERVAL, (gint) f))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the slide show interval."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_SLIDE_SHOW_INTERVAL, (gint) f)) != GP_OK) return (result); } /* Resolution */ @@ -1138,10 +1015,7 @@ int camera_config_set (Camera *camera, CameraWidget *window) if (strcmp (c, "High (1152 x 872)") == 0) j = 1; else if (strcmp (c, "Low (576 x 436)") == 0) j = 3; else j = 0; - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_RESOLUTION, j))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the resolution."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_RESOLUTION, j)) != GP_OK) return (result); } /****************/ @@ -1164,11 +1038,9 @@ int camera_config_set (Camera *camera, CameraWidget *window) } /* Go! */ - if (error_happened (camera, k_localization_data_put (konica_data->device, data, data_size))) { - g_free (data); - return (GP_ERROR); - } + result = k_localization_data_put (konica_data->device, data, data_size); g_free (data); + if (result != GP_OK) return (result); } } @@ -1180,10 +1052,7 @@ int camera_config_set (Camera *camera, CameraWidget *window) else if (strcmp (c, "PAL") == 0) tv_output_format = K_TV_OUTPUT_FORMAT_PAL; else if (strcmp (c, "Do not display TV menu") == 0) tv_output_format = K_TV_OUTPUT_FORMAT_HIDE; else g_assert_not_reached (); - if (error_happened (camera, k_localization_tv_output_format_set (konica_data->device, tv_output_format))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the TV output format."); - return (GP_ERROR); - } + if ((result = k_localization_tv_output_format_set (konica_data->device, tv_output_format)) != GP_OK) return (result); } /* Date Format */ @@ -1194,10 +1063,7 @@ int camera_config_set (Camera *camera, CameraWidget *window) else if (strcmp (c, "Day/Month/Year") == 0) date_format = K_DATE_FORMAT_DAY_MONTH_YEAR; else if (strcmp (c, "Year/Month/Day") == 0) date_format = K_DATE_FORMAT_YEAR_MONTH_DAY; else g_assert_not_reached (); - if (error_happened (camera, k_localization_date_format_set (konica_data->device, date_format))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the date format."); - return (GP_ERROR); - } + if ((result = k_localization_date_format_set (konica_data->device, date_format)) != GP_OK) return (result); } /********************************/ @@ -1215,20 +1081,14 @@ int camera_config_set (Camera *camera, CameraWidget *window) else if (strcmp (c, "Auto") == 0) j = 2; else if (strcmp (c, "Auto, red-eye reduction") == 0) j = 6; else g_assert_not_reached (); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_FLASH, j))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the flash."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_FLASH, j)) != GP_OK) return (result); } /* Exposure */ g_assert ((widget = gp_widget_child_by_label (section, "Exposure")) != NULL); if (gp_widget_changed (widget)) { gp_widget_value_get (widget, &f); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_EXPOSURE, (gint) f))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the exposure."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_EXPOSURE, (gint) f)) != GP_OK) return (result); } /* Focus will be set together with self timer. */ @@ -1250,10 +1110,7 @@ int camera_config_set (Camera *camera, CameraWidget *window) if (strcmp (c, "Self Timer (only next picture)") == 0) focus_self_timer++; else if (strcmp (c, "Normal") == 0); else g_assert_not_reached (); - if (error_happened (camera, k_set_preference (konica_data->device, K_PREFERENCE_FOCUS_SELF_TIMER, focus_self_timer))) { - gp_debug_printf (GP_DEBUG_LOW, "konica", "An error occurred while setting the self timer and focus."); - return (GP_ERROR); - } + if ((result = k_set_preference (konica_data->device, K_PREFERENCE_FOCUS_SELF_TIMER, focus_self_timer)) != GP_OK) return (result); } /* We are done. */ @@ -1262,12 +1119,13 @@ int camera_config_set (Camera *camera, CameraWidget *window) } -int camera_config (Camera *camera) +gint +camera_config (Camera *camera) { + gint result; CameraWidget* window = NULL; - gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering camera_config ***"); - if (camera_config_get (camera, &window) == GP_OK) { + if ((result = camera_config_get (camera, &window)) == GP_OK) { /* Prompt the user with the config window. */ if (gp_frontend_prompt (camera, window) == GP_PROMPT_CANCEL) { @@ -1277,11 +1135,27 @@ int camera_config (Camera *camera) return (camera_config_set (camera, window)); } else { if (window) gp_widget_unref (window); - return (GP_ERROR); + return (result); } } +gchar* +camera_result_as_string (Camera* camera, gint result) +{ + /* Really an error? */ + g_return_val_if_fail (result >= 0, _("Unknown error")); + + /* libgphoto2 error? */ + if (-result < 100) return (gp_result_as_string (result)); + + /* Our error? */ + if ((0 - result - 100) < (guint) (sizeof (konica_results) / sizeof (*konica_results))) return _(konica_results [0 - result - 100]); + + return _("Unknown error"); +} + + gboolean localization_file_read (Camera *camera, gchar *file_name, guchar **data, gulong *data_size) { FILE *file; diff --git a/camlibs/konica/library.h b/camlibs/konica/library.h index 2fa15038e..859ff9888 100644 --- a/camlibs/konica/library.h +++ b/camlibs/konica/library.h @@ -1,7 +1,41 @@ +/********************/ /* Type definitions */ +/********************/ typedef struct { - gpio_device *device; - gboolean image_id_long; - CameraFilesystem *filesystem; + gpio_device* device; + gboolean image_id_long; + CameraFilesystem* filesystem; } konica_data_t; + +/***************/ +/* Definitions */ +/***************/ +#define KONICA_ERROR_FOCUSING_ERROR -100 +#define KONICA_ERROR_IRIS_ERROR -101 +#define KONICA_ERROR_STROBE_ERROR -102 +#define KONICA_ERROR_EEPROM_CHECKSUM_ERROR -103 +#define KONICA_ERROR_INTERNAL_ERROR1 -104 +#define KONICA_ERROR_INTERNAL_ERROR2 -105 +#define KONICA_ERROR_NO_CARD_PRESENT -106 +#define KONICA_ERROR_CARD_NOT_SUPPORTED -107 +#define KONICA_ERROR_CARD_REMOVED_DURING_ACCESS -108 +#define KONICA_ERROR_IMAGE_NUMBER_NOT_VALID -109 +#define KONICA_ERROR_CARD_CAN_NOT_BE_WRITTEN -110 +#define KONICA_ERROR_CARD_IS_WRITE_PROTECTED -111 +#define KONICA_ERROR_NO_SPACE_LEFT_ON_CARD -112 +#define KONICA_ERROR_NO_IMAGE_ERASED_AS_IMAGE_PROTECTED -113 +#define KONICA_ERROR_LIGHT_TOO_DARK -114 +#define KONICA_ERROR_AUTOFOCUS_ERROR -115 +#define KONICA_ERROR_SYSTEM_ERROR -116 +#define KONICA_ERROR_ILLEGAL_PARAMETER -117 +#define KONICA_ERROR_COMMAND_CANNOT_BE_CANCELLED -118 +#define KONICA_ERROR_LOCALIZATION_DATA_EXCESS -119 +#define KONICA_ERROR_LOCALIZATION_DATA_CORRUPT -120 +#define KONICA_ERROR_UNSUPPORTED_COMMAND -121 +#define KONICA_ERROR_OTHER_COMMAND_EXECUTING -122 +#define KONICA_ERROR_COMMAND_ORDER_ERROR -123 +#define KONICA_ERROR_UNKNOWN_ERROR -124 + +#define KONICA_NUM_ERRORS 25 + diff --git a/camlibs/konica/lowlevel.c b/camlibs/konica/lowlevel.c index daa498d81..8ad5c4056 100644 --- a/camlibs/konica/lowlevel.c +++ b/camlibs/konica/lowlevel.c @@ -17,7 +17,7 @@ /***************/ /* Definitions */ /***************/ -#define DEFAULT_TIMEOUT 200 +#define DEFAULT_TIMEOUT 1000 #define STX 0x02 /****************/ #define ETX 0x03 /* */ #define ENQ 0x05 /* */ @@ -33,30 +33,33 @@ /**************/ /* Prototypes */ /**************/ -l_return_status_t l_esc_read (gpio_device *device, guchar *c); +gint l_esc_read (gpio_device* device, guchar* c); -l_return_status_t l_send (gpio_device *device, unsigned char *send_buffer, unsigned int send_buffer_size); +gint l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size); -l_return_status_t l_receive (gpio_device *device, unsigned char **rb, unsigned int *rbs, guint timeout); +gint l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout); /*************/ /* Functions */ /*************/ -l_return_status_t l_init (gpio_device *device) +gint +l_init (gpio_device* device) { - guchar c; - gint i; + guchar c; + gint i; + + g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); gpio_set_timeout (device, DEFAULT_TIMEOUT); - if (gpio_open (device) == GPIO_ERROR) return L_IO_ERROR; + if (gpio_open (device) == GPIO_ERROR) return GP_ERROR_IO; for (i = 0; ; i++) { /****************/ /* Write ENQ. */ /****************/ - if (gpio_write (device, "\5", 1) == GPIO_ERROR) return L_IO_ERROR; + if (gpio_write (device, "\5", 1) == GPIO_ERROR) return GP_ERROR_IO; if (gpio_read (device, &c, 1) < 1) { /******************************************************/ /* We didn't receive anything. We'll try up to five */ @@ -64,7 +67,7 @@ l_return_status_t l_init (gpio_device *device) /******************************************************/ if (i == 4) { gpio_close (device); - return (L_IO_ERROR); + return (GP_ERROR_IO); } continue; } @@ -73,7 +76,7 @@ l_return_status_t l_init (gpio_device *device) /******************************************************/ /* ACK received. We can proceed. */ /******************************************************/ - return (L_SUCCESS); + return (GP_OK); default: /******************************************************/ /* The camera seems to be sending something. We'll */ @@ -87,16 +90,22 @@ l_return_status_t l_init (gpio_device *device) } -l_return_status_t l_exit (gpio_device *device) +gint +l_exit (gpio_device* device) { - if (gpio_close (device) == GPIO_ERROR) return (L_IO_ERROR); - return L_SUCCESS; + g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); + + if (gpio_close (device) == GPIO_ERROR) return (GP_ERROR_IO); + return (GP_OK); } -l_return_status_t l_esc_read (gpio_device *device, guchar *c) +gint +l_esc_read (gpio_device* device, guchar* c) { - if (gpio_read (device, c, 1) < 1) return L_IO_ERROR; + g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); + + if (gpio_read (device, c, 1) < 1) return GP_ERROR_IO; /**********************************************************************/ /* STX, ETX, ENQ, ACK, XOFF, XON, NACK, and ETB have to be masked by */ /* ESC. If we receive one of those (except ETX and ETB) without mask, */ @@ -112,36 +121,39 @@ l_return_status_t l_esc_read (gpio_device *device, guchar *c) /**********************************************************************/ if ((*c == STX ) || (*c == ETX) || (*c == ENQ ) || (*c == ACK) || (*c == XOFF) || (*c == XON) || (*c == NACK) || (*c == ETB)) { gp_debug_printf (GP_DEBUG_HIGH, "konica", "Wrong ESC masking!"); - if ((*c == ETX) || (*c == ETB)) return (L_TRANSMISSION_ERROR); + if ((*c == ETX) || (*c == ETB)) return (GP_ERROR_CORRUPTED_DATA); } else if (*c == ESC) { - if (gpio_read (device, c, 1) < 1) return L_IO_ERROR; + if (gpio_read (device, c, 1) < 1) return GP_ERROR_IO; *c = (~*c & 0xff); if ((*c != STX ) && (*c != ETX ) && (*c != ENQ) && (*c != ACK ) && (*c != XOFF) && (*c != XON) && (*c != NACK) && (*c != ETB ) && (*c != ESC)) gp_debug_printf (GP_DEBUG_HIGH, "konica", "Wrong ESC masking!"); } - return (L_SUCCESS); + return (GP_OK); } -l_return_status_t l_send (gpio_device *device, guchar *send_buffer, guint send_buffer_size) +gint +l_send (gpio_device* device, guchar* send_buffer, guint send_buffer_size) { - guchar c; - guchar checksum; + guchar c; + guchar checksum; /**********************************************************************/ /* sb: A pointer to the buffer that we will send. */ /* sbs: Its size. */ /**********************************************************************/ - guchar *sb; - guint sbs; - gint i; + guchar* sb; + guint sbs; + gint i; + + g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); i = 0; for (;;) { /****************/ /* Write ENQ. */ /****************/ - if (gpio_write (device, "\5", 1) == GPIO_ERROR) return (L_IO_ERROR); + if (gpio_write (device, "\5", 1) == GPIO_ERROR) return (GP_ERROR_IO); /****************/ /* Read. */ /****************/ @@ -150,7 +162,7 @@ l_return_status_t l_send (gpio_device *device, guchar *send_buffer, guint send_b /* Let's try for a couple of times. */ /************************************/ i++; - if (i == 5) return (L_IO_ERROR); + if (i == 5) return (GP_ERROR_IO); continue; } switch (c) { @@ -177,11 +189,9 @@ l_return_status_t l_send (gpio_device *device, guchar *send_buffer, guint send_b /* Write NACK. */ /****************/ c = NACK; - if (gpio_write (device, &c, 1) == GPIO_ERROR) - return (L_IO_ERROR); + if (gpio_write (device, &c, 1) == GPIO_ERROR) return (GP_ERROR_IO); for (;;) { - if (gpio_read (device, &c, 1) < 1) - return (L_IO_ERROR); + if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case ENQ: /**************************************/ @@ -197,7 +207,7 @@ l_return_status_t l_send (gpio_device *device, guchar *send_buffer, guint send_b /**************************************/ /* This should not happen. */ /**************************************/ - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } break; } @@ -268,11 +278,11 @@ l_return_status_t l_send (gpio_device *device, guchar *send_buffer, guint send_b /************************/ if (gpio_write (device, sb, sbs) == GPIO_ERROR) { g_free (sb); - return (L_IO_ERROR); + return (GP_ERROR_IO); } if (gpio_read (device, &c, 1) < 1) { g_free (sb); - return L_IO_ERROR; + return GP_ERROR_IO; } switch (c) { case ACK: @@ -284,37 +294,40 @@ l_return_status_t l_send (gpio_device *device, guchar *send_buffer, guint send_b /* Write EOT. */ /****************/ c = EOT; - if (gpio_write (device, &c, 1) == GPIO_ERROR) return (L_IO_ERROR); - return (L_SUCCESS); + if (gpio_write (device, &c, 1) == GPIO_ERROR) return (GP_ERROR_IO); + return (GP_OK); case NACK: /******************************************************/ /* NACK received. We'll try up to three times. */ /******************************************************/ if (i == 2) { g_free (sb); - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } else break; default: /******************************************************/ /* Should not happen. */ /******************************************************/ - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } } } -l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint timeout) +gint +l_receive (gpio_device* device, guchar** rb, guint* rbs, guint timeout) { - guchar c, d; - gboolean error_flag; - guint i, j, rbs_internal; - unsigned char checksum; - l_return_status_t return_status; + guchar c, d; + gboolean error_flag; + guint i, j, rbs_internal; + guchar checksum; + gint result; + + g_return_val_if_fail (device, GP_ERROR_BAD_PARAMETERS); for (i = 0; ; ) { gpio_set_timeout (device, timeout); - if (gpio_read (device, &c, 1) < 1) return (L_IO_ERROR); + if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); gpio_set_timeout (device, DEFAULT_TIMEOUT); switch (c) { case ENQ: @@ -337,7 +350,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /* we can not get the camera back to working */ /* correctly. */ /**********************************************/ - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } i++; break; @@ -348,7 +361,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /* error). */ /******************************************************/ for (;;) { - if (gpio_read (device, &c, 1) < 0) return (L_TRANSMISSION_ERROR); + if (gpio_read (device, &c, 1) < 0) return (GP_ERROR_CORRUPTED_DATA); if (c == ENQ) break; } break; @@ -358,10 +371,10 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /**************/ /* Write ACK. */ /**************/ - if (gpio_write (device, "\6", 1) == GPIO_ERROR) return (L_IO_ERROR); + if (gpio_write (device, "\6", 1) == GPIO_ERROR) return (GP_ERROR_IO); for (*rbs = 0; ; ) { for (j = 0; ; j++) { - if (gpio_read (device, &c, 1) < 1) return (L_IO_ERROR); + if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case STX: /**********************************************/ @@ -378,11 +391,11 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /* Read 2 bytes for size (low order byte, high order */ /* byte) plus ESC quotes. */ /******************************************************/ - return_status = l_esc_read (device, &c); - if (return_status != L_SUCCESS) return (return_status); + result = l_esc_read (device, &c); + if (result != GP_OK) return (result); checksum = c; - return_status = l_esc_read (device, &d); - if (return_status != L_SUCCESS) return (return_status); + result = l_esc_read (device, &d); + if (result != GP_OK) return (result); checksum += d; rbs_internal = (d << 8) | c; if (*rbs == 0) *rb = g_new (guchar, rbs_internal); @@ -392,11 +405,11 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /******************************************************/ error_flag = FALSE; for (i = 0; i < rbs_internal; i++) { - return_status = l_esc_read (device, &((*rb)[*rbs + i])); - switch (return_status) { - case L_IO_ERROR: - return (L_IO_ERROR); - case L_TRANSMISSION_ERROR: + result = l_esc_read (device, &((*rb)[*rbs + i])); + switch (result) { + case GP_ERROR_IO: + return (GP_ERROR_IO); + case GP_ERROR_CORRUPTED_DATA: /**************************************/ /* We already received ETX or ETB. */ /* Later, we'll read the checksum */ @@ -405,7 +418,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /**************************************/ error_flag = TRUE; break; - case L_SUCCESS: + case GP_OK: /**************************************/ /* We can proceed. */ /**************************************/ @@ -415,7 +428,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint if (error_flag) break; } if (!error_flag) { - if (gpio_read (device, &d, 1) < 1) return (L_IO_ERROR); + if (gpio_read (device, &d, 1) < 1) return (GP_ERROR_IO); switch (d) { case ETX: /**************************************/ @@ -439,7 +452,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /* reject the packet. */ /**************************************/ while ((d != ETX) && (d != ETB)) { - if (gpio_read (device, &d, 1) < 1) return (L_IO_ERROR); + if (gpio_read (device, &d, 1) < 1) return (GP_ERROR_IO); } error_flag = TRUE; break; @@ -449,14 +462,14 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /******************************************************/ /* Read 1 byte for checksum plus ESC quotes. */ /******************************************************/ - return_status = l_esc_read (device, &c); - if (return_status != L_SUCCESS) return (return_status); + result = l_esc_read (device, &c); + if (result != GP_OK) return (result); if ((c == checksum) && (!error_flag)) { *rbs += rbs_internal; /****************/ /* Write ACK. */ /****************/ - if (gpio_write (device, "\6", 1) == GPIO_ERROR) return (L_IO_ERROR); + if (gpio_write (device, "\6", 1) == GPIO_ERROR) return (GP_ERROR_IO); break; } else { /**********************************************/ @@ -464,17 +477,17 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /* camera will send us the data at the most */ /* three times. */ /**********************************************/ - if (j == 2) return (L_TRANSMISSION_ERROR); + if (j == 2) return (GP_ERROR_CORRUPTED_DATA); /****************/ /* Write NACK. */ /****************/ c = NACK; - if (gpio_write (device, &c, 1) == GPIO_ERROR) return (L_IO_ERROR); + if (gpio_write (device, &c, 1) == GPIO_ERROR) return (GP_ERROR_IO); continue; } } if (gpio_read (device, &c, 1) < 1) - return (L_IO_ERROR); + return (GP_ERROR_IO); switch (c) { case EOT: /**********************************************/ @@ -485,7 +498,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /**********************************************/ /* Should not happen. */ /**********************************************/ - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } /**************************************************************/ /* Depending on d, we will either continue to receive data or */ @@ -499,7 +512,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /******************************************************/ /* We are all done. */ /******************************************************/ - return (L_SUCCESS); + return (GP_OK); case ETB: /******************************************************/ /* We expect more data. */ @@ -507,8 +520,7 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /****************/ /* Read ENQ. */ /****************/ - if (gpio_read (device, &c, 1) < 1) - return (L_IO_ERROR); + if (gpio_read (device, &c, 1) < 1) return (GP_ERROR_IO); switch (c) { case ENQ: /**********************************************/ @@ -519,83 +531,85 @@ l_return_status_t l_receive (gpio_device *device, guchar **rb, guint *rbs, guint /**********************************************/ /* Should not happen. */ /**********************************************/ - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } /****************/ /* Write ACK. */ /****************/ if (gpio_write (device, "\6", 1) == GPIO_ERROR) - return (L_IO_ERROR); + return (GP_ERROR_IO); break; default: /******************************************************/ /* Should not happen. */ /******************************************************/ - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } } } -l_return_status_t l_send_receive (gpio_device *device, guchar *send_buffer, guint send_buffer_size, guchar **receive_buffer, guint *receive_buffer_size) +gint +l_send_receive (gpio_device* device, guchar* send_buffer, guint send_buffer_size, guchar** receive_buffer, guint* receive_buffer_size) { - l_return_status_t return_status; + gint result; /****************/ /* Send data. */ /****************/ - return_status = l_send (device, send_buffer, send_buffer_size); - if (return_status != L_SUCCESS) return (return_status); + result = l_send (device, send_buffer, send_buffer_size); + if (result != GP_OK) return (result); /********************************/ /* Receive control data. */ /********************************/ - return_status = l_receive (device, receive_buffer, receive_buffer_size, 3000); - if (return_status != L_SUCCESS) return (return_status); + result = l_receive (device, receive_buffer, receive_buffer_size, 3000); + if (result != GP_OK) return (result); if (((*receive_buffer)[0] != send_buffer[0]) || ((*receive_buffer)[1] != send_buffer[1])) { gp_debug_printf (GP_DEBUG_HIGH, "konica", "Error: Commands differ! %i %i != %i %i.\n", (*receive_buffer)[0], (*receive_buffer)[1], send_buffer[0], send_buffer[1]); - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } - else return (return_status); + else return (result); } -l_return_status_t l_send_receive_receive ( - gpio_device *device, - guchar *send_buffer, - guint send_buffer_size, - guchar **image_buffer, - guint *image_buffer_size, - guchar **receive_buffer, - guint *receive_buffer_size, - guint timeout) +gint +l_send_receive_receive ( + gpio_device* device, + guchar* send_buffer, + guint send_buffer_size, + guchar** image_buffer, + guint* image_buffer_size, + guchar** receive_buffer, + guint* receive_buffer_size, + guint timeout) { - l_return_status_t return_status; + gint result; /****************/ /* Send data. */ /****************/ - return_status = l_send (device, send_buffer, send_buffer_size); - if (return_status != L_SUCCESS) return (return_status); + result = l_send (device, send_buffer, send_buffer_size); + if (result != GP_OK) return (result); /************************/ /* Receive data. */ /************************/ - return_status = l_receive (device, image_buffer, image_buffer_size, timeout); - if (return_status != L_SUCCESS) return (return_status); + result = l_receive (device, image_buffer, image_buffer_size, timeout); + if (result != GP_OK) return (result); /********************************/ /* Receive control data. */ /********************************/ - return_status = l_receive (device, receive_buffer, receive_buffer_size, DEFAULT_TIMEOUT); - if (return_status != L_SUCCESS) return (return_status); + result = l_receive (device, receive_buffer, receive_buffer_size, DEFAULT_TIMEOUT); + if (result != GP_OK) return (result); if (((*receive_buffer)[0] != send_buffer[0]) || ((*receive_buffer)[1] != send_buffer[1])) { gp_debug_printf (GP_DEBUG_HIGH, "konica", "Error: Commands differ! %i %i != %i %i.\n", (*receive_buffer)[0], (*receive_buffer)[1], send_buffer[0], send_buffer[1]); - return (L_TRANSMISSION_ERROR); + return (GP_ERROR_CORRUPTED_DATA); } - return (return_status); + return (result); } diff --git a/camlibs/konica/lowlevel.h b/camlibs/konica/lowlevel.h index 57944bbd9..3440458e1 100644 --- a/camlibs/konica/lowlevel.h +++ b/camlibs/konica/lowlevel.h @@ -26,23 +26,13 @@ /****************************************************************/ -/****************************************************************/ -/* Type Definitions */ -/****************************************************************/ -typedef enum { - L_SUCCESS, - L_TRANSMISSION_ERROR, - L_IO_ERROR -} l_return_status_t; - - /****************************************************************/ /* Prototypes */ /****************************************************************/ -l_return_status_t l_init (gpio_device *device); +gint l_init (gpio_device* device); -l_return_status_t l_exit (gpio_device *device); +gint l_exit (gpio_device* device); /****************************************************************/ @@ -64,20 +54,20 @@ l_return_status_t l_exit (gpio_device *device); /* that, depending on command and return */ /* status, other bytes will follow. */ /****************************************************************/ -l_return_status_t l_send_receive ( - gpio_device *device, - guchar *send_buffer, - guint send_buffer_size, - guchar **receive_buffer, - guint *receive_buffer_size); +gint l_send_receive ( + gpio_device* device, + guchar* send_buffer, + guint send_buffer_size, + guchar** receive_buffer, + guint* receive_buffer_size); -l_return_status_t l_send_receive_receive ( - gpio_device *device, - guchar *send_buffer, - guint send_buffer_size, - guchar **image_buffer, - guint *image_buffer_size, - guchar **receive_buffer, - guint *receive_buffer_size, - guint timeout); +gint l_send_receive_receive ( + gpio_device* device, + guchar* send_buffer, + guint send_buffer_size, + guchar** image_buffer, + guint* image_buffer_size, + guchar** receive_buffer, + guint* receive_buffer_size, + guint timeout);