source: trunk/core/conf.c @ 1245

Revision 1245, 33.2 KB checked in by reyalp, 3 years ago (diff)

G12+SX30 Patch to disable raw/dng saving in 'low light' + cleanup from philmoz in http://chdk.setepontos.com/index.php?topic=650.msg70704#msg70704

  • Property svn:eol-style set to native
Line 
1#include "platform.h"
2#include "keyboard.h"
3#include "conf.h"
4#include "histogram.h"
5#include "font.h"
6#include "camera.h"
7#include "raw.h"
8#include "gui_draw.h"
9#include "gui_osd.h"
10#include "gui_grid.h"
11#include "core.h"
12#include "stdlib.h"
13#include "script.h"
14
15//-------------------------------------------------------------------
16#define CONF_FILE  "A/CHDK/CCHDK.CFG"
17#define CONF_MAGICK_VALUE (0x33204741)
18
19#define CONF_INFO(id, param, type, def, func) { id, sizeof( param ), type, &param, {def}/*, func*/ }
20#define CONF_DEF_PTR    1
21#define CONF_DEF_VALUE  2
22
23//-------------------------------------------------------------------
24typedef struct {
25    unsigned short      id;
26    unsigned char       size;
27    char                type;
28    void                *var;
29    union {
30        void            *ptr;
31        int             i;
32        color           cl;
33    };
34    // Since only a few of the ConfInfo entries have a 'func' it saves space to not store the function addresses in the ConfInfo struct
35    // handled in conf_info_func code
36    //void                (*func)();
37} ConfInfo;
38
39//-------------------------------------------------------------------
40Conf conf;
41
42int state_shooting_progress = SHOOTING_PROGRESS_NONE;
43int state_save_raw_nth_only;
44int state_expos_recalculated;
45int state_expos_under;
46int state_expos_over;
47int auto_started;
48
49// reyalp: putting these in conf, since the conf values are lookups for them
50// prefixes and extentions available for raw images (index with conf.raw_prefix etc)
51const char* img_prefixes[NUM_IMG_PREFIXES]={ "IMG_", "CRW_", "SND_" /*, "AUT_", "ETC_","SDR_", "MVI_", "MRK_"*/};
52const char* img_exts[NUM_IMG_EXTS]={ ".JPG", ".CRW", ".CR2", ".THM", ".WAV"/*, ".AVI", ".MRK"*/};
53// ugh
54const char *video_bitrate_strings[VIDEO_BITRATE_STEPS]={ "0.25x", "0.5x","0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x", "2.5x", "3x"};
55
56//-------------------------------------------------------------------
57static int def_ubasic_vars[SCRIPT_NUM_PARAMS] = {0};
58static int def_batt_volts_max, def_batt_volts_min;
59static OSD_pos def_histo_pos, def_dof_pos, def_batt_icon_pos, def_space_icon_pos, def_space_hor_pos, def_space_ver_pos, def_batt_txt_pos, def_space_txt_pos,
60               def_mode_state_pos, def_mode_raw_pos, def_mode_video_pos, def_mode_ev_pos, def_values_pos, def_clock_pos, def_ev_video_pos, def_temp_pos;
61static int def_user_menu_vars[USER_MENU_ITEMS] = {0};
62
63static void conf_change_script_file();
64static void conf_change_histo_mode();
65static void conf_change_histo_layout();
66static void conf_change_font_cp();
67static void conf_change_menu_rbf_file();
68static void conf_change_menu_symbol_rbf_file();
69static void conf_change_alt_mode_button();
70static void conf_change_grid_file();
71static void conf_change_video_bitrate();
72static void conf_change_dng_ext();
73
74void camera_set_raw(int mode)
75{
76    conf.save_raw = mode;
77}
78
79void camera_set_nr(int mode)
80{
81        // "Auto", "Off", "On"
82    conf.raw_nr = mode;
83}
84int camera_get_script_autostart()
85{       
86        // 1 = Autostarted
87        return auto_started;
88}
89
90void camera_set_script_autostart(int state)
91{       
92        // 1 = Autostarted
93        auto_started = state;
94}
95
96int camera_get_nr()
97{
98        // "Auto", "Off", "On"
99    return conf.raw_nr;
100}
101
102
103void clear_values()
104{       
105        if (conf.platformid != PLATFORMID) // the following config entries will be resetted if you switch the camera using the same cfg
106        {
107    conf.raw_cache = 0;
108    conf.zoom_override_value = 0;
109    conf.fast_ev = 0;
110    conf.fast_movie_control = 0;
111    conf.fast_movie_quality_control = 0;
112    conf.zoom_scale = 100;
113    conf.platformid = PLATFORMID;
114    conf.flash_video_override = 0;
115        }
116
117        if (conf.clear_override)
118        {
119         conf.av_override_value=0;
120         conf.tv_override_koef=0;
121         conf.subj_dist_override_koef=0;
122         conf.iso_override_koef=0;
123         conf.nd_filter_state=0;
124        }
125        if (conf.clear_zoom_override)
126        {
127        conf.zoom_override = 0;
128        }
129        if (conf.clear_bracket)
130        {
131         conf.av_bracket_value=0;
132         conf.tv_bracket_value=0;
133         conf.iso_bracket_koef=0;
134         conf.subj_dist_bracket_koef=0;
135        }
136     if (conf.clear_video)
137        {
138         conf.video_mode = 0;
139         conf.video_quality = VIDEO_DEFAULT_QUALITY;
140         conf.video_bitrate = VIDEO_DEFAULT_BITRATE;
141         shooting_video_bitrate_change(conf.video_bitrate);
142        }
143        conf.edge_overlay_pano = 0; // reset it because otherwise this feature cant be used at startup (when buffer is empty) - needs workaround other than this!
144}
145
146static const ConfInfo conf_info[] = {
147/* !!! Do NOT change ID for items defined already! Append a new one at the end! !!! */
148    CONF_INFO(  1, conf.show_osd,               CONF_DEF_VALUE, i:1, NULL),
149    CONF_INFO(  2, conf.save_raw,               CONF_DEF_VALUE, i:0, NULL),
150    CONF_INFO(  3, conf.script_shoot_delay,     CONF_DEF_VALUE, i:0, NULL),
151    CONF_INFO(  4, conf.show_histo,             CONF_DEF_VALUE, i:0, NULL),
152    CONF_INFO(  5, conf.ubasic_vars,            CONF_DEF_PTR,   ptr:&def_ubasic_vars, NULL),
153    CONF_INFO(  6, conf.script_param_set,       CONF_DEF_VALUE, i:0, NULL),
154    CONF_INFO(  7, conf.show_dof,               CONF_DEF_VALUE, i:DOF_DONT_SHOW, NULL),
155    CONF_INFO(  8, conf.batt_volts_max,         CONF_DEF_PTR,   ptr:&def_batt_volts_max, NULL),
156    CONF_INFO(  9, conf.batt_volts_min,         CONF_DEF_PTR,   ptr:&def_batt_volts_min, NULL),
157    CONF_INFO( 10, conf.batt_step_25,           CONF_DEF_VALUE, i:1, NULL),
158    CONF_INFO( 11, conf.batt_perc_show,         CONF_DEF_VALUE, i:1, NULL),
159    CONF_INFO( 12, conf.batt_volts_show,        CONF_DEF_VALUE, i:0, NULL),
160    CONF_INFO( 13, conf.batt_icon_show,         CONF_DEF_VALUE, i:1, NULL),
161    CONF_INFO( 14, conf.show_state,             CONF_DEF_VALUE, i:1, NULL),
162    CONF_INFO( 15, conf.show_values,            CONF_DEF_VALUE, i:0, NULL),
163    CONF_INFO( 16, conf.show_overexp,           CONF_DEF_VALUE, i:1, NULL),
164    CONF_INFO( 17, conf.histo_mode,             CONF_DEF_VALUE, i:HISTO_MODE_LINEAR, conf_change_histo_mode),
165    CONF_INFO( 18, conf.histo_auto_ajust,       CONF_DEF_VALUE, i:1, NULL),
166    CONF_INFO( 19, conf.histo_ignore_boundary,  CONF_DEF_VALUE, i:4, NULL),
167    CONF_INFO( 20, conf.histo_layout,           CONF_DEF_VALUE, i:OSD_HISTO_LAYOUT_A, conf_change_histo_layout),
168    CONF_INFO( 21, conf.histo_pos,              CONF_DEF_PTR,   ptr:&def_histo_pos, NULL),
169    CONF_INFO( 22, conf.dof_pos,                CONF_DEF_PTR,   ptr:&def_dof_pos, NULL),
170    CONF_INFO( 23, conf.batt_icon_pos,          CONF_DEF_PTR,   ptr:&def_batt_icon_pos, NULL),
171    CONF_INFO( 24, conf.batt_txt_pos,           CONF_DEF_PTR,   ptr:&def_batt_txt_pos , NULL),
172    CONF_INFO( 25, conf.mode_state_pos,         CONF_DEF_PTR,   ptr:&def_mode_state_pos , NULL),
173    CONF_INFO( 26, conf.values_pos,             CONF_DEF_PTR,   ptr:&def_values_pos , NULL),
174    CONF_INFO( 27, conf.histo_color,            CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_WHITE), NULL),
175    CONF_INFO( 28, conf.osd_color,              CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_FG), NULL),
176    CONF_INFO( 29, conf.batt_icon_color,        CONF_DEF_VALUE, cl:COLOR_WHITE, NULL),
177    CONF_INFO( 30, conf.menu_color,             CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_FG), NULL),
178    CONF_INFO( 31, conf.reader_color,           CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_GREY, COLOR_WHITE), NULL),
179    CONF_INFO( 32, conf.ricoh_ca1_mode,         CONF_DEF_VALUE, i:0, NULL),
180    CONF_INFO( 33, conf.flashlight,             CONF_DEF_VALUE, i:0, NULL),
181//    CONF_INFO( 34, conf.ns_enable_memdump,      CONF_DEF_VALUE, i:0, NULL),
182    CONF_INFO( 34, conf.debug_shortcut_action,  CONF_DEF_VALUE, i:0, NULL), // backwards compatible
183    CONF_INFO( 35, conf.raw_in_dir,             CONF_DEF_VALUE, i:0, NULL),
184    CONF_INFO( 36, conf.raw_prefix,             CONF_DEF_VALUE, i:RAW_PREFIX_CRW, NULL),
185    CONF_INFO( 37, conf.raw_ext,                CONF_DEF_VALUE, i:DEFAULT_RAW_EXT, NULL),
186    CONF_INFO( 38, conf.reader_file,            CONF_DEF_PTR,   ptr:"A/README.TXT", NULL),
187    CONF_INFO( 39, conf.reader_pos,             CONF_DEF_VALUE, i:0, NULL),
188    CONF_INFO( 40, conf.sokoban_level,          CONF_DEF_VALUE, i:0, NULL),
189    CONF_INFO( 41, conf.show_clock,             CONF_DEF_VALUE, i:2, NULL),
190    CONF_INFO( 42, conf.clock_pos,              CONF_DEF_PTR,   ptr:&def_clock_pos , NULL),
191    CONF_INFO( 43, conf.reader_autoscroll,      CONF_DEF_VALUE, i:0, NULL),
192    CONF_INFO( 44, conf.reader_autoscroll_delay,CONF_DEF_VALUE, i:5, NULL),
193    CONF_INFO( 45, conf.reader_rbf_file,        CONF_DEF_PTR,   ptr:"", NULL),
194    CONF_INFO( 46, conf.reader_codepage,        CONF_DEF_VALUE, i:FONT_CP_WIN, NULL),
195    CONF_INFO( 47, conf.splash_show,            CONF_DEF_VALUE, i:1, NULL),
196    CONF_INFO( 48, conf.histo_color2,           CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_RED, COLOR_WHITE), NULL),
197    CONF_INFO( 49, conf.zebra_draw,             CONF_DEF_VALUE, i:0, NULL),
198    CONF_INFO( 50, conf.zebra_mode,             CONF_DEF_VALUE, i:ZEBRA_MODE_BLINKED_2, NULL),
199    CONF_INFO( 51, conf.zebra_restore_screen,   CONF_DEF_VALUE, i:1, NULL),
200    CONF_INFO( 52, conf.zebra_restore_osd,      CONF_DEF_VALUE, i:1, NULL),
201    CONF_INFO( 53, conf.zebra_over,             CONF_DEF_VALUE, i:1, NULL),
202    CONF_INFO( 54, conf.zebra_under,            CONF_DEF_VALUE, i:0, NULL),
203    CONF_INFO( 55, conf.zebra_color,            CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_RED, COLOR_RED), NULL),
204    CONF_INFO( 56, conf.zebra_draw_osd,         CONF_DEF_VALUE, i:ZEBRA_DRAW_HISTO, NULL),
205    CONF_INFO( 57, conf.user_menu_as_root,      CONF_DEF_VALUE, i:0, NULL),
206    CONF_INFO( 58, conf.zoom_value,             CONF_DEF_VALUE, i:ZOOM_SHOW_X, NULL),
207    CONF_INFO( 59, conf.use_zoom_mf,            CONF_DEF_VALUE, i:0, NULL),
208    CONF_INFO( 60, conf.raw_save_first_only,    CONF_DEF_VALUE, i:0, NULL),
209    CONF_INFO( 61, conf.reader_wrap_by_words,   CONF_DEF_VALUE, i:1, NULL),
210    CONF_INFO( 62, conf.menu_symbol_enable,     CONF_DEF_VALUE, i:1, NULL),
211    CONF_INFO( 63, conf.alt_mode_button,        CONF_DEF_VALUE, i:KEY_PRINT, conf_change_alt_mode_button),
212    CONF_INFO( 64, conf.lang_file,              CONF_DEF_PTR,   ptr:"", NULL),
213    CONF_INFO( 65, conf.font_cp,                CONF_DEF_VALUE, i:FONT_CP_WIN_1251, conf_change_font_cp),
214    CONF_INFO( 66, conf.menu_rbf_file,          CONF_DEF_PTR,   ptr:"", conf_change_menu_rbf_file),
215    CONF_INFO( 67, conf.alt_prevent_shutdown,   CONF_DEF_VALUE, i:ALT_PREVENT_SHUTDOWN_ALT, conf_update_prevent_shutdown),
216    CONF_INFO( 68, conf.show_grid_lines,        CONF_DEF_VALUE, i:0, NULL),
217    CONF_INFO( 69, conf.grid_lines_file,        CONF_DEF_PTR,   ptr:"", conf_change_grid_file),
218    CONF_INFO( 70, conf.raw_nr,                 CONF_DEF_VALUE, i:NOISE_REDUCTION_AUTO_CANON, NULL),
219    CONF_INFO( 71, conf.grid_force_color,       CONF_DEF_VALUE, i:0, NULL),
220    CONF_INFO( 72, conf.grid_color,             CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_FG), NULL),
221
222    CONF_INFO( 80, conf.dof_subj_dist_as_near_limit,CONF_DEF_VALUE, i:0, NULL),
223    CONF_INFO( 81, conf.dof_use_exif_subj_dist,     CONF_DEF_VALUE, i:0, NULL),
224    CONF_INFO( 82, conf.dof_subj_dist_in_misc,      CONF_DEF_VALUE, i:1, NULL),
225    CONF_INFO( 83, conf.dof_near_limit_in_misc,     CONF_DEF_VALUE, i:1, NULL),
226    CONF_INFO( 84, conf.dof_far_limit_in_misc,      CONF_DEF_VALUE, i:1, NULL),
227    CONF_INFO( 85, conf.dof_hyperfocal_in_misc,     CONF_DEF_VALUE, i:1, NULL),
228    CONF_INFO( 86, conf.dof_depth_in_misc,          CONF_DEF_VALUE, i:0, NULL),
229
230        CONF_INFO( 87, conf.values_show_in_review,    CONF_DEF_VALUE, i:0, NULL),
231    CONF_INFO( 88, conf.values_show_zoom,         CONF_DEF_VALUE, i:1, NULL),
232    CONF_INFO( 89, conf.values_show_real_aperture,CONF_DEF_VALUE, i:0, NULL),
233    CONF_INFO( 90, conf.values_show_real_iso,     CONF_DEF_VALUE, i:1, NULL),
234    CONF_INFO( 91, conf.values_show_market_iso,   CONF_DEF_VALUE, i:0, NULL),
235    CONF_INFO( 92, conf.values_show_iso_only_in_autoiso_mode, CONF_DEF_VALUE, i:0, NULL),
236    CONF_INFO( 93, conf.values_show_ev_seted,     CONF_DEF_VALUE, i:0, NULL),
237    CONF_INFO( 94, conf.values_show_ev_measured,  CONF_DEF_VALUE, i:0, NULL),
238    CONF_INFO( 95, conf.values_show_bv_measured,  CONF_DEF_VALUE, i:0, NULL),
239    CONF_INFO( 96, conf.values_show_bv_seted,     CONF_DEF_VALUE, i:0, NULL),
240    CONF_INFO( 97, conf.values_show_overexposure, CONF_DEF_VALUE, i:0, NULL),
241    CONF_INFO( 98, conf.values_show_luminance,    CONF_DEF_VALUE, i:0, NULL),
242
243    CONF_INFO( 99, conf.video_mode,             CONF_DEF_VALUE, i:0, NULL),
244    CONF_INFO(100, conf.video_quality,          CONF_DEF_VALUE, i:VIDEO_DEFAULT_QUALITY,NULL),
245    CONF_INFO(101, conf.video_bitrate,          CONF_DEF_VALUE, i:VIDEO_DEFAULT_BITRATE, conf_change_video_bitrate),
246   
247    CONF_INFO(102, conf.tv_override_value,      CONF_DEF_VALUE, i:0, NULL),     
248    CONF_INFO(103, conf.tv_override_koef,       CONF_DEF_VALUE, i:0, NULL),     
249
250    CONF_INFO(104, conf.av_override_value,      CONF_DEF_VALUE, i:0, NULL),
251    CONF_INFO(105, conf.iso_override_value,     CONF_DEF_VALUE, i:0, NULL),
252    CONF_INFO(106, conf.iso_override_koef,      CONF_DEF_VALUE, i:0, NULL),
253   
254    CONF_INFO(107, conf.subj_dist_override_value,CONF_DEF_VALUE, i:0, NULL),
255    CONF_INFO(108, conf.subj_dist_override_koef, CONF_DEF_VALUE, i:0, NULL),
256   
257    CONF_INFO(109, conf.tv_bracket_value,       CONF_DEF_VALUE, i:0, NULL),
258    CONF_INFO(110, conf.av_bracket_value,       CONF_DEF_VALUE, i:0, NULL),
259    CONF_INFO(111, conf.iso_bracket_value,      CONF_DEF_VALUE, i:0, NULL),
260    CONF_INFO(112, conf.iso_bracket_koef,       CONF_DEF_VALUE, i:0, NULL),
261    CONF_INFO(113, conf.subj_dist_bracket_value,CONF_DEF_VALUE, i:0, NULL),
262    CONF_INFO(114, conf.subj_dist_bracket_koef, CONF_DEF_VALUE, i:0, NULL),
263    CONF_INFO(115, conf.bracket_type,           CONF_DEF_VALUE, i:0, NULL),
264   
265    CONF_INFO(116, conf.recalc_exposure,        CONF_DEF_VALUE, i:0, NULL),
266    CONF_INFO(117, conf.tv_exposure_order,      CONF_DEF_VALUE, i:2, NULL),
267    CONF_INFO(118, conf.av_exposure_order,      CONF_DEF_VALUE, i:1, NULL),
268    CONF_INFO(119, conf.iso_exposure_order,     CONF_DEF_VALUE, i:3, NULL),
269   
270    CONF_INFO(120, conf.script_startup,         CONF_DEF_VALUE, i:0, NULL),
271    CONF_INFO(121, conf.remote_enable,          CONF_DEF_VALUE, i:0, NULL),
272   
273    CONF_INFO(122, conf.values_show_canon_overexposure, CONF_DEF_VALUE, i:0, NULL),
274    CONF_INFO(123, conf.clear_override,         CONF_DEF_VALUE, i:1, NULL),
275   
276    CONF_INFO(124, conf.show_osd_in_review,     CONF_DEF_VALUE, i:0, NULL),
277   
278    CONF_INFO(125, conf.dof_dist_from_lens,     CONF_DEF_VALUE, i:0, NULL),
279   
280    CONF_INFO(126, conf.clear_bracket,          CONF_DEF_VALUE, i:1, NULL),
281    CONF_INFO(127, conf.zebra_multichannel,     CONF_DEF_VALUE, i:0, NULL),
282
283    CONF_INFO(128, conf.nd_filter_state,        CONF_DEF_VALUE, i:0, NULL),
284    CONF_INFO(129, conf.histo_show_ev_grid,     CONF_DEF_VALUE, i:0, NULL),
285   
286    CONF_INFO(130, conf.osd_color_warn,         CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_RED), NULL),
287    CONF_INFO(131, conf.space_color,            CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_FG), NULL),
288    CONF_INFO(132, conf.space_icon_show,        CONF_DEF_VALUE, i:0, NULL),
289    CONF_INFO(133, conf.space_icon_pos,         CONF_DEF_PTR, ptr:&def_space_icon_pos, NULL),
290    CONF_INFO(134, conf.space_perc_show,        CONF_DEF_VALUE, i:0, NULL),
291    CONF_INFO(135, conf.space_mb_show,          CONF_DEF_VALUE, i:1, NULL),
292    CONF_INFO(136, conf.space_txt_pos,          CONF_DEF_PTR,   ptr:&def_space_txt_pos , NULL),
293    CONF_INFO(137, conf.show_remaining_raw,     CONF_DEF_VALUE, i:1, NULL),
294    CONF_INFO(138, conf.mode_raw_pos,           CONF_DEF_PTR,   ptr:&def_mode_raw_pos , NULL),
295    CONF_INFO(139, conf.show_raw_state,         CONF_DEF_VALUE, i:1, NULL),
296   
297    CONF_INFO(140, conf.show_values_in_video,   CONF_DEF_VALUE, i:0, NULL),
298    CONF_INFO(141, conf.tv_enum_type,           CONF_DEF_VALUE, i:1, NULL),
299
300    CONF_INFO(142, conf.user_menu_enable,       CONF_DEF_VALUE, i:0, NULL),
301    CONF_INFO(143, conf.user_menu_vars,         CONF_DEF_PTR,   ptr:&def_user_menu_vars, NULL),
302    CONF_INFO(144, conf.zoom_scale,             CONF_DEF_VALUE, i:100, NULL),
303    CONF_INFO(145, conf.space_bar_show,         CONF_DEF_VALUE, i:1, NULL),
304    CONF_INFO(146, conf.space_bar_size,         CONF_DEF_VALUE, i:1, NULL),
305    CONF_INFO(147, conf.space_ver_pos,          CONF_DEF_PTR, ptr:&def_space_ver_pos, NULL),
306    CONF_INFO(148, conf.space_hor_pos,          CONF_DEF_PTR, ptr:&def_space_hor_pos, NULL),   
307    CONF_INFO(149, conf.space_bar_width,        CONF_DEF_VALUE, i:2, NULL),
308    CONF_INFO(150, conf.space_perc_warn,        CONF_DEF_VALUE, i:10, NULL),
309    CONF_INFO(151, conf.space_mb_warn,          CONF_DEF_VALUE, i:20, NULL),
310    CONF_INFO(152, conf.space_warn_type,        CONF_DEF_VALUE, i:0, NULL),
311    CONF_INFO(153, conf.remaining_raw_treshold, CONF_DEF_VALUE, i:0, NULL),
312    CONF_INFO(154, conf.unlock_optical_zoom_for_video, CONF_DEF_VALUE, i:1, NULL),
313    CONF_INFO(155, conf.clock_format,           CONF_DEF_VALUE, i:0, NULL),
314    CONF_INFO(156, conf.clock_indicator,        CONF_DEF_VALUE, i:0, NULL),
315    CONF_INFO(157, conf.clock_halfpress,        CONF_DEF_VALUE, i:1, NULL),
316   
317    CONF_INFO(158, conf.autoiso_enable,         CONF_DEF_VALUE, i:0, NULL),
318    CONF_INFO(159, conf.autoiso_shutter,        CONF_DEF_VALUE, i:0, NULL),
319    CONF_INFO(160, conf.autoiso_user_factor,    CONF_DEF_VALUE, i:5, NULL),
320    CONF_INFO(161, conf.autoiso_is_factor,      CONF_DEF_VALUE, i:2, NULL),
321    CONF_INFO(162, conf.autoiso_max_iso_hi,     CONF_DEF_VALUE, i:55, NULL),
322    CONF_INFO(163, conf.autoiso_max_iso_auto,   CONF_DEF_VALUE, i:35, NULL),
323    CONF_INFO(164, conf.autoiso_min_iso,        CONF_DEF_VALUE, i:5, NULL),
324
325    CONF_INFO(165, conf.menu_title_color,       CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_WHITE, COLOR_BLACK), NULL),
326    CONF_INFO(166, conf.menu_cursor_color,      CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_SELECTED_BG, COLOR_SELECTED_FG), NULL),
327    CONF_INFO(167, conf.menu_center,            CONF_DEF_VALUE, i:1, NULL),
328    CONF_INFO(168, conf.mute_on_zoom,           CONF_DEF_VALUE, i:0, NULL),
329    CONF_INFO(169, conf.bad_pixel_removal,      CONF_DEF_VALUE, i:0, NULL),
330    CONF_INFO(170, conf.video_af_key,           CONF_DEF_VALUE, i:0, NULL),
331    CONF_INFO(171, conf.osd_color_override,     CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_RED), NULL),
332    CONF_INFO(172, conf.override_disable,       CONF_DEF_VALUE, i:2, NULL),
333    CONF_INFO(173, conf.override_disable_all,   CONF_DEF_VALUE, i:1, NULL),
334    CONF_INFO(174, conf.hide_osd,   CONF_DEF_VALUE, i:1, NULL),
335    CONF_INFO(175, conf.save_raw_in_video,      CONF_DEF_VALUE, i:1, NULL),
336    CONF_INFO(176, conf.show_movie_time,        CONF_DEF_VALUE, i:3, NULL),
337    CONF_INFO(177, conf.show_movie_refresh,     CONF_DEF_VALUE, i:1, NULL),
338    CONF_INFO(178, conf.mode_video_pos,         CONF_DEF_PTR,   ptr:&def_mode_video_pos , NULL),
339    CONF_INFO(179, conf.clear_video,            CONF_DEF_VALUE, i:0, NULL),
340    CONF_INFO(180, conf.fast_ev,                CONF_DEF_VALUE, i:0, NULL),
341    CONF_INFO(181, conf.fast_ev_step,           CONF_DEF_VALUE, i:1, NULL),
342    CONF_INFO(182, conf.mode_ev_pos,            CONF_DEF_PTR,   ptr:&def_mode_ev_pos , NULL),
343    CONF_INFO(183, conf.menu_symbol_rbf_file,   CONF_DEF_PTR,   ptr:"A/CHDK/SYMBOLS/icon_10.rbf", conf_change_menu_symbol_rbf_file),
344    CONF_INFO(184, conf.menu_symbol_color,      CONF_DEF_VALUE, cl:MAKE_COLOR(COLOR_BG, COLOR_FG), NULL),
345    CONF_INFO(185, conf.curve_file,             CONF_DEF_PTR, ptr:"", NULL),
346    CONF_INFO(186, conf.curve_enable,           CONF_DEF_VALUE, i:0, NULL),
347    CONF_INFO(187, conf.edge_overlay_enable,    CONF_DEF_VALUE, i:0, NULL),
348    CONF_INFO(188, conf.edge_overlay_thresh,    CONF_DEF_VALUE, i:60, NULL),
349    CONF_INFO(189, conf.edge_overlay_color,     CONF_DEF_VALUE, cl:0x66, NULL),
350    CONF_INFO(190, conf.synch_enable,           CONF_DEF_VALUE, i:0, NULL),
351    CONF_INFO(191, conf.synch_delay_enable,     CONF_DEF_VALUE, i:0, NULL),
352    CONF_INFO(192, conf.synch_delay_value,      CONF_DEF_VALUE, i:100, NULL),
353    CONF_INFO(193, conf.synch_delay_coarse_value, CONF_DEF_VALUE, i:0, NULL),
354    CONF_INFO(194, conf.script_file,            CONF_DEF_PTR,   ptr:"", conf_change_script_file),
355    CONF_INFO(195, conf.mem_view_addr_init,     CONF_DEF_VALUE, i:0x1000, NULL),
356    CONF_INFO(196, conf.save_raw_in_sports,     CONF_DEF_VALUE, i:0, NULL),
357    CONF_INFO(197, conf.save_raw_in_burst,      CONF_DEF_VALUE, i:0, NULL),
358    CONF_INFO(198, conf.save_raw_in_ev_bracketing, CONF_DEF_VALUE, i:0, NULL),
359    CONF_INFO(199, conf.save_raw_in_timer,      CONF_DEF_VALUE, i:0, NULL),
360    CONF_INFO(200, conf.raw_exceptions_warn,    CONF_DEF_VALUE, i:1, NULL),
361    CONF_INFO(201, conf.menu_select_first_entry, CONF_DEF_VALUE, i:1, NULL),
362    CONF_INFO(202, conf.fast_movie_control,     CONF_DEF_VALUE, i:0, NULL),
363    CONF_INFO(203, conf.show_temp,              CONF_DEF_VALUE, i:1, NULL),
364    CONF_INFO(204, conf.temp_pos,               CONF_DEF_PTR,   ptr:&def_temp_pos , NULL),
365    CONF_INFO(205, conf.fast_movie_quality_control, CONF_DEF_VALUE, i:1, NULL),
366    CONF_INFO(206, conf.remote_zoom_enable,     CONF_DEF_VALUE, i:0, NULL),
367    CONF_INFO(207, conf.zoom_timeout,           CONF_DEF_VALUE, i:5, NULL),
368        CONF_INFO(208, conf.start_sound,     CONF_DEF_VALUE, i:0, NULL),
369    CONF_INFO(209, conf.sub_batch_prefix,  CONF_DEF_VALUE, i:RAW_PREFIX_SND, NULL), // SND_
370    CONF_INFO(210, conf.sub_batch_ext,  CONF_DEF_VALUE, i:DEFAULT_RAW_EXT, NULL), // .CRW
371    CONF_INFO(211, conf.sub_in_dark_value,  CONF_DEF_VALUE, i:30, NULL),
372    CONF_INFO(212, conf.sub_out_dark_value,  CONF_DEF_VALUE, i:0, NULL),
373        CONF_INFO(213, conf.debug_display,     CONF_DEF_VALUE, i:0, NULL),
374        CONF_INFO(214, conf.script_param_save,     CONF_DEF_VALUE, i:1, NULL),
375    CONF_INFO(215, conf.ev_video_pos,           CONF_DEF_PTR,   ptr:&def_ev_video_pos, NULL),
376    CONF_INFO(216, conf.zoom_override_value,     CONF_DEF_VALUE, i:0, NULL),
377    CONF_INFO(217, conf.zoom_override,      CONF_DEF_VALUE, i:0, NULL),
378    CONF_INFO(218, conf.clear_zoom_override,         CONF_DEF_VALUE, i:1, NULL),                       
379    CONF_INFO(219, conf.bracketing_add_raw_suffix,         CONF_DEF_VALUE, i:0, NULL),                 
380    CONF_INFO(220, conf.temperature_unit,              CONF_DEF_VALUE, i:0, NULL),
381    CONF_INFO(221, conf.clear_zoom_override,         CONF_DEF_VALUE, i:1, NULL),                       
382    CONF_INFO(222, conf.edge_overlay_play,    CONF_DEF_VALUE, i:0, NULL),
383    CONF_INFO(223, conf.edge_overlay_pano,              CONF_DEF_VALUE, i:0, NULL),
384    CONF_INFO(224, conf.edge_overlay_zoom,                CONF_DEF_VALUE, i:1, NULL),
385    CONF_INFO(225, conf.raw_cache,              CONF_DEF_VALUE, i:0, NULL),
386    CONF_INFO(226, conf.dng_raw,                CONF_DEF_VALUE, i:0, conf_change_dng),
387    CONF_INFO(227, conf.flash_sync_curtain,     CONF_DEF_VALUE, i:0, NULL),
388    CONF_INFO(228, conf.raw_timer,     CONF_DEF_VALUE, i:0, NULL),
389    CONF_INFO(229, conf.platformid,     CONF_DEF_VALUE, i:PLATFORMID, NULL),
390    CONF_INFO(230, conf.save_raw_in_edgeoverlay,     CONF_DEF_VALUE, i:0, NULL),
391    CONF_INFO(231, conf.save_raw_in_auto,     CONF_DEF_VALUE, i:0, NULL),
392    CONF_INFO(232, conf.flash_video_override,     CONF_DEF_VALUE, i:0, NULL),
393    CONF_INFO(233, conf.flash_video_override_power,     CONF_DEF_VALUE, i:0, NULL),
394    CONF_INFO(234, conf.raw_dng_ext,     CONF_DEF_VALUE, i:0, NULL),
395    CONF_INFO(235, conf.dng_usb_ext,     CONF_DEF_VALUE, i:0, conf_change_dng_ext),
396    CONF_INFO(236, conf.flash_manual_override,     CONF_DEF_VALUE, i:0, NULL),
397    CONF_INFO(237, conf.fast_image_quality,     CONF_DEF_VALUE, i:3, NULL),
398        CONF_INFO(238, conf.debug_lua_restart_on_error,     CONF_DEF_VALUE, i:0, NULL),
399        CONF_INFO(239, conf.debug_propcase_page,     CONF_DEF_VALUE, i:0, NULL),
400        CONF_INFO(240, conf.debug_misc_vals_show,     CONF_DEF_VALUE, i:0, NULL),
401        CONF_INFO(241, conf.edge_overlay_filter,     CONF_DEF_VALUE, i:0, NULL),
402        CONF_INFO(242, conf.edge_overlay_show,     CONF_DEF_VALUE, i:0, NULL),
403    CONF_INFO(243, conf.edge_overlay_pano_overlap,   CONF_DEF_VALUE, i:30, NULL),
404    };
405#define CONF_NUM (sizeof(conf_info)/sizeof(conf_info[0]))
406
407// Since only a few of the ConfInfo entries have a 'func' it saves space to not store the function addresses in the ConfInfo struct
408void conf_info_func(unsigned short id)
409{
410    switch (id)
411    {
412    case  17: conf_change_histo_mode(); break;
413    case  20: conf_change_histo_layout(); break;
414    case  63: conf_change_alt_mode_button(); break;
415    case  65: conf_change_font_cp(); break;
416    case  66: conf_change_menu_rbf_file(); break;
417    case  67: conf_update_prevent_shutdown(); break;
418    case  69: conf_change_grid_file(); break;
419    case 101: conf_change_video_bitrate(); break;
420    case 183: conf_change_menu_symbol_rbf_file(); break;
421    case 194: conf_change_script_file(); break;
422    case 226: conf_change_dng(); break;
423    case 235: conf_change_dng_ext(); break;
424    }
425}
426
427//-------------------------------------------------------------------
428static void conf_change_histo_mode() {
429    histogram_set_mode(conf.histo_mode);
430}
431
432static void conf_change_histo_layout() {
433    if (conf.histo_layout==OSD_HISTO_LAYOUT_Y || conf.histo_layout==OSD_HISTO_LAYOUT_Y_argb) {
434        histogram_set_main(HISTO_Y);
435    } else {
436        histogram_set_main(HISTO_RGB);
437    }
438}
439
440static void conf_change_font_cp() {
441    font_init();
442    font_set(conf.font_cp);
443}
444
445static void conf_change_script_file() {
446#ifdef OPT_SCRIPTING
447    script_load(conf.script_file, 2);
448#endif
449}
450
451static void conf_change_menu_rbf_file() {
452    if (!rbf_load(conf.menu_rbf_file))
453        rbf_load_from_8x16(current_font);
454    rbf_set_codepage(FONT_CP_WIN);
455}
456
457static void conf_change_menu_symbol_rbf_file() {
458    if(!rbf_load_symbol(conf.menu_symbol_rbf_file)) conf.menu_symbol_enable=0;          //AKA
459}
460
461static void conf_change_alt_mode_button() {
462#if CAM_ADJUSTABLE_ALT_BUTTON
463    kbd_set_alt_mode_key_mask(conf.alt_mode_button);
464#else
465    conf.alt_mode_button = KEY_PRINT;
466#endif
467}
468
469static void conf_change_grid_file() {
470    grid_lines_load(conf.grid_lines_file);
471}
472
473static void conf_change_video_bitrate() {
474    shooting_video_bitrate_change(conf.video_bitrate);
475 }
476
477void conf_change_dng(void){
478#if DNG_SUPPORT
479 if (conf.dng_raw) {
480  if (!badpixel_list_loaded_b()) load_bad_pixels_list_b("A/CHDK/badpixel.bin");
481  if (!badpixel_list_loaded_b()) conf.dng_raw=0;
482 }
483 else unload_bad_pixels_list_b();
484#endif
485}
486
487void conf_change_dng_ext(void){
488#if defined (DNG_EXT_FROM)
489 save_ext_for_dng();
490 if (conf.dng_usb_ext) change_ext_to_dng(); else change_ext_to_default();
491#endif
492}
493
494/*
495update the prevent display off/prevent shutdown based on current state
496doesn't really belong in conf but not clear where else it should go
497*/
498void conf_update_prevent_shutdown(void) {
499        if(conf.alt_prevent_shutdown == ALT_PREVENT_SHUTDOWN_ALWAYS
500                || (conf.alt_prevent_shutdown == ALT_PREVENT_SHUTDOWN_ALT && gui_get_mode() != GUI_MODE_NONE)
501                || (conf.alt_prevent_shutdown == ALT_PREVENT_SHUTDOWN_ALT_SCRIPT && state_kbd_script_run)) {
502        disable_shutdown();
503        } else {
504        enable_shutdown();
505        }
506}
507
508//-------------------------------------------------------------------
509static void conf_init_defaults() {
510    // init some defaults values
511    def_batt_volts_max = get_vbatt_max();
512    def_batt_volts_min = get_vbatt_min();
513    def_histo_pos.x = 45;
514    def_histo_pos.y = vid_get_bitmap_screen_height()-HISTO_HEIGHT-40;
515    def_dof_pos.x = 90;
516    def_dof_pos.y = 45;
517    def_batt_icon_pos.x = 178;
518    def_batt_icon_pos.y = 0;
519    def_batt_txt_pos.x=178;
520    def_batt_txt_pos.y=1*FONT_HEIGHT;
521    def_space_icon_pos.x = vid_get_bitmap_screen_width()-100;
522    def_space_icon_pos.y = 0;
523    def_space_ver_pos.x = vid_get_bitmap_screen_width()-7;
524    def_space_ver_pos.y = 0;
525    def_space_hor_pos.x = 0;
526    def_space_hor_pos.y = vid_get_bitmap_screen_height()-7;
527    def_space_txt_pos.x=128;
528    def_space_txt_pos.y=0;
529    def_mode_state_pos.x=35;
530    def_mode_state_pos.y=0;
531    def_mode_raw_pos.x=vid_get_bitmap_screen_width()-7*FONT_WIDTH-2;
532    def_mode_raw_pos.y=vid_get_bitmap_screen_height()-3*FONT_HEIGHT-2;
533    def_mode_video_pos.x=vid_get_bitmap_screen_width()-25*FONT_WIDTH-2;
534    def_mode_video_pos.y=vid_get_bitmap_screen_height()-6*FONT_HEIGHT-2;
535    def_mode_ev_pos.x=vid_get_bitmap_screen_width()-40*FONT_WIDTH-2;
536    def_mode_ev_pos.y=vid_get_bitmap_screen_height()-8*FONT_HEIGHT-2;
537    def_values_pos.x=vid_get_bitmap_screen_width()-9*FONT_WIDTH;
538    def_values_pos.y=30;
539    def_clock_pos.x=vid_get_bitmap_screen_width()-5*FONT_WIDTH-2;
540    def_clock_pos.y=0;
541    def_temp_pos.x=vid_get_bitmap_screen_width()-9*FONT_WIDTH-2;
542    def_temp_pos.y=1*FONT_HEIGHT;
543    def_ev_video_pos.x=18;
544    def_ev_video_pos.y=80;
545
546}
547
548//-------------------------------------------------------------------
549void conf_load_defaults() {
550    register int i;
551
552    for (i=0; i<CONF_NUM; ++i) {
553        switch (conf_info[i].type) {
554            case CONF_DEF_VALUE:
555                memcpy(conf_info[i].var, &(conf_info[i].i), conf_info[i].size);
556                break;
557            case CONF_DEF_PTR:
558                memcpy(conf_info[i].var, conf_info[i].ptr, conf_info[i].size);
559                break;
560        }
561        conf_info_func(conf_info[i].id);
562        //if (conf_info[i].func) {
563        //    conf_info[i].func();
564        //}
565    }
566}
567
568//-------------------------------------------------------------------
569
570// Structure for saved conf info (allows for changes to ConfInfo without affecting saved configurations
571typedef struct
572{
573    unsigned short id;
574    unsigned short size;
575} ConfInfoSave;
576
577void conf_save() {
578    static const long t=CONF_MAGICK_VALUE;
579    register int i;
580    int fd;
581    char *buf = umalloc(sizeof(t) + CONF_NUM*sizeof(ConfInfoSave) + sizeof(conf));
582    char *p=buf;
583
584    fd = open(CONF_FILE, O_WRONLY|O_CREAT|O_TRUNC, 0777);
585    if (fd>=0){
586        memcpy(p, &t, sizeof(t));
587        p+=sizeof(t);
588        for (i=0; i<CONF_NUM; ++i) {
589            ((ConfInfoSave*)p)->id   = conf_info[i].id;
590            ((ConfInfoSave*)p)->size = conf_info[i].size;
591            p += sizeof(ConfInfoSave);
592            memcpy(p, conf_info[i].var, conf_info[i].size);
593            p += conf_info[i].size;
594        }
595
596        write(fd, buf, p-buf);
597        close(fd);
598    }
599        ufree(buf);
600}
601
602//-------------------------------------------------------------------
603void conf_restore() {
604    int fd, rcnt, i;
605    unsigned short id, size;
606    char *buf;
607    int offs;
608    struct stat st;
609
610    conf_init_defaults();
611
612    conf_load_defaults();
613
614    if( stat(CONF_FILE,&st) != 0 || st.st_size < sizeof(int))
615        return;
616
617    if(!(buf=umalloc(st.st_size)))
618        return;
619
620    fd = open(CONF_FILE, O_RDONLY, 0777);
621    if( fd < 0 ) {
622        ufree(buf);
623        return;
624    }
625   
626    rcnt = read(fd,buf,st.st_size);
627    close(fd);
628    // read magick value
629    if (*(int *)buf!=CONF_MAGICK_VALUE || rcnt != st.st_size) {
630        ufree(buf);
631        return;
632    }
633    offs=sizeof(int);
634    while (1) {
635        if (offs + sizeof(short) > rcnt)
636            break;
637        id=*((short *)(buf + offs));
638        offs += sizeof(short);
639
640        if (offs + sizeof(short) > rcnt)
641            break;
642        size=*((short *)(buf + offs));
643        offs += sizeof(short);
644
645        for (i=0; i<CONF_NUM; ++i) {
646            if (conf_info[i].id==id && conf_info[i].size==size) {
647                if (offs + size <= rcnt) {
648                   memcpy(conf_info[i].var, buf+offs, size);
649                   conf_info_func(conf_info[i].id);
650                   //if (conf_info[i].func) {
651                   //    conf_info[i].func();
652                   //}
653                }
654                offs += size;
655                break;
656            }
657        }
658        if (i == CONF_NUM) { // unknown id, just skip data
659            offs += size;
660        }
661    }
662    ufree(buf);
663    // clear any "clear on restart" values
664    clear_values();
665}
666
667//-------------------------------------------------------------------
668// Common code extracted from raw.c (raw_savefile) and gui_osd.c (gui_osd_draw_raw_info)
669// returns 0 if RAW save is disabled due to mode settings, etc, return 1 if RAW save OK
670int is_raw_enabled()
671{
672    int m = mode_get() & MODE_SHOOTING_MASK;
673
674    // NOTE: the conf.save_raw_in variables are negative logic
675    //       1 = disable saving raw in this mode, 0 = allow saving raw
676    //       variables should be named conf.disable_save_raw_in_XXX
677
678    return !(   // Return false if any of these tests are true
679        ((movie_status > 1) && conf.save_raw_in_video) ||                                   // True is movie mode and save_raw_in_video is disabled
680#ifdef CAM_DISABLE_RAW_IN_LOW_LIGHT_MODE
681        (shooting_get_prop(PROPCASE_RESOLUTION)==7) ||                                      // True if shooting resolution is 'low light'
682#endif
683        (shooting_get_prop(PROPCASE_RESOLUTION)==5) ||                                      // True if shooting resolution is ??? (what is mode 5)
684        ((m==MODE_SPORTS) && conf.save_raw_in_sports) ||                                    // True if sports mode and save_raw_in_sports is disabled
685        ((m==MODE_AUTO) && conf.save_raw_in_auto) ||                                        // True if auto mode and save_raw_in_auto is disabled
686        (conf.edge_overlay_enable && conf.save_raw_in_edgeoverlay) ||                       // True if edge overlay on and save_raw_in_edgeoverlay is disabled
687        ((shooting_get_drive_mode()==1) && conf.save_raw_in_burst && !(m==MODE_SPORTS)) ||  // True if drive mode is continuous and save_raw_in_burst is disabled and not sports mode
688        ((shooting_get_drive_mode()>=2) && conf.save_raw_in_timer) ||                       // True if drive mode is timer and save_raw_in_timer is disabled
689        ((shooting_get_prop(PROPCASE_BRACKET_MODE)==1) && conf.save_raw_in_ev_bracketing)   // True if bracketing enabled and save_raw_in_ev_bracketing is disabled
690    );
691}
692
693//-------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.