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