From 3118a779151d9b39b907a2b2817929011b0a9bd3 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Thu, 28 Sep 2023 10:27:33 +0200 Subject: [PATCH] merged with pktriggercord largely renames of functions added K-3III --- camlibs/pentax/Makefile-files | 8 +- camlibs/pentax/library.c | 50 +++++------ camlibs/pentax/pslr.c | 157 ++++++++++++++-------------------- camlibs/pentax/pslr.h | 42 ++++----- camlibs/pentax/pslr_enum.c | 46 +++++----- camlibs/pentax/pslr_enum.h | 47 +++++----- camlibs/pentax/pslr_lens.c | 2 +- camlibs/pentax/pslr_lens.h | 6 +- camlibs/pentax/pslr_log.c | 60 +++++++++++++ camlibs/pentax/pslr_log.h | 72 ++++++++++++++++ camlibs/pentax/pslr_model.c | 62 +++++++------- camlibs/pentax/pslr_model.h | 11 ++- camlibs/pentax/pslr_scsi.h | 35 +++----- camlibs/pentax/pslr_utils.c | 90 +++++++++++++++++++ camlibs/pentax/pslr_utils.h | 48 +++++++++++ 15 files changed, 482 insertions(+), 254 deletions(-) create mode 100644 camlibs/pentax/pslr_log.c create mode 100644 camlibs/pentax/pslr_log.h create mode 100644 camlibs/pentax/pslr_utils.c create mode 100644 camlibs/pentax/pslr_utils.h diff --git a/camlibs/pentax/Makefile-files b/camlibs/pentax/Makefile-files index b44c8dfa5a..7ffbafa8a2 100644 --- a/camlibs/pentax/Makefile-files +++ b/camlibs/pentax/Makefile-files @@ -10,16 +10,20 @@ camlibdoc_DATA += %reldir%/README.pentax EXTRA_LTLIBRARIES += pentax.la pentax_la_SOURCES = -pentax_la_SOURCES += %reldir%/pslr.c pentax_la_SOURCES += %reldir%/library.c +pentax_la_SOURCES += %reldir%/pslr.c pentax_la_SOURCES += %reldir%/pslr_enum.c +pentax_la_SOURCES += %reldir%/pslr_log.c pentax_la_SOURCES += %reldir%/pslr_lens.c pentax_la_SOURCES += %reldir%/pslr_model.c -pentax_la_SOURCES += %reldir%/pslr_enum.h +pentax_la_SOURCES += %reldir%/pslr_utils.c pentax_la_SOURCES += %reldir%/pslr.h +pentax_la_SOURCES += %reldir%/pslr_enum.h pentax_la_SOURCES += %reldir%/pslr_lens.h +pentax_la_SOURCES += %reldir%/pslr_log.h pentax_la_SOURCES += %reldir%/pslr_model.h pentax_la_SOURCES += %reldir%/pslr_scsi.h +pentax_la_SOURCES += %reldir%/pslr_utils.h pentax_la_SOURCES += %reldir%/exiftool_pentax_lens.txt pentax_la_SOURCES += %reldir%/js0n.c pentax_la_SOURCES += %reldir%/js0n.h diff --git a/camlibs/pentax/library.c b/camlibs/pentax/library.c index 260f77bf2c..be4f195c5f 100644 --- a/camlibs/pentax/library.c +++ b/camlibs/pentax/library.c @@ -204,7 +204,7 @@ camera_summary (Camera *camera, CameraText *summary, GPContext *context) pslr_get_status (&camera->pl->pslr, &status); - statusinfo = collect_status_info( &camera->pl->pslr, status ); + statusinfo = pslr_get_status_info( &camera->pl->pslr, status ); sprintf (summary->text, _( "Pentax K DSLR capture driver.\n" @@ -618,7 +618,7 @@ camera_get_config (Camera *camera, CameraWidget **window, GPContext *context) pslr_get_status (&camera->pl->pslr, &status); - model = pslr_camera_name (&camera->pl->pslr); + model = pslr_get_camera_name (&camera->pl->pslr); available_resolutions = pslr_get_model_jpeg_resolutions (&camera->pl->pslr); @@ -775,15 +775,15 @@ camera_get_config (Camera *camera, CameraWidget **window, GPContext *context) gp_widget_add_choice (t, _("B")); gp_widget_add_choice (t, _("X")); switch (status.exposure_mode) { - case PSLR_GUI_EXPOSURE_MODE_GREEN: gp_widget_set_value (t, _("GREEN"));break; - case PSLR_GUI_EXPOSURE_MODE_M: gp_widget_set_value (t, _("M"));break; - case PSLR_GUI_EXPOSURE_MODE_P: gp_widget_set_value (t, _("P"));break; - case PSLR_GUI_EXPOSURE_MODE_AV: gp_widget_set_value (t, _("AV"));break; - case PSLR_GUI_EXPOSURE_MODE_TV: gp_widget_set_value (t, _("TV"));break; - case PSLR_GUI_EXPOSURE_MODE_SV: gp_widget_set_value (t, _("SV"));break; - case PSLR_GUI_EXPOSURE_MODE_TAV: gp_widget_set_value (t, _("TAV"));break; - case PSLR_GUI_EXPOSURE_MODE_X: gp_widget_set_value (t, _("X"));break; - case PSLR_GUI_EXPOSURE_MODE_B: gp_widget_set_value (t, _("B"));break; + case PSLR_EXPOSURE_MODE_GREEN: gp_widget_set_value (t, _("GREEN"));break; + case PSLR_EXPOSURE_MODE_M: gp_widget_set_value (t, _("M"));break; + case PSLR_EXPOSURE_MODE_P: gp_widget_set_value (t, _("P"));break; + case PSLR_EXPOSURE_MODE_AV: gp_widget_set_value (t, _("AV"));break; + case PSLR_EXPOSURE_MODE_TV: gp_widget_set_value (t, _("TV"));break; + case PSLR_EXPOSURE_MODE_SV: gp_widget_set_value (t, _("SV"));break; + case PSLR_EXPOSURE_MODE_TAV: gp_widget_set_value (t, _("TAV"));break; + case PSLR_EXPOSURE_MODE_X: gp_widget_set_value (t, _("X"));break; + case PSLR_EXPOSURE_MODE_B: gp_widget_set_value (t, _("B"));break; default: sprintf(buf, _("Unknown mode %d"), status.exposure_mode); gp_widget_set_value (t, buf); @@ -839,22 +839,22 @@ camera_set_config (Camera *camera, CameraWidget *window, GPContext *context) ret = gp_widget_get_child_by_label (window, _("Shooting Mode"), &w); if ((ret == GP_OK) && gp_widget_changed (w)) { - pslr_gui_exposure_mode_t exposuremode; + pslr_exposure_mode_t exposuremode; gp_widget_set_changed (w, 0); gp_widget_get_value (w, &sval); - exposuremode = PSLR_GUI_EXPOSURE_MODE_MAX; - if (!strcmp(sval,_("GREEN"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_GREEN; - if (!strcmp(sval,_("M"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_M; - if (!strcmp(sval,_("B"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_B; - if (!strcmp(sval,_("P"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_P; - if (!strcmp(sval,_("SV"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_SV; - if (!strcmp(sval,_("TV"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_TV; - if (!strcmp(sval,_("AV"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_AV; - if (!strcmp(sval,_("TAV"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_TAV; - if (!strcmp(sval,_("X"))) exposuremode = PSLR_GUI_EXPOSURE_MODE_TAV; - if (exposuremode != PSLR_GUI_EXPOSURE_MODE_MAX) { + exposuremode = PSLR_EXPOSURE_MODE_MAX; + if (!strcmp(sval,_("GREEN"))) exposuremode = PSLR_EXPOSURE_MODE_GREEN; + if (!strcmp(sval,_("M"))) exposuremode = PSLR_EXPOSURE_MODE_M; + if (!strcmp(sval,_("B"))) exposuremode = PSLR_EXPOSURE_MODE_B; + if (!strcmp(sval,_("P"))) exposuremode = PSLR_EXPOSURE_MODE_P; + if (!strcmp(sval,_("SV"))) exposuremode = PSLR_EXPOSURE_MODE_SV; + if (!strcmp(sval,_("TV"))) exposuremode = PSLR_EXPOSURE_MODE_TV; + if (!strcmp(sval,_("AV"))) exposuremode = PSLR_EXPOSURE_MODE_AV; + if (!strcmp(sval,_("TAV"))) exposuremode = PSLR_EXPOSURE_MODE_TAV; + if (!strcmp(sval,_("X"))) exposuremode = PSLR_EXPOSURE_MODE_TAV; + if (exposuremode != PSLR_EXPOSURE_MODE_MAX) { pslr_set_exposure_mode(&camera->pl->pslr, exposuremode); pslr_get_status(&camera->pl->pslr, &status); } else { @@ -886,7 +886,7 @@ camera_set_config (Camera *camera, CameraWidget *window, GPContext *context) rational.denom = 10; rational.nom = (int)(10 * fval); - pslr_set_ec (&camera->pl->pslr, rational); + pslr_set_expose_compensation (&camera->pl->pslr, rational); } @@ -965,7 +965,7 @@ camera_set_config (Camera *camera, CameraWidget *window, GPContext *context) if ((ret == GP_OK) && gp_widget_changed (w)) { int bulb; - if (status.exposure_mode != PSLR_GUI_EXPOSURE_MODE_B) { + if (status.exposure_mode != PSLR_EXPOSURE_MODE_B) { gp_context_error (context, _("You need to switch the shooting mode or the camera to 'B' for bulb exposure.")); return GP_ERROR; } diff --git a/camlibs/pentax/pslr.c b/camlibs/pentax/pslr.c index 5f0397976d..8e072251eb 100644 --- a/camlibs/pentax/pslr.c +++ b/camlibs/pentax/pslr.c @@ -51,11 +51,12 @@ #include #include #include -#include #include "pslr.h" +#include "pslr_log.h" #include "pslr_scsi.h" #include "pslr_lens.h" +#include "pslr_utils.h" #define POLL_INTERVAL 50000 /* Number of us to wait when polling */ #define BLKSZ 65536 /* Block size for downloads; if too big, we get @@ -63,14 +64,6 @@ #define BLOCK_RETRY 3 /* Number of retries, since we can occasionally * get SCSI errors when downloading data */ -void sleep_sec(double sec) { - int i; - for (i=0; iraw_format; int imgfmt = st->image_format; if (imgfmt == PSLR_IMAGE_FORMAT_JPEG) { @@ -368,7 +361,7 @@ pslr_handle_t pslr_init( char *model, char *device ) { char **drives; const char *camera_name; - DPRINT("[C]\tplsr_init()\n"); + DPRINT("[C]\tpslr_init()\n"); if ( device == NULL ) { drives = get_drives(&driveNum); @@ -390,7 +383,7 @@ pslr_handle_t pslr_init( char *model, char *device ) { pslr.fd = fd; if ( model != NULL ) { // user specified the camera model - camera_name = pslr_camera_name( &pslr ); + camera_name = pslr_get_camera_name( &pslr ); DPRINT("\tName of the camera: %s\n", camera_name); if ( str_comparison_i( camera_name, model, strlen( camera_name) ) == 0 ) { return &pslr; @@ -482,7 +475,7 @@ int pslr_get_status(pslr_handle_t h, pslr_status *ps) { return PSLR_OK; } -char *format_rational( pslr_rational_t rational, char * fmt ) { +char *pslr_format_rational( pslr_rational_t rational, char * fmt ) { char *ret = malloc(32); if ( rational.denom == 0 ) { snprintf( ret, 32, "unknown" ); @@ -516,11 +509,10 @@ char *get_white_balance_adjust_str( uint32_t adjust_mg, uint32_t adjust_ba ) { return ret; } -static char *pslr_get_af_name(pslr_handle_t h, uint32_t af_point) { ipslr_handle_t *p = (ipslr_handle_t *) h; if (p->model->af_point_num==11) { - return get_pslr_af11_point_str(af_point); + return pslr_get_af11_point_str(af_point); } else { char *raw = malloc(11); sprintf(raw, "%d", af_point); @@ -528,54 +520,54 @@ char *pslr_get_af_name(pslr_handle_t h, uint32_t af_point) { } } -char *collect_status_info( pslr_handle_t h, pslr_status status ) { +char *pslr_get_status_info( pslr_handle_t h, pslr_status status ) { char *strbuffer = malloc(8192); sprintf(strbuffer,"%-32s: %d\n", "current iso", status.current_iso); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d/%d\n", "current shutter speed", status.current_shutter_speed.nom, status.current_shutter_speed.denom); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d/%d\n", "camera max shutter speed", status.max_shutter_speed.nom, status.max_shutter_speed.denom); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "current aperture", format_rational( status.current_aperture, "%.1f")); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens max aperture", format_rational( status.lens_max_aperture, "%.1f")); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens min aperture", format_rational( status.lens_min_aperture, "%.1f")); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "current aperture", pslr_format_rational( status.current_aperture, "%.1f")); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens max aperture", pslr_format_rational( status.lens_max_aperture, "%.1f")); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens min aperture", pslr_format_rational( status.lens_min_aperture, "%.1f")); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d/%d\n", "set shutter speed", status.set_shutter_speed.nom, status.set_shutter_speed.denom); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "set aperture", format_rational( status.set_aperture, "%.1f")); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "set aperture", pslr_format_rational( status.set_aperture, "%.1f")); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "fixed iso", status.fixed_iso); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d-%d\n", "auto iso", status.auto_iso_min,status.auto_iso_max); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg quality", status.jpeg_quality); sprintf(strbuffer+strlen(strbuffer),"%-32s: %dM\n", "jpeg resolution", pslr_get_jpeg_resolution( h, status.jpeg_resolution)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "jpeg image tone", get_pslr_jpeg_image_tone_str(status.jpeg_image_tone)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "jpeg image tone", pslr_get_jpeg_image_tone_str(status.jpeg_image_tone)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg saturation", status.jpeg_saturation); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg contrast", status.jpeg_contrast); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg sharpness", status.jpeg_sharpness); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "jpeg hue", status.jpeg_hue); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s mm\n", "zoom", format_rational(status.zoom, "%.2f")); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s mm\n", "zoom", pslr_format_rational(status.zoom, "%.2f")); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "focus", status.focus); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "color space", get_pslr_color_space_str(status.color_space)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "image format", get_pslr_image_format_str(status.image_format)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "raw format", get_pslr_raw_format_str(status.raw_format)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "color space", pslr_get_color_space_str(status.color_space)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "image format", pslr_get_image_format_str(status.image_format)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "raw format", pslr_get_raw_format_str(status.raw_format)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "light meter flags", status.light_meter_flags); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "ec", format_rational( status.ec, "%.2f" ) ); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s EV steps\n", "custom ev steps", get_pslr_custom_ev_steps_str(status.custom_ev_steps)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s EV steps\n", "custom sensitivity steps", get_pslr_custom_sensitivity_steps_str(status.custom_sensitivity_steps)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "ec", pslr_format_rational( status.ec, "%.2f" ) ); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s EV steps\n", "custom ev steps", pslr_get_custom_ev_steps_str(status.custom_ev_steps)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s EV steps\n", "custom sensitivity steps", pslr_get_custom_sensitivity_steps_str(status.custom_sensitivity_steps)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "exposure mode", status.exposure_mode); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "scene mode", get_pslr_scene_mode_str(status.scene_mode)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "scene mode", pslr_get_scene_mode_str(status.scene_mode)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "user mode flag", status.user_mode_flag); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "ae metering mode", get_pslr_ae_metering_str(status.ae_metering_mode)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "af mode", get_pslr_af_mode_str(status.af_mode)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "af point select", get_pslr_af_point_sel_str(status.af_point_select)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "ae metering mode", pslr_get_ae_metering_str(status.ae_metering_mode)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "af mode", pslr_get_af_mode_str(status.af_mode)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "af point select", pslr_get_af_point_sel_str(status.af_point_select)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "selected af point", pslr_get_af_name( h, status.selected_af_point)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "focused af point", pslr_get_af_name( h, status.focused_af_point)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "drive mode", get_pslr_drive_mode_str(status.drive_mode)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "drive mode", pslr_get_drive_mode_str(status.drive_mode)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "auto bracket mode", status.auto_bracket_mode > 0 ? "on" : "off"); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "auto bracket picture count", status.auto_bracket_picture_count); sprintf(strbuffer+strlen(strbuffer),"%-32s: %d\n", "auto bracket picture counter", status.auto_bracket_picture_counter); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "auto bracket ev", format_rational(status.auto_bracket_ev, "%.2f")); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "auto bracket ev", pslr_format_rational(status.auto_bracket_ev, "%.2f")); sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "shake reduction", status.shake_reduction > 0 ? "on" : "off"); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "white balance mode", get_pslr_white_balance_mode_str(status.white_balance_mode)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "white balance mode", pslr_get_white_balance_mode_str(status.white_balance_mode)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "white balance adjust", get_white_balance_adjust_str(status.white_balance_adjust_mg, status.white_balance_adjust_ba)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "flash mode", get_pslr_flash_mode_str(status.flash_mode)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "flash mode", pslr_get_flash_mode_str(status.flash_mode)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %.2f\n", "flash exposure compensation", (1.0 * status.flash_exposure_compensation/256)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %.2f\n", "manual mode ev", (1.0 * status.manual_mode_ev / 10)); - sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens", get_lens_name(status.lens_id1, status.lens_id2)); + sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "lens", pslr_get_lens_name(status.lens_id1, status.lens_id2)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %.2fV %.2fV %.2fV %.2fV\n", "battery", 0.01 * status.battery_1, 0.01 * status.battery_2, 0.01 * status.battery_3, 0.01 * status.battery_4); sprintf(strbuffer+strlen(strbuffer),"%-32s: %s\n", "buffer mask", int_to_binary(status.bufmask)); return strbuffer; @@ -612,7 +604,7 @@ char *get_hardwired_setting_uint16_info( pslr_uint16_setting setting) { return strbuffer; } -char *collect_settings_info( pslr_handle_t h, pslr_settings settings ) { +char *pslr_get_settings_info( pslr_handle_t h, pslr_settings settings ) { char *strbuffer = malloc(8192); sprintf(strbuffer,"%-32s: %-8s%s\n", "one push bracketing", get_special_setting_info(settings.one_push_bracketing.pslr_setting_status) ?: settings.one_push_bracketing.value ? "on" : "off", get_hardwired_setting_bool_info(settings.one_push_bracketing)); sprintf(strbuffer+strlen(strbuffer),"%-32s: %-8s%s\n", "bulb mode", get_special_setting_info(settings.bulb_mode_press_press.pslr_setting_status) ?: settings.bulb_mode_press_press.value ? "press-press" : "press-hold", get_hardwired_setting_bool_info(settings.bulb_mode_press_press)); @@ -749,8 +741,8 @@ int pslr_set_iso(pslr_handle_t h, uint32_t value, uint32_t auto_min_value, uint3 return ipslr_handle_command_x18( p, true, X18_ISO, 3, value, auto_min_value, auto_max_value); } -int pslr_set_ec(pslr_handle_t h, pslr_rational_t value) { - DPRINT("[C]\tpslr_set_ec(0x%X 0x%X)\n", value.nom, value.denom); +int pslr_set_expose_compensation(pslr_handle_t h, pslr_rational_t value) { + DPRINT("[C]\tpslr_set_expose_compensation(0x%X 0x%X)\n", value.nom, value.denom); ipslr_handle_t *p = (ipslr_handle_t *) h; return ipslr_handle_command_x18( p, true, X18_EC, 2, value.nom, value.denom, 0); } @@ -811,7 +803,7 @@ int pslr_set_jpeg_stars(pslr_handle_t h, int jpeg_stars ) { if ( jpeg_stars > p->model->max_jpeg_stars ) { return PSLR_PARAM; } - hwqual = get_hw_jpeg_quality( p->model, jpeg_stars ); + hwqual = pslr_get_hw_jpeg_quality( p->model, jpeg_stars ); return ipslr_handle_command_x18( p, true, X18_JPEG_STARS, 2, 1, hwqual, 0); } @@ -1142,7 +1134,7 @@ void pslr_buffer_close(pslr_handle_t h) { p->segment_count = 0; } -int pslr_select_af_point(pslr_handle_t h, uint32_t point) { +int pslr_set_selected_af_point(pslr_handle_t h, uint32_t point) { ipslr_handle_t *p = (ipslr_handle_t *) h; return ipslr_handle_command_x18( p, true, X18_AF_POINT, 1, point, 0, 0); } @@ -1236,8 +1228,8 @@ bool pslr_get_model_has_settings_parser(pslr_handle_t h) { return def_num>0; } -const char *pslr_camera_name(pslr_handle_t h) { - DPRINT("[C]\tpslr_camera_name()\n"); +const char *pslr_get_camera_name(pslr_handle_t h) { + DPRINT("[C]\tpslr_get_camera_name()\n"); ipslr_handle_t *p = (ipslr_handle_t *) h; int ret; if (p->id == 0) { @@ -1258,7 +1250,7 @@ const char *pslr_camera_name(pslr_handle_t h) { pslr_buffer_type pslr_get_jpeg_buffer_type(pslr_handle_t h, int jpeg_stars) { ipslr_handle_t *p = (ipslr_handle_t *) h; - return 2 + get_hw_jpeg_quality( p->model, jpeg_stars ); + return 2 + pslr_get_hw_jpeg_quality( p->model, jpeg_stars ); } static int ipslr_set_mode(ipslr_handle_t *p, uint32_t mode) { @@ -1491,19 +1483,19 @@ static int ipslr_identify(ipslr_handle_t *p) { p->id = get_uint32_le(&idbuf[0]); } DPRINT("\tid of the camera: %x\n", p->id); - p->model = find_model_by_id( p->id ); + p->model = pslr_find_model_by_id( p->id ); return PSLR_OK; } -int pslr_read_datetime(pslr_handle_t *h, int *year, int *month, int *day, int *hour, int *min, int *sec) { +int pslr_get_datetime(pslr_handle_t *h, int *year, int *month, int *day, int *hour, int *min, int *sec) { ipslr_handle_t *p = (ipslr_handle_t *) h; - DPRINT("[C]\t\tipslr_read_datetime()\n"); + DPRINT("[C]\t\tipslr_get_datetime()\n"); uint8_t idbuf[800]; int n; CHECK(command(p->fd, 0x20, 0x06, 0)); n = get_result(p->fd); - DPRINT("[C]\t\tipslr_read_datetime() bytes: %d\n",n); + DPRINT("[C]\t\tipslr_get_datetime() bytes: %d\n",n); if (n!= 24) { return PSLR_READ_ERROR; } @@ -1524,15 +1516,15 @@ int pslr_read_datetime(pslr_handle_t *h, int *year, int *month, int *day, int *h return PSLR_OK; } -int pslr_read_dspinfo(pslr_handle_t *h, char* firmware) { +int pslr_get_dspinfo(pslr_handle_t *h, char* firmware) { ipslr_handle_t *p = (ipslr_handle_t *) h; - DPRINT("[C]\t\tipslr_read_dspinfo()\n"); + DPRINT("[C]\t\tipslr_get_dspinfo()\n"); uint8_t buf[4]; int n; CHECK(command(p->fd, 0x01, 0x01, 0)); n = get_result(p->fd); - DPRINT("[C]\t\tipslr_read_dspinfo() bytes: %d\n",n); + DPRINT("[C]\t\tipslr_get_dspinfo() bytes: %d\n",n); if (n!= 4) { return PSLR_READ_ERROR; } @@ -1545,16 +1537,16 @@ int pslr_read_dspinfo(pslr_handle_t *h, char* firmware) { return PSLR_OK; } -int pslr_read_setting(pslr_handle_t *h, int offset, uint32_t *value) { +int pslr_get_setting(pslr_handle_t *h, int offset, uint32_t *value) { ipslr_handle_t *p = (ipslr_handle_t *) h; - DPRINT("[C]\t\tipslr_read_setting(%d)\n", offset); + DPRINT("[C]\t\tipslr_get_setting(%d)\n", offset); uint8_t buf[4]; int n; CHECK(ipslr_write_args(p, 1, offset)); CHECK(command(p->fd, 0x20, 0x09, 4)); n = get_result(p->fd); - DPRINT("[C]\t\tipslr_read_setting() bytes: %d\n",n); + DPRINT("[C]\t\tipslr_get_setting() bytes: %d\n",n); if (n!= 4) { return PSLR_READ_ERROR; } @@ -1569,9 +1561,9 @@ int pslr_read_setting(pslr_handle_t *h, int offset, uint32_t *value) { return PSLR_OK; } -int pslr_write_setting(pslr_handle_t *h, int offset, uint32_t value) { +int pslr_set_setting(pslr_handle_t *h, int offset, uint32_t value) { ipslr_handle_t *p = (ipslr_handle_t *) h; - DPRINT("[C]\t\tipslr_write_setting(%d)=%d\n", offset, value); + DPRINT("[C]\t\tipslr_set_setting(%d)=%d\n", offset, value); CHECK(ipslr_cmd_00_09(p, 1)); CHECK(ipslr_write_args(p, 2, offset, value)); CHECK(command(p->fd, 0x20, 0x08, 8)); @@ -1579,20 +1571,20 @@ int pslr_write_setting(pslr_handle_t *h, int offset, uint32_t value) { return PSLR_OK; } -int pslr_write_setting_by_name(pslr_handle_t *h, char *name, uint32_t value) { +int pslr_set_setting_by_name(pslr_handle_t *h, char *name, uint32_t value) { ipslr_handle_t *p = (ipslr_handle_t *) h; int def_num; char cameraid[10]; sprintf(cameraid, "0x%0x", p->model->id); // printf("cameraid: %s\n", cameraid); pslr_setting_def_t *defs = setting_file_process(cameraid, &def_num); - pslr_setting_def_t *setting_def = find_setting_by_name(defs, def_num, name); + pslr_setting_def_t *setting_def = pslr_find_setting_by_name(defs, def_num, name); if (setting_def != NULL) { if (strcmp(setting_def->type,"boolean") == 0) { - pslr_write_setting(h, setting_def->address, value); + pslr_set_setting(h, setting_def->address, value); } else if (strcmp(setting_def->type, "uint16") == 0) { - pslr_write_setting(h, setting_def->address, value >> 8); - pslr_write_setting(h, setting_def->address+1, value & 0xff); + pslr_set_setting(h, setting_def->address, value >> 8); + pslr_set_setting(h, setting_def->address+1, value & 0xff); } } return PSLR_OK; @@ -1604,19 +1596,19 @@ bool pslr_has_setting_by_name(pslr_handle_t *h, char *name) { char cameraid[10]; sprintf(cameraid, "0x%0x", p->model->id); pslr_setting_def_t *defs = setting_file_process(cameraid, &def_num); - pslr_setting_def_t *setting_def = find_setting_by_name(defs, def_num, name); + pslr_setting_def_t *setting_def = pslr_find_setting_by_name(defs, def_num, name); // printf("%d %d\n", def_num, (setting_def != NULL)); return (setting_def != NULL); } -int pslr_read_settings(pslr_handle_t *h) { +int pslr_get_settings(pslr_handle_t *h) { ipslr_handle_t *p = (ipslr_handle_t *) h; int index=0; uint32_t value; int ret; while (indexsettings_buffer[index] = value; @@ -1629,7 +1621,7 @@ int pslr_get_settings_json(pslr_handle_t h, pslr_settings *ps) { DPRINT("[C]\tpslr_get_settings_json()\n"); ipslr_handle_t *p = (ipslr_handle_t *) h; memset( ps, 0, sizeof( pslr_settings )); - CHECK(pslr_read_settings(h)); + CHECK(pslr_get_settings(h)); char cameraid[20]; sprintf(cameraid, "0x%05x", p->id); DPRINT("cameraid:%s\n", cameraid); @@ -1807,7 +1799,7 @@ static int read_result(FDTYPE fd, uint8_t *buf, uint32_t n) { return PSLR_OK; } -char *copyright() { +char *pslr_copyright() { char *ret = malloc(sizeof(char)*1024); sprintf(ret, "Copyright (C) 2011-2019 Andras Salamon\n\ \n\ @@ -1816,20 +1808,3 @@ pslr-shoot (C) 2009 Ramiro Barreiro\n\ PK-Remote (C) 2008 Pontus Lidman \n\n"); return ret; } - -void write_debug( const char* message, ... ) { - - // Be sure debug is really on as DPRINT doesn't know - // - if ( !debug ) { - return; - } - - // Write to stderr - // - va_list argp; - va_start(argp, message); - vfprintf( stderr, message, argp ); - va_end(argp); - return; -} diff --git a/camlibs/pentax/pslr.h b/camlibs/pentax/pslr.h index 61baa43c07..bb5448fcce 100644 --- a/camlibs/pentax/pslr.h +++ b/camlibs/pentax/pslr.h @@ -66,9 +66,9 @@ typedef struct { const char *extension; } user_file_format_t; -extern user_file_format_t file_formats[3]; +extern user_file_format_t pslr_user_file_formats[3]; -user_file_format_t *get_file_format_t( user_file_format uff ); +user_file_format_t *pslr_get_user_file_format_t( user_file_format uff ); // OFF-AUTO: Off-Auto-Aperture typedef enum { @@ -116,8 +116,6 @@ typedef struct { typedef void (*pslr_progress_callback_t)(uint32_t current, uint32_t total); -void sleep_sec(double sec); - pslr_handle_t pslr_init(char *model, char *device); int pslr_connect(pslr_handle_t h); int pslr_disconnect(pslr_handle_t h); @@ -129,12 +127,11 @@ int pslr_focus(pslr_handle_t h); int pslr_get_status(pslr_handle_t h, pslr_status *sbuf); int pslr_get_status_buffer(pslr_handle_t h, uint8_t *st_buf); -int pslr_get_settings(pslr_handle_t h, pslr_settings *ps); int pslr_get_settings_json(pslr_handle_t h, pslr_settings *ps); int pslr_get_settings_buffer(pslr_handle_t h, uint8_t *st_buf); -char *collect_status_info( pslr_handle_t h, pslr_status status ); -char *collect_settings_info( pslr_handle_t h, pslr_settings settings ); +char *pslr_get_status_info( pslr_handle_t h, pslr_status status ); +char *pslr_get_settings_info( pslr_handle_t h, pslr_settings settings ); int pslr_get_buffer(pslr_handle_t h, int bufno, pslr_buffer_type type, int resolution, uint8_t **pdata, uint32_t *pdatalen); @@ -145,7 +142,7 @@ int pslr_set_progress_callback(pslr_handle_t h, pslr_progress_callback_t cb, int pslr_set_shutter(pslr_handle_t h, pslr_rational_t value); int pslr_set_aperture(pslr_handle_t h, pslr_rational_t value); int pslr_set_iso(pslr_handle_t h, uint32_t value, uint32_t auto_min_value, uint32_t auto_max_value); -int pslr_set_ec(pslr_handle_t h, pslr_rational_t value); +int pslr_set_expose_compensation(pslr_handle_t h, pslr_rational_t value); int pslr_set_white_balance(pslr_handle_t h, pslr_white_balance_mode_t wb_mode); int pslr_set_white_balance_adjustment(pslr_handle_t h, pslr_white_balance_mode_t wb_mode, uint32_t wbadj_mg, uint32_t wbadj_ba); @@ -169,7 +166,7 @@ int pslr_set_jpeg_hue(pslr_handle_t h, int32_t hue); int pslr_set_image_format(pslr_handle_t h, pslr_image_format_t format); int pslr_set_raw_format(pslr_handle_t h, pslr_raw_format_t format); int pslr_set_user_file_format(pslr_handle_t h, user_file_format uff); -user_file_format get_user_file_format( pslr_status *st ); +user_file_format pslr_get_user_file_format( pslr_status *st ); int pslr_delete_buffer(pslr_handle_t h, int bufno); @@ -190,9 +187,9 @@ void pslr_buffer_close(pslr_handle_t h); uint32_t pslr_buffer_get_size(pslr_handle_t h); int pslr_set_exposure_mode(pslr_handle_t h, pslr_exposure_mode_t mode); -int pslr_select_af_point(pslr_handle_t h, uint32_t point); +int pslr_set_selected_af_point(pslr_handle_t h, uint32_t point); -const char *pslr_camera_name(pslr_handle_t h); +const char *pslr_get_camera_name(pslr_handle_t h); int pslr_get_model_max_jpeg_stars(pslr_handle_t h); int pslr_get_model_jpeg_property_levels(pslr_handle_t h); int pslr_get_model_status_buffer_size(pslr_handle_t h); @@ -214,25 +211,22 @@ bool pslr_get_model_bufmask_single(pslr_handle_t h); pslr_buffer_type pslr_get_jpeg_buffer_type(pslr_handle_t h, int quality); int pslr_get_jpeg_resolution(pslr_handle_t h, int hwres); -int pslr_read_datetime(pslr_handle_t *h, int *year, int *month, int *day, int *hour, int *min, int *sec); +int pslr_get_datetime(pslr_handle_t *h, int *year, int *month, int *day, int *hour, int *min, int *sec); -int pslr_read_dspinfo(pslr_handle_t *h, char *firmware); +int pslr_get_dspinfo(pslr_handle_t *h, char *firmware); -int pslr_read_setting(pslr_handle_t *h, int offset, uint32_t *value); -int pslr_write_setting(pslr_handle_t *h, int offset, uint32_t value); -int pslr_write_setting_by_name(pslr_handle_t *h, char *name, uint32_t value); +int pslr_get_setting(pslr_handle_t *h, int offset, uint32_t *value); +int pslr_set_setting(pslr_handle_t *h, int offset, uint32_t value); +int pslr_set_setting_by_name(pslr_handle_t *h, char *name, uint32_t value); bool pslr_has_setting_by_name(pslr_handle_t *h, char *name); -int pslr_read_settings(pslr_handle_t *h); +int pslr_get_settings(pslr_handle_t *h); pslr_gui_exposure_mode_t exposure_mode_conversion( pslr_exposure_mode_t exp ); -char *format_rational( pslr_rational_t rational, char * fmt ); +char *pslr_format_rational( pslr_rational_t rational, char * fmt ); int pslr_test( pslr_handle_t h, bool cmd9_wrap, int subcommand, int argnum, int arg1, int arg2, int arg3, int arg4); -char *copyright(void); - -void write_debug( const char* message, ... ); - -int debug_onoff(ipslr_handle_t *p, char debug_mode); +char *pslr_copyright(void); -#endif /* !defined(CAMLIBS_PENTAX_PSLR_H) */ +int pslr_set_debugmode(ipslr_handle_t *p, char debug_mode); +#endif diff --git a/camlibs/pentax/pslr_enum.c b/camlibs/pentax/pslr_enum.c index 543efde622..b1f84934dc 100644 --- a/camlibs/pentax/pslr_enum.c +++ b/camlibs/pentax/pslr_enum.c @@ -193,7 +193,7 @@ const char* pslr_scene_mode_str[PSLR_SCENE_MODE_MAX] = { }; -/* case insensitive comparison - strnicmp */ +/* case insenstive comparison - strnicmp */ int str_comparison_i (const char *s1, const char *s2, int n) { if ( s1 == NULL ) { return s2 == NULL ? 0 : -(*s2); @@ -242,55 +242,55 @@ const char *get_pslr_str( const char** array, int length, int value ) { } -pslr_color_space_t get_pslr_color_space( char *str ) { +pslr_color_space_t pslr_get_color_space( char *str ) { return find_in_array( pslr_color_space_str, sizeof(pslr_color_space_str)/sizeof(pslr_color_space_str[0]),str); } -const char *get_pslr_color_space_str( pslr_color_space_t value ) { +const char *pslr_get_color_space_str( pslr_color_space_t value ) { return get_pslr_str( pslr_color_space_str, sizeof(pslr_color_space_str)/sizeof(pslr_color_space_str[0]),value); } -pslr_af_mode_t get_pslr_af_mode( char *str ) { +pslr_af_mode_t pslr_get_af_mode( char *str ) { return find_in_array( pslr_af_mode_str, sizeof(pslr_af_mode_str)/sizeof(pslr_af_mode_str[0]),str); } -const char *get_pslr_af_mode_str( pslr_af_mode_t value ) { +const char *pslr_get_af_mode_str( pslr_af_mode_t value ) { return get_pslr_str( pslr_af_mode_str, sizeof(pslr_af_mode_str)/sizeof(pslr_af_mode_str[0]),value); } -pslr_ae_metering_t get_pslr_ae_metering( char *str ) { +pslr_ae_metering_t pslr_get_ae_metering( char *str ) { return find_in_array( pslr_ae_metering_str, sizeof(pslr_ae_metering_str)/sizeof(pslr_ae_metering_str[0]),str); } -const char *get_pslr_ae_metering_str( pslr_ae_metering_t value ) { +const char *pslr_get_ae_metering_str( pslr_ae_metering_t value ) { return get_pslr_str( pslr_ae_metering_str, sizeof(pslr_ae_metering_str)/sizeof(pslr_ae_metering_str[0]),value); } -pslr_flash_mode_t get_pslr_flash_mode( char *str ) { +pslr_flash_mode_t pslr_get_flash_mode( char *str ) { return find_in_array( pslr_flash_mode_str, sizeof(pslr_flash_mode_str)/sizeof(pslr_flash_mode_str[0]),str); } -const char *get_pslr_flash_mode_str( pslr_flash_mode_t value ) { +const char *pslr_get_flash_mode_str( pslr_flash_mode_t value ) { return get_pslr_str( pslr_flash_mode_str, sizeof(pslr_flash_mode_str)/sizeof(pslr_flash_mode_str[0]),value); } -pslr_drive_mode_t get_pslr_drive_mode( char *str ) { +pslr_drive_mode_t pslr_get_drive_mode( char *str ) { return find_in_array( pslr_drive_mode_str, sizeof(pslr_drive_mode_str)/sizeof(pslr_drive_mode_str[0]),str); } -const char *get_pslr_drive_mode_str( pslr_drive_mode_t value ) { +const char *pslr_get_drive_mode_str( pslr_drive_mode_t value ) { return get_pslr_str( pslr_drive_mode_str, sizeof(pslr_drive_mode_str)/sizeof(pslr_drive_mode_str[0]),value); } -pslr_af_point_sel_t get_pslr_af_point_sel( char *str ) { +pslr_af_point_sel_t pslr_get_af_point_sel( char *str ) { return find_in_array( pslr_af_point_sel_str, sizeof(pslr_af_point_sel_str)/sizeof(pslr_af_point_sel_str[0]),str); } -const char *get_pslr_af_point_sel_str( pslr_af_point_sel_t value ) { +const char *pslr_get_af_point_sel_str( pslr_af_point_sel_t value ) { return get_pslr_str( pslr_af_point_sel_str, sizeof(pslr_af_point_sel_str)/sizeof(pslr_af_point_sel_str[0]),value); } -char *get_pslr_af11_point_str( uint32_t value ) { +char *pslr_get_af11_point_str( uint32_t value ) { if (value==0) { return "none"; } @@ -315,38 +315,38 @@ char *get_pslr_af11_point_str( uint32_t value ) { } -pslr_jpeg_image_tone_t get_pslr_jpeg_image_tone( char *str ) { +pslr_jpeg_image_tone_t pslr_get_jpeg_image_tone( char *str ) { return find_in_array( pslr_jpeg_image_tone_str, sizeof(pslr_jpeg_image_tone_str)/sizeof(pslr_jpeg_image_tone_str[0]),str); } -const char *get_pslr_jpeg_image_tone_str( pslr_jpeg_image_tone_t value ) { +const char *pslr_get_jpeg_image_tone_str( pslr_jpeg_image_tone_t value ) { return get_pslr_str( pslr_jpeg_image_tone_str, sizeof(pslr_jpeg_image_tone_str)/sizeof(pslr_jpeg_image_tone_str[0]),value); } -pslr_white_balance_mode_t get_pslr_white_balance_mode( char *str ) { +pslr_white_balance_mode_t pslr_get_white_balance_mode( char *str ) { return find_in_array( pslr_white_balance_mode_str, sizeof(pslr_white_balance_mode_str)/sizeof(pslr_white_balance_mode_str[0]),str); } -const char *get_pslr_white_balance_mode_str( pslr_white_balance_mode_t value ) { +const char *pslr_get_white_balance_mode_str( pslr_white_balance_mode_t value ) { return get_pslr_str( pslr_white_balance_mode_str, sizeof(pslr_white_balance_mode_str)/sizeof(pslr_white_balance_mode_str[0]),value); } -const char *get_pslr_custom_ev_steps_str( pslr_custom_ev_steps_t value ) { +const char *pslr_get_custom_ev_steps_str( pslr_custom_ev_steps_t value ) { return get_pslr_str( pslr_custom_ev_steps_str, sizeof(pslr_custom_ev_steps_str)/sizeof(pslr_custom_ev_steps_str[0]),value); } -const char *get_pslr_custom_sensitivity_steps_str( pslr_custom_sensitivity_steps_t value ) { +const char *pslr_get_custom_sensitivity_steps_str( pslr_custom_sensitivity_steps_t value ) { return get_pslr_str( pslr_custom_sensitivity_steps_str, sizeof(pslr_custom_sensitivity_steps_str)/sizeof(pslr_custom_sensitivity_steps_str[0]),value); } -const char *get_pslr_image_format_str( pslr_image_format_t value ) { +const char *pslr_get_image_format_str( pslr_image_format_t value ) { return get_pslr_str( pslr_image_format_str, sizeof(pslr_image_format_str)/sizeof(pslr_image_format_str[0]),value); } -const char *get_pslr_raw_format_str( pslr_raw_format_t value ) { +const char *pslr_get_raw_format_str( pslr_raw_format_t value ) { return get_pslr_str( pslr_raw_format_str, sizeof(pslr_raw_format_str)/sizeof(pslr_raw_format_str[0]),value); } -const char *get_pslr_scene_mode_str( pslr_scene_mode_t value ) { +const char *pslr_get_scene_mode_str( pslr_scene_mode_t value ) { return get_pslr_str( pslr_scene_mode_str, sizeof(pslr_scene_mode_str)/sizeof(pslr_scene_mode_str[0]),value); } diff --git a/camlibs/pentax/pslr_enum.h b/camlibs/pentax/pslr_enum.h index 14255bca1a..969769146a 100644 --- a/camlibs/pentax/pslr_enum.h +++ b/camlibs/pentax/pslr_enum.h @@ -26,7 +26,6 @@ and GNU Lesser General Public License along with this program. If not, see . */ - #ifndef CAMLIBS_PENTAX_PSLR_ENUM_H #define CAMLIBS_PENTAX_PSLR_ENUM_H @@ -202,41 +201,41 @@ typedef enum { int str_comparison_i (const char *s1, const char *s2, int n); int find_in_array( const char** array, int length, char* str ); -pslr_color_space_t get_pslr_color_space( char *str ); -const char *get_pslr_color_space_str( pslr_color_space_t value ); +pslr_color_space_t pslr_get_color_space( char *str ); +const char *pslr_get_color_space_str( pslr_color_space_t value ); -pslr_af_mode_t get_pslr_af_mode( char *str ); -const char *get_pslr_af_mode_str( pslr_af_mode_t value ); +pslr_af_mode_t pslr_get_af_mode( char *str ); +const char *pslr_get_af_mode_str( pslr_af_mode_t value ); -pslr_ae_metering_t get_pslr_ae_metering( char *str ); -const char *get_pslr_ae_metering_str( pslr_ae_metering_t value ); +pslr_ae_metering_t pslr_get_ae_metering( char *str ); +const char *pslr_get_ae_metering_str( pslr_ae_metering_t value ); -pslr_flash_mode_t get_pslr_flash_mode( char *str ); -const char *get_pslr_flash_mode_str( pslr_flash_mode_t value ); +pslr_flash_mode_t pslr_get_flash_mode( char *str ); +const char *pslr_get_flash_mode_str( pslr_flash_mode_t value ); -pslr_drive_mode_t get_pslr_drive_mode( char *str ); -const char *get_pslr_drive_mode_str( pslr_drive_mode_t value ); +pslr_drive_mode_t pslr_get_drive_mode( char *str ); +const char *pslr_get_drive_mode_str( pslr_drive_mode_t value ); -pslr_af_point_sel_t get_pslr_af_point_sel( char *str ); -const char *get_pslr_af_point_sel_str( pslr_af_point_sel_t value ); +pslr_af_point_sel_t pslr_get_af_point_sel( char *str ); +const char *pslr_get_af_point_sel_str( pslr_af_point_sel_t value ); -char *get_pslr_af11_point_str( uint32_t value ); +char *pslr_get_af11_point_str( uint32_t value ); -pslr_jpeg_image_tone_t get_pslr_jpeg_image_tone( char *str ); -const char *get_pslr_jpeg_image_tone_str( pslr_jpeg_image_tone_t value ); +pslr_jpeg_image_tone_t pslr_get_jpeg_image_tone( char *str ); +const char *pslr_get_jpeg_image_tone_str( pslr_jpeg_image_tone_t value ); -pslr_white_balance_mode_t get_pslr_white_balance_mode( char *str ); -const char *get_pslr_white_balance_mode_str( pslr_white_balance_mode_t value ); +pslr_white_balance_mode_t pslr_get_white_balance_mode( char *str ); +const char *pslr_get_white_balance_mode_str( pslr_white_balance_mode_t value ); /* pslr_custom_ev_steps_t get_pslr_custom_ev_steps( char *str ); */ -const char *get_pslr_custom_ev_steps_str( pslr_custom_ev_steps_t value ); +const char *pslr_get_custom_ev_steps_str( pslr_custom_ev_steps_t value ); -const char *get_pslr_custom_sensitivity_steps_str( pslr_custom_sensitivity_steps_t value ); +const char *pslr_get_custom_sensitivity_steps_str( pslr_custom_sensitivity_steps_t value ); -const char *get_pslr_image_format_str( pslr_image_format_t value ); +const char *pslr_get_image_format_str( pslr_image_format_t value ); -const char *get_pslr_raw_format_str( pslr_raw_format_t value ); +const char *pslr_get_raw_format_str( pslr_raw_format_t value ); -const char *get_pslr_scene_mode_str( pslr_scene_mode_t value ); +const char *pslr_get_scene_mode_str( pslr_scene_mode_t value ); -#endif /* !defined(CAMLIBS_PENTAX_PSLR_ENUM_H) */ +#endif diff --git a/camlibs/pentax/pslr_lens.c b/camlibs/pentax/pslr_lens.c index 83c334f7cd..635af17909 100644 --- a/camlibs/pentax/pslr_lens.c +++ b/camlibs/pentax/pslr_lens.c @@ -38,7 +38,7 @@ static const struct { #include "exiftool_pentax_lens.txt" }; -const char *get_lens_name( uint32_t id1, uint32_t id2) { +const char *pslr_get_lens_name( uint32_t id1, uint32_t id2) { int lens_num = sizeof(lens_id)/sizeof(lens_id[0]); int i; for ( i=0; i. */ - #ifndef CAMLIBS_PENTAX_PSLR_LENS_H #define CAMLIBS_PENTAX_PSLR_LENS_H #include -const char *get_lens_name( uint32_t id1, uint32_t id2); - -#endif /* !defined(CAMLIBS_PENTAX_PSLR_LENS_H) */ +const char *pslr_get_lens_name( uint32_t id1, uint32_t id2); +#endif diff --git a/camlibs/pentax/pslr_log.c b/camlibs/pentax/pslr_log.c new file mode 100644 index 0000000000..d2a179bb20 --- /dev/null +++ b/camlibs/pentax/pslr_log.c @@ -0,0 +1,60 @@ +/* + pkTriggerCord + Remote control of Pentax DSLR cameras. + Copyright (C) 2011-2020 Andras Salamon + + which is based on: + + pslr-shoot + + Command line remote control of Pentax DSLR cameras. + Copyright (C) 2009 Ramiro Barreiro + With fragments of code from PK-Remote by Pontus Lidman. + + + This program 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 3 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + and GNU Lesser General Public License + along with this program. If not, see . + */ + +#include +#include + +#include "pslr_log.h" + +pslr_verbosity_t verbosity_level = PSLR_ERROR; + +void pslr_set_verbosity(pslr_verbosity_t verbosity) { + verbosity_level = verbosity; +} + +pslr_verbosity_t pslr_get_verbosity() { + return verbosity_level; +} + +bool pslr_verbosity_enabled(pslr_verbosity_t level) { + return level >= verbosity_level; +} + +void pslr_write_log(pslr_verbosity_t level, const char* message, ...) { + // immediatly returns for disabled log levels + if (!pslr_verbosity_enabled(level)) { + return; + } + + // Write to stderr + va_list argp; + va_start(argp, message); + vfprintf( stderr, message, argp ); + va_end(argp); +} \ No newline at end of file diff --git a/camlibs/pentax/pslr_log.h b/camlibs/pentax/pslr_log.h new file mode 100644 index 0000000000..2c5943f843 --- /dev/null +++ b/camlibs/pentax/pslr_log.h @@ -0,0 +1,72 @@ +/* + pkTriggerCord + Copyright (C) 2011-2020 Andras Salamon + Remote control of Pentax DSLR cameras. + + Support for K200D added by Jens Dreyer 04/2011 + Support for K-r added by Vincenc Podobnik 06/2011 + Support for K-30 added by Camilo Polymeris 09/2012 + Support for K-01 added by Ethan Queen 01/2013 + Support for K-3 added by Tao Wang 01/2016 + + based on: + + PK-Remote + Remote control of Pentax DSLR cameras. + Copyright (C) 2008 Pontus Lidman + + PK-Remote for Windows + Copyright (C) 2010 Tomasz Kos + + This program 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 3 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + and GNU Lesser General Public License + along with this program. If not, see . + */ + +#ifndef CAMLIBS_PENTAX_PSLR_LOG_H +#define CAMLIBS_PENTAX_PSLR_LOG_H + +#ifdef ANDROID +#include +#define DPRINT(...) __android_log_print(ANDROID_LOG_DEBUG, "PkTriggerCord", __VA_ARGS__) +#else +#ifdef LIBGPHOTO +#include +#define DPRINT(x...) gp_log (GP_LOG_DEBUG, "pentax", x) +#else +#define DPRINT(x...) pslr_write_log(PSLR_DEBUG, x) +#endif +#endif + +#define PSLR_DEBUG_ENABLED pslr_verbosity_enabled(PSLR_DEBUG) + +#include + +typedef enum { + PSLR_DEBUG, + PSLR_WARNING, + PSLR_ERROR, + PSLR_SILENT, +} pslr_verbosity_t; + +extern pslr_verbosity_t verbosity_level; + +void pslr_set_verbosity(pslr_verbosity_t verbosity); +pslr_verbosity_t pslr_get_verbosity(); + +bool pslr_verbosity_enabled(pslr_verbosity_t level); + +//TODO : offer a write_log_callback equivalent so a caller can fully configure what happends when pslr_write_log is called ? +void pslr_write_log(pslr_verbosity_t level, const char* message, ...); + +#endif diff --git a/camlibs/pentax/pslr_model.c b/camlibs/pentax/pslr_model.c index 101a75a664..86b5e74e33 100644 --- a/camlibs/pentax/pslr_model.c +++ b/camlibs/pentax/pslr_model.c @@ -47,6 +47,7 @@ #include #include "pslr_model.h" +#include "pslr_log.h" #include "pslr.h" static uint8_t lastbuf[MAX_STATUS_BUF_SIZE]; @@ -140,7 +141,7 @@ void set_uint32_be(uint32_t v, uint8_t *buf) { buf[3] = v; } -char *shexdump(uint8_t *buf, uint32_t bufLen) { +char *pslr_hexdump(uint8_t *buf, uint32_t bufLen) { char *ret = malloc(4*bufLen); uint32_t i; sprintf(ret,"%s",""); @@ -163,13 +164,13 @@ char *shexdump(uint8_t *buf, uint32_t bufLen) { } void hexdump(uint8_t *buf, uint32_t bufLen) { - char *dmp = shexdump(buf, bufLen); - DPRINT("%s",dmp); + char *dmp = pslr_hexdump(buf, bufLen); + printf("%s",dmp); free(dmp); } void hexdump_debug(uint8_t *buf, uint32_t bufLen) { - char *dmp = shexdump(buf, bufLen); + char *dmp = pslr_hexdump(buf, bufLen); DPRINT("%s",dmp); free(dmp); } @@ -204,7 +205,7 @@ int _get_user_jpeg_stars( ipslr_model_info_t *model, int hwqual ) { } } -int get_hw_jpeg_quality( ipslr_model_info_t *model, int user_jpeg_stars) { +int pslr_get_hw_jpeg_quality( ipslr_model_info_t *model, int user_jpeg_stars) { if ( model->id == 0x12f71 ) { // K5IIs hack // TODO: test it @@ -222,7 +223,7 @@ int get_hw_jpeg_quality( ipslr_model_info_t *model, int user_jpeg_stars) { static void ipslr_status_parse_k10d(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } memset(status, 0, sizeof (*status)); @@ -268,7 +269,7 @@ static void ipslr_status_parse_k20d(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } memset(status, 0, sizeof (*status)); @@ -427,7 +428,7 @@ static void ipslr_status_parse_kx(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -446,7 +447,7 @@ void ipslr_status_parse_kx(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_kr(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -462,7 +463,7 @@ void ipslr_status_parse_kr(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k5(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -481,7 +482,7 @@ void ipslr_status_parse_k5(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k30(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -502,7 +503,7 @@ void ipslr_status_parse_k30(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k01(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -522,7 +523,7 @@ void ipslr_status_parse_k01(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k50(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -538,7 +539,7 @@ void ipslr_status_parse_k50(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k500(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -557,7 +558,7 @@ void ipslr_status_parse_k500(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_km(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -575,7 +576,7 @@ void ipslr_status_parse_km(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k3(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -595,7 +596,7 @@ void ipslr_status_parse_k3(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_ks1(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -613,7 +614,7 @@ void ipslr_status_parse_ks1(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k1(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -657,7 +658,7 @@ void ipslr_status_parse_k1(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k70(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -727,7 +728,7 @@ void ipslr_status_parse_k70(ipslr_handle_t *p, pslr_status *status) { static void ipslr_status_parse_k200d(ipslr_handle_t *p, pslr_status *status) { uint8_t *buf = p->status_buffer; - if ( debug ) { + if ( PSLR_DEBUG_ENABLED ) { ipslr_status_diff(buf); } @@ -778,7 +779,7 @@ void ipslr_status_parse_k200d(ipslr_handle_t *p, pslr_status *status) { // 4= remote, 5= remote 3s delay } -pslr_setting_def_t *find_setting_by_name (pslr_setting_def_t *array, int array_length, char *name) { +pslr_setting_def_t *pslr_find_setting_by_name (pslr_setting_def_t *array, int array_length, char *name) { if (array == NULL || array_length == 0) { return NULL; } @@ -800,7 +801,7 @@ char *read_json_file(int *jsonsize) { jsonfd = open(PKTDATADIR "/pentax_settings.json", O_RDONLY); } if (jsonfd == -1) { - fprintf(stderr, "Cannot open pentax_settings.json file\n"); + pslr_write_log(PSLR_ERROR, "Cannot open pentax_settings.json file\n"); return NULL; } } @@ -826,12 +827,12 @@ pslr_setting_def_t *setting_file_process(const char *cameraid, int *def_num) { size_t json_part_length; const char *json_part; if (!(json_part = js0n(cameraid, strlen(cameraid), jsontext, jsonsize, &json_part_length))) { - fprintf(stderr, "JSON: Cannot find camera model\n"); + pslr_write_log(PSLR_ERROR, "JSON: Cannot find camera model\n"); return NULL; } if (!(json_part = js0n("fields", strlen("fields"), json_part, json_part_length, &json_part_length))) { - fprintf(stderr, "JSON: No fields defined for the camera model\n"); + pslr_write_log(PSLR_ERROR, "JSON: No fields defined for the camera model\n"); return NULL; } int ai=0; @@ -842,7 +843,7 @@ pslr_setting_def_t *setting_file_process(const char *cameraid, int *def_num) { const char *camera_field_name_ptr; char *camera_field_name; if (!(camera_field_name_ptr=js0n( "name", strlen("name"), json_array_part, json_array_part_length, &name_length))) { - fprintf(stderr, "No name is defined\n"); + pslr_write_log(PSLR_ERROR, "No name is defined\n"); return NULL; } else { camera_field_name=malloc(name_length+1); @@ -852,7 +853,7 @@ pslr_setting_def_t *setting_file_process(const char *cameraid, int *def_num) { const char *camera_field_type_ptr; char *camera_field_type; if (!(camera_field_type_ptr=js0n( "type", strlen("type"), json_array_part, json_array_part_length, &type_length))) { - fprintf(stderr, "No type is defined\n"); + pslr_write_log(PSLR_ERROR, "No type is defined\n"); return NULL; } else { camera_field_type=malloc(type_length+1); @@ -889,7 +890,6 @@ pslr_setting_def_t *setting_file_process(const char *cameraid, int *def_num) { return ret; } -static pslr_bool_setting ipslr_settings_parse_bool(const uint8_t *buf, const pslr_setting_def_t *def) { pslr_bool_setting bool_setting; if (def->value != NULL) { @@ -909,7 +909,6 @@ pslr_bool_setting ipslr_settings_parse_bool(const uint8_t *buf, const pslr_setti return bool_setting; } -static pslr_uint16_setting ipslr_settings_parse_uint16(const uint8_t *buf, const pslr_setting_def_t *def) { pslr_uint16_setting uint16_setting; if (def->value != NULL) { @@ -944,7 +943,7 @@ void ipslr_settings_parser_json(const char *cameraid, ipslr_handle_t *p, pslr_se } else if (strcmp(def.type, "uint16") == 0) { uint16_setting = ipslr_settings_parse_uint16(buf, &def); } else { - fprintf(stderr, "Invalid json type: %s\n", def.type); + pslr_write_log(PSLR_ERROR, "Invalid json type: %s\n", def.type); } if (strcmp(def.name, "bulb_mode_press_press") == 0) { settings->bulb_mode_press_press = bool_setting; @@ -1007,10 +1006,11 @@ ipslr_model_info_t camera_models[] = { { 0x13240, "K-1 II", false, false, true, true, false, true, 456, 3, {36, 22, 12, 2}, 9, 8000, 100, 819200, 100, 819200, PSLR_JPEG_IMAGE_TONE_FLAT, true, 33, ipslr_status_parse_k1 }, { 0x13222, "K-70", false, false, true, true, true, true, 456, 3, {24, 14, 6, 2}, 9, 6000, 100, 102400, 100, 102400, PSLR_JPEG_IMAGE_TONE_AUTO, true, 11, ipslr_status_parse_k70}, { 0x1322c, "KP", false, false, true, true, false, true, 456, 3, {24, 14, 6, 2}, 9, 6000, 100, 819200, 100, 819200, PSLR_JPEG_IMAGE_TONE_AUTO, true, 27, ipslr_status_parse_k70}, - { 0x13010, "645Z", false, false, true, true, false, false, 0, 3, {51, 32, 21, 3}, 9, 4000, 100, 204800, 100, 204800, PSLR_JPEG_IMAGE_TONE_CROSS_PROCESSING, true, 35, NULL} + { 0x13010, "645Z", false, false, true, true, false, false, 0, 3, {51, 32, 21, 3}, 9, 4000, 100, 204800, 100, 204800, PSLR_JPEG_IMAGE_TONE_CROSS_PROCESSING, true, 35, NULL}, + { 0x13254, "K-3III", false, false, true, true, false, true, 452, 4, {24, 14, 6, 2}, 9, 8000, 100, 51200, 100, 51200, PSLR_JPEG_IMAGE_TONE_BLEACH_BYPASS, true, 27, ipslr_status_parse_k3} }; -ipslr_model_info_t *find_model_by_id( uint32_t id ) { +ipslr_model_info_t *pslr_find_model_by_id( uint32_t id ) { unsigned int i; for ( i = 0; i. */ - #ifndef CAMLIBS_PENTAX_PSLR_MODEL_H #define CAMLIBS_PENTAX_PSLR_MODEL_H @@ -146,7 +145,7 @@ typedef struct { } pslr_setting_def_t; typedef void (*ipslr_status_parse_t)(ipslr_handle_t *p, pslr_status *status); -pslr_setting_def_t *find_setting_by_name (pslr_setting_def_t *array, int array_length, char *name); +pslr_setting_def_t *pslr_find_setting_by_name (pslr_setting_def_t *array, int array_length, char *name); void ipslr_settings_parser_json(const char *cameraid, ipslr_handle_t *p, pslr_settings *settings); pslr_setting_def_t *setting_file_process(const char *cameraid, int *def_num); @@ -193,9 +192,9 @@ struct ipslr_handle { uint8_t settings_buffer[SETTINGS_BUFFER_SIZE]; }; -ipslr_model_info_t *find_model_by_id( uint32_t id ); +ipslr_model_info_t *pslr_find_model_by_id( uint32_t id ); -int get_hw_jpeg_quality( ipslr_model_info_t *model, int user_jpeg_stars); +int pslr_get_hw_jpeg_quality( ipslr_model_info_t *model, int user_jpeg_stars); uint32_t get_uint32_be(uint8_t *buf); uint32_t get_uint32_le(uint8_t *buf); @@ -206,9 +205,9 @@ typedef uint32_t (*get_uint32_func)(uint8_t *buf); typedef uint16_t (*get_uint16_func)(const uint8_t *buf); typedef int32_t (*get_int32_func)(uint8_t *buf); -char *shexdump(uint8_t *buf, uint32_t bufLen); +char *pslr_hexdump(uint8_t *buf, uint32_t bufLen); void hexdump(uint8_t *buf, uint32_t bufLen); void hexdump_debug(uint8_t *buf, uint32_t bufLen); const char* int_to_binary( uint16_t x ); -#endif /* !defined(CAMLIBS_PENTAX_PSLR_MODEL_H) */ +#endif diff --git a/camlibs/pentax/pslr_scsi.h b/camlibs/pentax/pslr_scsi.h index f3b6608153..4005478e02 100644 --- a/camlibs/pentax/pslr_scsi.h +++ b/camlibs/pentax/pslr_scsi.h @@ -32,29 +32,18 @@ #include #include -extern bool debug; -extern void write_debug( const char* message, ... ); - -#ifdef ANDROID -#include -#define DPRINT(...) __android_log_print(ANDROID_LOG_DEBUG, "PkTriggerCord", __VA_ARGS__) -#else -#ifdef LIBGPHOTO2 -#include -#define DPRINT(x...) gp_log (GP_LOG_DEBUG, "pentax", x) -#else -#define DPRINT(x...) write_debug(x) -#endif +#ifdef RAD10 +#include #endif -#define CHECK(x) do { \ - int __r; \ - __r = (x); \ - if (__r != PSLR_OK) { \ - fprintf(stderr, "%s:%d:%s failed: %d\n", __FILE__, __LINE__, #x, __r); \ - return __r; \ - } \ -} while (0) +#define CHECK(x) do { \ + int __r; \ + __r = (x); \ + if (__r != PSLR_OK) { \ + pslr_write_log(PSLR_ERROR, "%s:%d:%s failed: %d\n", __FILE__, __LINE__, #x, __r); \ + return __r; \ + } \ + } while (0) typedef enum { PSLR_OK = 0, @@ -69,6 +58,7 @@ typedef enum { /* This also could be used to specify FDTYPE HANDLE for Win32, but this seems tricky with includes */ #ifdef LIBGPHOTO2 +typedef struct _GPPort GPPort; #define FDTYPE GPPort* #define PRIFDTYPE "p" #else @@ -90,5 +80,4 @@ pslr_result get_drive_info(char* drive_name, FDTYPE* device, char* product_id, int product_id_size_max); void close_drive(FDTYPE *device); - -#endif /* !defined(CAMLIBS_PENTAX_PSLR_SCSI_H) */ +#endif diff --git a/camlibs/pentax/pslr_utils.c b/camlibs/pentax/pslr_utils.c new file mode 100644 index 0000000000..8062d63f7b --- /dev/null +++ b/camlibs/pentax/pslr_utils.c @@ -0,0 +1,90 @@ +/* + pkTriggerCord + Remote control of Pentax DSLR cameras. + Copyright (C) 2011-2020 Andras Salamon + + based on: + + pslr-shoot + + Command line remote control of Pentax DSLR cameras. + Copyright (C) 2009 Ramiro Barreiro + With fragments of code from PK-Remote by Pontus Lidman. + + + This program 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 3 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + and GNU Lesser General Public License + along with this program. If not, see . + */ + +#ifdef RAD10 +#include +#include +#include "tdbtimes.h" +#else +#include +#include +#endif + +#include "pslr.h" +#include "pslr_utils.h" + +double timeval_diff_sec(struct timeval *t2, struct timeval *t1) { + //DPRINT("tv2 %ld %ld t1 %ld %ld\n", t2->tv_sec, t2->tv_usec, t1->tv_sec, t1->tv_usec); + return (t2->tv_usec - t1->tv_usec) / 1000000.0 + (t2->tv_sec - t1->tv_sec); +} + +void sleep_sec(double sec) { + int i; + for (i=0; i 100, even for a pinhole. + On the other hand, the fastest lens I know of is a f:0.8 Zeiss*/ + if (F > 100 || F < 0.8) { + F = 0; + } + aperture.nom = F * 10; + aperture.denom = 10; + + return aperture; +} + +pslr_rational_t parse_shutter_speed(char *shutter_speed_str) { + char C; + float F = 0; + pslr_rational_t shutter_speed = {0, 0}; + if (sscanf(shutter_speed_str, "%d/%d%c", &shutter_speed.nom, &shutter_speed.denom, &C) == 2) { + // noop + } else if ((sscanf(shutter_speed_str, "%d%c", &shutter_speed.nom, &C)) == 1) { + shutter_speed.denom = 1; + } else if ((sscanf(shutter_speed_str, "%f%c", &F, &C)) == 1) { + F = F * 1000; + shutter_speed.denom = 1000; + shutter_speed.nom = F; + } else { + shutter_speed.nom = 0; + shutter_speed.denom = 0; + } + return shutter_speed; +} diff --git a/camlibs/pentax/pslr_utils.h b/camlibs/pentax/pslr_utils.h new file mode 100644 index 0000000000..1d9ee400ae --- /dev/null +++ b/camlibs/pentax/pslr_utils.h @@ -0,0 +1,48 @@ +/* + pkTriggerCord + Copyright (C) 2011-2020 Andras Salamon + Remote control of Pentax DSLR cameras. + + based on: + + PK-Remote + Remote control of Pentax DSLR cameras. + Copyright (C) 2008 Pontus Lidman + + PK-Remote for Windows + Copyright (C) 2010 Tomasz Kos + + This program 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 3 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 Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + and GNU Lesser General Public License + along with this program. If not, see . + */ + +#ifndef CAMLIBS_PENTAX_PKTRIGGERCORD_COMMON_H +#define CAMLIBS_PENTAX_PKTRIGGERCORD_COMMON_H + +#ifdef RAD10 +#include +#else +#include +#endif +#include +#include + +#include "pslr_model.h" + +double timeval_diff_sec(struct timeval *t2, struct timeval *t1); +void sleep_sec(double sec); +pslr_rational_t parse_shutter_speed(char *shutter_speed_str); +pslr_rational_t parse_aperture(char *aperture_str); + +#endif