diff --git a/ChangeLog b/ChangeLog index 59a2bdab9..3b8df6af3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2001-10-01 Lutz Müller + + * camlibs/konica/konica.[c,h]: + * camlibs/konica/library.c: Moving towards glib-free code... + 2001-09-27 Lutz Müller * camlibs/sierra/protocol.c: diff --git a/camlibs/konica/konica.c b/camlibs/konica/konica.c index ca7b17382..59a2ba165 100644 --- a/camlibs/konica/konica.c +++ b/camlibs/konica/konica.c @@ -27,75 +27,80 @@ #include "lowlevel.h" #include "konica.h" -static int -GP_RESULT (unsigned char byte1, unsigned char byte2) -{ - switch ((byte2 << 8 ) | byte1) { - case 0x0000: - return (GP_OK); - case 0x0101: - return (KONICA_ERROR_FOCUSING_ERROR); - case 0x0102: - return (KONICA_ERROR_IRIS_ERROR); - case 0x0201: - return (KONICA_ERROR_STROBE_ERROR); - case 0x0203: - return (KONICA_ERROR_EEPROM_CHECKSUM_ERROR); - case 0x0205: - return (KONICA_ERROR_INTERNAL_ERROR1); - case 0x0206: - return (KONICA_ERROR_INTERNAL_ERROR2); - case 0x0301: - return (KONICA_ERROR_NO_CARD_PRESENT); - case 0x0311: - return (KONICA_ERROR_CARD_NOT_SUPPORTED); - case 0x0321: - return (KONICA_ERROR_CARD_REMOVED_DURING_ACCESS); - case 0x0340: - return (KONICA_ERROR_IMAGE_NUMBER_NOT_VALID); - case 0x0341: - return (KONICA_ERROR_CARD_CAN_NOT_BE_WRITTEN); - case 0x0381: - return (KONICA_ERROR_CARD_IS_WRITE_PROTECTED); - case 0x0382: - return (KONICA_ERROR_NO_SPACE_LEFT_ON_CARD); - case 0x0390: - return (KONICA_ERROR_IMAGE_PROTECTED); - case 0x0401: - return (KONICA_ERROR_LIGHT_TOO_DARK); - case 0x0402: - return (KONICA_ERROR_AUTOFOCUS_ERROR); - case 0x0501: - return (KONICA_ERROR_SYSTEM_ERROR); - case 0x0800: - return (KONICA_ERROR_ILLEGAL_PARAMETER); - case 0x0801: - return (KONICA_ERROR_COMMAND_CANNOT_BE_CANCELLED); - case 0x0b00: - return (KONICA_ERROR_LOCALIZATION_DATA_EXCESS); - case 0x0bff: - return (KONICA_ERROR_LOCALIZATION_DATA_CORRUPT); - case 0x0c01: - return (KONICA_ERROR_UNSUPPORTED_COMMAND); - case 0x0c02: - return (KONICA_ERROR_OTHER_COMMAND_EXECUTING); - case 0x0c03: - return (KONICA_ERROR_COMMAND_ORDER_ERROR); - case 0x0fff: - return (KONICA_ERROR_UNKNOWN_ERROR); - default: - gp_debug_printf (GP_DEBUG_MEDIUM, "konica", - "The camera has just sent an error that has not " - "yet been discovered. Please report the following " - "to the maintainer of this driver with some " - "additional information how you got this error.\n" - " - Byte 1: %i\n" - " - Byte 2: %i\n" - "Thank you very much!\n", - byte1, - byte2); - return (GP_ERROR); - } +#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);} +#define CHECK_RESULT(r,f) { \ + int res = (r); \ + if (res < 0) { \ + if (f) \ + free (f); \ + return (res); \ + } \ + switch (((f)[3] << 8) | (f)[2]) { \ + case 0x0000: \ + break; \ + case 0x0101: \ + return (KONICA_ERROR_FOCUSING_ERROR);\ + case 0x0102:\ + return (KONICA_ERROR_IRIS_ERROR);\ + case 0x0201:\ + return (KONICA_ERROR_STROBE_ERROR);\ + case 0x0203:\ + return (KONICA_ERROR_EEPROM_CHECKSUM_ERROR);\ + case 0x0205:\ + return (KONICA_ERROR_INTERNAL_ERROR1);\ + case 0x0206:\ + return (KONICA_ERROR_INTERNAL_ERROR2);\ + case 0x0301:\ + return (KONICA_ERROR_NO_CARD_PRESENT);\ + case 0x0311:\ + return (KONICA_ERROR_CARD_NOT_SUPPORTED);\ + case 0x0321:\ + return (KONICA_ERROR_CARD_REMOVED_DURING_ACCESS);\ + case 0x0340:\ + return (KONICA_ERROR_IMAGE_NUMBER_NOT_VALID);\ + case 0x0341:\ + return (KONICA_ERROR_CARD_CAN_NOT_BE_WRITTEN);\ + case 0x0381:\ + return (KONICA_ERROR_CARD_IS_WRITE_PROTECTED);\ + case 0x0382:\ + return (KONICA_ERROR_NO_SPACE_LEFT_ON_CARD);\ + case 0x0390:\ + return (KONICA_ERROR_IMAGE_PROTECTED);\ + case 0x0401:\ + return (KONICA_ERROR_LIGHT_TOO_DARK);\ + case 0x0402:\ + return (KONICA_ERROR_AUTOFOCUS_ERROR);\ + case 0x0501:\ + return (KONICA_ERROR_SYSTEM_ERROR);\ + case 0x0800:\ + return (KONICA_ERROR_ILLEGAL_PARAMETER);\ + case 0x0801:\ + return (KONICA_ERROR_COMMAND_CANNOT_BE_CANCELLED);\ + case 0x0b00:\ + return (KONICA_ERROR_LOCALIZATION_DATA_EXCESS);\ + case 0x0bff:\ + return (KONICA_ERROR_LOCALIZATION_DATA_CORRUPT);\ + case 0x0c01:\ + return (KONICA_ERROR_UNSUPPORTED_COMMAND);\ + case 0x0c02:\ + return (KONICA_ERROR_OTHER_COMMAND_EXECUTING);\ + case 0x0c03:\ + return (KONICA_ERROR_COMMAND_ORDER_ERROR);\ + case 0x0fff:\ + return (KONICA_ERROR_UNKNOWN_ERROR);\ + default:\ + gp_debug_printf (GP_DEBUG_MEDIUM, "konica",\ + "The camera has just sent an error that has not "\ + "yet been discovered. Please report the following "\ + "to the maintainer of this driver with some "\ + "additional information how you got this error.\n"\ + " - Byte 1: %i\n"\ + " - Byte 2: %i\n"\ + "Thank you very much!\n",\ + (f)[2],\ + (f)[3]);\ + return (GP_ERROR);\ + }\ } int @@ -131,24 +136,25 @@ k_erase_image (gp_port* device, gboolean image_id_long, gulong image_id) /************************************************/ guchar sb[] = {0x00, 0x80, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; if (!image_id_long) { sb[6] = image_id; sb[7] = image_id >> 8; - result = l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL); + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, + 0, NULL, NULL), rb); } else { sb[6] = image_id >> 16; sb[7] = image_id >> 24; sb[8] = image_id; sb[9] = image_id >> 8; - result = l_send_receive (device, sb, 10, &rb, &rbs, 0, NULL, NULL); + CHECK_RESULT (l_send_receive (device, sb, 10, &rb, &rbs, + 0, NULL, NULL), rb); } - if (result == GP_OK) result = GP_RESULT (rb [2], rb [3]); + g_free (rb); - return (result); + return (GP_OK); } @@ -174,14 +180,14 @@ k_format_memory_card (gp_port* device) /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0x10, 0x80, 0x00, 0x00, 0x02, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - result = l_send_receive (device, sb, 6, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + CHECK_RESULT (l_send_receive (device, sb, 6, &rb, &rbs, + 0, NULL, NULL), rb); + g_free (rb); - return (result); + return (GP_OK); } @@ -210,23 +216,23 @@ gint k_erase_all (gp_port* device, guint* number_of_images_not_erased) /* 0xXX: Byte 1 of number of images not erased */ /************************************************/ guchar sb[] = {0x20, 0x80, 0x00, 0x00, 0x02, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - g_return_val_if_fail (number_of_images_not_erased, GP_ERROR_BAD_PARAMETERS); + CHECK_NULL (number_of_images_not_erased); - result = l_send_receive (device, sb, 6, &rb, &rbs, 0, NULL, NULL); - 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]; - } + CHECK_RESULT (l_send_receive (device, sb, 6, &rb, &rbs, + 0, NULL, NULL), rb); + + *number_of_images_not_erased = (rb[5] << 8) | rb[4]; g_free (rb); - return (result); + return (GP_OK); } -gint k_set_protect_status (gp_port *device, gboolean image_id_long, gulong image_id, gboolean protected) +int +k_set_protect_status (gp_port *device, gboolean image_id_long, + gulong image_id, gboolean protected) { /************************************************/ /* Command to set the protect status of one */ @@ -257,7 +263,6 @@ gint k_set_protect_status (gp_port *device, gboolean image_id_long, gulong image /************************************************/ guchar sb[] = {0x30, 0x80, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; @@ -265,18 +270,20 @@ gint k_set_protect_status (gp_port *device, gboolean image_id_long, gulong image if (protected) sb[8] = 0x01; sb[6] = image_id; sb[7] = image_id >> 8; - result = l_send_receive (device, sb, 10, &rb, &rbs, 0, NULL, NULL); + CHECK_RESULT (l_send_receive (device, sb, 10, &rb, &rbs, + 0, NULL, NULL), rb); } 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; - result = l_send_receive (device, sb, 12, &rb, &rbs, 0, NULL, NULL); + CHECK_RESULT (l_send_receive (device, sb, 12, &rb, &rbs, + 0, NULL, NULL), rb); } - if (result == GP_OK) result = GP_RESULT (rb [2], rb [3]); + g_free (rb); - return (result); + return (GP_OK); } @@ -320,14 +327,12 @@ k_get_image ( /* 0xXX: Byte 0 of return status */ /* 0xXX: Byte 1 of return status */ /************************************************/ - guchar sb[] = {0x00, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - gint result; + guchar sb[] = {0x00, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00}; guchar *rb = NULL; guint rbs; - 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); + CHECK_NULL (image_buffer && image_buffer_size); switch (image_type) { case K_THUMBNAIL: @@ -343,21 +348,23 @@ k_get_image ( if (!image_id_long) { sb[6] = image_id; sb[7] = image_id >> 8; - result = l_send_receive (device, sb, 8, &rb, &rbs, 5000, image_buffer, image_buffer_size); + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, 5000, + image_buffer, image_buffer_size), rb); } else { sb[6] = image_id >> 16; sb[7] = image_id >> 24; sb[8] = image_id; sb[9] = image_id >> 8; - result = l_send_receive (device, sb, 10, &rb, &rbs, 5000, image_buffer, image_buffer_size); + CHECK_RESULT (l_send_receive (device, sb, 10, &rb, &rbs, 5000, + image_buffer, image_buffer_size), rb); } - if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + g_free (rb); - return (result); + return (GP_OK); } -gint +int k_get_image_information ( gp_port* device, gboolean image_id_long, @@ -405,52 +412,42 @@ k_get_image_information ( /* 0x01: protected */ /* 0x00: Byte 1 of protect status */ /************************************************/ - guchar sb[] = {0x20, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}; - gint result; + guchar sb[] = {0x20, 0x88, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00}; guchar* rb = NULL; guint rbs; - 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); + CHECK_NULL (image_id && exif_size && protected && information_buffer && + information_buffer_size); if (!image_id_long) { sb[6] = image_number; sb[7] = image_number >> 8; - result = l_send_receive (device, sb, 8, &rb, &rbs, 1000, information_buffer, information_buffer_size); - 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); - } - } + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, 1000, + information_buffer, information_buffer_size), rb); + *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; - result = l_send_receive (device, sb, 10, &rb, &rbs, 1000, information_buffer, information_buffer_size); - 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); - } - } + CHECK_RESULT (l_send_receive (device, sb, 10, &rb, &rbs, 1000, + information_buffer, information_buffer_size), rb); + *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 (result); + return (GP_OK); } - -gint -k_get_preview (gp_port* device, gboolean thumbnail, guchar** image_buffer, guint* image_buffer_size) +int +k_get_preview (gp_port* device, gboolean thumbnail, + guchar** image_buffer, guint* image_buffer_size) { /************************************************/ /* Command to get the preview from the camera. */ @@ -474,39 +471,23 @@ k_get_preview (gp_port* device, gboolean thumbnail, guchar** image_buffer, guint /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0x40, 0x88, 0x00, 0x00, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - 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); + CHECK_NULL (image_buffer && image_buffer_size); + + if (thumbnail) + sb[4] = 0x01; + CHECK_RESULT (l_send_receive (device, sb, 6, &rb, &rbs, 5000, + image_buffer, image_buffer_size), rb); - if (thumbnail) sb[4] = 0x01; - result = l_send_receive (device, sb, 6, &rb, &rbs, 5000, image_buffer, image_buffer_size); - if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); g_free (rb); - return (result); + return (GP_OK); } - -gint k_get_io_capability ( - gp_port* 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) +int +k_get_io_capability (gp_port *device, + KBitRate *bit_rates, KBitFlag *bit_flags) { /************************************************/ /* Command to get the IO capability from the */ @@ -529,53 +510,22 @@ gint k_get_io_capability ( /* 0xXX: Byte 1 of supported flags */ /************************************************/ guchar sb[] = {0x00, 0x90, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - 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); + CHECK_NULL (bit_rates && bit_flags); + + CHECK_RESULT (l_send_receive (device, sb, 4, &rb, &rbs, + 0, NULL, NULL), rb); + + *bit_rates = (rb[5] << 8) | rb[4]; + *bit_flags = (rb[6] << 8) | rb[5]; - result = (l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL)); - 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]); - *bit_rate_2400 = ((rb[4] ^ (1 << 3)) && ~rb[4]); - *bit_rate_4800 = ((rb[4] ^ (1 << 4)) && ~rb[4]); - *bit_rate_9600 = ((rb[4] ^ (1 << 5)) && ~rb[4]); - *bit_rate_19200 = ((rb[4] ^ (1 << 6)) && ~rb[4]); - *bit_rate_38400 = ((rb[4] ^ (1 << 7)) && ~rb[4]); - *bit_rate_57600 = ((rb[5] ^ (1 << 0)) && ~rb[5]); - *bit_rate_115200 = ((rb[5] ^ (1 << 1)) && ~rb[5]); - *bit_flag_8_bits = ((rb[6] ^ (1 << 0)) && ~rb[6]); - *bit_flag_stop_2_bits = ((rb[6] ^ (1 << 1)) && ~rb[6]); - *bit_flag_parity_on = ((rb[6] ^ (1 << 2)) && ~rb[6]); - *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 result; + return (GP_OK); } - -gint +int k_get_information ( gp_port* device, gchar** model, @@ -687,70 +637,50 @@ k_get_information ( /************************************************/ guchar sb[] = {0x10, 0x90, 0x00, 0x00}; guint i, j; - gint result; guchar* rb = NULL; guint rbs; - 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); + CHECK_NULL (model && serial_number && hardware_version_major && + hardware_version_minor && software_version_major && + software_version_minor && testing_software_version_major && + testing_software_version_minor && name && manufacturer); + + CHECK_RESULT (l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL), + rb); + + /* Model */ + for (i = 0; i < 4; i++) if (rb[8 + i] == 0) break; + *model = g_new0 (gchar, i + 1); + for (j = 0; j < i; j++) (*model)[j] = rb[8 + j]; + + /* Serial Number */ + for (i = 0; i < 10; i++) if (rb[12 + i] == 0) break; + *serial_number = g_new0 (gchar, i + 1); + for (j = 0; j < i; j++) + (*serial_number)[j] = rb[12 + j]; + + /* Versions */ + *hardware_version_major = rb[22]; + *hardware_version_minor = rb[23]; + *software_version_major = rb[24]; + *software_version_minor = rb[25]; + *testing_software_version_major = rb[26]; + *testing_software_version_minor = rb[27]; + + /* Name */ + for (i = 0; i < 22; i++) if (rb[28 + i] == 0) break; + *name = g_new0 (gchar, i + 1); + for (j = 0; j < i; j++) (*name)[j] = rb[28 + j]; + + /* Manufacturer */ + for (i = 0; i < 30; i++) if (rb[50 + i] == 0) break; + *manufacturer = g_new0 (gchar, i + 1); + for (j = 0; j < i; j++) (*manufacturer)[j] = rb[50 + j]; - result = l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) { - result = GP_RESULT (rb[2], rb[3]); - if (result == GP_OK) { - /****************/ - /* Model */ - /****************/ - for (i = 0; i < 4; i++) if (rb[8 + i] == 0) break; - *model = g_new0 (gchar, i + 1); - for (j = 0; j < i; j++) (*model)[j] = rb[8 + j]; - /************************/ - /* Serial Number */ - /************************/ - for (i = 0; i < 10; i++) if (rb[12 + i] == 0) break; - *serial_number = g_new0 (gchar, i + 1); - for (j = 0; j < i; j++) - (*serial_number)[j] = rb[12 + j]; - /****************/ - /* Versions */ - /****************/ - *hardware_version_major = rb[22]; - *hardware_version_minor = rb[23]; - *software_version_major = rb[24]; - *software_version_minor = rb[25]; - *testing_software_version_major = rb[26]; - *testing_software_version_minor = rb[27]; - /****************/ - /* Name */ - /****************/ - for (i = 0; i < 22; i++) if (rb[28 + i] == 0) break; - *name = g_new0 (gchar, i + 1); - for (j = 0; j < i; j++) (*name)[j] = rb[28 + j]; - /****************/ - /* Manufacturer */ - /****************/ - for (i = 0; i < 30; i++) if (rb[50 + i] == 0) break; - *manufacturer = g_new0 (gchar, i + 1); - for (j = 0; j < i; j++) (*manufacturer)[j] = rb[50 + j]; - } - } g_free (rb); - return result; + return (GP_OK); } - int k_get_status (gp_port* device, KStatus *status) { @@ -815,92 +745,90 @@ k_get_status (gp_port* device, KStatus *status) /* 0xXX: Byte 1 of total strobes */ /************************************************/ guchar sb[] = {0x20, 0x90, 0x00, 0x00, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - result = l_send_receive (device, sb, 6, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) { - result = GP_RESULT (rb[2], rb[3]); - if (result == GP_OK) { - status->self_test_result = (rb[5] << 8) | rb[4]; - switch (rb[6]) { - case 0x00: - status->power_level = K_POWER_LEVEL_LOW; - break; - case 0x01: - status->power_level = K_POWER_LEVEL_NORMAL; - break; - case 0x02: - status->power_level = K_POWER_LEVEL_HIGH; - break; - default: - gp_debug_printf (GP_DEBUG_HIGH, "konica", - "Unknown power level %i!", - rb[6]); - break; - } - switch (rb[7]) { - case 0x00: - status->power_source = K_POWER_SOURCE_BATTERY; - break; - case 0x01: - status->power_source = K_POWER_SOURCE_AC; - break; - default: - gp_debug_printf (GP_DEBUG_HIGH, "konica", - "Unknown power source %i!", - rb[7]); - break; - } - switch (rb[8]) { - case 0x07: - status->card_status = K_CARD_STATUS_CARD; - break; - case 0x12: - status->card_status = K_CARD_STATUS_NO_CARD; - break; - default: - gp_debug_printf (GP_DEBUG_HIGH, "konica", - "Unknown card status %i!", - rb[8]); - break; - } - switch (rb[9]) { - case 0x00: - status->display = K_DISPLAY_BUILT_IN; - break; - case 0x02: - status->display = K_DISPLAY_TV; - break; - default: - gp_debug_printf (GP_DEBUG_HIGH, "konica", - "Unkown display %i!", rb[9]); - break; - } - status->card_size = (rb[11] << 8) | rb[10]; - status->pictures = (rb[13] << 8) | rb[12]; - status->pictures_left = (rb[15] << 8) | rb[14]; - status->date.year = rb[16]; - status->date.month = rb[17]; - status->date.day = rb[18]; - status->date.hour = rb[19]; - status->date.minute = rb[20]; - status->date.second = rb[21]; - status->io_setting_bit_rate = (rb[23] << 8) | rb[22]; - status->io_setting_flags = (rb[25] << 8) | rb[24]; - status->flash = rb[26]; - status->resolution = rb[27]; - status->focus = rb[28]; - status->exposure = rb[29]; - status->total_pictures = (rb[31] << 8) | rb[30]; - status->total_strobes = (rb[33] << 8) | rb[32]; - } - } - g_free (rb); - return (result); -} + CHECK_NULL (status); + CHECK_RESULT (l_send_receive (device, sb, 6, &rb, &rbs, 0, NULL, NULL), + rb); + + status->self_test_result = (rb[5] << 8) | rb[4]; + switch (rb[6]) { + case 0x00: + status->power_level = K_POWER_LEVEL_LOW; + break; + case 0x01: + status->power_level = K_POWER_LEVEL_NORMAL; + break; + case 0x02: + status->power_level = K_POWER_LEVEL_HIGH; + break; + default: + gp_debug_printf (GP_DEBUG_HIGH, "konica", + "Unknown power level %i!", + rb[6]); + break; + } + switch (rb[7]) { + case 0x00: + status->power_source = K_POWER_SOURCE_BATTERY; + break; + case 0x01: + status->power_source = K_POWER_SOURCE_AC; + break; + default: + gp_debug_printf (GP_DEBUG_HIGH, "konica", + "Unknown power source %i!", + rb[7]); + break; + } + switch (rb[8]) { + case 0x07: + status->card_status = K_CARD_STATUS_CARD; + break; + case 0x12: + status->card_status = K_CARD_STATUS_NO_CARD; + break; + default: + gp_debug_printf (GP_DEBUG_HIGH, "konica", + "Unknown card status %i!", + rb[8]); + break; + } + switch (rb[9]) { + case 0x00: + status->display = K_DISPLAY_BUILT_IN; + break; + case 0x02: + status->display = K_DISPLAY_TV; + break; + default: + gp_debug_printf (GP_DEBUG_HIGH, "konica", + "Unkown display %i!", rb[9]); + break; + } + status->card_size = (rb[11] << 8) | rb[10]; + status->pictures = (rb[13] << 8) | rb[12]; + status->pictures_left = (rb[15] << 8) | rb[14]; + status->date.year = rb[16]; + status->date.month = rb[17]; + status->date.day = rb[18]; + status->date.hour = rb[19]; + status->date.minute = rb[20]; + status->date.second = rb[21]; + status->bit_rate = (rb[23] << 8) | rb[22]; + status->bit_flags = (rb[25] << 8) | rb[24]; + status->flash = rb[26]; + status->resolution = rb[27]; + status->focus = rb[28]; + status->exposure = rb[29]; + status->total_pictures = (rb[31] << 8) | rb[30]; + status->total_strobes = (rb[33] << 8) | rb[32]; + + g_free (rb); + return (GP_OK); +} int k_get_date_and_time (gp_port *device, KDate *date) @@ -928,24 +856,21 @@ k_get_date_and_time (gp_port *device, KDate *date) /* 0xXX: Second */ /************************************************/ guchar sb[] = {0x30, 0x90, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - result = l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL); - if ((result == GP_OK) && - ((result = GP_RESULT (rb[2], rb[3])) == GP_OK)) { - date->year = rb[4]; - date->month = rb[5]; - date->day = rb[6]; - date->hour = rb[7]; - date->minute = rb[8]; - date->second = rb[9]; - } - g_free (rb); - return (result); -}; + CHECK_RESULT (l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL), + rb); + date->year = rb[4]; + date->month = rb[5]; + date->day = rb[6]; + date->hour = rb[7]; + date->minute = rb[8]; + date->second = rb[9]; + g_free (rb); + return (GP_OK); +}; int k_get_preferences (gp_port *device, KPreferences *preferences) @@ -975,32 +900,22 @@ k_get_preferences (gp_port *device, KPreferences *preferences) /* 0xXX: Byte 1 of slide show interval */ /************************************************/ guchar sb[] = {0x40, 0x90, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - result = l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL); - if ((result == GP_OK) && - ((result = GP_RESULT (rb[2], rb[3])) == GP_OK)) { - preferences->shutoff_time = rb[4]; - preferences->self_timer_time = rb[5]; - preferences->beep = rb[6]; - preferences->slide_show_interval = rb[7]; - } + CHECK_RESULT (l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL), + rb); + preferences->shutoff_time = rb[4]; + preferences->self_timer_time = rb[5]; + preferences->beep = rb[6]; + preferences->slide_show_interval = rb[7]; + g_free (rb); - return (result); + return (GP_OK); } - -gint -k_set_io_capability ( - gp_port* 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) +int +k_set_io_capability (gp_port *device, KBitRate bit_rate, KBitFlag bit_flags) { /************************************************/ /* Command to set the IO capability of the */ @@ -1022,49 +937,18 @@ k_set_io_capability ( /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0x80, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - switch (bit_rate) { - case 300: - sb[4] = (1 << 0); - break; - case 600: - sb[4] = (1 << 1); - break; - case 1200: - sb[4] = (1 << 2); - break; - case 2400: - sb[4] = (1 << 3); - break; - case 4800: - sb[4] = (1 << 4); - break; - case 9600: - sb[4] = (1 << 5); - break; - case 19200: - sb[4] = (1 << 6); - break; - case 38400: - sb[4] = (1 << 7); - break; - case 57600: - sb[5] = (1 << 0); - break; - case 115200: - sb[5] = (1 << 1); - break; - default: - return (GP_ERROR_NOT_SUPPORTED); - } - 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, 0, NULL, NULL); - if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + sb[4] = bit_rate; + sb[5] = bit_rate >> 8; + sb[6] = bit_flags; + + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL), + rb); + g_free (rb); - return (result); + return (GP_OK); } @@ -1093,7 +977,6 @@ k_set_date_and_time (gp_port *device, KDate date) /************************************************/ guchar sb[] = {0xb0, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - int result; guchar* rb = NULL; guint rbs; @@ -1103,11 +986,10 @@ k_set_date_and_time (gp_port *device, KDate date) sb[7] = date.hour; sb[8] = date.minute; sb[9] = date.second; - result = l_send_receive (device, sb, 10, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) - result = GP_RESULT (rb[2], rb[3]); + CHECK_RESULT (l_send_receive (device, sb, 10, &rb, &rbs, 0, NULL, NULL), + rb); g_free (rb); - return (result); + return (GP_OK); } @@ -1131,7 +1013,6 @@ k_set_preference (gp_port *device, KPreference preference, unsigned int value) /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0xc0, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - int result; guchar* rb = NULL; guint rbs; @@ -1170,11 +1051,10 @@ k_set_preference (gp_port *device, KPreference preference, unsigned int value) } sb[6] = value; sb[7] = value >> 8; - result = l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) - result = GP_RESULT (rb[2], rb[3]); + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL), + rb); g_free (rb); - return (result); + return (GP_OK); } int @@ -1196,19 +1076,17 @@ k_reset_preferences (gp_port *device) /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0xc1, 0x90, 0x00, 0x00}; - int result; guchar* rb = NULL; guint rbs; - result = l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) - result = GP_RESULT (rb[2], rb[3]); + CHECK_RESULT (l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL), + rb); g_free (rb); - return (result); + return (GP_OK); } -gint +int k_take_picture ( gp_port* device, gboolean image_id_long, @@ -1249,37 +1127,29 @@ k_take_picture ( /* 0x00: Byte 1 of protect status */ /************************************************/ guchar sb[] = {0x00, 0x91, 0x00, 0x00, 0x02, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - 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); + CHECK_NULL (image_id && exif_size && protected && information_buffer && + information_buffer_size); - result = l_send_receive (device, sb, 6, &rb, &rbs, 60000, information_buffer, information_buffer_size); - 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]; - *protected = (rb[8] != 0x00); - } else { - *image_id = (rb[5] << 24) | (rb[4] << 16) | (rb[7] << 8) | (rb[6]); - *exif_size = (rb[9] << 8) | rb[8]; - *protected = (rb[10] != 0x00); - } - } - } + CHECK_RESULT (l_send_receive (device, sb, 6, &rb, &rbs, 60000, + information_buffer, information_buffer_size), rb); + + if (!image_id_long) { + *image_id = 0x00 | 0x00 | (rb[5] << 8) | rb[4]; + *exif_size = (rb[7] << 8) | rb[6]; + *protected = (rb[8] != 0x00); + } else { + *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 (result); + return (GP_OK); } - int k_localization_tv_output_format_set (gp_port *device, KTVOutputFormat tv_output_format) @@ -1312,7 +1182,6 @@ k_localization_tv_output_format_set (gp_port *device, /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0x00, 0x92, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; - int result; guchar* rb = NULL; guint rbs; @@ -1329,14 +1198,12 @@ k_localization_tv_output_format_set (gp_port *device, default: return (GP_ERROR_BAD_PARAMETERS); } - result = l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) - result = GP_RESULT (rb[2], rb[3]); + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL), + rb); g_free (rb); - return (result); + return (GP_OK); } - int k_localization_date_format_set (gp_port* device, KDateFormat date_format) { @@ -1368,7 +1235,6 @@ k_localization_date_format_set (gp_port* device, KDateFormat date_format) /* 0xXX: Byte 1 of return status */ /************************************************/ guchar sb[] = {0x00, 0x92, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00}; - int result; guchar* rb = NULL; guint rbs; @@ -1385,14 +1251,12 @@ k_localization_date_format_set (gp_port* device, KDateFormat date_format) default: return (GP_ERROR_BAD_PARAMETERS); } - result = l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) - result = GP_RESULT (rb[2], rb[3]); + CHECK_RESULT (l_send_receive (device, sb, 8, &rb, &rbs, 0, NULL, NULL), + rb); g_free (rb); - return (result); + return (GP_OK); } - int k_localization_data_put (gp_port* device, guchar* data, gulong data_size) { @@ -1441,8 +1305,9 @@ k_localization_data_put (gp_port* device, guchar* data, gulong data_size) static guint packet_size = 1024; guchar sb[16 + packet_size]; - g_return_val_if_fail (data_size >= 512, GP_ERROR_BAD_PARAMETERS); - g_return_val_if_fail (data, GP_ERROR_BAD_PARAMETERS); + CHECK_NULL (data); + if (data_size < 512) + return (GP_ERROR_BAD_PARAMETERS); sb[0] = 0x00; sb[1] = 0x92; @@ -1462,6 +1327,7 @@ k_localization_data_put (gp_port* device, guchar* data, gulong data_size) sb[15] = 0x00; i = 0; while (TRUE) { + /* Set up the packet. */ sb[10] = i >> 16; sb[11] = i >> 24; @@ -1471,38 +1337,47 @@ k_localization_data_put (gp_port* device, guchar* data, gulong data_size) if ((i + j) < data_size) sb[16 + j] = data[i + j]; else sb[16 + j] = 0xFF; } - /********************************************************/ - /* We could wait until the camera sends us */ - /* K_ERROR_LOCALIZATION_DATA_EXCESS, but it does that */ - /* not until the 70000th byte or so. However, as we can */ - /* provoke the message with sb[14] = 0x01, we do so as */ - /* soon as we exceed the 65535th byte to shorten the */ - /* transmission time. We can't do that before or the */ - /* camera reports K_ERROR_LOCALIZATION_DATA_CORRUPT. */ - /********************************************************/ - if (i + packet_size > 65536) sb[14] = 0x01; - result = l_send_receive (device, sb, packet_size + 16, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) result = GP_RESULT (rb[2], rb[3]); + + /* + * We could wait until the camera sends us + * K_ERROR_LOCALIZATION_DATA_EXCESS, but it does that + * not until the 70000th byte or so. However, as we can + * provoke the message with sb[14] = 0x01, we do so as + * soon as we exceed the 65535th byte to shorten the + * transmission time. We can't do that before or the + * camera reports K_ERROR_LOCALIZATION_DATA_CORRUPT. + */ + if (i + packet_size > 65536) + sb[14] = 0x01; + result = l_send_receive (device, sb, packet_size + 16, + &rb, &rbs, 0, NULL, NULL); + if (result == GP_OK) { + if ((rb[3] == 0x0b) && (rb[2] == 0x00)) { + + /* + * The camera does no longer want to receive + * localization data. We are done. + */ + return (GP_OK); + } else if ((rb[3] == 0x00) && (rb[2] == 0x00)) { + + /* + * Everything is fine. Continue sending + * packets but make sure we don't loop + * forever. + */ + if (i > 131072) + return (GP_ERROR); + } + } + CHECK_RESULT (result, rb); g_free (rb); - switch (result) { - case GP_OK: - /* Everything is fine. Continue sending packets. However, make sure we don't loop forever. */ - if (i > 131072) return (GP_ERROR_BAD_PARAMETERS); - break; - case KONICA_ERROR_LOCALIZATION_DATA_EXCESS: - /* The camera does no longer want to receive localization data. We are done. */ - return (GP_OK); - default: - /* Something went wrong. */ - return (result); - } i += packet_size; } } - -gint -k_cancel (gp_port* device, k_command_t* command) +int +k_cancel (gp_port* device, KCommand* command) { /************************************************/ /* Command to cancel a command. */ @@ -1522,17 +1397,14 @@ k_cancel (gp_port* device, k_command_t* command) /* 0xXX: Byte 1 of cancelled command */ /************************************************/ guchar sb[] = {0x00, 0x9e, 0x00, 0x00}; - gint result; guchar* rb = NULL; guint rbs; - g_return_val_if_fail (command, GP_ERROR_BAD_PARAMETERS); + CHECK_NULL (command); - result = l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL); - if (result == GP_OK) { - result = GP_RESULT (rb[2], rb[3]); - if (result == GP_OK) *command = (rb[5] << 8) | rb[4]; - } + CHECK_RESULT (l_send_receive (device, sb, 4, &rb, &rbs, 0, NULL, NULL), + rb); + *command = (rb[5] << 8) | rb[4]; g_free (rb); - return (result); + return (GP_OK); } diff --git a/camlibs/konica/konica.h b/camlibs/konica/konica.h index 1043ada8c..fe895f410 100644 --- a/camlibs/konica/konica.h +++ b/camlibs/konica/konica.h @@ -1,50 +1,39 @@ -/****************************************************************/ -/* konica.c - Library giving access to all features of the */ -/* camera. */ -/* */ -/* Copyright (C) 2000 The Free Software Foundation */ -/* */ -/* Author: Lutz Müller */ -/* */ -/* This program is free software; you can redistribute it */ -/* and/or modify it under the terms of the GNU General Public */ -/* License as published by the Free Software Foundation; either */ -/* version 2 of the License, or (at your option) any later */ -/* version. */ -/* */ -/* This program is distributed in the hope that it will be */ -/* useful, but WITHOUT ANY WARRANTY; without even the implied */ -/* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ -/* PURPOSE. See the GNU General Public License for more */ -/* details. */ -/* */ -/* You should have received a copy of the GNU General Public */ -/* License along with this program; if not, write to the Free */ -/* Software Foundation, Inc., 59 Temple Place, Suite 330, */ -/* Boston, MA 02111-1307, USA. */ -/****************************************************************/ +/* konica.h + * + * Copyright (C) 2001 Lutz Müller + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ - -/****************************************************************/ -/* Type Definitions */ -/****************************************************************/ - - -/****************************************************************/ -/* The following are the commands that are supported by the */ -/* camera. All other commands will be rejected as unsupported. */ -/* */ -/* 0x9200: On 'HP PhotoSmart C20', this command seems to */ -/* set the language by transferring huge amounts */ -/* of data. For 'Q-M100', this command is not */ -/* defined according to Konica. */ -/* 0x9e10: Used for development and testing of the camera. */ -/* 0x9e20: Used for development and testing of the camera. */ -/* */ -/* For those commands, no documentation is available. They are */ -/* therefore not implemented. */ -/****************************************************************/ -typedef enum { +/* + * The following are the commands that are supported by the + * camera. All other commands will be rejected as unsupported. + * + * 0x9200: On 'HP PhotoSmart C20', this command seems to + * set the language by transferring huge amounts + * of data. For 'Q-M100', this command is not + * defined according to Konica. + * 0x9e10: Used for development and testing of the camera. + * 0x9e20: Used for development and testing of the camera. + * + * For those commands, no documentation is available. They are + * therefore not implemented. + */ +typedef enum +{ K_ERASE_IMAGE = 0x8000, K_FORMAT_MEMORY_CARD = 0x8010, K_ERASE_ALL = 0x8020, @@ -68,123 +57,115 @@ typedef enum { K_CANCEL = 0x9e00 // ? = 0x9e10, // ? = 0x9e20, -} k_command_t; +} KCommand; -/****************************************************************/ -/* The following are the preferences that can be set. The */ -/* sixteen bits that identify the preference are as follows. */ -/* Low order byte: 0000 0aa0 */ -/* High order byte: 1x0b xxxx */ -/* x can be 1 or 0 with no effect on the command. The a and b */ -/* bits identify the preference and are as follows. */ -/* */ -/* b: 0 1 */ -/* aa: ---------------------------------------------------- */ -/* 00 | resolution flash */ -/* 01 | exposure focus / self timer */ -/* 10 | self timer time auto off time */ -/* 11 | slide show interval beep */ -/* */ -/* */ -/* A short explanation of the values of the preferences: */ -/* */ -/* */ -/* RESOLUTION (default: 2) */ -/* Only the low order byte is processed. */ -/* - 0: medium resolution (same as 2) */ -/* - 1: high resolution (1152 x 872) */ -/* - 2: medium resolution (1152 x 872) */ -/* - 3: low resolution ( 576 x 436) */ -/* Other values are accepted as well, produce however strange */ -/* results on the display, as the camera will calculate the */ -/* remaining pictures on the basis of this value. Those values */ -/* are at some point changed to 'normal' ones. */ -/* Each pixel has an area of 4.6um x 4.6 um. */ -/* */ -/* */ -/* EXPOSURE (default: 0) */ -/* Only the low order byte is processed. */ -/* - 0 to 255. */ -/* The behaviour is somewhat strange. Sending a value will */ -/* not necessarily set the value to exactly the sent one. */ -/* The following table gives an overview. */ -/* sent received sent received */ -/* ---------------- ---------------- */ -/* 0 - 0 128 129 */ -/* 1 0 129 130 */ -/* 2 1 131 - 131 */ -/* 3 2 132 133 */ -/* 4 3 133 134 */ -/* 5 - 5 134 135 */ -/* 6 5 135 136 */ -/* 7 6 136 - 136 */ -/* 8 7 (...) */ -/* 9 8 246 - 246 */ -/* 10 - 10 247 248 */ -/* (...) 248 249 */ -/* 120 - 120 249 250 */ -/* 121 120 250 251 */ -/* 122 121 251 - 251 */ -/* 123 122 252 253 */ -/* 124 123 253 254 */ -/* 125 - 125 254 255 */ -/* 126 125 255 0 */ -/* 127 126 */ -/* */ -/* Additional information from HP: */ -/* - Range: EV 6 to EV 16 (ISO 100). */ -/* - Exposure times: 1/500th to 2 (sec) */ -/* */ -/* */ -/* SELF_TIMER_TIME (default: 10) */ -/* - 3 to 40. Measured in seconds. */ -/* All other values are rejected. */ -/* */ -/* */ -/* SLIDE_SHOW_INTERVAL (default: 3) */ -/* - 1 to 30. Measured in seconds. */ -/* All other values are rejected. */ -/* */ -/* */ -/* FLASH (default: 2) */ -/* Only the low order byte is processed. */ -/* - 0: off */ -/* - 1: on */ -/* - 2: auto */ -/* - 5: on, redeye */ -/* - 6: auto, redeye */ -/* Other values are accepted as well, but will be changed to 2 */ -/* at some point. */ -/* */ -/* */ -/* FOCUS_SELF_TIMER (default: 0) */ -/* Only the low order byte is processed. */ -/* - 0: fixed, next picture in normal mode */ -/* - 1: fixed, next picture in self timer mode */ -/* - 2: auto, next picture in normal mode */ -/* - 3: auto, next picture in self timer mode */ -/* After the next picture has been taken in self timer mode, */ -/* the value is automatically changed to the next lower even */ -/* value (normal mode). */ -/* */ -/* Additional information from HP: */ -/* - Fixed: 2.6 feet to infinity */ -/* - Auto: 8 inches to infinity */ -/* */ -/* */ -/* AUTO_OFF_TIME (default: 5) */ -/* Only the low order byte is processed. */ -/* - 0: Will be changed by the camera to 255. */ -/* - 1 to 255. Measured in minutes. */ -/* */ -/* */ -/* BEEP (default: 1) */ -/* Only the low order byte is processed. */ -/* - 0: off */ -/* - 1 to 255: on */ -/****************************************************************/ -typedef enum { +/* + * The following are the preferences that can be set. The + * sixteen bits that identify the preference are as follows. + * Low order byte: 0000 0aa0 + * High order byte: 1x0b xxxx + * x can be 1 or 0 with no effect on the command. The a and b + * bits identify the preference and are as follows. + * + * b: 0 1 + * aa: ---------------------------------------------------- + * 00 | resolution flash + * 01 | exposure focus / self timer + * 10 | self timer time auto off time + * 11 | slide show interval beep + * + * A short explanation of the values of the preferences: + * + * RESOLUTION (default: 2) + * Only the low order byte is processed. + * - 0: medium resolution (same as 2) + * - 1: high resolution (1152 x 872) + * - 2: medium resolution (1152 x 872) + * - 3: low resolution ( 576 x 436) + * Other values are accepted as well, produce however strange + * results on the display, as the camera will calculate the + * remaining pictures on the basis of this value. Those values + * are at some point changed to 'normal' ones. + * Each pixel has an area of 4.6um x 4.6 um. + * + * EXPOSURE (default: 0) + * Only the low order byte is processed. + * - 0 to 255. + * The behaviour is somewhat strange. Sending a value will + * not necessarily set the value to exactly the sent one. + * The following table gives an overview. + * sent received sent received + * ---------------- ---------------- + * 0 - 0 128 129 + * 1 0 129 130 + * 2 1 131 - 131 + * 3 2 132 133 + * 4 3 133 134 + * 5 - 5 134 135 + * 6 5 135 136 + * 7 6 136 - 136 + * 8 7 (...) + * 9 8 246 - 246 + * 10 - 10 247 248 + * (...) 248 249 + * 120 - 120 249 250 + * 121 120 250 251 + * 122 121 251 - 251 + * 123 122 252 253 + * 124 123 253 254 + * 125 - 125 254 255 + * 126 125 255 0 + * 127 126 + * + * Additional information from HP: + * - Range: EV 6 to EV 16 (ISO 100). + * - Exposure times: 1/500th to 2 (sec) + * + * SELF_TIMER_TIME (default: 10) + * - 3 to 40. Measured in seconds. + * All other values are rejected. + * + * SLIDE_SHOW_INTERVAL (default: 3) + * - 1 to 30. Measured in seconds. + * All other values are rejected. + * + * FLASH (default: 2) + * Only the low order byte is processed. + * - 0: off + * - 1: on + * - 2: auto + * - 5: on, redeye + * - 6: auto, redeye + * Other values are accepted as well, but will be changed to 2 + * at some point. + * + * FOCUS_SELF_TIMER (default: 0) + * Only the low order byte is processed. + * - 0: fixed, next picture in normal mode + * - 1: fixed, next picture in self timer mode + * - 2: auto, next picture in normal mode + * - 3: auto, next picture in self timer mode + * After the next picture has been taken in self timer mode, + * the value is automatically changed to the next lower even + * value (normal mode). + * + * Additional information from HP: + * - Fixed: 2.6 feet to infinity + * - Auto: 8 inches to infinity + * + * AUTO_OFF_TIME (default: 5) + * Only the low order byte is processed. + * - 0: Will be changed by the camera to 255. + * - 1 to 255. Measured in minutes. + * + * BEEP (default: 1) + * Only the low order byte is processed. + * - 0: off + * - 1 to 255: on + */ +typedef enum +{ K_PREFERENCE_RESOLUTION, K_PREFERENCE_EXPOSURE, K_PREFERENCE_SELF_TIMER_TIME, @@ -196,100 +177,93 @@ typedef enum { } KPreference; -typedef enum { +typedef enum +{ K_POWER_LEVEL_LOW, K_POWER_LEVEL_NORMAL, K_POWER_LEVEL_HIGH } KPowerLevel; -typedef enum { +typedef enum +{ K_POWER_SOURCE_BATTERY, K_POWER_SOURCE_AC } KPowerSource; -typedef enum { +typedef enum +{ K_THUMBNAIL, K_IMAGE_JPEG, K_IMAGE_EXIF } KImageType; -typedef enum { +typedef enum +{ K_DISPLAY_BUILT_IN, K_DISPLAY_TV } KDisplay; -typedef enum { +typedef enum +{ K_CARD_STATUS_CARD, K_CARD_STATUS_NO_CARD } KCardStatus; - -typedef enum { +typedef enum +{ K_DATE_FORMAT_MONTH_DAY_YEAR, K_DATE_FORMAT_DAY_MONTH_YEAR, K_DATE_FORMAT_YEAR_MONTH_DAY } KDateFormat; - -typedef enum { +typedef enum +{ K_TV_OUTPUT_FORMAT_NTSC, K_TV_OUTPUT_FORMAT_PAL, K_TV_OUTPUT_FORMAT_HIDE } KTVOutputFormat; +/* + * Two flavours of Konica's protocol exist: One uses two bytes + * for image IDs (qm100, unsigned int), the other one uses four + * (qm200, unsigned long). + */ +int k_init (gp_port *device); -/****************************************************************/ -/* Functions */ -/****************************************************************/ +typedef enum +{ + K_BIT_RATE_300 = 1 << 0, + K_BIT_RATE_600 = 1 << 1, + K_BIT_RATE_1200 = 1 << 2, + K_BIT_RATE_2400 = 1 << 3, + K_BIT_RATE_4800 = 1 << 4, + K_BIT_RATE_9600 = 1 << 5, + K_BIT_RATE_19200 = 1 << 6, + K_BIT_RATE_38400 = 1 << 7, + K_BIT_RATE_57600 = 1 << 8, + K_BIT_RATE_115200 = 1 << 9 +} KBitRate; +typedef enum +{ + K_BIT_FLAG_8_BITS = 1 << 0, + K_BIT_FLAG_STOP_2_BITS = 1 << 1, + K_BIT_FLAG_PARITY_ON = 1 << 2, + K_BIT_FLAG_PARITY_ODD = 1 << 3, + K_BIT_FLAG_HW_FLOW_CTRL = 1 << 4 +} KBitFlag; -/****************************************************************/ -/* Two flavours of Konica's protocol exist: One uses two bytes */ -/* for image IDs (qm100, unsigned int), the other one uses four */ -/* (qm200, unsigned long). */ -/****************************************************************/ -gint k_init (gp_port *device); - - -gint k_get_io_capability ( - gp_port *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); - - -int k_set_io_capability ( - gp_port *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); - +int k_get_io_capability (gp_port *, KBitRate *bit_rates, KBitFlag *bit_flags); +int k_set_io_capability (gp_port *, KBitRate bit_rate, KBitFlag bit_flags); int k_erase_all (gp_port *device, guint *number_of_images_not_erased); - int k_format_memory_card (gp_port *device); - int k_take_picture ( gp_port *device, gboolean image_id_long, @@ -339,7 +313,8 @@ typedef struct { unsigned int card_size; unsigned int pictures, pictures_left; KDate date; - unsigned int io_setting_bit_rate, io_setting_flags; + unsigned int bit_rate; + KBitFlag bit_flags; unsigned char flash, resolution, focus, exposure; unsigned char total_pictures, total_strobes; } KStatus; @@ -347,7 +322,7 @@ typedef struct { int k_get_status (gp_port *device, KStatus *status); -gint k_get_information ( +int k_get_information ( gp_port *device, gchar **model, gchar **serial_number, @@ -361,7 +336,7 @@ gint k_get_information ( gchar **manufacturer); -gint k_get_image_information ( +int k_get_image_information ( gp_port *device, gboolean image_id_long, gulong image_number, @@ -388,11 +363,11 @@ int k_localization_tv_output_format_set (gp_port *device, KTVOutputFormat tv_output_format); -gint k_localization_date_format_set (gp_port *device, KDateFormat date_format); +int k_localization_date_format_set (gp_port *device, KDateFormat date_format); -gint k_localization_data_put (gp_port *device, guchar *data, gulong data_size); +int k_localization_data_put (gp_port *device, guchar *data, gulong data_size); -gint k_cancel (gp_port *device, k_command_t *command); +int k_cancel (gp_port *device, KCommand *command); diff --git a/camlibs/konica/library.c b/camlibs/konica/library.c index 78e4505b5..33c2e81dd 100644 --- a/camlibs/konica/library.c +++ b/camlibs/konica/library.c @@ -19,6 +19,7 @@ */ #include #include +#include #include #include #include @@ -195,14 +196,10 @@ static gint init_serial_connection (Camera *camera) { gint i; - gboolean bit_flag_8_bits, bit_flag_stop_2_bits, bit_flag_parity_on; - gboolean bit_flag_parity_odd, bit_flag_use_hw_flow_control; + KBitRate bit_rates; + KBitFlag bit_flags; 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}; gp_port_settings settings; guint speed; @@ -248,53 +245,108 @@ init_serial_connection (Camera *camera) /* What are the camera's abilities? */ gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Getting IO " "capabilities...\n"); - CHECK (k_get_io_capability (camera->port, &bit_rate_supported [0], - &bit_rate_supported [1], &bit_rate_supported [2], - &bit_rate_supported [3], &bit_rate_supported [4], - &bit_rate_supported [5], &bit_rate_supported [6], - &bit_rate_supported [7], &bit_rate_supported [8], - &bit_rate_supported [9], &bit_flag_8_bits, - &bit_flag_stop_2_bits, &bit_flag_parity_on, - &bit_flag_parity_odd, &bit_flag_use_hw_flow_control)); - + CHECK (k_get_io_capability (camera->port, &bit_rates, &bit_flags)); if (!camera->port_info->speed) { /* Set the highest possible speed */ for (i = 9; i >= 0; i--) - if (bit_rate_supported [i]) - break; + if ((1 << i) & bit_rates) + break; if (i < 0) return (GP_ERROR_IO_SERIAL_SPEED); - camera->port_info->speed = bit_rate [i]; + bit_rates = (1 << i); + switch (i) { + case 0: + camera->port_info->speed = 300; + break; + case 1: + camera->port_info->speed = 600; + break; + case 2: + camera->port_info->speed = 1200; + break; + case 3: + camera->port_info->speed = 2400; + break; + case 4: + camera->port_info->speed = 4800; + break; + case 5: + camera->port_info->speed = 9600; + break; + case 6: + camera->port_info->speed = 19200; + break; + case 7: + camera->port_info->speed = 38400; + break; + case 8: + camera->port_info->speed = 57600; + break; + case 9: + camera->port_info->speed = 115200; + break; + default: + return (GP_ERROR_IO_SERIAL_SPEED); + } } else { /* Does the camera allow us to set the bit rate to the * given one? */ speed = camera->port_info->speed; - if (((speed == 300) && (!bit_rate_supported[0])) || - ((speed == 600) && (!bit_rate_supported[1])) || - ((speed == 1200) && (!bit_rate_supported[2])) || - ((speed == 2400) && (!bit_rate_supported[3])) || - ((speed == 4800) && (!bit_rate_supported[4])) || - ((speed == 9600) && (!bit_rate_supported[5])) || - ((speed == 19200) && (!bit_rate_supported[6])) || - ((speed == 38400) && (!bit_rate_supported[7])) || - ((speed == 57600) && (!bit_rate_supported[8])) || - ((speed == 115200) && (!bit_rate_supported[9])) || - ((speed != 300) && (speed != 600) && - (speed != 1200) && (speed != 2400) && - (speed != 4800) && (speed != 9600) && - (speed != 19200) && (speed != 38400) && - (speed != 57600) && (speed != 115200))) + if (((speed == 300) && (!(bit_rates & (1 << 0)))) || + ((speed == 600) && (!(bit_rates & (1 << 1)))) || + ((speed == 1200) && (!(bit_rates & (1 << 2)))) || + ((speed == 2400) && (!(bit_rates & (1 << 3)))) || + ((speed == 4800) && (!(bit_rates & (1 << 4)))) || + ((speed == 9600) && (!(bit_rates & (1 << 5)))) || + ((speed == 19200) && (!(bit_rates & (1 << 6)))) || + ((speed == 38400) && (!(bit_rates & (1 << 7)))) || + ((speed == 57600) && (!(bit_rates & (1 << 8)))) || + ((speed == 115200) && (!(bit_rates & (1 << 9))))) return (GP_ERROR_IO_SERIAL_SPEED); + switch (speed) { + case 300: + bit_rates = 1 << 0; + break; + case 600: + bit_rates = 1 << 1; + break; + case 1200: + bit_rates = 1 << 2; + break; + case 2400: + bit_rates = 1 << 3; + break; + case 4800: + bit_rates = 1 << 4; + break; + case 9600: + bit_rates = 1 << 5; + break; + case 19200: + bit_rates = 1 << 6; + break; + case 38400: + bit_rates = 1 << 7; + break; + case 57600: + bit_rates = 1 << 8; + break; + case 115200: + bit_rates = 1 << 9; + break; + default: + return (GP_ERROR_IO_SERIAL_SPEED); + } } /* Request the new speed */ - gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Setting speed to " - "%i...\n", camera->port_info->speed); - CHECK (k_set_io_capability (camera->port, camera->port_info->speed, - TRUE, FALSE, FALSE, FALSE, FALSE)); + gp_debug_printf (GP_DEBUG_LOW, "konica", "-> Setting new speed (%x)" + "...", bit_rates); + bit_flags = K_BIT_FLAG_8_BITS; + CHECK (k_set_io_capability (camera->port, bit_rates, bit_flags)); /* Reconnect */ settings.serial.speed = camera->port_info->speed;