dialog_camera_property_bitmask.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <curses.h>
  15. #define LOG_LEVEL 3
  16. #define LOG_PREFIX "dlg_prop_enum"
  17. #include <syslog.h>
  18. #include <camera_manager.h>
  19. #include <csi_camera_platform_spec.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_bitmask(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. char *title = property->name;
  32. char *prompt = "Please set camera property";
  33. int item_pos = 0;
  34. again:
  35. item_reset();
  36. const camera_spec_bitmasks_t *bitmasks_array = camera_spec_get_bitmask_array(property->id);
  37. if (bitmasks_array == NULL)
  38. return KEY_ESC;
  39. for (int i = 0; i < bitmasks_array->count; i++) {
  40. item_make("bit-%02d: %s", bitmasks_array->bitmask[i],
  41. camera_string_bitmask_name(property->id, bitmasks_array->bitmask[i]));
  42. item_add_str("%s",
  43. (bitmasks_array->bitmask[i] & property->default_value.enum_value) ? " (default)" : "");
  44. if (bitmasks_array->bitmask[i] & property->value.enum_value) {
  45. item_set_selected(1);
  46. item_set_tag('*');
  47. }
  48. else {
  49. item_set_selected(0);
  50. item_set_tag(' ');
  51. }
  52. }
  53. int list_height = MIN(bitmasks_array->count + 1, 8);
  54. ret_key = dialog_checkbox(
  55. title, prompt,
  56. CHECKLIST_HEIGTH_MIN + list_height + 2,
  57. WIN_COLS - CHECKLIST_WIDTH_MIN - 32,
  58. list_height, item_pos);
  59. LOG_D("dialog_checkbox() ret_key=%d\n", ret_key);
  60. if (ret_key == KEY_ESC) {
  61. return KEY_ESC;
  62. } else if (ret_key == 0) {/* select */
  63. item_pos = item_n();
  64. int bitmask_value = bitmasks_array->bitmask[item_n()];
  65. if (item_is_selected()) {
  66. property->value.bitmask_value |= bitmask_value;
  67. } else {
  68. property->value.bitmask_value &= ~bitmask_value;
  69. }
  70. int enum_id = bitmasks_array->bitmask[item_n()];
  71. LOG_D("%s item: pos=%d, enum=%d-%s, bitmask_value=%08x\n",
  72. item_is_selected() ? "Select" : "Unselect",
  73. item_n(), enum_id,
  74. camera_string_bitmask_name(property->id, enum_id),
  75. property->value.bitmask_value);
  76. goto again;
  77. return ret_key;
  78. } else if (ret_key == 1) {/* help */
  79. LOG_W("Help does not support yet\n");
  80. return ret_key;
  81. } else {
  82. LOG_E("Unknown return value: %d\n", ret_key);
  83. return KEY_ESC;
  84. }
  85. }