1 /* Copyright (c) 2013-2014, 2016-2017, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 // System dependencies
30 #include <ctype.h>
31 #include <errno.h>
32 #include <unistd.h>
33 
34 // Camera dependencies
35 #include "mm_qcamera_main_menu.h"
36 #include "mm_qcamera_app.h"
37 #include "mm_qcamera_dbg.h"
38 
39 /*===========================================================================
40  * Macro
41  *===========================================================================*/
42 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
43 #define VIDEO_BUFFER_SIZE       (PREVIEW_WIDTH * PREVIEW_HEIGHT * 3/2)
44 #define THUMBNAIL_BUFFER_SIZE   (THUMBNAIL_WIDTH * THUMBNAIL_HEIGHT * 3/2)
45 #define SNAPSHOT_BUFFER_SIZE    (PICTURE_WIDTH * PICTURE_HEIGHT * 3/2)
46 //TODO:check this Macros with current app.
47 
48 /*===========================================================================
49  * Defines
50  *===========================================================================*/
51 //#define VIDEO_FRAMES_NUM      4
52 #define THUMBNAIL_FRAMES_NUM  1
53 #define SNAPSHOT_FRAMES_NUM   1
54 #define MAX_NUM_FORMAT        32
55 #define ZOOM_STEP             2
56 #define ZOOM_MIN_VALUE        0
57 #define EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR 12
58 #define EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR -12
59 #define EXPOSURE_COMPENSATION_DEFAULT_NUMERATOR 0
60 #define EXPOSURE_COMPENSATION_DENOMINATOR 6
61 
62 //TODO: find correct values of Contrast defines.
63 #define CAMERA_MIN_CONTRAST    0
64 #define CAMERA_DEF_CONTRAST    5
65 #define CAMERA_MAX_CONTRAST    10
66 #define CAMERA_CONTRAST_STEP   1
67 
68 //TODO: find correct values of Brightness defines.
69 #define CAMERA_MIN_BRIGHTNESS  0
70 #define CAMERA_DEF_BRIGHTNESS  3
71 #define CAMERA_MAX_BRIGHTNESS  6
72 #define CAMERA_BRIGHTNESS_STEP 1
73 
74 //TODO: find correct values of Saturation defines.
75 #define CAMERA_MIN_SATURATION  0
76 #define CAMERA_DEF_SATURATION  5
77 #define CAMERA_MAX_SATURATION  10
78 #define CAMERA_SATURATION_STEP 1
79 
80 #define CAMERA_MIN_SHARPNESS 0
81 #define CAMERA_MAX_SHARPNESS 10
82 #define CAMERA_DEF_SHARPNESS 5
83 #define CAMERA_SHARPNESS_STEP 1
84 
85 const CAMERA_MAIN_MENU_TBL_T camera_main_menu_tbl[] = {
86   {START_PREVIEW,              "Start preview"},
87   {STOP_PREVIEW,               "Stop preview/video"},
88   {SET_WHITE_BALANCE,          "Set white balance mode"},
89   {SET_TINTLESS_ENABLE,        "Set Tintless Enable"},
90   {TOGGLE_SHDR,                "Toggle sHDR Mode , Default is Off"},
91   {SET_EXP_METERING,           "Set exposure metering mode"},
92   {TOGGLE_IRLED,               "Toggle IR Mode, Default is Off"},
93   {TOGGLE_EZTUNE,              "Toggle EZtune. Default EZTune Off"},
94   {SET_ISO,                    "ISO changes."},
95   {BRIGHTNESS_GOTO_SUBMENU,    "Brightness changes."},
96   {CONTRAST_GOTO_SUBMENU,      "Contrast changes."},
97   {EV_GOTO_SUBMENU,            "EV changes."},
98   {SATURATION_GOTO_SUBMENU,    "Saturation changes."},
99   {SET_ZOOM,                   "Set Digital Zoom."},
100   {SET_SHARPNESS,              "Set Sharpness."},
101   {TAKE_JPEG_SNAPSHOT,         "Take a snapshot"},
102   {START_RECORDING,            "Start RECORDING"},
103   {STOP_RECORDING,             "Stop RECORDING"},
104   {BEST_SHOT,                  "Set best-shot mode"},
105   {LIVE_SHOT,                  "Take a live snapshot"},
106   {FLASH_MODES,                "Set Flash modes"},
107   {TOGGLE_ZSL,                 "Toggle ZSL On/Off"},
108   {TAKE_RAW_SNAPSHOT,          "Take RAW snapshot"},
109   {SWITCH_SNAP_RESOLUTION,     "Select Jpeg resolution"},
110   {TOGGLE_WNR,                 "Toggle Wavelet Denoise"},
111   {SPECIAL_EFFECTS,            "Set spceial snapshot effects"},
112   {SET_MN_WHITE_BALANCE,       "Set white balance manually"},
113   {ANTI_BANDING,               "Anit-banding/Auto Flicker Correction"},
114   {SET_FLIP_MODE,              "Set Flip Mode"},
115   {BURST_MODE_SNAPSHOT,        "Enables continuous image capture during snapshot operation"},
116   {CONCURRENT_NDR_NONHDR,      "Capture non-HDR images concurrent with HDR"},
117   {EXIT,                       "Exit"}
118 };
119 
120 CAMERA_SENSOR_MENU_TLB_T sensor_tbl[] = {
121         {"Primary Camera",      0},
122         {"Secondary Camera",    0},
123         {"Camera Sensor 3",     0},
124         {"Camera Sensor 4",     0}
125 };
126 
127 const CAMERA_BRIGHTNESS_TBL_T brightness_change_tbl[] = {
128   {INC_BRIGHTNESS, "Increase Brightness by one step."},
129   {DEC_BRIGHTNESS, "Decrease Brightness by one step."},
130 };
131 
132 const CAMERA_CONTRST_TBL_T contrast_change_tbl[] = {
133   {INC_CONTRAST, "Increase Contrast by one step."},
134   {DEC_CONTRAST, "Decrease Contrast by one step."},
135 };
136 
137 const CAMERA_EV_TBL_T camera_EV_tbl[] = {
138   {INCREASE_EV, "Increase EV by one step."},
139   {DECREASE_EV, "Decrease EV by one step."},
140 };
141 
142 const CAMERA_SATURATION_TBL_T camera_saturation_tbl[] = {
143   {INC_SATURATION, "Increase Satuation by one step."},
144   {DEC_SATURATION, "Decrease Satuation by one step."},
145 };
146 
147 const CAMERA_SHARPNESS_TBL_T camera_sharpness_tbl[] = {
148   {INC_SHARPNESS, "Increase Sharpness."},
149   {DEC_SHARPNESS, "Decrease Sharpness."},
150 };
151 
152 const MN_WHITE_BALANCE_TBL_T mn_white_balance_tbl[] = {
153   {   MANUAL_WB_CCT,        "Manual White Balance - CCT"},
154   {   MANUAL_WB_GAIN,       "Manual White Balance - RGB Gain"},
155 };
156 
157 const WHITE_BALANCE_TBL_T white_balance_tbl[] = {
158   {   WB_OFF,                "White Balance - OFF"},
159   {   WB_AUTO,               "White Balance - Auto"},
160   {   WB_INCANDESCENT,       "White Balance - Incandescent"},
161   {   WB_FLUORESCENT,        "White Balance - Fluorescent"},
162   {   WB_WARM_FLUORESCENT,   "White Balance - Warm Fluorescent"},
163   {   WB_DAYLIGHT,           "White Balance - Daylight"},
164   {   WB_CLOUDY_DAYLIGHT,    "White Balance - Cloudy Daylight"},
165   {   WB_TWILIGHT,           "White Balance - Twilight"},
166   {   WB_SHADE,              "White Balance - Shade"},
167   {   WB_MANUAL,             "White Balance - Manual"},
168 };
169 
170 const GET_CTRL_TBL_T get_ctrl_tbl[] = {
171   {     WHITE_BALANCE_STATE,            "Get white balance state (auto/off)"},
172   {     WHITE_BALANCE_TEMPERATURE,      "Get white balance temperature"},
173   {     BRIGHTNESS_CTRL,                "Get brightness value"},
174   {     EV,                             "Get exposure value"},
175   {     CONTRAST_CTRL,                  "Get contrast value"},
176   {     SATURATION_CTRL,                "Get saturation value"},
177   {     SHARPNESS_CTRL,                 "Get sharpness value"},
178 };
179 
180 const EXP_METERING_TBL_T exp_metering_tbl[] = {
181   {   AUTO_EXP_FRAME_AVG,          "Exposure Metering - Frame Average"},
182   {   AUTO_EXP_CENTER_WEIGHTED,    "Exposure Metering - Center Weighted"},
183   {   AUTO_EXP_SPOT_METERING,      "Exposure Metering - Spot Metering"},
184   {   AUTO_EXP_SMART_METERING,     "Exposure Metering - Smart Metering"},
185   {   AUTO_EXP_USER_METERING,      "Exposure Metering - User Metering"},
186   {   AUTO_EXP_SPOT_METERING_ADV,  "Exposure Metering - Spot Metering Adv"},
187   {   AUTO_EXP_CENTER_WEIGHTED_ADV,"Exposure Metering - Center Weighted Adv"},
188 };
189 
190 const ISO_TBL_T iso_tbl[] = {
191   {   ISO_AUTO,   "ISO: Auto"},
192   {   ISO_DEBLUR, "ISO: Deblur"},
193   {   ISO_100,    "ISO: 100"},
194   {   ISO_200,    "ISO: 200"},
195   {   ISO_400,    "ISO: 400"},
196   {   ISO_800,    "ISO: 800"},
197   {   ISO_1600,   "ISO: 1600"},
198 };
199 
200 const ZOOM_TBL_T zoom_tbl[] = {
201   {   ZOOM_IN,  "Zoom In one step"},
202   {   ZOOM_OUT, "Zoom Out one step"},
203 };
204 
205 const BESTSHOT_MODE_TBT_T bestshot_mode_tbl[] = {
206   {BESTSHOT_AUTO,           "Bestshot Mode: Auto"},
207   {BESTSHOT_ACTION,         "Bestshot Mode: Action"},
208   {BESTSHOT_PORTRAIT,       "Bestshot Mode: Portrait"},
209   {BESTSHOT_LANDSCAPE,      "Bestshot Mode: Landscape"},
210   {BESTSHOT_NIGHT,          "Bestshot Mode: Night"},
211   {BESTSHOT_NIGHT_PORTRAIT, "Bestshot Mode: Night Portrait"},
212   {BESTSHOT_THEATRE,        "Bestshot Mode: Theatre"},
213   {BESTSHOT_BEACH,          "Bestshot Mode: Beach"},
214   {BESTSHOT_SNOW,           "Bestshot Mode: Snow"},
215   {BESTSHOT_SUNSET,         "Bestshot Mode: Sunset"},
216   {BESTSHOT_ANTISHAKE,      "Bestshot Mode: Antishake"},
217   {BESTSHOT_FIREWORKS,      "Bestshot Mode: Fireworks"},
218   {BESTSHOT_SPORTS,         "Bestshot Mode: Sports"},
219   {BESTSHOT_PARTY,          "Bestshot Mode: Party"},
220   {BESTSHOT_CANDLELIGHT,    "Bestshot Mode: Candlelight"},
221   {BESTSHOT_ASD,            "Bestshot Mode: ASD"},
222   {BESTSHOT_BACKLIGHT,      "Bestshot Mode: Backlight"},
223   {BESTSHOT_FLOWERS,        "Bestshot Mode: Flowers"},
224   {BESTSHOT_AR,             "Bestshot Mode: Augmented Reality"},
225   {BESTSHOT_HDR,            "Bestshot Mode: HDR"},
226 };
227 
228 const SPECIAL_EFFECT_MODE_TBT_T camEffect_mode_tbl[] = {
229   {SPL_EFFECT_OFF,          "Special Effect Mode: Off"},
230   {SPL_EFFECT_MONO,         "Special Effect Mode: Mono"},
231   {SPL_EFFECT_NEGATIVE,     "Special Effect Mode: Negative"},
232   {SPL_EFFECT_SOLARIZE,     "Special Effect Mode: Solarize"},
233   {SPL_EFFECT_SEPIA,        "Special Effect Mode: Sepia"},
234   {SPL_EFFECT_POSTERIZE,    "Special Effect Mode: Posterize"},
235   {SPL_EFFECT_WHITEBOARD,   "Special Effect Mode: Whiteboard"},
236   {SPL_EFFECT_BLACKBOARD,   "Special Effect Mode: Blackboard"},
237   {SPL_EFFECT_AQUA,         "Special Effect Mode: Aqua"},
238   {SPL_EFFECT_EMBOSS,       "Special Effect Mode: Emboss"},
239   {SPL_EFFECT_SKETCH,       "Special Effect Mode: Sketch"},
240   {SPL_EFFECT_NEON,         "Special Effect Mode: Neon"},
241   {SPL_EFFECT_BEAUTY,       "Special Effect Mode: Beuty"},
242 };
243 
244 const ANTI_BANDING_TBT_T antiBanding_tbl[] = {
245   {ANTIBANDING_OFF,        "Anti Banding: Off"},
246   {ANTIBANDING_60HZ,       "Anti Banding: 60HZ"},
247   {ANTIBANDING_50HZ,       "Anti Banding: 50HZ"},
248   {ANTIBANDING_AUTO,       "Anti Banding: Auto"},
249 };
250 
251 const FLIP_MODES_TBT_T flipModes_tbl[] = {
252   {MODE_NO_FLIP,        "Flip Mode: Off"},
253   {MODE_FLIP_H,         "Flip Mode: H"},
254   {MODE_FLIP_V,          "Flip Mode: V"},
255   {MODE_FLIP_V_H,       "Flip Mode: V H"},
256 };
257 
258 const FLASH_MODE_TBL_T flashmodes_tbl[] = {
259   {   FLASH_MODE_OFF,   "Flash Mode Off"},
260   {   FLASH_MODE_AUTO,  "Flash Mode Auto"},
261   {   FLASH_MODE_ON,    "Flash Mode On"},
262   {   FLASH_MODE_TORCH, "Flash Mode Torch"},
263 };
264 
265 DIMENSION_TBL_T dimension_tbl[] = {
266 {VGA_WIDTH,      VGA_HEIGHT,      "VGA",   "Size: VGA <640x480>"   , 0},
267 {MP1_WIDTH,      MP1_HEIGHT,      "1MP",   "Size: 1MP <1280x960>"  , 0},
268 {MP5_WIDTH,      MP5_HEIGHT,      "5MP",   "Size: 5MP <2592x1944>",  0},
269 {MP8_WIDTH,      MP8_HEIGHT,      "8MP",   "Size: 8MP <3264x2448>",  0},
270 {MP12_WIDTH,     MP12_HEIGHT,     "12MP",  "Size: 12MP <4000x3000>", 0},
271 };
272 
273 /*===========================================================================
274  * Forward declarations
275  *===========================================================================*/
276 //static void system_dimension_set(mm_camera_test_obj_t *test_obj);
277 /*===========================================================================
278  * Static global variables
279  *===========================================================================*/
280 USER_INPUT_DISPLAY_T input_display;
281 int preview_video_resolution_flag = 0;
282 
283 //TODO: default values.
284 #if 1
285 int brightness = CAMERA_DEF_BRIGHTNESS;
286 int contrast = CAMERA_DEF_CONTRAST;
287 int saturation = CAMERA_DEF_SATURATION;
288 int sharpness = CAMERA_DEF_SHARPNESS;
289 int ev_numerator = 0;
290 
291 #else
292 int brightness = 0;
293 int contrast = 0;
294 int saturation = 0;
295 int sharpness = 0;
296 #endif
297 //TODO: find new method to calculate ev.
298 //int32_t ev_numerator = EXPOSURE_COMPENSATION_DEFAULT_NUMERATOR;
299 
300 //TODO:
301 //fps_mode_t fps_mode = FPS_MODE_FIXED;
302 int zoom_level;
303 int zoom_max_value;
304 int cam_id;
305 int is_rec = 0;
306 
307 
308 static int submain();
309 
310 /*===========================================================================
311  * FUNCTION    - keypress_to_event -
312  *
313  * DESCRIPTION:
314  *==========================================================================*/
keypress_to_event(char keypress)315 int keypress_to_event(char keypress)
316 {
317   int out_buf = INVALID_KEY_PRESS;
318   if ((keypress >= 'A' && keypress <= 'Z') ||
319     (keypress >= 'a' && keypress <= 'z')) {
320     out_buf = tolower(keypress);
321     out_buf = out_buf - 'a';
322   } else if (keypress >= '0' && keypress <= '9') {
323     out_buf = (keypress - '0')+ ('z' - 'a');
324   }
325   return out_buf;
326 }
327 
next_menu(menu_id_change_t current_menu_id,char keypress,camera_action_t * action_id_ptr,int * action_param)328 int next_menu(menu_id_change_t current_menu_id, char keypress, camera_action_t * action_id_ptr, int * action_param)
329 {
330   int output_to_event;
331   menu_id_change_t next_menu_id = MENU_ID_INVALID;
332   * action_id_ptr = ACTION_NO_ACTION;
333 
334   output_to_event = keypress_to_event(keypress);
335   LOGD("output_to_event=%d\n",output_to_event);
336   LOGD("current_menu_id=%d\n",current_menu_id);
337 
338   switch(current_menu_id) {
339     case MENU_ID_MAIN:
340       switch(output_to_event) {
341         case START_PREVIEW:
342           * action_id_ptr = ACTION_START_PREVIEW;
343           LOGD("START_PREVIEW\n");
344           break;
345         case STOP_PREVIEW:
346           * action_id_ptr = ACTION_STOP_PREVIEW;
347           LOGD("STOP_PREVIEW\n");
348           break;
349 
350         case SET_WHITE_BALANCE:
351           next_menu_id = MENU_ID_WHITEBALANCECHANGE;
352           LOGD("next_menu_id = MENU_ID_WHITEBALANCECHANGE = %d\n", next_menu_id);
353           break;
354         case SET_MN_WHITE_BALANCE:
355           next_menu_id = MENU_ID_WHITEBALANCE_MANUAL;
356           LOGD("next_menu_id = MENU_ID_WHITEBALANCECHANGE = %d\n", next_menu_id);
357           break;
358 
359         case SET_TINTLESS_ENABLE:
360           * action_id_ptr = ACTION_SET_TINTLESS_ENABLE;
361           next_menu_id = MENU_ID_MAIN;
362           LOGD("next_menu_id = MENU_ID_TINTLESSENABLE = %d\n", next_menu_id);
363           break;
364 
365         case TOGGLE_SHDR:
366           * action_id_ptr = ACTION_TOGGLE_SHDR;
367           LOGD("next_menu_id = MENU_ID_TOGGLE SHDR = %d\n", next_menu_id);
368           break;
369 
370         case SET_EXP_METERING:
371           next_menu_id = MENU_ID_EXPMETERINGCHANGE;
372           LOGD("next_menu_id = MENU_ID_EXPMETERINGCHANGE = %d\n", next_menu_id);
373           break;
374         case BRIGHTNESS_GOTO_SUBMENU:
375           next_menu_id = MENU_ID_BRIGHTNESSCHANGE;
376           LOGD("next_menu_id = MENU_ID_BRIGHTNESSCHANGE = %d\n", next_menu_id);
377           break;
378 
379         case CONTRAST_GOTO_SUBMENU:
380           next_menu_id = MENU_ID_CONTRASTCHANGE;
381           break;
382 
383         case EV_GOTO_SUBMENU:
384           next_menu_id = MENU_ID_EVCHANGE;
385           break;
386 
387         case SATURATION_GOTO_SUBMENU:
388           next_menu_id = MENU_ID_SATURATIONCHANGE;
389           break;
390 
391         case TOGGLE_EZTUNE:
392           * action_id_ptr = ACTION_TOGGLE_EZTUNE;
393           LOGD("next_menu_id = MENU_ID_TOGGLE EZTUNE = %d\n", next_menu_id);
394           break;
395         case TOGGLE_IRLED:
396           * action_id_ptr = ACTION_TOGGLE_IR_MODE;
397           LOGD("next_menu_id = MENU_ID_TOGGLE IRLED = %d\n", next_menu_id);
398           break;
399 
400         case SET_ISO:
401           next_menu_id = MENU_ID_ISOCHANGE;
402           LOGD("next_menu_id = MENU_ID_ISOCHANGE = %d\n", next_menu_id);
403           break;
404 
405         case SET_ZOOM:
406           next_menu_id = MENU_ID_ZOOMCHANGE;
407           LOGD("next_menu_id = MENU_ID_ZOOMCHANGE = %d\n", next_menu_id);
408           break;
409 
410         case BEST_SHOT:
411           next_menu_id = MENU_ID_BESTSHOT;
412           LOGD("next_menu_id = MENU_ID_BESTSHOT = %d\n", next_menu_id);
413           break;
414 
415         case LIVE_SHOT:
416           * action_id_ptr = ACTION_TAKE_LIVE_SNAPSHOT;
417           LOGD("\nTaking Live snapshot\n");
418           break;
419 
420         case FLASH_MODES:
421           next_menu_id = MENU_ID_FLASHMODE;
422           LOGD("next_menu_id = MENU_ID_FLASHMODE = %d\n", next_menu_id);
423           break;
424 
425         case SET_SHARPNESS:
426           next_menu_id = MENU_ID_SHARPNESSCHANGE;
427           LOGD("next_menu_id = MENU_ID_SHARPNESSCHANGE = %d\n", next_menu_id);
428           break;
429 
430         case SWITCH_SNAP_RESOLUTION:
431           next_menu_id = MENU_ID_SWITCH_RES;
432           LOGD("next_menu_id = MENU_ID_SWITCH_RES = %d\n", next_menu_id);
433           break;
434 
435         case TAKE_JPEG_SNAPSHOT:
436           * action_id_ptr = ACTION_TAKE_JPEG_SNAPSHOT;
437           printf("\n Taking JPEG snapshot\n");
438           break;
439 
440         case START_RECORDING:
441           * action_id_ptr = ACTION_START_RECORDING;
442           LOGD("Start recording\n");
443           break;
444         case STOP_RECORDING:
445           * action_id_ptr = ACTION_STOP_RECORDING;
446           LOGD("Stop recording\n");
447           break;
448         case TOGGLE_ZSL:
449           * action_id_ptr = ACTION_TOGGLE_ZSL;
450           LOGD("Toggle ZSL\n");
451           break;
452         case TAKE_RAW_SNAPSHOT:
453           * action_id_ptr = ACTION_TAKE_RAW_SNAPSHOT;
454           next_menu_id = MENU_ID_MAIN;
455           LOGD("Capture RAW\n");
456           break;
457         case TOGGLE_WNR:
458           * action_id_ptr = ACTION_TOGGLE_WNR;
459           next_menu_id = MENU_ID_MAIN;
460           LOGD("Toggle WNR");
461           break;
462         case SPECIAL_EFFECTS:
463           next_menu_id = MENU_ID_SPECIAL_EFFECTS;
464           LOGD("next menu ID is set to MENU_ID_SPECIAL_EFFECTS\n");
465           break;
466         case ANTI_BANDING:
467           next_menu_id = MENU_ID_ANTI_BANDING;
468           LOGD("next menu ID is set to MENU_ID_ANTI_BANDING\n");
469           break;
470          case SET_FLIP_MODE:
471           next_menu_id = MENU_ID_FLIP_MODE;
472           LOGD("next menu ID is set to MENU_ID_FLIP_MODE\n");
473           break;
474         case BURST_MODE_SNAPSHOT:
475           * action_id_ptr = ACTION_BURST_MODE_SNAPSHOT;
476           next_menu_id = MENU_ID_MAIN;
477           break;
478         case CONCURRENT_NDR_NONHDR:
479           * action_id_ptr = ACTION_CONCURRENT_NDR_NONHDR;
480           next_menu_id = MENU_ID_MAIN;
481           break;
482         case EXIT:
483           * action_id_ptr = ACTION_EXIT;
484           LOGD("Exit \n");
485           break;
486         default:
487           next_menu_id = MENU_ID_MAIN;
488           LOGD("next_menu_id = MENU_ID_MAIN = %d\n", next_menu_id);
489           break;
490       }
491       break;
492 
493     case MENU_ID_SWITCH_RES:
494         printf("MENU_ID_SWITCH_RES\n");
495         *action_id_ptr = ACTION_SWITCH_RESOLUTION;
496         *action_param = output_to_event;
497         int available_sizes = sizeof(dimension_tbl)/sizeof(dimension_tbl[0]);
498         if ( ( *action_param >= 0 ) &&
499              ( *action_param < available_sizes ) &&
500              ( dimension_tbl[*action_param].supported )) {
501             next_menu_id = MENU_ID_MAIN;
502         }
503         else {
504           next_menu_id = current_menu_id;
505         }
506         break;
507 
508     case MENU_ID_SENSORS:
509         next_menu_id = MENU_ID_MAIN;
510         *action_id_ptr = ACTION_SWITCH_CAMERA;
511         *action_param = output_to_event;
512         break;
513 
514     case MENU_ID_WHITEBALANCE_MANUAL:
515       printf("MENU_ID_WHITEBALANCE_MANUAL\n");
516       if (output_to_event >= MANUAL_WB_MAX) {
517         next_menu_id = current_menu_id;
518         * action_id_ptr = ACTION_NO_ACTION;
519       }else {
520         next_menu_id = MENU_ID_MAIN;
521         * action_id_ptr = ACTION_SET_MN_WHITE_BALANCE;
522         * action_param = output_to_event;
523       }
524       break;
525     case MENU_ID_WHITEBALANCECHANGE:
526       printf("MENU_ID_WHITEBALANCECHANGE\n");
527       if (output_to_event >= WB_MAX) {
528         next_menu_id = current_menu_id;
529         * action_id_ptr = ACTION_NO_ACTION;
530       }else {
531         next_menu_id = MENU_ID_MAIN;
532         * action_id_ptr = ACTION_SET_WHITE_BALANCE;
533         * action_param = output_to_event;
534       }
535       break;
536 
537     case MENU_ID_EXPMETERINGCHANGE:
538       printf("MENU_ID_EXPMETERINGCHANGE\n");
539       if (output_to_event >= AUTO_EXP_MAX) {
540         next_menu_id = current_menu_id;
541         * action_id_ptr = ACTION_NO_ACTION;
542       } else {
543         next_menu_id = MENU_ID_MAIN;
544         * action_id_ptr = ACTION_SET_EXP_METERING;
545         * action_param = output_to_event;
546       }
547       break;
548 
549     case MENU_ID_BRIGHTNESSCHANGE:
550       switch (output_to_event) {
551         case INC_BRIGHTNESS:
552           * action_id_ptr = ACTION_BRIGHTNESS_INCREASE;
553           next_menu_id = MENU_ID_MAIN;
554           break;
555 
556         case DEC_BRIGHTNESS:
557           * action_id_ptr = ACTION_BRIGHTNESS_DECREASE;
558           next_menu_id = MENU_ID_MAIN;
559           break;
560 
561         default:
562           next_menu_id = MENU_ID_BRIGHTNESSCHANGE;
563           break;
564       }
565       break;
566 
567     case MENU_ID_CONTRASTCHANGE:
568       switch (output_to_event) {
569         case INC_CONTRAST:
570           * action_id_ptr = ACTION_CONTRAST_INCREASE;
571           next_menu_id = MENU_ID_MAIN;
572           break;
573 
574         case DEC_CONTRAST:
575           * action_id_ptr = ACTION_CONTRAST_DECREASE;
576           next_menu_id = MENU_ID_MAIN;
577           break;
578 
579         default:
580           next_menu_id = MENU_ID_CONTRASTCHANGE;
581           break;
582       }
583       break;
584 
585     case MENU_ID_EVCHANGE:
586       switch (output_to_event) {
587         case INCREASE_EV:
588           * action_id_ptr = ACTION_EV_INCREASE;
589           next_menu_id = MENU_ID_MAIN;
590           break;
591 
592         case DECREASE_EV:
593           * action_id_ptr = ACTION_EV_DECREASE;
594           next_menu_id = MENU_ID_MAIN;
595           break;
596 
597         default:
598           next_menu_id = MENU_ID_EVCHANGE;
599           break;
600       }
601       break;
602 
603     case MENU_ID_SATURATIONCHANGE:
604       switch (output_to_event) {
605         case INC_SATURATION:
606           * action_id_ptr = ACTION_SATURATION_INCREASE;
607           next_menu_id = MENU_ID_MAIN;
608           break;
609 
610         case DEC_SATURATION:
611           * action_id_ptr = ACTION_SATURATION_DECREASE;
612           next_menu_id = MENU_ID_MAIN;
613           break;
614 
615         default:
616           next_menu_id = MENU_ID_EVCHANGE;
617           break;
618       }
619       break;
620 
621     case MENU_ID_ISOCHANGE:
622       printf("MENU_ID_ISOCHANGE\n");
623       if (output_to_event >= ISO_MAX) {
624         next_menu_id = current_menu_id;
625         * action_id_ptr = ACTION_NO_ACTION;
626       } else {
627         next_menu_id = MENU_ID_MAIN;
628         * action_id_ptr = ACTION_SET_ISO;
629         * action_param = output_to_event;
630       }
631       break;
632 
633     case MENU_ID_ZOOMCHANGE:
634       switch(output_to_event){
635         case ZOOM_IN:
636         case ZOOM_OUT:
637             next_menu_id = MENU_ID_MAIN;
638             * action_id_ptr = ACTION_SET_ZOOM;
639             * action_param = output_to_event;
640             break;
641        default:
642             next_menu_id = current_menu_id;
643             * action_id_ptr = ACTION_NO_ACTION;
644       }
645       break;
646 
647     case MENU_ID_SHARPNESSCHANGE:
648       switch (output_to_event) {
649         case INC_SHARPNESS:
650           * action_id_ptr = ACTION_SHARPNESS_INCREASE;
651           next_menu_id = MENU_ID_MAIN;
652           break;
653         case DEC_SHARPNESS:
654           * action_id_ptr = ACTION_SHARPNESS_DECREASE;
655           next_menu_id = MENU_ID_MAIN;
656           break;
657         default:
658           next_menu_id = MENU_ID_SHARPNESSCHANGE;
659           break;
660       }
661       break;
662 
663     case MENU_ID_BESTSHOT:
664       if (output_to_event >= BESTSHOT_MAX) {
665         next_menu_id = current_menu_id;
666         * action_id_ptr = ACTION_NO_ACTION;
667       } else {
668         next_menu_id = MENU_ID_MAIN;
669         * action_id_ptr = ACTION_SET_BESTSHOT_MODE;
670         * action_param = output_to_event;
671       }
672       break;
673 
674     case MENU_ID_FLASHMODE:
675       if (output_to_event >= FLASH_MODE_MAX) {
676         next_menu_id = current_menu_id;
677         * action_id_ptr = ACTION_NO_ACTION;
678       } else {
679         next_menu_id = MENU_ID_MAIN;
680         * action_id_ptr = ACTION_SET_FLASH_MODE;
681         * action_param = output_to_event;
682       }
683       break;
684 
685     case MENU_ID_SPECIAL_EFFECTS:
686       if (output_to_event >= SPL_EFFECT_MAX) {
687         * action_id_ptr = ACTION_NO_ACTION;
688         next_menu_id = current_menu_id;
689       } else {
690         * action_id_ptr = ACTION_SPECIAL_EFFECTS;
691         next_menu_id = MENU_ID_MAIN;
692         * action_param = output_to_event;
693       }
694       break;
695 
696     case MENU_ID_ANTI_BANDING:
697       if (output_to_event >= ANTIBANDING_MAX) {
698         * action_id_ptr = ACTION_NO_ACTION;
699         next_menu_id = current_menu_id;
700       } else {
701         * action_id_ptr = ACTION_ANTI_BANDING;
702         next_menu_id = MENU_ID_MAIN;
703         * action_param = output_to_event;
704       }
705       break;
706     case MENU_ID_FLIP_MODE:
707       if (output_to_event >= MODE_FLIP_MAX) {
708         * action_id_ptr = ACTION_NO_ACTION;
709         next_menu_id = current_menu_id;
710       } else {
711         * action_id_ptr = ACTION_FLIP_MODE;
712         next_menu_id = MENU_ID_MAIN;
713         * action_param = output_to_event;
714       }
715       break;
716    default:
717       LOGD("menu id is wrong: %d\n", current_menu_id);
718       break;
719   }
720 
721   return next_menu_id;
722 }
723 
724 /*===========================================================================
725  * FUNCTION    - print_menu_preview_video -
726  *
727  * DESCRIPTION:
728  * ===========================================================================*/
print_menu_preview_video(void)729 static void print_menu_preview_video(void) {
730   unsigned int i;
731   if (!is_rec) {
732     printf("\n");
733     printf("===========================================\n");
734     printf("      Camera is in preview/video mode now        \n");
735     printf("===========================================\n\n");
736   } else {
737     printf("\n");
738     printf("===========================================\n");
739     printf("      Camera is in RECORDING mode now       \n");
740     printf("        Press 'Q' To Stop Recording          \n");
741     printf("        Press 'S' To Take Live Snapshot       \n");
742     printf("===========================================\n\n");
743   }
744   char menuNum = 'A';
745   for (i = 0; i < sizeof(camera_main_menu_tbl)/sizeof(camera_main_menu_tbl[0]); i++) {
746     if (i == BASE_OFFSET) {
747       menuNum = '1';
748     }
749 
750     printf("%c.  %s\n", menuNum, camera_main_menu_tbl[i].menu_name);
751     menuNum++;
752   }
753 
754   printf("\nPlease enter your choice: ");
755 
756   return;
757 }
758 
camera_preview_video_mn_wb_tbl(void)759 static void camera_preview_video_mn_wb_tbl(void) {
760   unsigned int i;
761   printf("\n");
762   printf("==========================================================\n");
763   printf("      Camera is in manual white balance change mode       \n");
764   printf("==========================================================\n\n");
765 
766   char submenuNum = 'A';
767   for (i = 0 ; i < sizeof(mn_white_balance_tbl) /
768                    sizeof(mn_white_balance_tbl[0]); i++) {
769         printf("%c.  %s\n", submenuNum, mn_white_balance_tbl[i].wb_name);
770         submenuNum++;
771   }
772   printf("\nPlease enter your choice for White Balance modes: ");
773   return;
774 }
camera_preview_video_wb_change_tbl(void)775 static void camera_preview_video_wb_change_tbl(void) {
776   unsigned int i;
777   printf("\n");
778   printf("==========================================================\n");
779   printf("      Camera is in white balance change mode       \n");
780   printf("==========================================================\n\n");
781 
782   char submenuNum = 'A';
783   for (i = 0 ; i < sizeof(white_balance_tbl) /
784                    sizeof(white_balance_tbl[0]); i++) {
785         printf("%c.  %s\n", submenuNum, white_balance_tbl[i].wb_name);
786         submenuNum++;
787   }
788   printf("\nPlease enter your choice for White Balance modes: ");
789   return;
790 }
791 
camera_preview_video_get_ctrl_value_tbl(void)792 static void camera_preview_video_get_ctrl_value_tbl(void) {
793   unsigned int i;
794   printf("\n");
795   printf("==========================================================\n");
796   printf("      Camera is in get control value mode       \n");
797   printf("==========================================================\n\n");
798 
799   char submenuNum = 'A';
800   for (i = 0 ; i < sizeof(get_ctrl_tbl) /
801                    sizeof(get_ctrl_tbl[0]); i++) {
802         printf("%c.  %s\n", submenuNum, get_ctrl_tbl[i].get_ctrl_name);
803         submenuNum++;
804   }
805   printf("\nPlease enter your choice for control value you want to get: ");
806   return;
807 }
808 
camera_preview_video_exp_metering_change_tbl(void)809 static void camera_preview_video_exp_metering_change_tbl(void) {
810   unsigned int i;
811   printf("\n");
812   printf("==========================================================\n");
813   printf("      Camera is in exposure metering change mode       \n");
814   printf("==========================================================\n\n");
815 
816   char submenuNum = 'A';
817   for (i = 0 ; i < sizeof(exp_metering_tbl) /
818                    sizeof(exp_metering_tbl[0]); i++) {
819         printf("%c.  %s\n", submenuNum, exp_metering_tbl[i].exp_metering_name);
820         submenuNum++;
821   }
822   printf("\nPlease enter your choice for exposure metering modes: ");
823   return;
824 }
825 
camera_contrast_change_tbl(void)826 static void camera_contrast_change_tbl(void) {
827     unsigned int i;
828 
829     printf("\n");
830     printf("==========================================================\n");
831     printf("      Camera is in change contrast resolution mode       \n");
832     printf("==========================================================\n\n");
833 
834     char contrastmenuNum = 'A';
835     for (i = 0; i < sizeof(contrast_change_tbl) /
836                     sizeof(contrast_change_tbl[0]); i++) {
837         printf("%c.  %s\n", contrastmenuNum,
838                             contrast_change_tbl[i].contrast_name);
839         contrastmenuNum++;
840     }
841 
842     printf("\nPlease enter your choice for contrast Change: ");
843     return;
844 }
845 
camera_EV_change_tbl(void)846 static void camera_EV_change_tbl(void) {
847   unsigned int i;
848 
849   printf("\n");
850   printf("===========================================\n");
851   printf("      Camera is in EV change mode now       \n");
852   printf("===========================================\n\n");
853 
854   char submenuNum = 'A';
855   for (i = 0; i < sizeof(camera_EV_tbl)/sizeof(camera_EV_tbl[0]); i++) {
856     printf("%c.  %s\n", submenuNum, camera_EV_tbl[i].EV_name);
857     submenuNum++;
858   }
859 
860   printf("\nPlease enter your choice for EV changes: ");
861   return;
862 }
863 
camera_resolution_change_tbl(void)864 static void camera_resolution_change_tbl(void) {
865     unsigned int i;
866 
867     printf("\n");
868     printf("==========================================================\n");
869     printf("      Camera is in snapshot resolution mode               \n");
870     printf("==========================================================\n\n");
871 
872     char submenuNum = 'A';
873     for (i = 0; i < sizeof(dimension_tbl) /
874       sizeof(dimension_tbl[0]); i++) {
875         if ( dimension_tbl[i].supported ) {
876             printf("%c.  %s\n", submenuNum,
877                     dimension_tbl[i].str_name);
878             submenuNum++;
879         }
880     }
881 
882     printf("\nPlease enter your choice for Resolution: ");
883     return;
884 }
885 
camera_preview_video_zoom_change_tbl(void)886 static void camera_preview_video_zoom_change_tbl(void) {
887     unsigned int i;
888     zoom_max_value = MAX_ZOOMS_CNT;
889 
890     char submenuNum = 'A';
891     for (i = 0 ; i < sizeof(zoom_tbl) /
892                    sizeof(zoom_tbl[0]); i++) {
893         printf("%c.  %s\n", submenuNum, zoom_tbl[i].zoom_direction_name);
894         submenuNum++;
895     }
896     printf("\nPlease enter your choice for zoom change direction: ");
897     return;
898 }
899 
camera_brightness_change_tbl(void)900 static void camera_brightness_change_tbl(void) {
901     unsigned int i;
902 
903     printf("\n");
904     printf("==========================================================\n");
905     printf("      Camera is in change brightness mode       \n");
906     printf("==========================================================\n\n");
907 
908     char brightnessmenuNum = 'A';
909     for (i = 0; i < sizeof(brightness_change_tbl) /
910                     sizeof(brightness_change_tbl[0]); i++) {
911         printf("%c.  %s\n", brightnessmenuNum,
912                             brightness_change_tbl[i].brightness_name);
913         brightnessmenuNum++;
914     }
915 
916     printf("\nPlease enter your choice for Brightness Change: ");
917     return;
918 }
919 
camera_saturation_change_tbl(void)920 static void camera_saturation_change_tbl(void) {
921     unsigned int i;
922 
923     printf("\n");
924     printf("==========================================================\n");
925     printf("      Camera is in change saturation mode       \n");
926     printf("==========================================================\n\n");
927 
928     char saturationmenuNum = 'A';
929     for (i = 0; i < sizeof(camera_saturation_tbl) /
930                     sizeof(camera_saturation_tbl[0]); i++) {
931         printf("%c.  %s\n", saturationmenuNum,
932                             camera_saturation_tbl[i].saturation_name);
933         saturationmenuNum++;
934     }
935 
936     printf("\nPlease enter your choice for Saturation Change: ");
937     return;
938 }
939 
camera_preview_video_iso_change_tbl(void)940 static void camera_preview_video_iso_change_tbl(void) {
941   unsigned int i;
942   printf("\n");
943   printf("==========================================================\n");
944   printf("      Camera is in ISO change mode       \n");
945   printf("==========================================================\n\n");
946 
947   char submenuNum = 'A';
948   for (i = 0 ; i < sizeof(iso_tbl) /
949                    sizeof(iso_tbl[0]); i++) {
950         printf("%c.  %s\n", submenuNum, iso_tbl[i].iso_modes_name);
951         submenuNum++;
952   }
953   printf("\nPlease enter your choice for iso modes: ");
954   return;
955 }
956 
camera_preview_video_sharpness_change_tbl(void)957 static void camera_preview_video_sharpness_change_tbl(void) {
958   unsigned int i;
959   printf("\n");
960   printf("==========================================================\n");
961   printf("      Camera is in sharpness change mode       \n");
962   printf("==========================================================\n\n");
963 
964   char submenuNum = 'A';
965   for (i = 0 ; i < sizeof(camera_sharpness_tbl) /
966                    sizeof(camera_sharpness_tbl[0]); i++) {
967         printf("%c.  %s\n", submenuNum, camera_sharpness_tbl[i].sharpness_name);
968         submenuNum++;
969   }
970   printf("\nPlease enter your choice for sharpness modes: ");
971   return;
972 }
973 
camera_set_bestshot_tbl(void)974 static void camera_set_bestshot_tbl(void)
975 {
976   unsigned int i;
977 
978   printf("\n");
979   printf("===========================================\n");
980   printf("      Camera is in set besthot mode now       \n");
981   printf("===========================================\n\n");
982 
983 
984   char bsmenuNum = 'A';
985   for (i = 0; i < sizeof(bestshot_mode_tbl)/sizeof(bestshot_mode_tbl[0]); i++) {
986     printf("%c.  %s\n", bsmenuNum,
987       bestshot_mode_tbl[i].name);
988     bsmenuNum++;
989   }
990 
991   printf("\nPlease enter your choice of Bestshot Mode: ");
992   return;
993 }
994 
camera_set_flashmode_tbl(void)995 static void camera_set_flashmode_tbl(void)
996 {
997   unsigned int i;
998 
999   printf("\n");
1000   printf("===========================================\n");
1001   printf("      Camera is in set flash mode now       \n");
1002   printf("===========================================\n\n");
1003 
1004 
1005   char bsmenuNum = 'A';
1006   for (i = 0; i < sizeof(flashmodes_tbl)/sizeof(flashmodes_tbl[0]); i++) {
1007     printf("%c.  %s\n", bsmenuNum,
1008       flashmodes_tbl[i].name);
1009     bsmenuNum++;
1010   }
1011 
1012   printf("\nPlease enter your choice of Bestshot Mode: ");
1013   return;
1014 }
1015 
camera_sensors_tbl(void)1016 static void camera_sensors_tbl(void)
1017 {
1018   unsigned int i;
1019   size_t available_sensors = sizeof(sensor_tbl)/sizeof(sensor_tbl[0]);
1020 
1021   printf("\n");
1022   printf("===========================================\n");
1023   printf("      Camera Sensor to be used:            \n");
1024   printf("===========================================\n\n");
1025 
1026 
1027   char bsmenuNum = 'A';
1028   for (i = 0; ( i < available_sensors ) && ( sensor_tbl[i].present ) ; i++) {
1029     printf("%c.  %s\n", bsmenuNum,
1030             sensor_tbl[i].menu_name);
1031     bsmenuNum++;
1032   }
1033 
1034   printf("\nPlease enter your choice for sensor: ");
1035   return;
1036 }
1037 
camera_special_effects_tbl(void)1038 static void camera_special_effects_tbl(void)
1039 {
1040   unsigned int i;
1041   size_t available_effects = sizeof(camEffect_mode_tbl)/sizeof(camEffect_mode_tbl[0]);
1042 
1043   printf("\n");
1044   printf("===========================================\n");
1045   printf("      Camera Available Special Effects:            \n");
1046   printf("===========================================\n\n");
1047 
1048 
1049   char bsmenuNum = 'A';
1050   for (i = 0; ( i < available_effects ) ; i++) {
1051     printf("%c.  %s\n", bsmenuNum,
1052             camEffect_mode_tbl[i].name);
1053     bsmenuNum++;
1054   }
1055 
1056   printf("\nPlease enter your choice for sensor: ");
1057   return;
1058 }
1059 
camera_anti_banding_tbl(void)1060 static void camera_anti_banding_tbl(void)
1061 {
1062   unsigned int i;
1063   size_t available_effects = sizeof(antiBanding_tbl)/sizeof(antiBanding_tbl[0]);
1064 
1065   printf("\n");
1066   printf("===========================================\n");
1067   printf("      Camera Available Anti Banding Options:            \n");
1068   printf("===========================================\n\n");
1069 
1070 
1071   char bsmenuNum = 'A';
1072   for (i = 0; ( i < available_effects ) ; i++) {
1073     printf("%c.  %s\n", bsmenuNum,
1074             antiBanding_tbl[i].name);
1075     bsmenuNum++;
1076   }
1077 
1078   printf("\nPlease enter your choice for sensor: ");
1079   return;
1080 }
1081 
camera_flip_tbl(void)1082 static void camera_flip_tbl(void)
1083 {
1084   unsigned int i;
1085   size_t available_effects = sizeof(flipModes_tbl)/sizeof(flipModes_tbl[0]);
1086 
1087   printf("\n");
1088   printf("===========================================\n");
1089   printf("      Camera Available FLIP MODES:            \n");
1090   printf("===========================================\n\n");
1091 
1092 
1093   char bsmenuNum = 'A';
1094   for (i = 0; ( i < available_effects ) ; i++) {
1095     printf("%c.  %s\n", bsmenuNum,
1096             flipModes_tbl[i].name);
1097     bsmenuNum++;
1098   }
1099 
1100   printf("\nPlease enter your choice for sensor: ");
1101   return;
1102 }
1103 
1104 /*===========================================================================
1105  * FUNCTION     - increase_contrast -
1106  *
1107  * DESCRIPTION:
1108  * ===========================================================================*/
increase_contrast(mm_camera_lib_handle * lib_handle)1109 int increase_contrast (mm_camera_lib_handle *lib_handle) {
1110         contrast += CAMERA_CONTRAST_STEP;
1111         if (contrast > CAMERA_MAX_CONTRAST) {
1112                 contrast = CAMERA_MAX_CONTRAST;
1113                 printf("Reached max CONTRAST. \n");
1114         }
1115         printf("Increase Contrast to %d\n", contrast);
1116         return mm_camera_lib_send_command(lib_handle,
1117                                           MM_CAMERA_LIB_CONTRAST,
1118                                           &contrast,
1119                                           NULL);
1120 }
1121 
1122 /*===========================================================================
1123  * FUNCTION     - decrease_contrast -
1124  *
1125  * DESCRIPTION:
1126  * ===========================================================================*/
decrease_contrast(mm_camera_lib_handle * lib_handle)1127 int decrease_contrast (mm_camera_lib_handle *lib_handle) {
1128         contrast -= CAMERA_CONTRAST_STEP;
1129         if (contrast < CAMERA_MIN_CONTRAST) {
1130                 contrast = CAMERA_MIN_CONTRAST;
1131                 printf("Reached min CONTRAST. \n");
1132         }
1133         printf("Decrease Contrast to %d\n", contrast);
1134         return mm_camera_lib_send_command(lib_handle,
1135                                           MM_CAMERA_LIB_CONTRAST,
1136                                           &contrast,
1137                                           NULL);
1138 }
1139 
1140 /*===========================================================================
1141  * FUNCTION     - decrease_brightness -
1142  *
1143  * DESCRIPTION:
1144  * ===========================================================================*/
decrease_brightness(mm_camera_lib_handle * lib_handle)1145 int decrease_brightness (mm_camera_lib_handle *lib_handle) {
1146         brightness -= CAMERA_BRIGHTNESS_STEP;
1147         if (brightness < CAMERA_MIN_BRIGHTNESS) {
1148                 brightness = CAMERA_MIN_BRIGHTNESS;
1149                 printf("Reached min BRIGHTNESS. \n");
1150         }
1151         printf("Decrease Brightness to %d\n", brightness);
1152         return mm_camera_lib_send_command(lib_handle,
1153                                           MM_CAMERA_LIB_BRIGHTNESS,
1154                                           &brightness,
1155                                           NULL);
1156 }
1157 
1158 /*===========================================================================
1159  * FUNCTION     - increase_brightness -
1160  *
1161  * DESCRIPTION:
1162  * ===========================================================================*/
increase_brightness(mm_camera_lib_handle * lib_handle)1163 int increase_brightness (mm_camera_lib_handle *lib_handle) {
1164         brightness += CAMERA_BRIGHTNESS_STEP;
1165         if (brightness > CAMERA_MAX_BRIGHTNESS) {
1166                 brightness = CAMERA_MAX_BRIGHTNESS;
1167                 printf("Reached max BRIGHTNESS. \n");
1168         }
1169         printf("Increase Brightness to %d\n", brightness);
1170         return mm_camera_lib_send_command(lib_handle,
1171                                           MM_CAMERA_LIB_BRIGHTNESS,
1172                                           &brightness,
1173                                           NULL);
1174 }
1175 
1176 /*===========================================================================
1177  * FUNCTION     - increase_EV -
1178  *
1179  * DESCRIPTION:
1180  * ===========================================================================*/
1181 
increase_EV(mm_camera_lib_handle * lib_handle)1182 int increase_EV (mm_camera_lib_handle *lib_handle) {
1183 
1184     ev_numerator += 4;
1185     if(ev_numerator >= EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR &&
1186             ev_numerator <= EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR){
1187 
1188     } else {
1189        printf("Reached max EV.\n");
1190     }
1191     printf("Increase EV to %d\n", ev_numerator);
1192     return mm_camera_lib_send_command(lib_handle,
1193                                        MM_CAMERA_LIB_EV,
1194                                        &ev_numerator,
1195                                        NULL);
1196 }
1197 
1198 /*===========================================================================
1199  * FUNCTION     - decrease_EV -
1200  *
1201  * DESCRIPTION:
1202  * ===========================================================================*/
decrease_EV(mm_camera_lib_handle * lib_handle)1203 int decrease_EV (mm_camera_lib_handle *lib_handle) {
1204 
1205     ev_numerator -= 4;
1206     if(ev_numerator >= EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR &&
1207             ev_numerator <= EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR){
1208 
1209     } else {
1210        printf("Reached min EV.\n");
1211     }
1212     printf("Decrease EV to %d\n", ev_numerator);
1213     return mm_camera_lib_send_command(lib_handle,
1214                                        MM_CAMERA_LIB_EV,
1215                                        &ev_numerator,
1216                                        NULL);
1217 
1218 }
1219 
1220 /*===========================================================================
1221  * FUNCTION     - increase_saturation -
1222  *
1223  * DESCRIPTION:
1224  * ===========================================================================*/
increase_saturation(mm_camera_lib_handle * lib_handle)1225 int increase_saturation (mm_camera_lib_handle *lib_handle) {
1226 #if 0
1227   saturation += CAMERA_SATURATION_STEP;
1228   if (saturation > CAMERA_MAX_SATURATION) {
1229     saturation = CAMERA_MAX_SATURATION;
1230     printf("Reached max saturation. \n");
1231   }
1232   printf("Increase Saturation to %d\n", saturation);
1233   return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_SATURATION, saturation);
1234 #endif
1235   saturation += CAMERA_SATURATION_STEP;
1236   if (saturation > CAMERA_MAX_SATURATION) {
1237     saturation = CAMERA_MAX_SATURATION;
1238     printf("Reached max saturation. \n");
1239   }
1240   printf("Increase saturation to %d\n", saturation);
1241   return mm_camera_lib_send_command(lib_handle,
1242                                        MM_CAMERA_LIB_SATURATION,
1243                                        &saturation,
1244                                        NULL);
1245 }
1246 
1247 /*===========================================================================
1248  * FUNCTION     - decrease_saturation -
1249  *
1250  * DESCRIPTION:
1251  * ===========================================================================*/
decrease_saturation(mm_camera_lib_handle * lib_handle)1252 int decrease_saturation (mm_camera_lib_handle *lib_handle) {
1253 #if 0
1254   saturation -= CAMERA_SATURATION_STEP;
1255   if (saturation < CAMERA_MIN_SATURATION) {
1256     saturation = CAMERA_MIN_SATURATION;
1257     printf("Reached min saturation. \n");
1258   }
1259   printf("Dcrease Saturation to %d\n", saturation);
1260   return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_SATURATION, saturation);
1261 #endif
1262   saturation -= CAMERA_SATURATION_STEP;
1263   if (saturation < CAMERA_MIN_SATURATION) {
1264     saturation = CAMERA_MIN_SATURATION;
1265     printf("Reached min saturation. \n");
1266   }
1267   printf("decrease saturation to %d\n", saturation);
1268   return mm_camera_lib_send_command(lib_handle,
1269                                        MM_CAMERA_LIB_SATURATION,
1270                                        &saturation,
1271                                        NULL);
1272 }
1273 
1274 
take_jpeg_snapshot(mm_camera_test_obj_t * test_obj,int is_burst_mode)1275 int take_jpeg_snapshot(mm_camera_test_obj_t *test_obj, int is_burst_mode)
1276 {
1277   LOGH("\nEnter take_jpeg_snapshot!!\n");
1278   int rc = mm_app_take_picture (test_obj, (uint8_t)is_burst_mode);
1279   if (MM_CAMERA_OK != rc) {
1280     LOGE(" mm_app_take_picture() err=%d\n",  rc);
1281   }
1282   return rc;
1283 }
1284 
1285 /*===========================================================================
1286  * FUNCTION    - main -
1287  *
1288  * DESCRIPTION:
1289  *==========================================================================*/
main()1290 int main()
1291 {
1292     char tc_buf[3];
1293     int mode = 0;
1294     int rc = 0;
1295 
1296     printf("Please Select Execution Mode:\n");
1297     printf("0: Menu Based 1: Regression\n");
1298     fgets(tc_buf, 3, stdin);
1299     mode = tc_buf[0] - '0';
1300     if(mode == 0) {
1301       printf("\nStarting Menu based!!\n");
1302     } else if(mode == 1) {
1303       printf("Starting Regression testing!!\n");
1304       if(!mm_app_start_regression_test(1)) {
1305          printf("\nRegressiion test passed!!\n");
1306          return 0;
1307       } else {
1308         printf("\nRegression test failed!!\n");
1309         exit(-1);
1310       }
1311     } else {
1312        printf("\nPlease Enter 0 or 1\n");
1313        printf("\nExisting the App!!\n");
1314        exit(-1);
1315     }
1316 
1317 
1318     rc = submain();
1319 
1320     printf("Exiting application\n");
1321 
1322     return rc;
1323 }
1324 /*===========================================================================
1325  * FUNCTION     - set_manual_whitebalance -
1326  *
1327  * DESCRIPTION:
1328  * ===========================================================================*/
set_manual_whitebalance(mm_camera_lib_handle * lib_handle,int wb_action_param)1329 int set_manual_whitebalance (mm_camera_lib_handle *lib_handle, int wb_action_param) {
1330 
1331     cam_manual_wb_parm_t manual_info ;
1332     float fgain[3];
1333     char data[20], *pSTR, *ePTR;
1334     int iV, i;
1335 
1336     switch (wb_action_param) {
1337       case CAM_MANUAL_WB_MODE_CCT:
1338            printf("\nCAM_MANUAL_WB_MODE_CCT\n");
1339            manual_info.type = CAM_MANUAL_WB_MODE_CCT;
1340            #if 1
1341            printf("\nEnter CCT value:");
1342            fgets(data, sizeof(data), stdin);
1343 
1344            for (pSTR = data; ; pSTR = ePTR) {
1345                iV = strtod(pSTR, &ePTR);
1346                if (pSTR == ePTR)
1347                   break;
1348                manual_info.cct = iV;
1349                if (*ePTR == '\n')
1350                   break;
1351            }
1352           #endif
1353           LOGD("you entered: %d\n", manual_info.cct);
1354           break;
1355       case CAM_MANUAL_WB_MODE_GAIN:
1356            printf("\nCAM_MANUAL_WB_MODE_GAIN\n");
1357            manual_info.type = CAM_MANUAL_WB_MODE_GAIN;
1358            #if 1
1359            i = 0;
1360            printf("\nEnter R, G, B gain value (separated by whitespace):");
1361            fgets(data, sizeof(data), stdin);
1362 
1363            for (pSTR = data; ; pSTR = ePTR) {
1364                fgain[i] = strtof(pSTR, &ePTR);
1365                if (pSTR == ePTR)
1366                   break;
1367                if (*ePTR == '\n')
1368                   break;
1369                i++;
1370            }
1371            #endif
1372            manual_info.gains.r_gain = fgain[0];
1373            manual_info.gains.g_gain = fgain[1];
1374            manual_info.gains.b_gain = fgain[2];
1375 
1376            LOGD("you entered: %f\n",
1377                manual_info.gains.r_gain);
1378            LOGD("you entered: %f\n",
1379                manual_info.gains.g_gain);
1380            LOGD("you entered: %f\n",
1381                manual_info.gains.b_gain);
1382            break;
1383       default:
1384            break;
1385     }
1386 
1387     return mm_camera_lib_send_command(lib_handle,
1388                                      MM_CAMERA_LIB_MN_WB,
1389                                      &manual_info,
1390                                      NULL);
1391 }
1392 /*===========================================================================
1393  * FUNCTION     - set_whitebalance -
1394  *
1395  * DESCRIPTION:
1396  * ===========================================================================*/
set_whitebalance(mm_camera_lib_handle * lib_handle,int wb_action_param)1397 int set_whitebalance (mm_camera_lib_handle *lib_handle, int wb_action_param) {
1398         cam_wb_mode_type type = 0;
1399         switch (wb_action_param) {
1400                 case WB_OFF:
1401                         printf("\n WB_OFF\n");
1402                         type = CAM_WB_MODE_OFF;
1403                         break;
1404                 case WB_AUTO:
1405                         printf("\n WB_AUTO\n");
1406                         type = CAM_WB_MODE_AUTO;
1407                         break;
1408                 case WB_INCANDESCENT:
1409                         printf("\n WB_INCANDESCENT\n");
1410                         type = CAM_WB_MODE_INCANDESCENT;
1411                         break;
1412                 case WB_FLUORESCENT:
1413                         printf("\n WB_FLUORESCENT\n");
1414                         type = CAM_WB_MODE_FLUORESCENT;
1415                         break;
1416                 case WB_WARM_FLUORESCENT:
1417                         printf("\n WB_WARM_FLUORESCENT\n");
1418                         type = CAM_WB_MODE_WARM_FLUORESCENT;
1419                         break;
1420                 case WB_DAYLIGHT:
1421                         printf("\n WB_DAYLIGHT\n");
1422                         type = CAM_WB_MODE_DAYLIGHT;
1423                         break;
1424                 case WB_CLOUDY_DAYLIGHT:
1425                         printf("\n WB_CLOUDY_DAYLIGHT\n");
1426                         type = CAM_WB_MODE_CLOUDY_DAYLIGHT;
1427                         break;
1428                case WB_TWILIGHT:
1429                         printf("\n WB_TWILIGHT\n");
1430                         type = CAM_WB_MODE_TWILIGHT;
1431                         break;
1432                case WB_SHADE:
1433                         printf("\n WB_SHADE\n");
1434                         type = CAM_WB_MODE_SHADE;
1435                         break;
1436                case WB_MANUAL:
1437                         printf("\n WB_WB_MANUAL\n");
1438                         type = CAM_WB_MODE_MANUAL;
1439                         break;
1440                 default:
1441                         break;
1442         }
1443         return mm_camera_lib_send_command(lib_handle,
1444                                           MM_CAMERA_LIB_WB,
1445                                           &type,
1446                                           NULL);
1447 }
1448 
1449 
1450 /*===========================================================================
1451  * FUNCTION     - set_exp_metering -
1452  *
1453  * DESCRIPTION:
1454  * ===========================================================================*/
set_exp_metering(mm_camera_lib_handle * lib_handle,int exp_metering_action_param)1455 int set_exp_metering (mm_camera_lib_handle *lib_handle, int exp_metering_action_param) {
1456         cam_auto_exposure_mode_type type = 0;
1457         switch (exp_metering_action_param) {
1458 		case AUTO_EXP_FRAME_AVG:
1459                         printf("\nAUTO_EXP_FRAME_AVG\n");
1460                         type = CAM_AEC_MODE_FRAME_AVERAGE;
1461                         break;
1462                 case AUTO_EXP_CENTER_WEIGHTED:
1463                         printf("\n AUTO_EXP_CENTER_WEIGHTED\n");
1464                         type = CAM_AEC_MODE_CENTER_WEIGHTED;
1465                         break;
1466                 case AUTO_EXP_SPOT_METERING:
1467                         printf("\n AUTO_EXP_SPOT_METERING\n");
1468                         type = CAM_AEC_MODE_SPOT_METERING;
1469                         break;
1470                 case AUTO_EXP_SMART_METERING:
1471                         printf("\n AUTO_EXP_SMART_METERING\n");
1472                         type = CAM_AEC_MODE_SMART_METERING;
1473                         break;
1474                 case AUTO_EXP_USER_METERING:
1475                         printf("\n AUTO_EXP_USER_METERING\n");
1476                         type = CAM_AEC_MODE_USER_METERING;
1477                         break;
1478                 case AUTO_EXP_SPOT_METERING_ADV:
1479                         printf("\n AUTO_EXP_SPOT_METERING_ADV\n");
1480                         type = CAM_AEC_MODE_SPOT_METERING_ADV;
1481                         break;
1482                 case AUTO_EXP_CENTER_WEIGHTED_ADV:
1483                         printf("\n AUTO_EXP_CENTER_WEIGHTED_ADV\n");
1484                         type = CAM_AEC_MODE_CENTER_WEIGHTED_ADV;
1485                         break;
1486                 default:
1487                         break;
1488         }
1489         return mm_camera_lib_send_command(lib_handle,
1490                                           MM_CAMERA_LIB_EXPOSURE_METERING,
1491                                           &type,
1492                                           NULL);
1493 }
1494 
get_ctrl_value(int ctrl_value_mode_param)1495 int get_ctrl_value (int ctrl_value_mode_param){
1496 #if 0
1497     int rc = 0;
1498     struct v4l2_control ctrl;
1499 
1500     if (ctrl_value_mode_param == WHITE_BALANCE_STATE) {
1501         printf("You chose WHITE_BALANCE_STATE\n");
1502         ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
1503     }
1504     else if (ctrl_value_mode_param == WHITE_BALANCE_TEMPERATURE) {
1505         printf("You chose WHITE_BALANCE_TEMPERATURE\n");
1506         ctrl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
1507     }
1508     else if (ctrl_value_mode_param == BRIGHTNESS_CTRL) {
1509         printf("You chose brightness value\n");
1510         ctrl.id = V4L2_CID_BRIGHTNESS;
1511     }
1512     else if (ctrl_value_mode_param == EV) {
1513         printf("You chose exposure value\n");
1514         ctrl.id = V4L2_CID_EXPOSURE;
1515     }
1516     else if (ctrl_value_mode_param == CONTRAST_CTRL) {
1517         printf("You chose contrast value\n");
1518         ctrl.id = V4L2_CID_CONTRAST;
1519     }
1520     else if (ctrl_value_mode_param == SATURATION_CTRL) {
1521         printf("You chose saturation value\n");
1522         ctrl.id = V4L2_CID_SATURATION;
1523     } else if (ctrl_value_mode_param == SHARPNESS_CTRL) {
1524         printf("You chose sharpness value\n");
1525         ctrl.id = V4L2_CID_SHARPNESS;
1526     }
1527 
1528   //  rc = ioctl(camfd, VIDIOC_G_CTRL, &ctrl);
1529     return rc;
1530 #endif
1531   return ctrl_value_mode_param;
1532 }
1533 
1534 /*===========================================================================
1535  * FUNCTION     - toggle_afr -
1536  *
1537  * DESCRIPTION:
1538  * ===========================================================================*/
toggle_afr()1539 int toggle_afr () {
1540 #if 0
1541     if (fps_mode == FPS_MODE_AUTO) {
1542         printf("\nSetting FPS_MODE_FIXED\n");
1543         fps_mode = FPS_MODE_FIXED;
1544     } else {
1545         printf("\nSetting FPS_MODE_AUTO\n");
1546         fps_mode = FPS_MODE_AUTO;
1547     }
1548     return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_FPS_MODE, fps_mode);
1549 #endif
1550   return 0;
1551 }
set_zoom(mm_camera_lib_handle * lib_handle,int zoom_action_param)1552 int set_zoom (mm_camera_lib_handle *lib_handle, int zoom_action_param) {
1553 
1554     if (zoom_action_param == ZOOM_IN) {
1555         zoom_level += ZOOM_STEP;
1556         if (zoom_level > zoom_max_value)
1557             zoom_level = zoom_max_value;
1558     } else if (zoom_action_param == ZOOM_OUT) {
1559         zoom_level -= ZOOM_STEP;
1560         if (zoom_level < ZOOM_MIN_VALUE)
1561             zoom_level = ZOOM_MIN_VALUE;
1562     } else {
1563         LOGD(" Invalid zoom_action_param value\n");
1564         return -EINVAL;
1565     }
1566     return mm_camera_lib_send_command(lib_handle,
1567                                       MM_CAMERA_LIB_ZOOM,
1568                                       &zoom_level,
1569                                       NULL);
1570 }
1571 
1572 /*===========================================================================
1573  * FUNCTION     - set_iso -
1574  *
1575  * DESCRIPTION:
1576  * ===========================================================================*/
set_iso(mm_camera_lib_handle * lib_handle,int iso_action_param)1577 int set_iso (mm_camera_lib_handle *lib_handle, int iso_action_param) {
1578     cam_iso_mode_type type = 0;
1579     switch (iso_action_param) {
1580         case ISO_AUTO:
1581             printf("\n ISO_AUTO\n");
1582             type = CAM_ISO_MODE_AUTO;
1583             break;
1584         case ISO_DEBLUR:
1585             printf("\n ISO_DEBLUR\n");
1586             type = CAM_ISO_MODE_DEBLUR;
1587             break;
1588         case ISO_100:
1589             printf("\n ISO_100\n");
1590             type = CAM_ISO_MODE_100;
1591             break;
1592         case ISO_200:
1593             printf("\n ISO_200\n");
1594             type = CAM_ISO_MODE_200;
1595             break;
1596         case ISO_400:
1597             printf("\n ISO_400\n");
1598             type = CAM_ISO_MODE_400;
1599             break;
1600         case ISO_800:
1601             printf("\n ISO_800\n");
1602             type = CAM_ISO_MODE_800;
1603             break;
1604         case ISO_1600:
1605             printf("\n ISO_1600\n");
1606             type = CAM_ISO_MODE_1600;
1607             break;
1608         default:
1609             break;
1610     }
1611     return mm_camera_lib_send_command(lib_handle,
1612                                       MM_CAMERA_LIB_ISO,
1613                                       &type,
1614                                       NULL);
1615 }
1616 
1617 /*===========================================================================
1618  * FUNCTION     - increase_sharpness -
1619  *
1620  * DESCRIPTION:
1621  * ===========================================================================*/
increase_sharpness(mm_camera_lib_handle * lib_handle)1622 int increase_sharpness (mm_camera_lib_handle *lib_handle) {
1623     sharpness += CAMERA_SHARPNESS_STEP;
1624     if (sharpness > CAMERA_MAX_SHARPNESS) {
1625         sharpness = CAMERA_MAX_SHARPNESS;
1626         printf("Reached max SHARPNESS. \n");
1627     }
1628     printf("Increase Sharpness to %d\n", sharpness);
1629     return mm_camera_lib_send_command(lib_handle,
1630                                       MM_CAMERA_LIB_SHARPNESS,
1631                                       &sharpness,
1632                                       NULL);
1633 }
1634 
1635 /*===========================================================================
1636  * FUNCTION     - decrease_sharpness -
1637  *
1638  * DESCRIPTION:
1639  * ===========================================================================*/
decrease_sharpness(mm_camera_lib_handle * lib_handle)1640 int decrease_sharpness (mm_camera_lib_handle *lib_handle) {
1641     sharpness -= CAMERA_SHARPNESS_STEP;
1642     if (sharpness < CAMERA_MIN_SHARPNESS) {
1643         sharpness = CAMERA_MIN_SHARPNESS;
1644         printf("Reached min SHARPNESS. \n");
1645     }
1646     printf("Decrease Sharpness to %d\n", sharpness);
1647     return mm_camera_lib_send_command(lib_handle,
1648                                       MM_CAMERA_LIB_SHARPNESS,
1649                                       &sharpness,
1650                                       NULL);
1651 }
1652 
set_flash_mode(mm_camera_lib_handle * lib_handle,int action_param)1653 int set_flash_mode (mm_camera_lib_handle *lib_handle, int action_param) {
1654     cam_flash_mode_t type = 0;
1655     switch (action_param) {
1656         case FLASH_MODE_OFF:
1657             printf("\n FLASH_MODE_OFF\n");
1658             type = CAM_FLASH_MODE_OFF;
1659             break;
1660         case FLASH_MODE_AUTO:
1661             printf("\n FLASH_MODE_AUTO\n");
1662             type = CAM_FLASH_MODE_AUTO;
1663             break;
1664         case FLASH_MODE_ON:
1665             printf("\n FLASH_MODE_ON\n");
1666             type = CAM_FLASH_MODE_ON;
1667             break;
1668         case FLASH_MODE_TORCH:
1669             printf("\n FLASH_MODE_TORCH\n");
1670             type = CAM_FLASH_MODE_TORCH;
1671             break;
1672         default:
1673             break;
1674     }
1675     return mm_camera_lib_send_command(lib_handle,
1676                                       MM_CAMERA_LIB_FLASH,
1677                                       &type,
1678                                       NULL);
1679 }
1680 
set_specialEffects(mm_camera_lib_handle * lib_handle,int action_param)1681 int set_specialEffects(mm_camera_lib_handle *lib_handle, int action_param) {
1682     cam_effect_mode_type effect = 0;
1683 
1684     switch (action_param) {
1685         case SPL_EFFECT_OFF:
1686             printf("\n SPECIAL EFFECT OFF\n");
1687             effect  = CAM_EFFECT_MODE_OFF ;
1688             break;
1689         case SPL_EFFECT_MONO:
1690             printf("\n SPECIAL EFFECT MONO\n");
1691             effect  = CAM_EFFECT_MODE_MONO;
1692             break;
1693         case SPL_EFFECT_NEGATIVE:
1694             printf("\n SPECIAL EFFECT NEGATIVE\n");
1695             effect  = CAM_EFFECT_MODE_NEGATIVE;
1696             break;
1697         case SPL_EFFECT_SOLARIZE:
1698             printf("\n SPECIAL EFFECT SOLARIZE\n");
1699             effect  = CAM_EFFECT_MODE_SOLARIZE ;
1700             break;
1701         case SPL_EFFECT_SEPIA:
1702             printf("\n SPECIAL EFFECT SEPIA\n");
1703             effect  = CAM_EFFECT_MODE_SEPIA ;
1704             break;
1705         case SPL_EFFECT_POSTERIZE:
1706             printf("\n SPECIAL EFFECT POSTERIZE\n");
1707             effect  = CAM_EFFECT_MODE_POSTERIZE ;
1708             break;
1709         case SPL_EFFECT_WHITEBOARD:
1710             printf("\n SPECIAL EFFECT WHITEBOARD\n");
1711             effect  = CAM_EFFECT_MODE_WHITEBOARD ;
1712             break;
1713         case SPL_EFFECT_BLACKBOARD:
1714             printf("\n SPECIAL EFFECT BLACKBOARD\n");
1715             effect  = CAM_EFFECT_MODE_BLACKBOARD ;
1716             break;
1717         case SPL_EFFECT_AQUA:
1718             printf("\n SPECIAL EFFECT AQUA\n");
1719             effect  = CAM_EFFECT_MODE_AQUA ;
1720             break;
1721         case SPL_EFFECT_EMBOSS:
1722             printf("\n SPECIAL EFFECT EMBOSS\n");
1723             effect  = CAM_EFFECT_MODE_EMBOSS ;
1724             break;
1725         case SPL_EFFECT_SKETCH:
1726             printf("\n SPECIAL EFFECT SKETCH\n");
1727             effect  = CAM_EFFECT_MODE_SKETCH ;
1728             break;
1729         case SPL_EFFECT_NEON:
1730             printf("\n SPECIAL EFFECT NEON\n");
1731             effect  = CAM_EFFECT_MODE_NEON ;
1732             break;
1733         case SPL_EFFECT_BEAUTY:
1734             printf("\n SPECIAL EFFECT BEAUTY\n");
1735             effect  = CAM_EFFECT_MODE_BEAUTY ;
1736             break;
1737         default:
1738             printf("\n SPECIAL EFFECT OFF\n");
1739             effect  = CAM_EFFECT_MODE_OFF ;
1740             break;
1741         }
1742         return mm_camera_lib_send_command(lib_handle,
1743                                           MM_CAMERA_LIB_SPL_EFFECT,
1744                                           &effect,
1745                                           NULL);
1746 }
1747 
set_antiBanding(mm_camera_lib_handle * lib_handle,int action_param)1748 int set_antiBanding(mm_camera_lib_handle *lib_handle, int action_param) {
1749     cam_antibanding_mode_type effect = 0;
1750 
1751     switch (action_param) {
1752         case ANTIBANDING_OFF:
1753             printf("\n ANTI BANDING OFF\n");
1754             effect  = CAM_ANTIBANDING_MODE_OFF;
1755             break;
1756         case ANTIBANDING_60HZ:
1757             printf("\n ANTI BANDING 60 HZ\n");
1758             effect  = CAM_ANTIBANDING_MODE_60HZ;
1759             break;
1760         case ANTIBANDING_50HZ:
1761             printf("\n ANTI BANDING 50 HZ\n");
1762             effect  = CAM_ANTIBANDING_MODE_50HZ;
1763             break;
1764         case ANTIBANDING_AUTO:
1765             printf("\n ANTI BANDING AUTO\n");
1766             effect  = CAM_ANTIBANDING_MODE_AUTO;
1767             break;
1768         default:
1769             printf("\n ANTI BANDING OFF\n");
1770             effect  = CAM_ANTIBANDING_MODE_OFF;
1771             break;
1772         }
1773         return mm_camera_lib_send_command(lib_handle,
1774                                           MM_CAMERA_LIB_ANTIBANDING,
1775                                           &effect,
1776                                           NULL);
1777 }
set_flipMode(mm_camera_lib_handle * lib_handle,int action_param)1778 int set_flipMode(mm_camera_lib_handle *lib_handle, int action_param) {
1779     cam_flip_t effect = 0;
1780 
1781     printf("%s:action_param = %d", __func__, action_param);
1782 
1783     switch (action_param) {
1784         case MODE_NO_FLIP:
1785             printf("\n FLIP MODE OFF\n");
1786             effect  = FLIP_NONE;
1787             break;
1788         case MODE_FLIP_H:
1789             printf("\n FLIP MODE HORIZONTAL\n");
1790             effect  = FLIP_H;
1791             break;
1792         case MODE_FLIP_V:
1793             printf("\n FLIP MODE VERTICAL\n");
1794             effect  = FLIP_V;
1795             break;
1796         case MODE_FLIP_V_H:
1797             printf("\n FLIP MODE VERTICAL HORIZONTAL\n");
1798             effect  = FLIP_V_H;
1799             break;
1800         default:
1801             printf("\n FLIP MODE OFF\n");
1802             effect  = FLIP_NONE;
1803             break;
1804         }
1805         return mm_camera_lib_send_command(lib_handle,
1806                                           MM_CAMERA_LIB_FLIP,
1807                                           &effect,
1808                                           NULL);
1809 }
1810 
set_bestshot_mode(mm_camera_lib_handle * lib_handle,int action_param)1811 int set_bestshot_mode(mm_camera_lib_handle *lib_handle, int action_param) {
1812     cam_scene_mode_type type = 0;
1813     switch (action_param) {
1814        case BESTSHOT_AUTO:
1815             printf("\n BEST SHOT AUTO\n");
1816             type = CAM_SCENE_MODE_OFF;
1817             break;
1818         case BESTSHOT_ACTION:
1819             printf("\n BEST SHOT ACTION\n");
1820             type = CAM_SCENE_MODE_ACTION;
1821             break;
1822         case BESTSHOT_PORTRAIT:
1823             printf("\n BEST SHOT PORTRAIT\n");
1824             type = CAM_SCENE_MODE_PORTRAIT;
1825             break;
1826         case BESTSHOT_LANDSCAPE:
1827             printf("\n BEST SHOT LANDSCAPE\n");
1828             type = CAM_SCENE_MODE_LANDSCAPE;
1829             break;
1830         case BESTSHOT_NIGHT:
1831             printf("\n BEST SHOT NIGHT\n");
1832             type = CAM_SCENE_MODE_NIGHT;
1833             break;
1834         case BESTSHOT_NIGHT_PORTRAIT:
1835             printf("\n BEST SHOT NIGHT PORTRAIT\n");
1836             type = CAM_SCENE_MODE_NIGHT_PORTRAIT;
1837             break;
1838         case BESTSHOT_THEATRE:
1839             printf("\n BEST SHOT THREATRE\n");
1840             type = CAM_SCENE_MODE_THEATRE;
1841             break;
1842         case BESTSHOT_BEACH:
1843             printf("\n BEST SHOT BEACH\n");
1844             type = CAM_SCENE_MODE_BEACH;
1845             break;
1846         case BESTSHOT_SNOW:
1847             printf("\n BEST SHOT SNOW\n");
1848             type = CAM_SCENE_MODE_SNOW;
1849             break;
1850         case BESTSHOT_SUNSET:
1851             printf("\n BEST SHOT SUNSET\n");
1852             type = CAM_SCENE_MODE_SUNSET;
1853             break;
1854         case BESTSHOT_ANTISHAKE:
1855             printf("\n BEST SHOT ANTISHAKE\n");
1856             type = CAM_SCENE_MODE_ANTISHAKE;
1857             break;
1858         case BESTSHOT_FIREWORKS:
1859             printf("\n BEST SHOT FIREWORKS\n");
1860             type = CAM_SCENE_MODE_FIREWORKS;
1861             break;
1862         case BESTSHOT_SPORTS:
1863             printf("\n BEST SHOT SPORTS\n");
1864             type = CAM_SCENE_MODE_SPORTS;
1865             break;
1866         case BESTSHOT_PARTY:
1867             printf("\n BEST SHOT PARTY\n");
1868             type = CAM_SCENE_MODE_PARTY;
1869             break;
1870         case BESTSHOT_CANDLELIGHT:
1871             printf("\n BEST SHOT CANDLELIGHT\n");
1872             type = CAM_SCENE_MODE_CANDLELIGHT;
1873             break;
1874         case BESTSHOT_ASD:
1875             printf("\n BEST SHOT ASD\n");
1876             type = CAM_SCENE_MODE_AUTO;
1877             break;
1878         case BESTSHOT_BACKLIGHT:
1879             printf("\n BEST SHOT BACKLIGHT\n");
1880             type = CAM_SCENE_MODE_BACKLIGHT;
1881             break;
1882         case BESTSHOT_FLOWERS:
1883             printf("\n BEST SHOT FLOWERS\n");
1884             type = CAM_SCENE_MODE_FLOWERS;
1885             break;
1886         case BESTSHOT_AR:
1887             printf("\n BEST SHOT AR\n");
1888             type = CAM_SCENE_MODE_AR;
1889             break;
1890         case BESTSHOT_HDR:
1891             printf("\n BEST SHOT HDR\n");
1892             type = CAM_SCENE_MODE_OFF;
1893             break;
1894         default:
1895             break;
1896         }
1897         return mm_camera_lib_send_command(lib_handle,
1898                                           MM_CAMERA_LIB_BESTSHOT,
1899                                           &type,
1900                                           NULL);
1901 }
1902 /*===========================================================================
1903  * FUNCTION     - print_current_menu -
1904  *
1905  * DESCRIPTION:
1906  * ===========================================================================*/
print_current_menu(menu_id_change_t current_menu_id)1907 int print_current_menu (menu_id_change_t current_menu_id) {
1908   if (current_menu_id == MENU_ID_MAIN) {
1909     print_menu_preview_video ();
1910   } else if (current_menu_id == MENU_ID_WHITEBALANCECHANGE) {
1911     camera_preview_video_wb_change_tbl();
1912   } else if (current_menu_id == MENU_ID_WHITEBALANCE_MANUAL){
1913     camera_preview_video_mn_wb_tbl();
1914   } else if (current_menu_id == MENU_ID_EXPMETERINGCHANGE) {
1915     camera_preview_video_exp_metering_change_tbl();
1916   } else if (current_menu_id == MENU_ID_GET_CTRL_VALUE) {
1917     camera_preview_video_get_ctrl_value_tbl();
1918   } else if (current_menu_id == MENU_ID_ISOCHANGE) {
1919     camera_preview_video_iso_change_tbl();
1920   } else if (current_menu_id == MENU_ID_BRIGHTNESSCHANGE) {
1921     camera_brightness_change_tbl ();
1922   } else if (current_menu_id == MENU_ID_CONTRASTCHANGE) {
1923     camera_contrast_change_tbl ();
1924   } else if (current_menu_id == MENU_ID_EVCHANGE) {
1925     camera_EV_change_tbl ();
1926   } else if (current_menu_id == MENU_ID_SATURATIONCHANGE) {
1927     camera_saturation_change_tbl ();
1928   } else if (current_menu_id == MENU_ID_ZOOMCHANGE) {
1929     camera_preview_video_zoom_change_tbl();
1930   } else if (current_menu_id == MENU_ID_SHARPNESSCHANGE) {
1931     camera_preview_video_sharpness_change_tbl();
1932   } else if (current_menu_id == MENU_ID_BESTSHOT) {
1933     camera_set_bestshot_tbl();
1934   } else if (current_menu_id == MENU_ID_FLASHMODE) {
1935     camera_set_flashmode_tbl();
1936   } else if (current_menu_id == MENU_ID_SENSORS ) {
1937     camera_sensors_tbl();
1938   } else if (current_menu_id == MENU_ID_SWITCH_RES ) {
1939     camera_resolution_change_tbl();
1940   } else if (current_menu_id == MENU_ID_SPECIAL_EFFECTS ) {
1941     camera_special_effects_tbl();
1942   } else if (current_menu_id == MENU_ID_ANTI_BANDING ) {
1943     camera_anti_banding_tbl();
1944   } else if (current_menu_id == MENU_ID_FLIP_MODE ) {
1945     camera_flip_tbl();
1946   }else
1947     print_menu_preview_video ();
1948 
1949 
1950   return 0;
1951 }
1952 
filter_resolutions(mm_camera_lib_handle * lib_handle,DIMENSION_TBL_T * tbl,size_t tbl_size)1953 int filter_resolutions(mm_camera_lib_handle *lib_handle,
1954                        DIMENSION_TBL_T *tbl,
1955                        size_t tbl_size)
1956 {
1957     size_t i, j;
1958     cam_capability_t camera_cap;
1959     int rc = 0;
1960 
1961     if ( ( NULL == lib_handle ) || ( NULL == tbl ) ) {
1962         return -1;
1963     }
1964 
1965     rc = mm_camera_lib_get_caps(lib_handle, &camera_cap);
1966     if ( MM_CAMERA_OK != rc ) {
1967         LOGE("mm_camera_lib_get_caps() err=%d\n",  rc);
1968         return -1;
1969     }
1970 
1971     for( i = 0 ; i < tbl_size ; i++ ) {
1972         for( j = 0; j < camera_cap.picture_sizes_tbl_cnt; j++ ) {
1973             if ( ( tbl[i].width == camera_cap.picture_sizes_tbl[j].width ) &&
1974                  ( tbl[i].height == camera_cap.picture_sizes_tbl[j].height ) ) {
1975                 tbl[i].supported = 1;
1976                 rc = (int)i;
1977                 break;
1978             }
1979         }
1980     }
1981 
1982     return rc;
1983 }
1984 
1985 /*===========================================================================
1986  * FUNCTION   : enableAFR
1987  *
1988  * DESCRIPTION: This function will go through the list
1989  *              of supported FPS ranges and select the
1990  *              one which has maximum range
1991  *
1992  * PARAMETERS :
1993  *   @lib_handle   : camera test library handle
1994  *
1995  * RETURN     : uint32_t type of stream handle
1996  *              MM_CAMERA_OK  -- Success
1997  *              !=MM_CAMERA_OK -- Error status
1998  *==========================================================================*/
enableAFR(mm_camera_lib_handle * lib_handle)1999 int enableAFR(mm_camera_lib_handle *lib_handle)
2000 {
2001     size_t i, j;
2002     float max_range = 0.0f;
2003     cam_capability_t cap;
2004     int rc = MM_CAMERA_OK;
2005 
2006     if ( NULL == lib_handle ) {
2007         return MM_CAMERA_E_INVALID_INPUT;
2008     }
2009 
2010     rc = mm_camera_lib_get_caps(lib_handle, &cap);
2011     if ( MM_CAMERA_OK != rc ) {
2012         LOGE("mm_camera_lib_get_caps() err=%d\n",  rc);
2013         return rc;
2014     }
2015 
2016     for( i = 0, j = 0 ; i < cap.fps_ranges_tbl_cnt ; i++ ) {
2017         if ( max_range < (cap.fps_ranges_tbl[i].max_fps - cap.fps_ranges_tbl[i].min_fps) ) {
2018             j = i;
2019         }
2020     }
2021 
2022     rc = mm_camera_lib_send_command(lib_handle,
2023                                     MM_CAMERA_LIB_FPS_RANGE,
2024                                     &cap.fps_ranges_tbl[j],
2025                                     NULL);
2026 
2027     LOGE("FPS range [%5.2f:%5.2f] rc = %d\n",
2028               cap.fps_ranges_tbl[j].min_fps,
2029               cap.fps_ranges_tbl[j].max_fps,
2030               rc);
2031     LOGE("FPS range (video) [%5.2f:%5.2f] rc = %d\n",
2032               cap.fps_ranges_tbl[j].video_min_fps,
2033               cap.fps_ranges_tbl[j].video_max_fps,
2034               rc);
2035 
2036     return rc;
2037 }
2038 
2039 /*===========================================================================
2040  * FUNCTION     - submain -
2041  *
2042  * DESCRIPTION:
2043  * ===========================================================================*/
submain()2044 static int submain()
2045 {
2046     int rc = 0;
2047     char tc_buf[3];
2048     menu_id_change_t current_menu_id = MENU_ID_MAIN, next_menu_id;
2049     camera_action_t action_id;
2050     int action_param;
2051     uint8_t previewing = 0;
2052     int isZSL = 0;
2053     int isezTune = 0;
2054     int curr_irmode = 0;
2055     int isshdrmode = 0;
2056     uint8_t wnr_enabled = 0;
2057     mm_camera_lib_handle lib_handle;
2058     int num_cameras;
2059     int available_sensors =
2060         (int)(sizeof(sensor_tbl) / sizeof(sensor_tbl[0]));
2061     int available_snap_sizes =
2062         (int)(sizeof(dimension_tbl)/sizeof(dimension_tbl[0]));
2063     int i,c;
2064     mm_camera_lib_snapshot_params snap_dim;
2065     snap_dim.width = DEFAULT_SNAPSHOT_WIDTH;
2066     snap_dim.height = DEFAULT_SNAPSHOT_HEIGHT;
2067     cam_scene_mode_type default_scene= CAM_SCENE_MODE_OFF;
2068     int set_tintless= 0;
2069 
2070     mm_camera_test_obj_t test_obj;
2071     memset(&test_obj, 0, sizeof(mm_camera_test_obj_t));
2072     memset(&snap_dim, 0, sizeof(mm_camera_lib_snapshot_params));
2073     memset(&lib_handle, 0, sizeof(mm_camera_lib_handle));
2074     rc = mm_app_load_hal(&(lib_handle.app_ctx));
2075 
2076     if (rc != MM_CAMERA_OK) {
2077         LOGE("Error loading HAL err=%d\n",  rc);
2078         return -1;
2079     }
2080 
2081     num_cameras = mm_camera_lib_number_of_cameras(&lib_handle);
2082     if ( 0 >= num_cameras ) {
2083         LOGE(" No camera sensors reported!");
2084         rc = -1;
2085         goto ERROR;
2086     } else if ( 1 <= num_cameras ) {
2087         c = MIN(num_cameras, available_sensors);
2088         for ( i = 0 ; i < c ; i++ ) {
2089             sensor_tbl[i].present = 1;
2090         }
2091         current_menu_id = MENU_ID_SENSORS;
2092     } else {
2093         i = filter_resolutions(&lib_handle,
2094                                 dimension_tbl,
2095                                 (size_t)available_snap_sizes);
2096         if ( ( i < 0 ) || ( i >= available_snap_sizes ) ) {
2097             LOGE("filter_resolutions()\n");
2098             goto ERROR;
2099         }
2100         snap_dim.width = dimension_tbl[i].width;
2101         snap_dim.height = dimension_tbl[i].height;
2102 
2103         rc = enableAFR(&lib_handle);
2104         if (rc != MM_CAMERA_OK) {
2105             LOGE("enableAFR() err=%d\n",  rc);
2106             goto ERROR;
2107         }
2108 
2109         rc =  mm_camera_lib_send_command(&lib_handle,
2110                                          MM_CAMERA_LIB_BESTSHOT,
2111                                          &default_scene,
2112                                          NULL);
2113         if (rc != MM_CAMERA_OK) {
2114             LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2115             goto ERROR;
2116         }
2117     }
2118 
2119     do {
2120         print_current_menu (current_menu_id);
2121         fgets(tc_buf, 3, stdin);
2122 
2123         next_menu_id = next_menu(current_menu_id, tc_buf[0], & action_id, & action_param);
2124 
2125         if (next_menu_id != MENU_ID_INVALID) {
2126           current_menu_id = next_menu_id;
2127         }
2128 
2129         if (action_id == ACTION_NO_ACTION) {
2130           continue;
2131         }
2132 
2133         switch(action_id) {
2134             case ACTION_START_PREVIEW:
2135                 LOGE("ACTION_START_PREVIEW \n");
2136                 rc = mm_camera_lib_start_stream(&lib_handle);
2137                 if (rc != MM_CAMERA_OK) {
2138                     LOGE("mm_camera_lib_start_stream() err=%d\n",  rc);
2139                     goto ERROR;
2140                 }
2141                 previewing = 1;
2142                 break;
2143 
2144             case ACTION_STOP_PREVIEW:
2145                 LOGD("ACTION_STOP_PREVIEW \n");
2146                 rc = mm_camera_lib_stop_stream(&lib_handle);
2147                 if (rc != MM_CAMERA_OK) {
2148                     LOGE("mm_camera_lib_stop_stream() err=%d\n",  rc);
2149                     goto ERROR;
2150                 }
2151                 previewing = 0;
2152                 break;
2153 
2154             case ACTION_SET_MN_WHITE_BALANCE:
2155                 LOGE("Selection for the Manual White Balance changes\n");
2156                 set_manual_whitebalance(&lib_handle, action_param);
2157                 break;
2158 
2159             case ACTION_SET_WHITE_BALANCE:
2160                 LOGD("Selection for the White Balance changes\n");
2161                 set_whitebalance(&lib_handle, action_param);
2162                 break;
2163 
2164             case ACTION_SET_TINTLESS_ENABLE:
2165                 LOGD("Selection for the Tintless enable changes\n");
2166                 set_tintless = 1;
2167                 rc =  mm_camera_lib_send_command(&lib_handle,
2168                                                  MM_CAMERA_LIB_SET_TINTLESS,
2169                                                  &set_tintless,
2170                                                  NULL);
2171                 if (rc != MM_CAMERA_OK) {
2172                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2173                     goto ERROR;
2174                 }
2175                 break;
2176 
2177             case ACTION_SET_EXP_METERING:
2178                 LOGD("Selection for the Exposure Metering changes\n");
2179                 set_exp_metering(&lib_handle, action_param);
2180                 break;
2181 
2182             case ACTION_BRIGHTNESS_INCREASE:
2183                 printf("Increase brightness\n");
2184                 increase_brightness(&lib_handle);
2185                 break;
2186 
2187             case ACTION_BRIGHTNESS_DECREASE:
2188                 printf("Decrease brightness\n");
2189                 decrease_brightness(&lib_handle);
2190                 break;
2191 
2192             case ACTION_CONTRAST_INCREASE:
2193                 LOGD("Selection for the contrast increase\n");
2194                 increase_contrast (&lib_handle);
2195                 break;
2196 
2197             case ACTION_CONTRAST_DECREASE:
2198                 LOGD("Selection for the contrast decrease\n");
2199                 decrease_contrast (&lib_handle);
2200                 break;
2201 
2202             case ACTION_EV_INCREASE:
2203                 LOGD("Selection for the EV increase\n");
2204                 increase_EV (&lib_handle);
2205                 break;
2206 
2207             case ACTION_EV_DECREASE:
2208                 LOGD("Selection for the EV decrease\n");
2209                 decrease_EV (&lib_handle);
2210                 break;
2211 
2212             case ACTION_SATURATION_INCREASE:
2213                 LOGD("Selection for the EV increase\n");
2214                 increase_saturation (&lib_handle);
2215                 break;
2216 
2217             case ACTION_SATURATION_DECREASE:
2218                 LOGD("Selection for the EV decrease\n");
2219                 decrease_saturation (&lib_handle);
2220                 break;
2221 
2222             case ACTION_TOGGLE_AFR:
2223                 LOGD("Select for auto frame rate toggling\n");
2224                 toggle_afr();
2225                 break;
2226 
2227             case ACTION_TOGGLE_EZTUNE:
2228                 LOGE("Select for EzTune");
2229                 printf("EZTUNE Toggle\n");
2230                 isezTune = !isezTune;
2231                 if (isezTune) {
2232                     printf("EZ TUNE On !!!");
2233                 } else {
2234                     printf("EZ TUNE Off !!!");
2235                 }
2236 
2237                 rc = mm_camera_lib_send_command(&lib_handle,
2238                                       MM_CAMERA_LIB_EZTUNE_ENABLE,
2239                                       &isezTune,
2240                                       NULL);
2241                 if (rc != MM_CAMERA_OK) {
2242                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2243                     goto ERROR;
2244                 }
2245                 break;
2246 
2247             case ACTION_TOGGLE_IR_MODE:
2248                 LOGE("Select for IR Mode");
2249                 printf("IR Mode Toggle\n");
2250                 curr_irmode ++;
2251                 curr_irmode %= CAM_IR_MODE_MAX;
2252                 printf("IR Mode %s !!!",curr_irmode==0?"Off":(curr_irmode==1?"On":"Auto"));
2253 
2254                 rc = mm_camera_lib_send_command(&lib_handle,
2255                                       MM_CAMERA_LIB_IRMODE,
2256                                       &curr_irmode,
2257                                       NULL);
2258                 if (rc != MM_CAMERA_OK) {
2259                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2260                     goto ERROR;
2261                 }
2262                 break;
2263 
2264 
2265             case ACTION_TOGGLE_SHDR:
2266                 LOGE("Select for SHDR Mode");
2267                 printf("SHDR Mode Toggle\n");
2268                 isshdrmode = !isshdrmode;
2269                 if (!isshdrmode) {
2270                     printf("sHDR ON !!!");
2271                 } else {
2272                     printf("sHDR OFF !!!");
2273                 }
2274                 rc = mm_camera_lib_send_command(&lib_handle,
2275                                        MM_CAMERA_LIB_SHDR_MODE,
2276                                        &isshdrmode,
2277                                        NULL);
2278                 if (rc != MM_CAMERA_OK) {
2279                     LOGE("mm_camera_lib_send_command() err=%d\n", rc);
2280                     goto ERROR;
2281                 }
2282                 break;
2283 
2284 
2285             case ACTION_SET_ISO:
2286                 LOGD("Select for ISO changes\n");
2287                 set_iso(&lib_handle, action_param);
2288                 break;
2289 
2290             case ACTION_SET_ZOOM:
2291                 LOGD("Selection for the zoom direction changes\n");
2292                 set_zoom(&lib_handle, action_param);
2293                 printf("\nCurrent Zoom Value = %d ,Max Zoom Value = %d\n",zoom_level,zoom_max_value);
2294                 break;
2295 
2296             case ACTION_SHARPNESS_INCREASE:
2297                 LOGD("Selection for sharpness increase\n");
2298                 increase_sharpness(&lib_handle);
2299                 break;
2300 
2301             case ACTION_SHARPNESS_DECREASE:
2302                 LOGD("Selection for sharpness decrease\n");
2303                 decrease_sharpness(&lib_handle);
2304                 break;
2305 
2306             case ACTION_SET_BESTSHOT_MODE:
2307                 LOGD("Selection for bestshot\n");
2308                 set_bestshot_mode(&lib_handle, action_param);
2309                 break;
2310 
2311             case ACTION_SET_FLASH_MODE:
2312                 printf("\n Selection for flashmode\n");
2313                 set_flash_mode(&lib_handle, action_param);
2314                 break;
2315 
2316             case ACTION_SWITCH_CAMERA:
2317 
2318                 if (lib_handle.test_obj.cam != NULL) {
2319                     rc = mm_camera_lib_close(&lib_handle);
2320                     if (rc != MM_CAMERA_OK) {
2321                         LOGE("mm_camera_lib_close() err=%d\n",  rc);
2322                         goto ERROR;
2323                     }
2324                 }
2325 
2326                 rc = mm_camera_lib_open(&lib_handle, action_param);
2327                 if (rc != MM_CAMERA_OK) {
2328                     LOGE("mm_camera_lib_open() err=%d\n",  rc);
2329                     goto ERROR;
2330                 }
2331 
2332                 i = filter_resolutions(&lib_handle,
2333                                         dimension_tbl,
2334                                         sizeof(dimension_tbl)/sizeof(dimension_tbl[0]));
2335                 if ( ( i < 0 ) || ( i >=  available_snap_sizes ) ) {
2336                     LOGE("filter_resolutions()\n");
2337                     goto ERROR;
2338                 }
2339                 snap_dim.width = dimension_tbl[i].width;
2340                 snap_dim.height = dimension_tbl[i].height;
2341 
2342                 rc = enableAFR(&lib_handle);
2343                 if (rc != MM_CAMERA_OK) {
2344                     LOGE("enableAFR() err=%d\n",  rc);
2345                     goto ERROR;
2346                 }
2347 
2348                 rc =  mm_camera_lib_send_command(&lib_handle,
2349                                                  MM_CAMERA_LIB_BESTSHOT,
2350                                                  &default_scene,
2351                                                  NULL);
2352                 if (rc != MM_CAMERA_OK) {
2353                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2354                     goto ERROR;
2355                 }
2356                 break;
2357 
2358             case ACTION_TOGGLE_ZSL:
2359                 printf("ZSL Toggle !!!\n");
2360                 isZSL = !isZSL;
2361                 if ( isZSL ) {
2362                     printf("ZSL on !!!\n");
2363                 } else {
2364                     printf("ZSL off !!!\n");
2365                 }
2366                 snap_dim.isZSL = isZSL;
2367                 rc = mm_camera_lib_send_command(&lib_handle,
2368                                                 MM_CAMERA_LIB_ZSL_ENABLE,
2369                                                 &snap_dim,
2370                                                 NULL);
2371                 if (rc != MM_CAMERA_OK) {
2372                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2373                     goto ERROR;
2374                 }
2375                 break;
2376 
2377             case ACTION_TAKE_RAW_SNAPSHOT:
2378                 LOGH("\n Take RAW snapshot\n");
2379                 rc = mm_camera_lib_send_command(&lib_handle,
2380                                                 MM_CAMERA_LIB_DO_AF,
2381                                                 NULL,
2382                                                 NULL);
2383 
2384                 if (rc != MM_CAMERA_OK) {
2385                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2386                     goto ERROR;
2387                 }
2388                 rc = mm_camera_lib_send_command(&lib_handle,
2389                                                 MM_CAMERA_LIB_RAW_CAPTURE,
2390                                                 NULL,
2391                                                 NULL);
2392                 if (rc != MM_CAMERA_OK) {
2393                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2394                     goto ERROR;
2395                 }
2396                 break;
2397 
2398             case ACTION_TAKE_JPEG_SNAPSHOT:
2399                 LOGH("\n Take JPEG snapshot\n");
2400 
2401                 rc = mm_camera_lib_send_command(&lib_handle,
2402                                                 MM_CAMERA_LIB_JPEG_CAPTURE,
2403                                                 &snap_dim,
2404                                                 NULL);
2405                 if (rc != MM_CAMERA_OK) {
2406                     LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2407                     goto ERROR;
2408                 }
2409                 break;
2410             case ACTION_SWITCH_RESOLUTION:
2411                 printf("\n Switch snapshot resolution to %dx%d\n",
2412                        dimension_tbl[action_param].width,
2413                        dimension_tbl[action_param].height);
2414                 snap_dim.width = dimension_tbl[action_param].width;
2415                 snap_dim.height = dimension_tbl[action_param].height;
2416                 break;
2417 
2418            case ACTION_START_RECORDING:
2419              LOGD("Start recording action\n");
2420              mm_app_start_record_preview(&lib_handle.test_obj, &snap_dim);
2421              is_rec = 1;
2422              break;
2423 
2424            case ACTION_STOP_RECORDING:
2425              LOGD("Stop recording action\n");
2426              if(is_rec) {
2427                  mm_app_stop_record_preview(&lib_handle.test_obj);
2428                  is_rec = 0;
2429              }
2430 
2431              break;
2432       case ACTION_TAKE_LIVE_SNAPSHOT:
2433         printf("Selection for live shot\n");
2434 #if 0
2435         if(is_rec)
2436            mm_app_take_live_snapshot(cam_id);
2437         else
2438            printf("\n !!! Use live snapshot option while recording only !!!\n");
2439 #endif
2440         break;
2441 
2442         case ACTION_TOGGLE_WNR:
2443           wnr_enabled = !wnr_enabled;
2444           printf("WNR Enabled = %d\n", wnr_enabled);
2445           rc = mm_camera_lib_send_command(&lib_handle,
2446                                           MM_CAMERA_LIB_WNR_ENABLE,
2447                                           &wnr_enabled,
2448                                           NULL);
2449           if (rc != MM_CAMERA_OK) {
2450               LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2451               goto ERROR;
2452           }
2453           break;
2454 
2455          case ACTION_SPECIAL_EFFECTS:
2456           printf("Selection for special effects\n");
2457           rc = set_specialEffects(&lib_handle, action_param);
2458 
2459           if (rc != MM_CAMERA_OK) {
2460               LOGE("set_specialEffects() err=%d\n",  rc);
2461               goto ERROR;
2462           }
2463           break;
2464 
2465          case ACTION_ANTI_BANDING:
2466           printf("Selection for anti banding\n");
2467           rc = set_antiBanding(&lib_handle, action_param);
2468 
2469           if (rc != MM_CAMERA_OK) {
2470               LOGE("set_antiBanding() err=%d\n",  rc);
2471               goto ERROR;
2472           }
2473           break;
2474 
2475           case ACTION_FLIP_MODE:
2476           printf("Selection for anti banding\n");
2477           rc = set_flipMode(&lib_handle, action_param);
2478 
2479           if (rc != MM_CAMERA_OK) {
2480               LOGE("set_flipMode() err=%d\n",  rc);
2481               goto ERROR;
2482           }
2483           break;
2484 
2485          case ACTION_BURST_MODE_SNAPSHOT:
2486           printf("Selection for BURST_MODE_SNAPSHOT\n");
2487           break;
2488 
2489         case ACTION_CONCURRENT_NDR_NONHDR:
2490           printf("Selection for CONCURRENT_NDR_NONHDR\n");
2491           break;
2492 
2493         case ACTION_EXIT:
2494             printf("Exiting....\n");
2495             break;
2496         case ACTION_NO_ACTION:
2497             printf("Go back to main menu");
2498             break;
2499 
2500         default:
2501             printf("\n\n!!!!!WRONG INPUT: %d!!!!\n", action_id);
2502             break;
2503     }
2504 
2505     usleep(1000 * 1000);
2506     LOGD("action_id = %d\n", action_id);
2507 
2508   } while (action_id != ACTION_EXIT);
2509   action_id = ACTION_NO_ACTION;
2510 
2511     mm_camera_lib_close(&lib_handle);
2512     return 0;
2513 
2514 ERROR:
2515 
2516     mm_camera_lib_close(&lib_handle);
2517 
2518     return rc;
2519 }
2520 
2521