1/* Copyright (c) 2013-2014, 2016, 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
30// System dependencies
31#include <ctype.h>
32#include <errno.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
85const 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  {SET_TINTLESS_DISABLE,       "Set Tintless Disable"},
91  {SET_EXP_METERING,           "Set exposure metering mode"},
92  {GET_CTRL_VALUE,             "Get control value menu"},
93  {TOGGLE_AFR,                 "Toggle auto frame rate. Default fixed frame rate"},
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  {EXIT,                       "Exit"}
112};
113
114CAMERA_SENSOR_MENU_TLB_T sensor_tbl[] = {
115        {"Primary Camera",      0},
116        {"Secondary Camera",    0},
117        {"Camera Sensor 3",     0},
118        {"Camera Sensor 4",     0}
119};
120
121const CAMERA_BRIGHTNESS_TBL_T brightness_change_tbl[] = {
122  {INC_BRIGHTNESS, "Increase Brightness by one step."},
123  {DEC_BRIGHTNESS, "Decrease Brightness by one step."},
124};
125
126const CAMERA_CONTRST_TBL_T contrast_change_tbl[] = {
127  {INC_CONTRAST, "Increase Contrast by one step."},
128  {DEC_CONTRAST, "Decrease Contrast by one step."},
129};
130
131const CAMERA_EV_TBL_T camera_EV_tbl[] = {
132  {INCREASE_EV, "Increase EV by one step."},
133  {DECREASE_EV, "Decrease EV by one step."},
134};
135
136const CAMERA_SATURATION_TBL_T camera_saturation_tbl[] = {
137  {INC_SATURATION, "Increase Satuation by one step."},
138  {DEC_SATURATION, "Decrease Satuation by one step."},
139};
140
141const CAMERA_SHARPNESS_TBL_T camera_sharpness_tbl[] = {
142  {INC_SHARPNESS, "Increase Sharpness."},
143  {DEC_SHARPNESS, "Decrease Sharpness."},
144};
145
146const WHITE_BALANCE_TBL_T white_balance_tbl[] = {
147  {   WB_AUTO,               "White Balance - Auto"},
148  {   WB_INCANDESCENT,       "White Balance - Incandescent"},
149  {   WB_FLUORESCENT,        "White Balance - Fluorescent"},
150  {   WB_WARM_FLUORESCENT,   "White Balance - Warm Fluorescent"},
151  {   WB_DAYLIGHT,           "White Balance - Daylight"},
152  {   WB_CLOUDY_DAYLIGHT,    "White Balance - Cloudy Daylight"},
153  {   WB_TWILIGHT,           "White Balance - Twilight"},
154  {   WB_SHADE,              "White Balance - Shade"},
155};
156
157const GET_CTRL_TBL_T get_ctrl_tbl[] = {
158  {     WHITE_BALANCE_STATE,            "Get white balance state (auto/off)"},
159  {     WHITE_BALANCE_TEMPERATURE,      "Get white balance temperature"},
160  {     BRIGHTNESS_CTRL,                "Get brightness value"},
161  {     EV,                             "Get exposure value"},
162  {     CONTRAST_CTRL,                  "Get contrast value"},
163  {     SATURATION_CTRL,                "Get saturation value"},
164  {     SHARPNESS_CTRL,                 "Get sharpness value"},
165};
166
167const EXP_METERING_TBL_T exp_metering_tbl[] = {
168  {   AUTO_EXP_FRAME_AVG,          "Exposure Metering - Frame Average"},
169  {   AUTO_EXP_CENTER_WEIGHTED,    "Exposure Metering - Center Weighted"},
170  {   AUTO_EXP_SPOT_METERING,      "Exposure Metering - Spot Metering"},
171  {   AUTO_EXP_SMART_METERING,     "Exposure Metering - Smart Metering"},
172  {   AUTO_EXP_USER_METERING,      "Exposure Metering - User Metering"},
173  {   AUTO_EXP_SPOT_METERING_ADV,  "Exposure Metering - Spot Metering Adv"},
174  {   AUTO_EXP_CENTER_WEIGHTED_ADV,"Exposure Metering - Center Weighted Adv"},
175};
176
177const ISO_TBL_T iso_tbl[] = {
178  {   ISO_AUTO,   "ISO: Auto"},
179  {   ISO_DEBLUR, "ISO: Deblur"},
180  {   ISO_100,    "ISO: 100"},
181  {   ISO_200,    "ISO: 200"},
182  {   ISO_400,    "ISO: 400"},
183  {   ISO_800,    "ISO: 800"},
184  {   ISO_1600,   "ISO: 1600"},
185};
186
187const ZOOM_TBL_T zoom_tbl[] = {
188  {   ZOOM_IN,  "Zoom In one step"},
189  {   ZOOM_OUT, "Zoom Out one step"},
190};
191
192const BESTSHOT_MODE_TBT_T bestshot_mode_tbl[] = {
193  {BESTSHOT_AUTO,           "Bestshot Mode: Auto"},
194  {BESTSHOT_ACTION,         "Bestshot Mode: Action"},
195  {BESTSHOT_PORTRAIT,       "Bestshot Mode: Portrait"},
196  {BESTSHOT_LANDSCAPE,      "Bestshot Mode: Landscape"},
197  {BESTSHOT_NIGHT,          "Bestshot Mode: Night"},
198  {BESTSHOT_NIGHT_PORTRAIT, "Bestshot Mode: Night Portrait"},
199  {BESTSHOT_THEATRE,        "Bestshot Mode: Theatre"},
200  {BESTSHOT_BEACH,          "Bestshot Mode: Beach"},
201  {BESTSHOT_SNOW,           "Bestshot Mode: Snow"},
202  {BESTSHOT_SUNSET,         "Bestshot Mode: Sunset"},
203  {BESTSHOT_ANTISHAKE,      "Bestshot Mode: Antishake"},
204  {BESTSHOT_FIREWORKS,      "Bestshot Mode: Fireworks"},
205  {BESTSHOT_SPORTS,         "Bestshot Mode: Sports"},
206  {BESTSHOT_PARTY,          "Bestshot Mode: Party"},
207  {BESTSHOT_CANDLELIGHT,    "Bestshot Mode: Candlelight"},
208  {BESTSHOT_ASD,            "Bestshot Mode: ASD"},
209  {BESTSHOT_BACKLIGHT,      "Bestshot Mode: Backlight"},
210  {BESTSHOT_FLOWERS,        "Bestshot Mode: Flowers"},
211  {BESTSHOT_AR,             "Bestshot Mode: Augmented Reality"},
212  {BESTSHOT_HDR,            "Bestshot Mode: HDR"},
213};
214
215const FLASH_MODE_TBL_T flashmodes_tbl[] = {
216  {   FLASH_MODE_OFF,   "Flash Mode Off"},
217  {   FLASH_MODE_AUTO,  "Flash Mode Auto"},
218  {   FLASH_MODE_ON,    "Flash Mode On"},
219  {   FLASH_MODE_TORCH, "Flash Mode Torch"},
220};
221
222DIMENSION_TBL_T dimension_tbl[] = {
223{VGA_WIDTH,      VGA_HEIGHT,      "VGA",   "Size: VGA <640x480>"   , 0},
224{MP1_WIDTH,      MP1_HEIGHT,      "1MP",   "Size: 1MP <1280x960>"  , 0},
225{MP5_WIDTH,      MP5_HEIGHT,      "5MP",   "Size: 5MP <2592x1944>",  0},
226{MP8_WIDTH,      MP8_HEIGHT,      "8MP",   "Size: 8MP <3264x2448>",  0},
227{MP12_WIDTH,     MP12_HEIGHT,     "12MP",  "Size: 12MP <4000x3000>", 0},
228};
229
230/*===========================================================================
231 * Forward declarations
232 *===========================================================================*/
233//static void system_dimension_set(mm_camera_test_obj_t *test_obj);
234/*===========================================================================
235 * Static global variables
236 *===========================================================================*/
237USER_INPUT_DISPLAY_T input_display;
238int preview_video_resolution_flag = 0;
239
240//TODO: default values.
241#if 1
242int brightness = CAMERA_DEF_BRIGHTNESS;
243int contrast = CAMERA_DEF_CONTRAST;
244int saturation = CAMERA_DEF_SATURATION;
245int sharpness = CAMERA_DEF_SHARPNESS;
246#else
247int brightness = 0;
248int contrast = 0;
249int saturation = 0;
250int sharpness = 0;
251#endif
252//TODO: find new method to calculate ev.
253//int32_t ev_numerator = EXPOSURE_COMPENSATION_DEFAULT_NUMERATOR;
254
255//TODO:
256//fps_mode_t fps_mode = FPS_MODE_FIXED;
257int zoom_level;
258int zoom_max_value;
259int cam_id;
260int is_rec = 0;
261
262
263static int submain();
264
265/*===========================================================================
266 * FUNCTION    - keypress_to_event -
267 *
268 * DESCRIPTION:
269 *==========================================================================*/
270int keypress_to_event(char keypress)
271{
272  int out_buf = INVALID_KEY_PRESS;
273  if ((keypress >= 'A' && keypress <= 'Z') ||
274    (keypress >= 'a' && keypress <= 'z')) {
275    out_buf = tolower(keypress);
276    out_buf = out_buf - 'a';
277  } else if (keypress >= '0' && keypress <= '9') {
278    out_buf = keypress - '0';
279  }
280  return out_buf;
281}
282
283int next_menu(menu_id_change_t current_menu_id, char keypress, camera_action_t * action_id_ptr, int * action_param)
284{
285  int output_to_event;
286  menu_id_change_t next_menu_id = MENU_ID_INVALID;
287  * action_id_ptr = ACTION_NO_ACTION;
288
289  output_to_event = keypress_to_event(keypress);
290  LOGD("current_menu_id=%d\n",current_menu_id);
291  printf("output_to_event=%d\n",output_to_event);
292  switch(current_menu_id) {
293    case MENU_ID_MAIN:
294      switch(output_to_event) {
295        case START_PREVIEW:
296          * action_id_ptr = ACTION_START_PREVIEW;
297          LOGD("START_PREVIEW\n");
298          break;
299        case STOP_PREVIEW:
300          * action_id_ptr = ACTION_STOP_PREVIEW;
301          LOGD("STOP_PREVIEW\n");
302          break;
303
304        case SET_WHITE_BALANCE:
305          next_menu_id = MENU_ID_WHITEBALANCECHANGE;
306          LOGD("next_menu_id = MENU_ID_WHITEBALANCECHANGE = %d\n", next_menu_id);
307          break;
308
309        case SET_TINTLESS_ENABLE:
310          * action_id_ptr = ACTION_SET_TINTLESS_ENABLE;
311          next_menu_id = MENU_ID_MAIN;
312          LOGD("next_menu_id = MENU_ID_TINTLESSENABLE = %d\n", next_menu_id);
313          break;
314
315        case SET_TINTLESS_DISABLE:
316          * action_id_ptr = ACTION_SET_TINTLESS_DISABLE;
317          next_menu_id = MENU_ID_MAIN;
318          LOGD("next_menu_id = MENU_ID_TINTLESSDISABLE = %d\n", next_menu_id);
319          break;
320
321        case SET_EXP_METERING:
322          next_menu_id = MENU_ID_EXPMETERINGCHANGE;
323          LOGD("next_menu_id = MENU_ID_EXPMETERINGCHANGE = %d\n", next_menu_id);
324          break;
325
326        case GET_CTRL_VALUE:
327          next_menu_id = MENU_ID_GET_CTRL_VALUE;
328          LOGD("next_menu_id = MENU_ID_GET_CTRL_VALUE = %d\n", next_menu_id);
329          break;
330
331        case BRIGHTNESS_GOTO_SUBMENU:
332          next_menu_id = MENU_ID_BRIGHTNESSCHANGE;
333          LOGD("next_menu_id = MENU_ID_BRIGHTNESSCHANGE = %d\n", next_menu_id);
334          break;
335
336        case CONTRAST_GOTO_SUBMENU:
337          next_menu_id = MENU_ID_CONTRASTCHANGE;
338          break;
339
340        case EV_GOTO_SUBMENU:
341          next_menu_id = MENU_ID_EVCHANGE;
342          break;
343
344        case SATURATION_GOTO_SUBMENU:
345          next_menu_id = MENU_ID_SATURATIONCHANGE;
346          break;
347
348        case TOGGLE_AFR:
349          * action_id_ptr = ACTION_TOGGLE_AFR;
350          LOGD("next_menu_id = MENU_ID_TOGGLEAFR = %d\n", next_menu_id);
351          break;
352
353        case SET_ISO:
354          next_menu_id = MENU_ID_ISOCHANGE;
355          LOGD("next_menu_id = MENU_ID_ISOCHANGE = %d\n", next_menu_id);
356          break;
357
358        case SET_ZOOM:
359          next_menu_id = MENU_ID_ZOOMCHANGE;
360          LOGD("next_menu_id = MENU_ID_ZOOMCHANGE = %d\n", next_menu_id);
361          break;
362
363        case BEST_SHOT:
364          next_menu_id = MENU_ID_BESTSHOT;
365          LOGD("next_menu_id = MENU_ID_BESTSHOT = %d\n", next_menu_id);
366          break;
367
368        case LIVE_SHOT:
369          * action_id_ptr = ACTION_TAKE_LIVE_SNAPSHOT;
370          LOGD("\nTaking Live snapshot\n");
371          break;
372
373        case FLASH_MODES:
374          next_menu_id = MENU_ID_FLASHMODE;
375          LOGD("next_menu_id = MENU_ID_FLASHMODE = %d\n", next_menu_id);
376          break;
377
378        case SET_SHARPNESS:
379          next_menu_id = MENU_ID_SHARPNESSCHANGE;
380          LOGD("next_menu_id = MENU_ID_SHARPNESSCHANGE = %d\n", next_menu_id);
381          break;
382
383        case SWITCH_SNAP_RESOLUTION:
384          next_menu_id = MENU_ID_SWITCH_RES;
385          LOGD("next_menu_id = MENU_ID_SWITCH_RES = %d\n", next_menu_id);
386          break;
387
388        case TAKE_JPEG_SNAPSHOT:
389          * action_id_ptr = ACTION_TAKE_JPEG_SNAPSHOT;
390          printf("\n Taking JPEG snapshot\n");
391          break;
392
393        case START_RECORDING:
394          * action_id_ptr = ACTION_START_RECORDING;
395          LOGD("Start recording\n");
396          break;
397        case STOP_RECORDING:
398          * action_id_ptr = ACTION_STOP_RECORDING;
399          LOGD("Stop recording\n");
400          break;
401        case TOGGLE_ZSL:
402          * action_id_ptr = ACTION_TOGGLE_ZSL;
403          LOGD("Toggle ZSL\n");
404          break;
405        case TAKE_RAW_SNAPSHOT:
406            * action_id_ptr = ACTION_TAKE_RAW_SNAPSHOT;
407            next_menu_id = MENU_ID_MAIN;
408            LOGD("Capture RAW\n");
409            break;
410        case TOGGLE_WNR:
411            * action_id_ptr = ACTION_TOGGLE_WNR;
412            next_menu_id = MENU_ID_MAIN;
413            LOGD("Toggle WNR");
414            break;
415        case EXIT:
416          * action_id_ptr = ACTION_EXIT;
417          LOGD("Exit \n");
418          break;
419        default:
420          next_menu_id = MENU_ID_MAIN;
421          LOGD("next_menu_id = MENU_ID_MAIN = %d\n", next_menu_id);
422          break;
423      }
424      break;
425
426    case MENU_ID_SWITCH_RES:
427        printf("MENU_ID_SWITCH_RES\n");
428        *action_id_ptr = ACTION_SWITCH_RESOLUTION;
429        *action_param = output_to_event;
430        int available_sizes = sizeof(dimension_tbl)/sizeof(dimension_tbl[0]);
431        if ( ( *action_param >= 0 ) &&
432             ( *action_param < available_sizes ) &&
433             ( dimension_tbl[*action_param].supported )) {
434            next_menu_id = MENU_ID_MAIN;
435        }
436        else {
437          next_menu_id = current_menu_id;
438        }
439        break;
440
441    case MENU_ID_SENSORS:
442        next_menu_id = MENU_ID_MAIN;
443        *action_id_ptr = ACTION_SWITCH_CAMERA;
444        *action_param = output_to_event;
445        break;
446
447    case MENU_ID_WHITEBALANCECHANGE:
448      printf("MENU_ID_WHITEBALANCECHANGE\n");
449      if (output_to_event >= WB_MAX) {
450        next_menu_id = current_menu_id;
451        * action_id_ptr = ACTION_NO_ACTION;
452      } else {
453        next_menu_id = MENU_ID_MAIN;
454        * action_id_ptr = ACTION_SET_WHITE_BALANCE;
455        * action_param = output_to_event;
456      }
457      break;
458
459    case MENU_ID_EXPMETERINGCHANGE:
460      printf("MENU_ID_EXPMETERINGCHANGE\n");
461      if (output_to_event >= AUTO_EXP_MAX) {
462        next_menu_id = current_menu_id;
463        * action_id_ptr = ACTION_NO_ACTION;
464      } else {
465        next_menu_id = MENU_ID_MAIN;
466        * action_id_ptr = ACTION_SET_EXP_METERING;
467        * action_param = output_to_event;
468      }
469      break;
470
471    case MENU_ID_GET_CTRL_VALUE:
472      printf("MENU_ID_GET_CTRL_VALUE\n");
473      * action_id_ptr = ACTION_GET_CTRL_VALUE;
474      if (output_to_event > 0 &&
475        output_to_event <= (int)(sizeof(get_ctrl_tbl)/sizeof(get_ctrl_tbl[0]))) {
476          next_menu_id = MENU_ID_MAIN;
477          * action_param = output_to_event;
478      }
479      else {
480        next_menu_id = current_menu_id;
481      }
482      break;
483
484    case MENU_ID_BRIGHTNESSCHANGE:
485      switch (output_to_event) {
486        case INC_BRIGHTNESS:
487          * action_id_ptr = ACTION_BRIGHTNESS_INCREASE;
488          next_menu_id = MENU_ID_MAIN;
489          break;
490
491        case DEC_BRIGHTNESS:
492          * action_id_ptr = ACTION_BRIGHTNESS_DECREASE;
493          next_menu_id = MENU_ID_MAIN;
494          break;
495
496        default:
497          next_menu_id = MENU_ID_BRIGHTNESSCHANGE;
498          break;
499      }
500      break;
501
502    case MENU_ID_CONTRASTCHANGE:
503      switch (output_to_event) {
504        case INC_CONTRAST:
505          * action_id_ptr = ACTION_CONTRAST_INCREASE;
506          next_menu_id = MENU_ID_MAIN;
507          break;
508
509        case DEC_CONTRAST:
510          * action_id_ptr = ACTION_CONTRAST_DECREASE;
511          next_menu_id = MENU_ID_MAIN;
512          break;
513
514        default:
515          next_menu_id = MENU_ID_CONTRASTCHANGE;
516          break;
517      }
518      break;
519
520    case MENU_ID_EVCHANGE:
521      switch (output_to_event) {
522        case INCREASE_EV:
523          * action_id_ptr = ACTION_EV_INCREASE;
524          next_menu_id = MENU_ID_MAIN;
525          break;
526
527        case DECREASE_EV:
528          * action_id_ptr = ACTION_EV_DECREASE;
529          next_menu_id = MENU_ID_MAIN;
530          break;
531
532        default:
533          next_menu_id = MENU_ID_EVCHANGE;
534          break;
535      }
536      break;
537
538    case MENU_ID_SATURATIONCHANGE:
539      switch (output_to_event) {
540        case INC_SATURATION:
541          * action_id_ptr = ACTION_SATURATION_INCREASE;
542          next_menu_id = MENU_ID_MAIN;
543          break;
544
545        case DEC_SATURATION:
546          * action_id_ptr = ACTION_SATURATION_DECREASE;
547          next_menu_id = MENU_ID_MAIN;
548          break;
549
550        default:
551          next_menu_id = MENU_ID_EVCHANGE;
552          break;
553      }
554      break;
555
556    case MENU_ID_ISOCHANGE:
557      printf("MENU_ID_ISOCHANGE\n");
558      if (output_to_event >= ISO_MAX) {
559        next_menu_id = current_menu_id;
560        * action_id_ptr = ACTION_NO_ACTION;
561      } else {
562        next_menu_id = MENU_ID_MAIN;
563        * action_id_ptr = ACTION_SET_ISO;
564        * action_param = output_to_event;
565      }
566      break;
567
568    case MENU_ID_ZOOMCHANGE:
569      * action_id_ptr = ACTION_SET_ZOOM;
570      if (output_to_event > 0 &&
571        output_to_event <= (int)(sizeof(zoom_tbl)/sizeof(zoom_tbl[0]))) {
572          next_menu_id = MENU_ID_MAIN;
573          * action_param = output_to_event;
574      } else {
575        next_menu_id = current_menu_id;
576      }
577      break;
578
579    case MENU_ID_SHARPNESSCHANGE:
580      switch (output_to_event) {
581        case INC_SHARPNESS:
582          * action_id_ptr = ACTION_SHARPNESS_INCREASE;
583          next_menu_id = MENU_ID_MAIN;
584          break;
585        case DEC_SHARPNESS:
586          * action_id_ptr = ACTION_SHARPNESS_DECREASE;
587          next_menu_id = MENU_ID_MAIN;
588          break;
589        default:
590          next_menu_id = MENU_ID_SHARPNESSCHANGE;
591          break;
592      }
593      break;
594
595    case MENU_ID_BESTSHOT:
596      if (output_to_event >= BESTSHOT_MAX) {
597        next_menu_id = current_menu_id;
598        * action_id_ptr = ACTION_NO_ACTION;
599      } else {
600        next_menu_id = MENU_ID_MAIN;
601        * action_id_ptr = ACTION_SET_BESTSHOT_MODE;
602        * action_param = output_to_event;
603      }
604      break;
605
606    case MENU_ID_FLASHMODE:
607      if (output_to_event >= FLASH_MODE_MAX) {
608        next_menu_id = current_menu_id;
609        * action_id_ptr = ACTION_NO_ACTION;
610      } else {
611        next_menu_id = MENU_ID_MAIN;
612        * action_id_ptr = ACTION_SET_FLASH_MODE;
613        * action_param = output_to_event;
614      }
615      break;
616
617    default:
618      LOGD("menu id is wrong: %d\n", current_menu_id);
619      break;
620  }
621
622  return next_menu_id;
623}
624
625/*===========================================================================
626 * FUNCTION    - print_menu_preview_video -
627 *
628 * DESCRIPTION:
629 * ===========================================================================*/
630static void print_menu_preview_video(void) {
631  unsigned int i;
632  if (!is_rec) {
633    printf("\n");
634    printf("===========================================\n");
635    printf("      Camera is in preview/video mode now        \n");
636    printf("===========================================\n\n");
637  } else {
638    printf("\n");
639    printf("===========================================\n");
640    printf("      Camera is in RECORDING mode now       \n");
641    printf("        Press 'Q' To Stop Recording          \n");
642    printf("        Press 'S' To Take Live Snapshot       \n");
643    printf("===========================================\n\n");
644  }
645  char menuNum = 'A';
646  for (i = 0; i < sizeof(camera_main_menu_tbl)/sizeof(camera_main_menu_tbl[0]); i++) {
647    if (i == BASE_OFFSET) {
648      menuNum = '1';
649    }
650
651    printf("%c.  %s\n", menuNum, camera_main_menu_tbl[i].menu_name);
652    menuNum++;
653  }
654
655  printf("\nPlease enter your choice: ");
656
657  return;
658}
659
660static void camera_preview_video_wb_change_tbl(void) {
661  unsigned int i;
662  printf("\n");
663  printf("==========================================================\n");
664  printf("      Camera is in white balance change mode       \n");
665  printf("==========================================================\n\n");
666
667  char submenuNum = 'A';
668  for (i = 0 ; i < sizeof(white_balance_tbl) /
669                   sizeof(white_balance_tbl[0]); i++) {
670        printf("%c.  %s\n", submenuNum, white_balance_tbl[i].wb_name);
671        submenuNum++;
672  }
673  printf("\nPlease enter your choice for White Balance modes: ");
674  return;
675}
676
677static void camera_preview_video_get_ctrl_value_tbl(void) {
678  unsigned int i;
679  printf("\n");
680  printf("==========================================================\n");
681  printf("      Camera is in get control value mode       \n");
682  printf("==========================================================\n\n");
683
684  char submenuNum = 'A';
685  for (i = 0 ; i < sizeof(get_ctrl_tbl) /
686                   sizeof(get_ctrl_tbl[0]); i++) {
687        printf("%c.  %s\n", submenuNum, get_ctrl_tbl[i].get_ctrl_name);
688        submenuNum++;
689  }
690  printf("\nPlease enter your choice for control value you want to get: ");
691  return;
692}
693
694static void camera_preview_video_exp_metering_change_tbl(void) {
695  unsigned int i;
696  printf("\n");
697  printf("==========================================================\n");
698  printf("      Camera is in exposure metering change mode       \n");
699  printf("==========================================================\n\n");
700
701  char submenuNum = 'A';
702  for (i = 0 ; i < sizeof(exp_metering_tbl) /
703                   sizeof(exp_metering_tbl[0]); i++) {
704        printf("%c.  %s\n", submenuNum, exp_metering_tbl[i].exp_metering_name);
705        submenuNum++;
706  }
707  printf("\nPlease enter your choice for exposure metering modes: ");
708  return;
709}
710
711static void camera_contrast_change_tbl(void) {
712    unsigned int i;
713
714    printf("\n");
715    printf("==========================================================\n");
716    printf("      Camera is in change contrast resolution mode       \n");
717    printf("==========================================================\n\n");
718
719    char contrastmenuNum = 'A';
720    for (i = 0; i < sizeof(contrast_change_tbl) /
721                    sizeof(contrast_change_tbl[0]); i++) {
722        printf("%c.  %s\n", contrastmenuNum,
723                            contrast_change_tbl[i].contrast_name);
724        contrastmenuNum++;
725    }
726
727    printf("\nPlease enter your choice for contrast Change: ");
728    return;
729}
730
731static void camera_EV_change_tbl(void) {
732  unsigned int i;
733
734  printf("\n");
735  printf("===========================================\n");
736  printf("      Camera is in EV change mode now       \n");
737  printf("===========================================\n\n");
738
739  char submenuNum = 'A';
740  for (i = 0; i < sizeof(camera_EV_tbl)/sizeof(camera_EV_tbl[0]); i++) {
741    printf("%c.  %s\n", submenuNum, camera_EV_tbl[i].EV_name);
742    submenuNum++;
743  }
744
745  printf("\nPlease enter your choice for EV changes: ");
746  return;
747}
748
749static void camera_resolution_change_tbl(void) {
750    unsigned int i;
751
752    printf("\n");
753    printf("==========================================================\n");
754    printf("      Camera is in snapshot resolution mode               \n");
755    printf("==========================================================\n\n");
756
757    for (i = 0; i < sizeof(dimension_tbl) /
758      sizeof(dimension_tbl[0]); i++) {
759        if ( dimension_tbl[i].supported ) {
760            printf("%d.  %s\n", i,
761                    dimension_tbl[i].str_name);
762        }
763    }
764
765    printf("\nPlease enter your choice for Resolution: ");
766    return;
767}
768
769static void camera_preview_video_zoom_change_tbl(void) {
770    unsigned int i;
771    zoom_max_value = MAX_ZOOMS_CNT;
772    printf("\nCurrent Zoom Value = %d ,Max Zoom Value = %d\n",zoom_level,zoom_max_value);
773    char submenuNum = 'A';
774    for (i = 0 ; i < sizeof(zoom_tbl) /
775                   sizeof(zoom_tbl[0]); i++) {
776        printf("%c.  %s\n", submenuNum, zoom_tbl[i].zoom_direction_name);
777        submenuNum++;
778    }
779    printf("\nPlease enter your choice for zoom change direction: ");
780    return;
781}
782
783static void camera_brightness_change_tbl(void) {
784    unsigned int i;
785
786    printf("\n");
787    printf("==========================================================\n");
788    printf("      Camera is in change brightness mode       \n");
789    printf("==========================================================\n\n");
790
791    char brightnessmenuNum = 'A';
792    for (i = 0; i < sizeof(brightness_change_tbl) /
793                    sizeof(brightness_change_tbl[0]); i++) {
794        printf("%c.  %s\n", brightnessmenuNum,
795                            brightness_change_tbl[i].brightness_name);
796        brightnessmenuNum++;
797    }
798
799    printf("\nPlease enter your choice for Brightness Change: ");
800    return;
801}
802
803static void camera_saturation_change_tbl(void) {
804    unsigned int i;
805
806    printf("\n");
807    printf("==========================================================\n");
808    printf("      Camera is in change saturation mode       \n");
809    printf("==========================================================\n\n");
810
811    char saturationmenuNum = 'A';
812    for (i = 0; i < sizeof(camera_saturation_tbl) /
813                    sizeof(camera_saturation_tbl[0]); i++) {
814        printf("%c.  %s\n", saturationmenuNum,
815                            camera_saturation_tbl[i].saturation_name);
816        saturationmenuNum++;
817    }
818
819    printf("\nPlease enter your choice for Saturation Change: ");
820    return;
821}
822
823static void camera_preview_video_iso_change_tbl(void) {
824  unsigned int i;
825  printf("\n");
826  printf("==========================================================\n");
827  printf("      Camera is in ISO change mode       \n");
828  printf("==========================================================\n\n");
829
830  char submenuNum = 'A';
831  for (i = 0 ; i < sizeof(iso_tbl) /
832                   sizeof(iso_tbl[0]); i++) {
833        printf("%c.  %s\n", submenuNum, iso_tbl[i].iso_modes_name);
834        submenuNum++;
835  }
836  printf("\nPlease enter your choice for iso modes: ");
837  return;
838}
839
840static void camera_preview_video_sharpness_change_tbl(void) {
841  unsigned int i;
842  printf("\n");
843  printf("==========================================================\n");
844  printf("      Camera is in sharpness change mode       \n");
845  printf("==========================================================\n\n");
846
847  char submenuNum = 'A';
848  for (i = 0 ; i < sizeof(camera_sharpness_tbl) /
849                   sizeof(camera_sharpness_tbl[0]); i++) {
850        printf("%c.  %s\n", submenuNum, camera_sharpness_tbl[i].sharpness_name);
851        submenuNum++;
852  }
853  printf("\nPlease enter your choice for sharpness modes: ");
854  return;
855}
856
857static void camera_set_bestshot_tbl(void)
858{
859  unsigned int i;
860
861  printf("\n");
862  printf("===========================================\n");
863  printf("      Camera is in set besthot mode now       \n");
864  printf("===========================================\n\n");
865
866
867  char bsmenuNum = 'A';
868  for (i = 0; i < sizeof(bestshot_mode_tbl)/sizeof(bestshot_mode_tbl[0]); i++) {
869    printf("%c.  %s\n", bsmenuNum,
870      bestshot_mode_tbl[i].name);
871    bsmenuNum++;
872  }
873
874  printf("\nPlease enter your choice of Bestshot Mode: ");
875  return;
876}
877
878static void camera_set_flashmode_tbl(void)
879{
880  unsigned int i;
881
882  printf("\n");
883  printf("===========================================\n");
884  printf("      Camera is in set flash mode now       \n");
885  printf("===========================================\n\n");
886
887
888  char bsmenuNum = 'A';
889  for (i = 0; i < sizeof(flashmodes_tbl)/sizeof(flashmodes_tbl[0]); i++) {
890    printf("%c.  %s\n", bsmenuNum,
891      flashmodes_tbl[i].name);
892    bsmenuNum++;
893  }
894
895  printf("\nPlease enter your choice of Bestshot Mode: ");
896  return;
897}
898
899static void camera_sensors_tbl(void)
900{
901  unsigned int i;
902  size_t available_sensors = sizeof(sensor_tbl)/sizeof(sensor_tbl[0]);
903
904  printf("\n");
905  printf("===========================================\n");
906  printf("      Camera Sensor to be used:            \n");
907  printf("===========================================\n\n");
908
909
910  char bsmenuNum = 'A';
911  for (i = 0; ( i < available_sensors ) && ( sensor_tbl[i].present ) ; i++) {
912    printf("%c.  %s\n", bsmenuNum,
913            sensor_tbl[i].menu_name);
914    bsmenuNum++;
915  }
916
917  printf("\nPlease enter your choice for sensor: ");
918  return;
919}
920
921/*===========================================================================
922 * FUNCTION     - increase_contrast -
923 *
924 * DESCRIPTION:
925 * ===========================================================================*/
926int increase_contrast (mm_camera_lib_handle *lib_handle) {
927        contrast += CAMERA_CONTRAST_STEP;
928        if (contrast > CAMERA_MAX_CONTRAST) {
929                contrast = CAMERA_MAX_CONTRAST;
930                printf("Reached max CONTRAST. \n");
931        }
932        printf("Increase Contrast to %d\n", contrast);
933        return mm_camera_lib_send_command(lib_handle,
934                                          MM_CAMERA_LIB_CONTRAST,
935                                          &contrast,
936                                          NULL);
937}
938
939/*===========================================================================
940 * FUNCTION     - decrease_contrast -
941 *
942 * DESCRIPTION:
943 * ===========================================================================*/
944int decrease_contrast (mm_camera_lib_handle *lib_handle) {
945        contrast -= CAMERA_CONTRAST_STEP;
946        if (contrast < CAMERA_MIN_CONTRAST) {
947                contrast = CAMERA_MIN_CONTRAST;
948                printf("Reached min CONTRAST. \n");
949        }
950        printf("Decrease Contrast to %d\n", contrast);
951        return mm_camera_lib_send_command(lib_handle,
952                                          MM_CAMERA_LIB_CONTRAST,
953                                          &contrast,
954                                          NULL);
955}
956
957/*===========================================================================
958 * FUNCTION     - decrease_brightness -
959 *
960 * DESCRIPTION:
961 * ===========================================================================*/
962int decrease_brightness (mm_camera_lib_handle *lib_handle) {
963        brightness -= CAMERA_BRIGHTNESS_STEP;
964        if (brightness < CAMERA_MIN_BRIGHTNESS) {
965                brightness = CAMERA_MIN_BRIGHTNESS;
966                printf("Reached min BRIGHTNESS. \n");
967        }
968        printf("Decrease Brightness to %d\n", brightness);
969        return mm_camera_lib_send_command(lib_handle,
970                                          MM_CAMERA_LIB_BRIGHTNESS,
971                                          &brightness,
972                                          NULL);
973}
974
975/*===========================================================================
976 * FUNCTION     - increase_brightness -
977 *
978 * DESCRIPTION:
979 * ===========================================================================*/
980int increase_brightness (mm_camera_lib_handle *lib_handle) {
981        brightness += CAMERA_BRIGHTNESS_STEP;
982        if (brightness > CAMERA_MAX_BRIGHTNESS) {
983                brightness = CAMERA_MAX_BRIGHTNESS;
984                printf("Reached max BRIGHTNESS. \n");
985        }
986        printf("Increase Brightness to %d\n", brightness);
987        return mm_camera_lib_send_command(lib_handle,
988                                          MM_CAMERA_LIB_BRIGHTNESS,
989                                          &brightness,
990                                          NULL);
991}
992
993/*===========================================================================
994 * FUNCTION     - increase_EV -
995 *
996 * DESCRIPTION:
997 * ===========================================================================*/
998
999int increase_EV (void) {
1000#if 0
1001   int rc = 0;
1002   int32_t value = 0;
1003   rc = cam_config_is_parm_supported(cam_id, MM_CAMERA_PARM_EXPOSURE_COMPENSATION);
1004    if(!rc) {
1005       printf("MM_CAMERA_PARM_EXPOSURE_COMPENSATION mode is not supported for this sensor");
1006       return -1;
1007    }
1008    ev_numerator += 1;
1009    if(ev_numerator >= EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR &&
1010            ev_numerator <= EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR){
1011        int16_t  numerator16 = (int16_t)(ev_numerator & 0x0000ffff);
1012        uint16_t denominator16 = EXPOSURE_COMPENSATION_DENOMINATOR;
1013        value = numerator16 << 16 | denominator16;
1014    } else {
1015       printf("Reached max EV.\n");
1016    }
1017    return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_EXPOSURE_COMPENSATION, value);
1018#endif
1019  return 0;
1020}
1021
1022/*===========================================================================
1023 * FUNCTION     - decrease_EV -
1024 *
1025 * DESCRIPTION:
1026 * ===========================================================================*/
1027int decrease_EV (void) {
1028#if 0
1029   int rc = 0;
1030   int32_t  value = 0;
1031   rc = cam_config_is_parm_supported(cam_id, MM_CAMERA_PARM_EXPOSURE_COMPENSATION);
1032    if(!rc) {
1033       printf("MM_CAMERA_PARM_EXPOSURE_COMPENSATION mode is not supported for this sensor");
1034       return -1;
1035    }
1036    ev_numerator -= 1;
1037    if(ev_numerator >= EXPOSURE_COMPENSATION_MINIMUM_NUMERATOR &&
1038            ev_numerator <= EXPOSURE_COMPENSATION_MAXIMUM_NUMERATOR){
1039        int16_t  numerator16 = (int16_t)(ev_numerator & 0x0000ffff);
1040        uint16_t denominator16 = EXPOSURE_COMPENSATION_DENOMINATOR;
1041        value = numerator16 << 16 | denominator16;
1042    } else {
1043       printf("Reached min EV.\n");
1044    }
1045    return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_EXPOSURE_COMPENSATION, value);
1046#endif
1047  return 0;
1048}
1049
1050/*===========================================================================
1051 * FUNCTION     - increase_saturation -
1052 *
1053 * DESCRIPTION:
1054 * ===========================================================================*/
1055int increase_saturation (mm_camera_lib_handle *lib_handle) {
1056#if 0
1057  saturation += CAMERA_SATURATION_STEP;
1058  if (saturation > CAMERA_MAX_SATURATION) {
1059    saturation = CAMERA_MAX_SATURATION;
1060    printf("Reached max saturation. \n");
1061  }
1062  printf("Increase Saturation to %d\n", saturation);
1063  return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_SATURATION, saturation);
1064#endif
1065  saturation += CAMERA_SATURATION_STEP;
1066  if (saturation > CAMERA_MAX_SATURATION) {
1067    saturation = CAMERA_MAX_SATURATION;
1068    printf("Reached max saturation. \n");
1069  }
1070  printf("Increase saturation to %d\n", contrast);
1071  return mm_camera_lib_send_command(lib_handle,
1072                                       MM_CAMERA_LIB_SATURATION,
1073                                       &saturation,
1074                                       NULL);
1075}
1076
1077/*===========================================================================
1078 * FUNCTION     - decrease_saturation -
1079 *
1080 * DESCRIPTION:
1081 * ===========================================================================*/
1082int decrease_saturation (mm_camera_lib_handle *lib_handle) {
1083#if 0
1084  saturation -= CAMERA_SATURATION_STEP;
1085  if (saturation < CAMERA_MIN_SATURATION) {
1086    saturation = CAMERA_MIN_SATURATION;
1087    printf("Reached min saturation. \n");
1088  }
1089  printf("Dcrease Saturation to %d\n", saturation);
1090  return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_SATURATION, saturation);
1091#endif
1092  saturation -= CAMERA_SATURATION_STEP;
1093  if (saturation < CAMERA_MIN_SATURATION) {
1094    saturation = CAMERA_MIN_SATURATION;
1095    printf("Reached min saturation. \n");
1096  }
1097  printf("decrease saturation to %d\n", contrast);
1098  return mm_camera_lib_send_command(lib_handle,
1099                                       MM_CAMERA_LIB_SATURATION,
1100                                       &saturation,
1101                                       NULL);
1102}
1103
1104
1105int take_jpeg_snapshot(mm_camera_test_obj_t *test_obj, int is_burst_mode)
1106{
1107  LOGH("\nEnter take_jpeg_snapshot!!\n");
1108  int rc = mm_app_take_picture (test_obj, (uint8_t)is_burst_mode);
1109  if (MM_CAMERA_OK != rc) {
1110    LOGE(" mm_app_take_picture() err=%d\n",  rc);
1111  }
1112  return rc;
1113}
1114
1115/*===========================================================================
1116 * FUNCTION    - main -
1117 *
1118 * DESCRIPTION:
1119 *==========================================================================*/
1120int main()
1121{
1122    char tc_buf[3];
1123    int mode = 0;
1124    int rc = 0;
1125
1126    printf("Please Select Execution Mode:\n");
1127    printf("0: Menu Based 1: Regression\n");
1128    fgets(tc_buf, 3, stdin);
1129    mode = tc_buf[0] - '0';
1130    if(mode == 0) {
1131      printf("\nStarting Menu based!!\n");
1132    } else if(mode == 1) {
1133      printf("Starting Regression testing!!\n");
1134      if(!mm_app_start_regression_test(1)) {
1135         printf("\nRegressiion test passed!!\n");
1136         return 0;
1137      } else {
1138        printf("\nRegression test failed!!\n");
1139        exit(-1);
1140      }
1141    } else {
1142       printf("\nPlease Enter 0 or 1\n");
1143       printf("\nExisting the App!!\n");
1144       exit(-1);
1145    }
1146
1147
1148    rc = submain();
1149
1150    printf("Exiting application\n");
1151
1152    return rc;
1153}
1154
1155/*===========================================================================
1156 * FUNCTION     - set_whitebalance -
1157 *
1158 * DESCRIPTION:
1159 * ===========================================================================*/
1160int set_whitebalance (mm_camera_lib_handle *lib_handle, int wb_action_param) {
1161        cam_wb_mode_type type = 0;
1162        switch (wb_action_param) {
1163                case WB_AUTO:
1164                        printf("\n WB_AUTO\n");
1165                        type = CAM_WB_MODE_AUTO;
1166                        break;
1167                case WB_INCANDESCENT:
1168                        printf("\n WB_INCANDESCENT\n");
1169                        type = CAM_WB_MODE_INCANDESCENT;
1170                        break;
1171                case WB_FLUORESCENT:
1172                        printf("\n WB_FLUORESCENT\n");
1173                        type = CAM_WB_MODE_FLUORESCENT;
1174                        break;
1175                case WB_WARM_FLUORESCENT:
1176                        printf("\n WB_WARM_FLUORESCENT\n");
1177                        type = CAM_WB_MODE_WARM_FLUORESCENT;
1178                        break;
1179                case WB_DAYLIGHT:
1180                        printf("\n WB_DAYLIGHT\n");
1181                        type = CAM_WB_MODE_DAYLIGHT;
1182                        break;
1183                case WB_CLOUDY_DAYLIGHT:
1184                        printf("\n WB_CLOUDY_DAYLIGHT\n");
1185                        type = CAM_WB_MODE_CLOUDY_DAYLIGHT;
1186                        break;
1187               case WB_TWILIGHT:
1188                        printf("\n WB_TWILIGHT\n");
1189                        type = CAM_WB_MODE_TWILIGHT;
1190                        break;
1191               case WB_SHADE:
1192                        printf("\n WB_SHADE\n");
1193                        type = CAM_WB_MODE_SHADE;
1194                        break;
1195                default:
1196                        break;
1197        }
1198        return mm_camera_lib_send_command(lib_handle,
1199                                          MM_CAMERA_LIB_WB,
1200                                          &type,
1201                                          NULL);
1202}
1203
1204
1205/*===========================================================================
1206 * FUNCTION     - set_exp_metering -
1207 *
1208 * DESCRIPTION:
1209 * ===========================================================================*/
1210int set_exp_metering (mm_camera_lib_handle *lib_handle, int exp_metering_action_param) {
1211        cam_auto_exposure_mode_type type = 0;
1212        switch (exp_metering_action_param) {
1213		case AUTO_EXP_FRAME_AVG:
1214                        printf("\nAUTO_EXP_FRAME_AVG\n");
1215                        type = CAM_AEC_MODE_FRAME_AVERAGE;
1216                        break;
1217                case AUTO_EXP_CENTER_WEIGHTED:
1218                        printf("\n AUTO_EXP_CENTER_WEIGHTED\n");
1219                        type = CAM_AEC_MODE_CENTER_WEIGHTED;
1220                        break;
1221                case AUTO_EXP_SPOT_METERING:
1222                        printf("\n AUTO_EXP_SPOT_METERING\n");
1223                        type = CAM_AEC_MODE_SPOT_METERING;
1224                        break;
1225                case AUTO_EXP_SMART_METERING:
1226                        printf("\n AUTO_EXP_SMART_METERING\n");
1227                        type = CAM_AEC_MODE_SMART_METERING;
1228                        break;
1229                case AUTO_EXP_USER_METERING:
1230                        printf("\n AUTO_EXP_USER_METERING\n");
1231                        type = CAM_AEC_MODE_USER_METERING;
1232                        break;
1233                case AUTO_EXP_SPOT_METERING_ADV:
1234                        printf("\n AUTO_EXP_SPOT_METERING_ADV\n");
1235                        type = CAM_AEC_MODE_SPOT_METERING_ADV;
1236                        break;
1237                case AUTO_EXP_CENTER_WEIGHTED_ADV:
1238                        printf("\n AUTO_EXP_CENTER_WEIGHTED_ADV\n");
1239                        type = CAM_AEC_MODE_CENTER_WEIGHTED_ADV;
1240                        break;
1241                default:
1242                        break;
1243        }
1244        return mm_camera_lib_send_command(lib_handle,
1245                                          MM_CAMERA_LIB_EXPOSURE_METERING,
1246                                          &type,
1247                                          NULL);
1248}
1249
1250int get_ctrl_value (int ctrl_value_mode_param){
1251#if 0
1252    int rc = 0;
1253    struct v4l2_control ctrl;
1254
1255    if (ctrl_value_mode_param == WHITE_BALANCE_STATE) {
1256        printf("You chose WHITE_BALANCE_STATE\n");
1257        ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
1258    }
1259    else if (ctrl_value_mode_param == WHITE_BALANCE_TEMPERATURE) {
1260        printf("You chose WHITE_BALANCE_TEMPERATURE\n");
1261        ctrl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
1262    }
1263    else if (ctrl_value_mode_param == BRIGHTNESS_CTRL) {
1264        printf("You chose brightness value\n");
1265        ctrl.id = V4L2_CID_BRIGHTNESS;
1266    }
1267    else if (ctrl_value_mode_param == EV) {
1268        printf("You chose exposure value\n");
1269        ctrl.id = V4L2_CID_EXPOSURE;
1270    }
1271    else if (ctrl_value_mode_param == CONTRAST_CTRL) {
1272        printf("You chose contrast value\n");
1273        ctrl.id = V4L2_CID_CONTRAST;
1274    }
1275    else if (ctrl_value_mode_param == SATURATION_CTRL) {
1276        printf("You chose saturation value\n");
1277        ctrl.id = V4L2_CID_SATURATION;
1278    } else if (ctrl_value_mode_param == SHARPNESS_CTRL) {
1279        printf("You chose sharpness value\n");
1280        ctrl.id = V4L2_CID_SHARPNESS;
1281    }
1282
1283  //  rc = ioctl(camfd, VIDIOC_G_CTRL, &ctrl);
1284    return rc;
1285#endif
1286  return ctrl_value_mode_param;
1287}
1288
1289/*===========================================================================
1290 * FUNCTION     - toggle_afr -
1291 *
1292 * DESCRIPTION:
1293 * ===========================================================================*/
1294int toggle_afr () {
1295#if 0
1296    if (fps_mode == FPS_MODE_AUTO) {
1297        printf("\nSetting FPS_MODE_FIXED\n");
1298        fps_mode = FPS_MODE_FIXED;
1299    } else {
1300        printf("\nSetting FPS_MODE_AUTO\n");
1301        fps_mode = FPS_MODE_AUTO;
1302    }
1303    return mm_app_set_config_parm(cam_id, MM_CAMERA_PARM_FPS_MODE, fps_mode);
1304#endif
1305  return 0;
1306}
1307
1308int set_zoom (mm_camera_lib_handle *lib_handle, int zoom_action_param) {
1309
1310    if (zoom_action_param == ZOOM_IN) {
1311        zoom_level += ZOOM_STEP;
1312        if (zoom_level > zoom_max_value)
1313            zoom_level = zoom_max_value;
1314    } else if (zoom_action_param == ZOOM_OUT) {
1315        zoom_level -= ZOOM_STEP;
1316        if (zoom_level < ZOOM_MIN_VALUE)
1317            zoom_level = ZOOM_MIN_VALUE;
1318    } else {
1319        LOGD(" Invalid zoom_action_param value\n");
1320        return -EINVAL;
1321    }
1322    return mm_camera_lib_send_command(lib_handle,
1323                                      MM_CAMERA_LIB_ZOOM,
1324                                      &zoom_level,
1325                                      NULL);
1326}
1327
1328/*===========================================================================
1329 * FUNCTION     - set_iso -
1330 *
1331 * DESCRIPTION:
1332 * ===========================================================================*/
1333int set_iso (mm_camera_lib_handle *lib_handle, int iso_action_param) {
1334    cam_iso_mode_type type = 0;
1335    switch (iso_action_param) {
1336        case ISO_AUTO:
1337            printf("\n ISO_AUTO\n");
1338            type = CAM_ISO_MODE_AUTO;
1339            break;
1340        case ISO_DEBLUR:
1341            printf("\n ISO_DEBLUR\n");
1342            type = CAM_ISO_MODE_DEBLUR;
1343            break;
1344        case ISO_100:
1345            printf("\n ISO_100\n");
1346            type = CAM_ISO_MODE_100;
1347            break;
1348        case ISO_200:
1349            printf("\n ISO_200\n");
1350            type = CAM_ISO_MODE_200;
1351            break;
1352        case ISO_400:
1353            printf("\n ISO_400\n");
1354            type = CAM_ISO_MODE_400;
1355            break;
1356        case ISO_800:
1357            printf("\n ISO_800\n");
1358            type = CAM_ISO_MODE_800;
1359            break;
1360        case ISO_1600:
1361            printf("\n ISO_1600\n");
1362            type = CAM_ISO_MODE_1600;
1363            break;
1364        default:
1365            break;
1366    }
1367    return mm_camera_lib_send_command(lib_handle,
1368                                      MM_CAMERA_LIB_ISO,
1369                                      &type,
1370                                      NULL);
1371}
1372
1373/*===========================================================================
1374 * FUNCTION     - increase_sharpness -
1375 *
1376 * DESCRIPTION:
1377 * ===========================================================================*/
1378int increase_sharpness (mm_camera_lib_handle *lib_handle) {
1379    sharpness += CAMERA_SHARPNESS_STEP;
1380    if (sharpness > CAMERA_MAX_SHARPNESS) {
1381        sharpness = CAMERA_MAX_SHARPNESS;
1382        printf("Reached max SHARPNESS. \n");
1383    }
1384    printf("Increase Sharpness to %d\n", sharpness);
1385    return mm_camera_lib_send_command(lib_handle,
1386                                      MM_CAMERA_LIB_SHARPNESS,
1387                                      &sharpness,
1388                                      NULL);
1389}
1390
1391/*===========================================================================
1392 * FUNCTION     - decrease_sharpness -
1393 *
1394 * DESCRIPTION:
1395 * ===========================================================================*/
1396int decrease_sharpness (mm_camera_lib_handle *lib_handle) {
1397    sharpness -= CAMERA_SHARPNESS_STEP;
1398    if (sharpness < CAMERA_MIN_SHARPNESS) {
1399        sharpness = CAMERA_MIN_SHARPNESS;
1400        printf("Reached min SHARPNESS. \n");
1401    }
1402    printf("Decrease Sharpness to %d\n", sharpness);
1403    return mm_camera_lib_send_command(lib_handle,
1404                                      MM_CAMERA_LIB_SHARPNESS,
1405                                      &sharpness,
1406                                      NULL);
1407}
1408
1409int set_flash_mode (mm_camera_lib_handle *lib_handle, int action_param) {
1410    cam_flash_mode_t type = 0;
1411    switch (action_param) {
1412        case FLASH_MODE_OFF:
1413            printf("\n FLASH_MODE_OFF\n");
1414            type = CAM_FLASH_MODE_OFF;
1415            break;
1416        case FLASH_MODE_AUTO:
1417            printf("\n FLASH_MODE_AUTO\n");
1418            type = CAM_FLASH_MODE_AUTO;
1419            break;
1420        case FLASH_MODE_ON:
1421            printf("\n FLASH_MODE_ON\n");
1422            type = CAM_FLASH_MODE_ON;
1423            break;
1424        case FLASH_MODE_TORCH:
1425            printf("\n FLASH_MODE_TORCH\n");
1426            type = CAM_FLASH_MODE_TORCH;
1427            break;
1428        default:
1429            break;
1430    }
1431    return mm_camera_lib_send_command(lib_handle,
1432                                      MM_CAMERA_LIB_FLASH,
1433                                      &type,
1434                                      NULL);
1435}
1436
1437int set_bestshot_mode(mm_camera_lib_handle *lib_handle, int action_param) {
1438    cam_scene_mode_type type = 0;
1439    switch (action_param) {
1440       case BESTSHOT_AUTO:
1441            printf("\n BEST SHOT AUTO\n");
1442            type = CAM_SCENE_MODE_OFF;
1443            break;
1444        case BESTSHOT_ACTION:
1445            printf("\n BEST SHOT ACTION\n");
1446            type = CAM_SCENE_MODE_ACTION;
1447            break;
1448        case BESTSHOT_PORTRAIT:
1449            printf("\n BEST SHOT PORTRAIT\n");
1450            type = CAM_SCENE_MODE_PORTRAIT;
1451            break;
1452        case BESTSHOT_LANDSCAPE:
1453            printf("\n BEST SHOT LANDSCAPE\n");
1454            type = CAM_SCENE_MODE_LANDSCAPE;
1455            break;
1456        case BESTSHOT_NIGHT:
1457            printf("\n BEST SHOT NIGHT\n");
1458            type = CAM_SCENE_MODE_NIGHT;
1459            break;
1460        case BESTSHOT_NIGHT_PORTRAIT:
1461            printf("\n BEST SHOT NIGHT PORTRAIT\n");
1462            type = CAM_SCENE_MODE_NIGHT_PORTRAIT;
1463            break;
1464        case BESTSHOT_THEATRE:
1465            printf("\n BEST SHOT THREATRE\n");
1466            type = CAM_SCENE_MODE_THEATRE;
1467            break;
1468        case BESTSHOT_BEACH:
1469            printf("\n BEST SHOT BEACH\n");
1470            type = CAM_SCENE_MODE_BEACH;
1471            break;
1472        case BESTSHOT_SNOW:
1473            printf("\n BEST SHOT SNOW\n");
1474            type = CAM_SCENE_MODE_SNOW;
1475            break;
1476        case BESTSHOT_SUNSET:
1477            printf("\n BEST SHOT SUNSET\n");
1478            type = CAM_SCENE_MODE_SUNSET;
1479            break;
1480        case BESTSHOT_ANTISHAKE:
1481            printf("\n BEST SHOT ANTISHAKE\n");
1482            type = CAM_SCENE_MODE_ANTISHAKE;
1483            break;
1484        case BESTSHOT_FIREWORKS:
1485            printf("\n BEST SHOT FIREWORKS\n");
1486            type = CAM_SCENE_MODE_FIREWORKS;
1487            break;
1488        case BESTSHOT_SPORTS:
1489            printf("\n BEST SHOT SPORTS\n");
1490            type = CAM_SCENE_MODE_SPORTS;
1491            break;
1492        case BESTSHOT_PARTY:
1493            printf("\n BEST SHOT PARTY\n");
1494            type = CAM_SCENE_MODE_PARTY;
1495            break;
1496        case BESTSHOT_CANDLELIGHT:
1497            printf("\n BEST SHOT CANDLELIGHT\n");
1498            type = CAM_SCENE_MODE_CANDLELIGHT;
1499            break;
1500        case BESTSHOT_ASD:
1501            printf("\n BEST SHOT ASD\n");
1502            type = CAM_SCENE_MODE_AUTO;
1503            break;
1504        case BESTSHOT_BACKLIGHT:
1505            printf("\n BEST SHOT BACKLIGHT\n");
1506            type = CAM_SCENE_MODE_BACKLIGHT;
1507            break;
1508        case BESTSHOT_FLOWERS:
1509            printf("\n BEST SHOT FLOWERS\n");
1510            type = CAM_SCENE_MODE_FLOWERS;
1511            break;
1512        case BESTSHOT_AR:
1513            printf("\n BEST SHOT AR\n");
1514            type = CAM_SCENE_MODE_AR;
1515            break;
1516        case BESTSHOT_HDR:
1517            printf("\n BEST SHOT HDR\n");
1518            type = CAM_SCENE_MODE_OFF;
1519            break;
1520        default:
1521            break;
1522        }
1523        return mm_camera_lib_send_command(lib_handle,
1524                                          MM_CAMERA_LIB_BESTSHOT,
1525                                          &type,
1526                                          NULL);
1527}
1528/*===========================================================================
1529 * FUNCTION     - print_current_menu -
1530 *
1531 * DESCRIPTION:
1532 * ===========================================================================*/
1533int print_current_menu (menu_id_change_t current_menu_id) {
1534  if (current_menu_id == MENU_ID_MAIN) {
1535    print_menu_preview_video ();
1536  } else if (current_menu_id == MENU_ID_WHITEBALANCECHANGE) {
1537    camera_preview_video_wb_change_tbl();
1538  } else if (current_menu_id == MENU_ID_EXPMETERINGCHANGE) {
1539    camera_preview_video_exp_metering_change_tbl();
1540  } else if (current_menu_id == MENU_ID_GET_CTRL_VALUE) {
1541    camera_preview_video_get_ctrl_value_tbl();
1542  } else if (current_menu_id == MENU_ID_ISOCHANGE) {
1543    camera_preview_video_iso_change_tbl();
1544  } else if (current_menu_id == MENU_ID_BRIGHTNESSCHANGE) {
1545    camera_brightness_change_tbl ();
1546  } else if (current_menu_id == MENU_ID_CONTRASTCHANGE) {
1547    camera_contrast_change_tbl ();
1548  } else if (current_menu_id == MENU_ID_EVCHANGE) {
1549    camera_EV_change_tbl ();
1550  } else if (current_menu_id == MENU_ID_SATURATIONCHANGE) {
1551    camera_saturation_change_tbl ();
1552  } else if (current_menu_id == MENU_ID_ZOOMCHANGE) {
1553    camera_preview_video_zoom_change_tbl();
1554  } else if (current_menu_id == MENU_ID_SHARPNESSCHANGE) {
1555    camera_preview_video_sharpness_change_tbl();
1556  } else if (current_menu_id == MENU_ID_BESTSHOT) {
1557    camera_set_bestshot_tbl();
1558  } else if (current_menu_id == MENU_ID_FLASHMODE) {
1559    camera_set_flashmode_tbl();
1560  } else if (current_menu_id == MENU_ID_SENSORS ) {
1561    camera_sensors_tbl();
1562  } else if (current_menu_id == MENU_ID_SWITCH_RES ) {
1563    camera_resolution_change_tbl();
1564  }
1565
1566  return 0;
1567}
1568
1569int filter_resolutions(mm_camera_lib_handle *lib_handle,
1570                       DIMENSION_TBL_T *tbl,
1571                       size_t tbl_size)
1572{
1573    size_t i, j;
1574    cam_capability_t camera_cap;
1575    int rc = 0;
1576
1577    if ( ( NULL == lib_handle ) || ( NULL == tbl ) ) {
1578        return -1;
1579    }
1580
1581    rc = mm_camera_lib_get_caps(lib_handle, &camera_cap);
1582    if ( MM_CAMERA_OK != rc ) {
1583        LOGE("mm_camera_lib_get_caps() err=%d\n",  rc);
1584        return -1;
1585    }
1586
1587    for( i = 0 ; i < tbl_size ; i++ ) {
1588        for( j = 0; j < camera_cap.picture_sizes_tbl_cnt; j++ ) {
1589            if ( ( tbl[i].width == camera_cap.picture_sizes_tbl[j].width ) &&
1590                 ( tbl[i].height == camera_cap.picture_sizes_tbl[j].height ) ) {
1591                tbl[i].supported = 1;
1592                rc = (int)i;
1593                break;
1594            }
1595        }
1596    }
1597
1598    return rc;
1599}
1600
1601/*===========================================================================
1602 * FUNCTION   : enableAFR
1603 *
1604 * DESCRIPTION: This function will go through the list
1605 *              of supported FPS ranges and select the
1606 *              one which has maximum range
1607 *
1608 * PARAMETERS :
1609 *   @lib_handle   : camera test library handle
1610 *
1611 * RETURN     : uint32_t type of stream handle
1612 *              MM_CAMERA_OK  -- Success
1613 *              !=MM_CAMERA_OK -- Error status
1614 *==========================================================================*/
1615int enableAFR(mm_camera_lib_handle *lib_handle)
1616{
1617    size_t i, j;
1618    float max_range = 0.0f;
1619    cam_capability_t cap;
1620    int rc = MM_CAMERA_OK;
1621
1622    if ( NULL == lib_handle ) {
1623        return MM_CAMERA_E_INVALID_INPUT;
1624    }
1625
1626    rc = mm_camera_lib_get_caps(lib_handle, &cap);
1627    if ( MM_CAMERA_OK != rc ) {
1628        LOGE("mm_camera_lib_get_caps() err=%d\n",  rc);
1629        return rc;
1630    }
1631
1632    for( i = 0, j = 0 ; i < cap.fps_ranges_tbl_cnt ; i++ ) {
1633        if ( max_range < (cap.fps_ranges_tbl[i].max_fps - cap.fps_ranges_tbl[i].min_fps) ) {
1634            j = i;
1635        }
1636    }
1637
1638    rc = mm_camera_lib_send_command(lib_handle,
1639                                    MM_CAMERA_LIB_FPS_RANGE,
1640                                    &cap.fps_ranges_tbl[j],
1641                                    NULL);
1642
1643    LOGE("FPS range [%5.2f:%5.2f] rc = %d",
1644              cap.fps_ranges_tbl[j].min_fps,
1645              cap.fps_ranges_tbl[j].max_fps,
1646              rc);
1647
1648    return rc;
1649}
1650
1651/*===========================================================================
1652 * FUNCTION     - submain -
1653 *
1654 * DESCRIPTION:
1655 * ===========================================================================*/
1656static int submain()
1657{
1658    int rc = 0;
1659    char tc_buf[3];
1660    menu_id_change_t current_menu_id = MENU_ID_MAIN, next_menu_id;
1661    camera_action_t action_id;
1662    int action_param;
1663    uint8_t previewing = 0;
1664    int isZSL = 0;
1665    uint8_t wnr_enabled = 0;
1666    mm_camera_lib_handle lib_handle;
1667    int num_cameras;
1668    int available_sensors =
1669        (int)(sizeof(sensor_tbl) / sizeof(sensor_tbl[0]));
1670    int available_snap_sizes =
1671        (int)(sizeof(dimension_tbl)/sizeof(dimension_tbl[0]));
1672    int i,c;
1673    mm_camera_lib_snapshot_params snap_dim;
1674    snap_dim.width = DEFAULT_SNAPSHOT_WIDTH;
1675    snap_dim.height = DEFAULT_SNAPSHOT_HEIGHT;
1676    cam_scene_mode_type default_scene= CAM_SCENE_MODE_OFF;
1677    int set_tintless= 0;
1678
1679    mm_camera_test_obj_t test_obj;
1680    memset(&test_obj, 0, sizeof(mm_camera_test_obj_t));
1681
1682    rc = mm_camera_lib_open(&lib_handle, 0);
1683    if (rc != MM_CAMERA_OK) {
1684        LOGE("mm_camera_lib_open() err=%d\n",  rc);
1685        return -1;
1686    }
1687
1688    num_cameras = mm_camera_lib_number_of_cameras(&lib_handle);
1689    if ( 0 >= num_cameras ) {
1690        LOGE(" No camera sensors reported!");
1691        rc = -1;
1692        goto ERROR;
1693    } else if ( 1 <= num_cameras ) {
1694        c = MIN(num_cameras, available_sensors);
1695        for ( i = 0 ; i < c ; i++ ) {
1696            sensor_tbl[i].present = 1;
1697        }
1698        current_menu_id = MENU_ID_SENSORS;
1699    } else {
1700        i = filter_resolutions(&lib_handle,
1701                                dimension_tbl,
1702                                (size_t)available_snap_sizes);
1703        if ( ( i < 0 ) || ( i >= available_snap_sizes ) ) {
1704            LOGE("filter_resolutions()\n");
1705            goto ERROR;
1706        }
1707        snap_dim.width = dimension_tbl[i].width;
1708        snap_dim.height = dimension_tbl[i].height;
1709
1710        rc = enableAFR(&lib_handle);
1711        if (rc != MM_CAMERA_OK) {
1712            LOGE("enableAFR() err=%d\n",  rc);
1713            goto ERROR;
1714        }
1715
1716        rc =  mm_camera_lib_send_command(&lib_handle,
1717                                         MM_CAMERA_LIB_BESTSHOT,
1718                                         &default_scene,
1719                                         NULL);
1720        if (rc != MM_CAMERA_OK) {
1721            LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1722            goto ERROR;
1723        }
1724    }
1725    /*start the eztune server*/
1726    LOGH("Starting eztune Server \n");
1727    eztune_server_start(&lib_handle);
1728
1729    do {
1730        print_current_menu (current_menu_id);
1731        fgets(tc_buf, 3, stdin);
1732
1733        next_menu_id = next_menu(current_menu_id, tc_buf[0], & action_id, & action_param);
1734
1735        if (next_menu_id != MENU_ID_INVALID) {
1736          current_menu_id = next_menu_id;
1737        }
1738        if (action_id == ACTION_NO_ACTION) {
1739          continue;
1740        }
1741
1742        switch(action_id) {
1743            case ACTION_START_PREVIEW:
1744                LOGE("ACTION_START_PREVIEW \n");
1745                rc = mm_camera_lib_start_stream(&lib_handle);
1746                if (rc != MM_CAMERA_OK) {
1747                    LOGE("mm_camera_lib_start_stream() err=%d\n",  rc);
1748                    goto ERROR;
1749                }
1750                previewing = 1;
1751                break;
1752
1753            case ACTION_STOP_PREVIEW:
1754                LOGD("ACTION_STOP_PREVIEW \n");
1755                rc = mm_camera_lib_stop_stream(&lib_handle);
1756                if (rc != MM_CAMERA_OK) {
1757                    LOGE("mm_camera_lib_stop_stream() err=%d\n",  rc);
1758                    goto ERROR;
1759                }
1760                previewing = 0;
1761                break;
1762
1763            case ACTION_SET_WHITE_BALANCE:
1764                LOGD("Selection for the White Balance changes\n");
1765                set_whitebalance(&lib_handle, action_param);
1766                break;
1767
1768            case ACTION_SET_TINTLESS_ENABLE:
1769                LOGD("Selection for the Tintless enable changes\n");
1770                set_tintless = 1;
1771                rc =  mm_camera_lib_send_command(&lib_handle,
1772                                                 MM_CAMERA_LIB_SET_TINTLESS,
1773                                                 &set_tintless,
1774                                                 NULL);
1775                if (rc != MM_CAMERA_OK) {
1776                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1777                    goto ERROR;
1778                }
1779                break;
1780
1781            case ACTION_SET_TINTLESS_DISABLE:
1782                LOGD("Selection for the Tintless disable changes\n");
1783                set_tintless = 0;
1784                rc =  mm_camera_lib_send_command(&lib_handle,
1785                                                 MM_CAMERA_LIB_SET_TINTLESS,
1786                                                 &set_tintless,
1787                                                 NULL);
1788                if (rc != MM_CAMERA_OK) {
1789                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1790                    goto ERROR;
1791                }
1792                break;
1793
1794            case ACTION_SET_EXP_METERING:
1795                LOGD("Selection for the Exposure Metering changes\n");
1796                set_exp_metering(&lib_handle, action_param);
1797                break;
1798
1799            case ACTION_GET_CTRL_VALUE:
1800                LOGD("Selection for getting control value\n");
1801                get_ctrl_value(action_param);
1802                break;
1803
1804            case ACTION_BRIGHTNESS_INCREASE:
1805                printf("Increase brightness\n");
1806                increase_brightness(&lib_handle);
1807                break;
1808
1809            case ACTION_BRIGHTNESS_DECREASE:
1810                printf("Decrease brightness\n");
1811                decrease_brightness(&lib_handle);
1812                break;
1813
1814            case ACTION_CONTRAST_INCREASE:
1815                LOGD("Selection for the contrast increase\n");
1816                increase_contrast (&lib_handle);
1817                break;
1818
1819            case ACTION_CONTRAST_DECREASE:
1820                LOGD("Selection for the contrast decrease\n");
1821                decrease_contrast (&lib_handle);
1822                break;
1823
1824            case ACTION_EV_INCREASE:
1825                LOGD("Selection for the EV increase\n");
1826                increase_EV ();
1827                break;
1828
1829            case ACTION_EV_DECREASE:
1830                LOGD("Selection for the EV decrease\n");
1831                decrease_EV ();
1832                break;
1833
1834            case ACTION_SATURATION_INCREASE:
1835                LOGD("Selection for the EV increase\n");
1836                increase_saturation (&lib_handle);
1837                break;
1838
1839            case ACTION_SATURATION_DECREASE:
1840                LOGD("Selection for the EV decrease\n");
1841                decrease_saturation (&lib_handle);
1842                break;
1843
1844            case ACTION_TOGGLE_AFR:
1845                LOGD("Select for auto frame rate toggling\n");
1846                toggle_afr();
1847                break;
1848
1849            case ACTION_SET_ISO:
1850                LOGD("Select for ISO changes\n");
1851                set_iso(&lib_handle, action_param);
1852                break;
1853
1854            case ACTION_SET_ZOOM:
1855                LOGD("Selection for the zoom direction changes\n");
1856                set_zoom(&lib_handle, action_param);
1857                break;
1858
1859            case ACTION_SHARPNESS_INCREASE:
1860                LOGD("Selection for sharpness increase\n");
1861                increase_sharpness(&lib_handle);
1862                break;
1863
1864            case ACTION_SHARPNESS_DECREASE:
1865                LOGD("Selection for sharpness decrease\n");
1866                decrease_sharpness(&lib_handle);
1867                break;
1868
1869            case ACTION_SET_BESTSHOT_MODE:
1870                LOGD("Selection for bestshot\n");
1871                set_bestshot_mode(&lib_handle, action_param);
1872                break;
1873
1874            case ACTION_SET_FLASH_MODE:
1875                printf("\n Selection for flashmode\n");
1876                set_flash_mode(&lib_handle, action_param);
1877                break;
1878
1879            case ACTION_SWITCH_CAMERA:
1880                rc = mm_camera_lib_close(&lib_handle);
1881                if (rc != MM_CAMERA_OK) {
1882                    LOGE("mm_camera_lib_close() err=%d\n",  rc);
1883                    goto ERROR;
1884                }
1885
1886                rc = mm_camera_lib_open(&lib_handle, action_param);
1887                if (rc != MM_CAMERA_OK) {
1888                    LOGE("mm_camera_lib_open() err=%d\n",  rc);
1889                    goto ERROR;
1890                }
1891
1892                i = filter_resolutions(&lib_handle,
1893                                        dimension_tbl,
1894                                        sizeof(dimension_tbl)/sizeof(dimension_tbl[0]));
1895                if ( ( i < 0 ) || ( i >=  available_snap_sizes ) ) {
1896                    LOGE("filter_resolutions()\n");
1897                    goto ERROR;
1898                }
1899                snap_dim.width = dimension_tbl[i].width;
1900                snap_dim.height = dimension_tbl[i].height;
1901
1902                rc = enableAFR(&lib_handle);
1903                if (rc != MM_CAMERA_OK) {
1904                    LOGE("enableAFR() err=%d\n",  rc);
1905                    goto ERROR;
1906                }
1907
1908                rc =  mm_camera_lib_send_command(&lib_handle,
1909                                                 MM_CAMERA_LIB_BESTSHOT,
1910                                                 &default_scene,
1911                                                 NULL);
1912                if (rc != MM_CAMERA_OK) {
1913                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1914                    goto ERROR;
1915                }
1916                break;
1917
1918            case ACTION_TOGGLE_ZSL:
1919                printf("ZSL Toggle !!!\n");
1920                isZSL = !isZSL;
1921                if ( isZSL ) {
1922                    printf("ZSL on !!!\n");
1923                } else {
1924                    printf("ZSL off !!!\n");
1925                }
1926                rc = mm_camera_lib_send_command(&lib_handle,
1927                                                MM_CAMERA_LIB_ZSL_ENABLE,
1928                                                &isZSL,
1929                                                NULL);
1930                if (rc != MM_CAMERA_OK) {
1931                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1932                    goto ERROR;
1933                }
1934                break;
1935
1936            case ACTION_TAKE_RAW_SNAPSHOT:
1937                LOGH("\n Take RAW snapshot\n");
1938
1939                rc = mm_camera_lib_send_command(&lib_handle,
1940                                                MM_CAMERA_LIB_DO_AF,
1941                                                NULL,
1942                                                NULL);
1943
1944                if (rc != MM_CAMERA_OK) {
1945                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1946                    goto ERROR;
1947                }
1948
1949                rc = mm_camera_lib_send_command(&lib_handle,
1950                                                MM_CAMERA_LIB_RAW_CAPTURE,
1951                                                NULL,
1952                                                NULL);
1953                if (rc != MM_CAMERA_OK) {
1954                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1955                    goto ERROR;
1956                }
1957                break;
1958
1959            case ACTION_TAKE_JPEG_SNAPSHOT:
1960                LOGH("\n Take JPEG snapshot\n");
1961
1962                rc = mm_camera_lib_send_command(&lib_handle,
1963                                                MM_CAMERA_LIB_JPEG_CAPTURE,
1964                                                &snap_dim,
1965                                                NULL);
1966                if (rc != MM_CAMERA_OK) {
1967                    LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
1968                    goto ERROR;
1969                }
1970                break;
1971            case ACTION_SWITCH_RESOLUTION:
1972                printf("\n Switch snapshot resolution to %dx%d\n",
1973                       dimension_tbl[action_param].width,
1974                       dimension_tbl[action_param].height);
1975                snap_dim.width = dimension_tbl[action_param].width;
1976                snap_dim.height = dimension_tbl[action_param].height;
1977                break;
1978
1979      case ACTION_START_RECORDING:
1980        LOGD("Start recording action\n");
1981#if 0
1982        if (mm_app_start_video(cam_id) < 0)
1983          goto ERROR;
1984        is_rec = 1;
1985#endif
1986        break;
1987      case ACTION_STOP_RECORDING:
1988        LOGD("Stop recording action\n");
1989#if 0
1990        if(is_rec) {
1991          if (mm_app_stop_video(cam_id) < 0)
1992            goto ERROR;
1993          is_rec = 0;
1994        }
1995#endif
1996        break;
1997      case ACTION_TAKE_LIVE_SNAPSHOT:
1998        printf("Selection for live shot\n");
1999#if 0
2000        if(is_rec)
2001           mm_app_take_live_snapshot(cam_id);
2002        else
2003           printf("\n !!! Use live snapshot option while recording only !!!\n");
2004#endif
2005        break;
2006
2007        case ACTION_TOGGLE_WNR:
2008          wnr_enabled = !wnr_enabled;
2009          printf("WNR Enabled = %d\n", wnr_enabled);
2010          rc = mm_camera_lib_send_command(&lib_handle,
2011                                          MM_CAMERA_LIB_WNR_ENABLE,
2012                                          &wnr_enabled,
2013                                          NULL);
2014          if (rc != MM_CAMERA_OK) {
2015              LOGE("mm_camera_lib_send_command() err=%d\n",  rc);
2016              goto ERROR;
2017          }
2018          break;
2019
2020        case ACTION_EXIT:
2021            printf("Exiting....\n");
2022            break;
2023        case ACTION_NO_ACTION:
2024            printf("Go back to main menu");
2025            break;
2026
2027        default:
2028            printf("\n\n!!!!!WRONG INPUT: %d!!!!\n", action_id);
2029            break;
2030    }
2031
2032    usleep(1000 * 1000);
2033    LOGD("action_id = %d\n", action_id);
2034
2035  } while (action_id != ACTION_EXIT);
2036  action_id = ACTION_NO_ACTION;
2037
2038    mm_camera_lib_close(&lib_handle);
2039    return 0;
2040
2041ERROR:
2042
2043    mm_camera_lib_close(&lib_handle);
2044
2045    return rc;
2046}
2047
2048