diff --git a/Makefile b/Makefile index 7ebb4de..0197634 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ cli: $(CLI_TARGET) gui: $(GUI_TARGET) MANS = pktriggercord-cli.1 pktriggercord.1 -SRCOBJNAMES = pslr pslr_enum pslr_scsi pslr_lens pslr_model pktriggercord-servermode +SRCOBJNAMES = pslr pslr_enum pslr_scsi pslr_log pslr_lens pslr_model pktriggercord-servermode OBJS = $(SRCOBJNAMES:=.o) $(JSONDIR)/js0n.o WIN_DLLS_DIR=win_dlls SOURCE_PACKAGE_FILES = Makefile Changelog COPYING INSTALL BUGS $(MANS) pentax_scsi_protocol.md pentax.rules samsung.rules $(SRCOBJNAMES:=.h) $(SRCOBJNAMES:=.c) pslr_scsi_linux.c pslr_scsi_win.c pslr_scsi_openbsd.c exiftool_pentax_lens.txt pktriggercord.c pktriggercord-cli.c pktriggercord.ui pentax_settings.json $(SPECFILE) android_scsi_sg.h rad10/ src/ diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 2d3cf8e..afafa5d 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -7,6 +7,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := pktriggercord-cli LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../src/external/js0n/ LOCAL_SRC_FILES := ../../src/external/js0n/js0n.c \ + ../../pslr_log.c \ ../../pslr_enum.c \ ../../pslr_lens.c \ ../../pslr_model.c \ diff --git a/pktriggercord-cli.c b/pktriggercord-cli.c index e60a941..ec45c6c 100644 --- a/pktriggercord-cli.c +++ b/pktriggercord-cli.c @@ -50,6 +50,7 @@ #include "pslr.h" #include "pktriggercord-servermode.h" +#include "pslr_log.h" #ifdef WIN32 #define FILE_ACCESS O_WRONLY | O_CREAT | O_TRUNC | O_BINARY @@ -57,9 +58,6 @@ #define FILE_ACCESS O_WRONLY | O_CREAT | O_TRUNC #endif -bool debug = false; -bool warnings = false; - const char *shortopts = "m:q:a:r:d:t:o:i:F:fghvsSw"; pslr_settings settings; @@ -270,24 +268,13 @@ int open_file(char* output_file, int frameNo, user_file_format_t ufft) { snprintf(fileName, 256, "%.*s-%04d.%s", prefix_length, output_file, frameNo, ufft.extension); ofd = open(fileName, FILE_ACCESS, 0664); if (ofd == -1) { - fprintf(stderr, "Could not open %s\n", output_file); + pslr_write_log(PSLR_ERROR, "Could not open %s\n", output_file); return -1; } } return ofd; } -void warning_message( const char* message, ... ) { - if ( warnings ) { - // Write to stderr - // - va_list argp; - va_start(argp, message); - vfprintf( stderr, message, argp ); - va_end(argp); - } -} - void process_wbadj( const char* argv0, const char chr, uint32_t adj, uint32_t *wbadj_mg, uint32_t *wbadj_ba ) { if ( chr == 'M' ) { *wbadj_mg = 7 - adj; @@ -298,7 +285,7 @@ void process_wbadj( const char* argv0, const char chr, uint32_t adj, uint32_t *w } else if ( chr == 'A' ) { *wbadj_ba = 7 + adj; } else { - warning_message("%s: Invalid white_balance_adjustment\n", argv0); + pslr_write_log(PSLR_WARNING, "%s: Invalid white_balance_adjustment\n", argv0); } } @@ -346,7 +333,7 @@ void bulb_new(pslr_handle_t camhandle, pslr_rational_t shutter_speed) { } else if (pslr_has_setting_by_name(camhandle, "astrotracer")) { pslr_set_setting_by_name(camhandle, "astrotracer", 1); } else { - fprintf(stderr, "New bulb mode is not supported for this camera model\n"); + pslr_write_log(PSLR_ERROR, "New bulb mode is not supported for this camera model\n"); } int bulb_sec = (int)(shutter_speed.nom / shutter_speed.denom); if (pslr_has_setting_by_name(camhandle, "bulb_timer_sec")) { @@ -354,7 +341,7 @@ void bulb_new(pslr_handle_t camhandle, pslr_rational_t shutter_speed) { } else if (pslr_has_setting_by_name(camhandle, "astrotracer_timer_sec")) { pslr_set_setting_by_name(camhandle, "astrotracer_timer_sec", bulb_sec); } else { - fprintf(stderr, "New bulb mode is not supported for this camera model\n"); + pslr_write_log(PSLR_ERROR, "New bulb mode is not supported for this camera model\n"); } pslr_shutter(camhandle); } @@ -445,19 +432,19 @@ int main(int argc, char **argv) { usage(argv[0]); exit(-1); case 'w': - warnings = true; + pslr_set_verbosity(PSLR_WARNING); break; case 17: - warnings = false; + pslr_set_verbosity(PSLR_ERROR); break; case 4: - debug = true; + pslr_set_verbosity(PSLR_DEBUG); DPRINT( "Debug messaging is now enabled.\n" ); break; } } - if (debug) { + if (PSLR_DEBUG_ENABLED) { DPRINT("command line:\n%s\n", command_line(argc, argv)); } @@ -486,7 +473,7 @@ int main(int argc, char **argv) { } else if (!strcmp(optarg, "JPEG") || !strcmp(optarg, "JPG")) { uff = USER_FILE_FORMAT_JPEG; } else { - warning_message("%s: Invalid file format.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid file format.\n", argv[0]); } break; @@ -526,7 +513,7 @@ int main(int argc, char **argv) { } else if (!strcmp(optarg, "X")) { EM = PSLR_EXPOSURE_MODE_X; } else { - warning_message("%s: Invalid exposure mode.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid exposure mode.\n", argv[0]); } break; @@ -537,7 +524,7 @@ int main(int argc, char **argv) { case 7: color_space = pslr_get_color_space( optarg ); if ( color_space == (pslr_color_space_t)(-1) ) { - warning_message("%s: Invalid color space\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid color space\n", argv[0]); } break; @@ -545,28 +532,28 @@ int main(int argc, char **argv) { af_mode = pslr_get_af_mode( optarg ); if ( af_mode == (pslr_af_mode_t)(-1) || af_mode == (pslr_af_mode_t)(0) ) { // 0: changing MF does not work - warning_message("%s: Invalid af mode\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid af mode\n", argv[0]); } break; case 9: ae_metering = pslr_get_ae_metering( optarg ); if ( ae_metering == (pslr_ae_metering_t)(-1) ) { - warning_message("%s: Invalid ae metering\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid ae metering\n", argv[0]); } break; case 10: flash_mode = pslr_get_flash_mode( optarg ); if ( flash_mode == (pslr_flash_mode_t)(-1) ) { - warning_message("%s: Invalid flash_mode\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid flash_mode\n", argv[0]); } break; case 11: drive_mode = pslr_get_drive_mode( optarg ); if ( drive_mode == (pslr_drive_mode_t)(-1) ) { - warning_message("%s: Invalid drive_mode\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid drive_mode\n", argv[0]); } break; @@ -577,7 +564,7 @@ int main(int argc, char **argv) { if (af_point_selected != 0) { af_point_sel = PSLR_AF_POINT_SEL_SELECT; } else { - warning_message("%s: Invalid select af point: %s\n", argv[0], optarg); + pslr_write_log(PSLR_WARNING, "%s: Invalid select af point: %s\n", argv[0], optarg); } } break; @@ -585,14 +572,14 @@ int main(int argc, char **argv) { case 13: jpeg_image_tone = pslr_get_jpeg_image_tone( optarg ); if ( jpeg_image_tone == -1 ) { - warning_message("%s: Invalid jpeg_image_tone\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg_image_tone\n", argv[0]); } break; case 14: white_balance_mode = pslr_get_white_balance_mode( optarg ); if ( white_balance_mode == (pslr_white_balance_mode_t)(-1) ) { - warning_message("%s: Invalid white_balance_mode\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid white_balance_mode\n", argv[0]); } break; @@ -606,7 +593,7 @@ int main(int argc, char **argv) { process_wbadj( argv[0], c2, adj2, &white_balance_adjustment_mg, &white_balance_adjustment_ba ); } } else { - warning_message("%s: Invalid white_balance_adjustment\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid white_balance_adjustment\n", argv[0]); } break; @@ -629,21 +616,21 @@ int main(int argc, char **argv) { case 'q': quality = atoi(optarg); if (!quality) { - warning_message("%s: Invalid jpeg quality\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg quality\n", argv[0]); } break; case 'a': aperture = parse_aperture(optarg); if (aperture.nom == 0) { - warning_message( "%s: Invalid aperture value.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid aperture value.\n", argv[0]); } break; case 't': shutter_speed = parse_shutter_speed(optarg); if (shutter_speed.nom == 0) { - warning_message("%s: Invalid shutter speed value: %s\n", argv[0], optarg); + pslr_write_log(PSLR_WARNING, "%s: Invalid shutter speed value: %s\n", argv[0], optarg); } break; @@ -666,7 +653,7 @@ int main(int argc, char **argv) { case 'F': frames = atoi(optarg); if (frames > 9999) { - warning_message("%s: Invalid frame number.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid frame number.\n", argv[0]); frames = 9999; } break; @@ -674,7 +661,7 @@ int main(int argc, char **argv) { case 'd': delay = atoi(optarg); if (!delay) { - warning_message("%s: Invalid delay value\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid delay value\n", argv[0]); } break; @@ -685,7 +672,7 @@ int main(int argc, char **argv) { iso = atoi(optarg); } if (iso==0 && auto_iso_min==0) { - warning_message("%s: Invalid iso value\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid iso value\n", argv[0]); exit(-1); } break; @@ -753,7 +740,7 @@ int main(int argc, char **argv) { mult = 1024; break; default: - warning_message("%s: Invalid dump memory size: %s\n", argv[0], optarg); + pslr_write_log(PSLR_WARNING, "%s: Invalid dump memory size: %s\n", argv[0], optarg); } dump_memory_size *= mult; @@ -771,13 +758,13 @@ int main(int argc, char **argv) { servermode_socket(servermode_timeout); exit(0); #else - fprintf(stderr, "Servermode is not supported in Windows\n"); + pslr_write_log(PSLR_ERROR, "Servermode is not supported in Windows\n"); exit(-1); #endif } if (!output_file && !output_file_stdout && frames > 0) { - fprintf(stderr, "Should specify output filename (use '-o -' if you really want to output to stdout)\n"); + pslr_write_log(PSLR_ERROR, "Should specify output filename (use '-o -' if you really want to output to stdout)\n"); exit(-1); } @@ -802,7 +789,7 @@ int main(int argc, char **argv) { if ( dump_memory_size > 0 ) { int dfd = open(DUMP_FILE_NAME, FILE_ACCESS, 0664); if (dfd == -1) { - fprintf(stderr, "Could not open %s\n", DUMP_FILE_NAME); + pslr_write_log(PSLR_ERROR, "Could not open %s\n", DUMP_FILE_NAME); return -1; } else { printf("Dumping system memory to %s\n", DUMP_FILE_NAME); @@ -847,7 +834,7 @@ int main(int argc, char **argv) { if ( jpeg_image_tone != -1 ) { if ( jpeg_image_tone > pslr_get_model_max_supported_image_tone(camhandle) ) { - warning_message("%s: Invalid jpeg image tone setting.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg image tone setting.\n", argv[0]); } pslr_set_jpeg_image_tone( camhandle, jpeg_image_tone ); } @@ -885,7 +872,7 @@ int main(int argc, char **argv) { if (quality>-1) { if ( quality > pslr_get_model_max_jpeg_stars(camhandle) ) { - warning_message("%s: Invalid jpeg quality setting.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid jpeg quality setting.\n", argv[0]); } pslr_set_jpeg_stars(camhandle, quality); } @@ -918,7 +905,7 @@ int main(int argc, char **argv) { } if (EM != PSLR_EXPOSURE_MODE_MAX && status.exposure_mode != EM) { - warning_message( "%s: Cannot set %s mode; set the mode dial to %s or USER\n", argv[0], MODESTRING, MODESTRING); + pslr_write_log(PSLR_WARNING, "%s: Cannot set %s mode; set the mode dial to %s or USER\n", argv[0], MODESTRING, MODESTRING); } if (shutter_speed.nom) { @@ -926,25 +913,25 @@ int main(int argc, char **argv) { DPRINT("shutter_speed.denom=%d\n", shutter_speed.denom); if (shutter_speed.nom <= 0 || (shutter_speed.nom > 30 && status.exposure_mode != PSLR_GUI_EXPOSURE_MODE_B ) || shutter_speed.denom <= 0 || shutter_speed.denom > pslr_get_model_fastest_shutter_speed(camhandle)) { - warning_message("%s: Invalid shutter speed value.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Invalid shutter speed value.\n", argv[0]); } pslr_set_shutter(camhandle, shutter_speed); } else if ( status.exposure_mode == PSLR_GUI_EXPOSURE_MODE_B ) { - warning_message("%s: Shutter speed not specified in Bulb mode. Using 30s.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Shutter speed not specified in Bulb mode. Using 30s.\n", argv[0]); shutter_speed.nom = 30; shutter_speed.denom = 1; } if (aperture.nom) { if ((aperture.nom * status.lens_max_aperture.denom) > (aperture.denom * status.lens_max_aperture.nom)) { - warning_message("%s: Warning, selected aperture is smaller than this lens minimum aperture.\n", argv[0]); - warning_message("%s: Setting aperture to f:%d\n", argv[0], status.lens_max_aperture.nom / status.lens_max_aperture.denom); + pslr_write_log(PSLR_WARNING, "%s: Warning, selected aperture is smaller than this lens minimum aperture.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Setting aperture to f:%d\n", argv[0], status.lens_max_aperture.nom / status.lens_max_aperture.denom); } if ((aperture.nom * status.lens_min_aperture.denom) < (aperture.denom * status.lens_min_aperture.nom)) { - warning_message( "%s: Warning, selected aperture is wider than this lens maximum aperture.\n", argv[0]); - warning_message( "%s: Setting aperture to f:%.1f\n", argv[0], (float) status.lens_min_aperture.nom / (float) status.lens_min_aperture.denom); + pslr_write_log(PSLR_WARNING, "%s: Warning, selected aperture is wider than this lens maximum aperture.\n", argv[0]); + pslr_write_log(PSLR_WARNING, "%s: Setting aperture to f:%.1f\n", argv[0], (float) status.lens_min_aperture.nom / (float) status.lens_min_aperture.denom); } @@ -972,7 +959,7 @@ int main(int argc, char **argv) { exit(0); } - if (read_firmware_version || debug) { + if (read_firmware_version || PSLR_DEBUG_ENABLED) { char firmware[16]; pslr_get_dspinfo( camhandle, firmware ); if (!read_firmware_version) { diff --git a/pktriggercord-servermode.c b/pktriggercord-servermode.c index d61f521..a903c84 100644 --- a/pktriggercord-servermode.c +++ b/pktriggercord-servermode.c @@ -43,9 +43,10 @@ #include #include - +#include "pslr_log.h" #include "pslr.h" #include "pslr_lens.h" +#include "pktriggercord-servermode.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); @@ -197,12 +198,12 @@ int servermode_socket(int servermode_timeout) { //Create socket socket_desc = socket(AF_INET, SOCK_STREAM, 0); if (socket_desc == -1) { - fprintf(stderr, "Could not create socket"); + pslr_write_log(PSLR_ERROR, "Could not create socket"); } int enable = 1; if (setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) { - fprintf(stderr, "setsockopt(SO_REUSEADDR) failed"); + pslr_write_log(PSLR_ERROR, "setsockopt(SO_REUSEADDR) failed"); } DPRINT("Socket created\n"); @@ -213,7 +214,7 @@ int servermode_socket(int servermode_timeout) { //Bind if ( bind(socket_desc,(struct sockaddr *)&server, sizeof(server)) < 0) { - fprintf(stderr, "bind failed. Error"); + pslr_write_log(PSLR_ERROR, "bind failed. Error"); return 1; } DPRINT("bind done\n"); @@ -241,7 +242,7 @@ int servermode_socket(int servermode_timeout) { } else if (retval) { client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c); if (client_sock < 0) { - fprintf(stderr, "accept failed"); + pslr_write_log(PSLR_ERROR, "accept failed"); return 1; } DPRINT("Connection accepted\n"); @@ -458,7 +459,7 @@ int servermode_socket(int servermode_timeout) { DPRINT("Client disconnected\n"); fflush(stdout); } else if (read_size == -1) { - fprintf(stderr, "recv failed\n"); + pslr_write_log(PSLR_ERROR, "recv failed\n"); } } return 0; diff --git a/pktriggercord.c b/pktriggercord.c index b3f7ef9..6a5154b 100644 --- a/pktriggercord.c +++ b/pktriggercord.c @@ -39,6 +39,7 @@ #include "pslr.h" #include "pslr_lens.h" +#include "pslr_log.h" #include "pktriggercord-servermode.h" #ifdef WIN32 @@ -1102,7 +1103,7 @@ static bool auto_save_check(int format, int buffer) { if (old_path) { ssize_t r = chdir(old_path); if (r != 0) { - fprintf(stderr, "chdir(old_path) failed"); + pslr_write_log(PSLR_ERROR, "chdir(old_path) failed"); } free(old_path); @@ -1517,7 +1518,7 @@ G_MODULE_EXPORT void shutter_press(GtkAction *action) { } else if (pslr_has_setting_by_name(camhandle, "astrotracer")) { pslr_set_setting_by_name(camhandle, "astrotracer", 1); } else { - fprintf(stderr, "New bulb mode is not supported for this camera model\n"); + pslr_write_log(PSLR_ERROR, "New bulb mode is not supported for this camera model\n"); return; } if (pslr_has_setting_by_name(camhandle, "bulb_timer_sec")) { @@ -1525,7 +1526,7 @@ G_MODULE_EXPORT void shutter_press(GtkAction *action) { } else if (pslr_has_setting_by_name(camhandle, "astrotracer_timer_sec")) { pslr_set_setting_by_name(camhandle, "astrotracer_timer_sec", shutter_speed); } else { - fprintf(stderr, "New bulb mode is not supported for this camera model\n"); + pslr_write_log(PSLR_ERROR, "New bulb mode is not supported for this camera model\n"); return; } gettimeofday(&expected_bulb_end_time, NULL); @@ -2121,7 +2122,7 @@ static pslr_buffer_type get_image_type_based_on_ui() { static void save_buffer_single(const char *filename, const pslr_buffer_type imagetype) { int fd; if ((imagetype == PSLR_BUF_PEF || imagetype == PSLR_BUF_DNG)) { - fprintf(stderr, "Cannot download RAW images for this model if preview is already visible"); + pslr_write_log(PSLR_ERROR, "Cannot download RAW images for this model if preview is already visible"); } else { fd = open(filename, FILE_ACCESS, 0664); if (fd == -1) { diff --git a/pslr.c b/pslr.c index 03ab8fa..74b9764 100644 --- a/pslr.c +++ b/pslr.c @@ -54,6 +54,7 @@ #include #include "pslr.h" +#include "pslr_log.h" #include "pslr_scsi.h" #include "pslr_lens.h" @@ -1814,20 +1815,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/pslr.h b/pslr.h index 9984fe6..d288944 100644 --- a/pslr.h +++ b/pslr.h @@ -230,7 +230,5 @@ int pslr_test( pslr_handle_t h, bool cmd9_wrap, int subcommand, int argnum, int char *pslr_copyright(void); -void write_debug( const char* message, ... ); - int pslr_set_debugmode(ipslr_handle_t *p, char debug_mode); #endif diff --git a/pslr_log.c b/pslr_log.c new file mode 100644 index 0000000..d2a179b --- /dev/null +++ b/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/pslr_log.h b/pslr_log.h new file mode 100644 index 0000000..9b17a5e --- /dev/null +++ b/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 PSLR_LOG_H +#define 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/pslr_model.c b/pslr_model.c index af1d465..a522c5d 100644 --- a/pslr_model.c +++ b/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]; @@ -222,7 +223,7 @@ int pslr_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); } @@ -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); @@ -942,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; diff --git a/pslr_scsi.h b/pslr_scsi.h index 2a1b626..f33af94 100644 --- a/pslr_scsi.h +++ b/pslr_scsi.h @@ -32,29 +32,15 @@ #include #include -extern bool debug; -extern void write_debug( const char* message, ... ); - #ifdef RAD10 #include #endif -#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...) write_debug(x) -#endif -#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); \ + pslr_write_log(PSLR_ERROR, "%s:%d:%s failed: %d\n", __FILE__, __LINE__, #x, __r); \ return __r; \ } \ } while (0) diff --git a/pslr_scsi_linux.c b/pslr_scsi_linux.c index b21132e..b74384a 100644 --- a/pslr_scsi_linux.c +++ b/pslr_scsi_linux.c @@ -36,8 +36,9 @@ #endif #include #include -#include "pslr_model.h" +#include "pslr_log.h" +#include "pslr_model.h" #include "pslr_scsi.h" static const int MAX_DEVICE_NUM = 256;