/* Camicro - Microscope camera viewer. * * Copyright (C) 2019 Nicolas Schodet * * 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. * * Contact : * Web: http://ni.fr.eu.org/ * Email: */ #define _GNU_SOURCE #include #include "options.h" #include "cli.h" #include "utils.h" void options_add(GApplication *app) { g_application_set_option_context_summary(app, "Microscope camera viewer"); g_application_set_option_context_description(app, "Without options, run the GUI, else switch to batch mode to dump" " image from the camera."); g_application_add_main_option(app, "width", 'w', 0, G_OPTION_ARG_INT, "image width", "VALUE"); g_application_add_main_option(app, "exposure", 'e', 0, G_OPTION_ARG_DOUBLE, "exposure value", "MS"); g_application_add_main_option(app, "gain", 'g', 0, G_OPTION_ARG_DOUBLE, "gain value", "VALUE"); g_application_add_main_option(app, "count", 'n', 0, G_OPTION_ARG_INT, "number of image to take", "N"); g_application_add_main_option(app, "raw", 'r', 0, G_OPTION_ARG_NONE, "do not convert image", NULL); g_application_add_main_option(app, "output", 'o', 0, G_OPTION_ARG_FILENAME, "output file pattern (default: out%02d.png)", "PATTERN"); } gint options_handle(GApplication *app, GVariantDict *options_dict) { struct options options; options.width = -1; options.height = -1; options.exposure_ms = -1.0; options.gain = -1.0; options.count = 1; options.raw = false; options.out = NULL; bool option_set = false; if (g_variant_dict_lookup(options_dict, "width", "i", &options.width)) { option_set = true; if (options.width <= 0) utils_fatal("invalid width"); } if (g_variant_dict_lookup(options_dict, "exposure", "d", &options.exposure_ms)) { option_set = true; if (options.exposure_ms < 1.0) utils_fatal("invalid exposure"); } if (g_variant_dict_lookup(options_dict, "gain", "d", &options.gain)) { option_set = true; if (options.gain <= 0.0) utils_fatal("invalid gain"); } if (g_variant_dict_lookup(options_dict, "count", "i", &options.count)) { option_set = true; if (options.count <= 0) utils_fatal("invalid count"); } if (g_variant_dict_contains(options_dict, "raw")) { option_set = true; options.raw = true; } if (g_variant_dict_lookup(options_dict, "output", "^&ay", &options.out)) { option_set = true; int argtypes[1]; int formats = parse_printf_format(options.out, 1, argtypes); if (formats != 1 || argtypes[0] != PA_INT) utils_fatal("bad file pattern, use one %%d"); } else { options.out = "out%02d.png"; } if (option_set) return cli_run(&options); else return -1; }