dialog_camera_property_enum.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: LuChongzhi <chongzhi.lcz@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <stdio.h>
  10. #include <ctype.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14. #define LOG_LEVEL 3
  15. #define LOG_PREFIX "dlg_prop_enum"
  16. #include <syslog.h>
  17. #include <curses.h>
  18. #include <csi_camera_platform_spec.h>
  19. #include <camera_manager.h>
  20. #include <camera_string.h>
  21. #include "param.h"
  22. #include "app_dialogs.h"
  23. extern cams_t *cam_session;
  24. int dialog_camera_property_enum(csi_camera_property_description_s *property)
  25. {
  26. int ret_key = KEY_ESC;
  27. if (property == NULL) {
  28. LOG_W("property is NULL\n");
  29. return KEY_ESC;
  30. }
  31. item_reset();
  32. char *title = property->name;
  33. char *prompt = "Please set camera property";
  34. item_reset();
  35. const camera_spec_enums_s *enums_array = camera_spec_get_enum_array(property->id);
  36. if (enums_array == NULL)
  37. return KEY_ESC;
  38. for (int i = 0; i < enums_array->count; i++) {
  39. item_make("%d-%s",
  40. enums_array->enums[i],
  41. camera_string_enum_name(property->id, enums_array->enums[i]));
  42. item_add_str("%s",
  43. (enums_array->enums[i] == property->default_value.enum_value) ? " (default)" : "");
  44. if (enums_array->enums[i] == property->value.enum_value) {
  45. item_set_selected(1);
  46. item_set_tag('X');
  47. }
  48. else {
  49. item_set_selected(0);
  50. item_set_tag(' ');
  51. }
  52. }
  53. int list_height = MIN(enums_array->count + 1, 8);
  54. ret_key = dialog_checklist(
  55. title, prompt,
  56. CHECKLIST_HEIGTH_MIN + list_height + 2,
  57. WIN_COLS - CHECKLIST_WIDTH_MIN - 32,
  58. list_height,
  59. NULL, 0);
  60. LOG_D("dialog_checklist() ret_key=%d\n", ret_key);
  61. if (ret_key == KEY_ESC) {
  62. return KEY_ESC;
  63. } else if (ret_key == 0) {/* select */
  64. if (!item_is_selected())
  65. return KEY_ESC;
  66. int enum_id = enums_array->enums[item_n()];
  67. LOG_D("select item: pos=%d, enum=%d-%s\n",
  68. item_n(), enum_id,
  69. camera_string_enum_name(property->id, enum_id));
  70. property->value.enum_value = enum_id;
  71. return ret_key;
  72. } else if (ret_key == 1) {/* help */
  73. LOG_W("Help does not support yet\n");
  74. return ret_key;
  75. } else {
  76. LOG_E("Unknown return value: %d\n", ret_key);
  77. return KEY_ESC;
  78. }
  79. }