dialog_camera_property_boolean.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_boolean"
  17. #include <syslog.h>
  18. #include "param.h"
  19. #include "app_dialogs.h"
  20. #include <camera_manager.h>
  21. extern cams_t *cam_session;
  22. int dialog_camera_property_boolean(csi_camera_property_description_s *property)
  23. {
  24. int ret_key = KEY_ESC;
  25. if (property == NULL) {
  26. LOG_W("property is NULL\n");
  27. return KEY_ESC;
  28. }
  29. item_reset();
  30. char *title = property->name;
  31. char *prompt = "Please set camera property";
  32. item_reset();
  33. item_make("true");
  34. if (property->default_value.bool_value)
  35. item_add_str("(default)");
  36. if (property->value.bool_value) {
  37. item_set_tag('X');
  38. item_set_selected(1);
  39. } else {
  40. item_set_tag(' ');
  41. item_set_selected(0);
  42. }
  43. item_make("false");
  44. if (!property->default_value.bool_value)
  45. item_add_str(" (default)");
  46. if (!property->value.bool_value) {
  47. item_set_tag('X');
  48. item_set_selected(1);
  49. } else {
  50. item_set_tag(' ');
  51. item_set_selected(0);
  52. }
  53. ret_key = dialog_checklist(
  54. title, prompt,
  55. CHECKLIST_HEIGTH_MIN + 4,
  56. WIN_COLS - CHECKLIST_WIDTH_MIN - 32,
  57. 2,
  58. NULL, 0);
  59. LOG_D("dialog_checklist() ret_key=%d\n", ret_key);
  60. if (ret_key == KEY_ESC) {
  61. return KEY_ESC;
  62. } else if (ret_key == 0) {/* select */
  63. LOG_D("select item: %d, means '%s'\n", item_n(),
  64. (item_n() == 0) ? "true" : "false");
  65. property->value.bool_value = (item_n() == 0) ? true : false;
  66. return ret_key;
  67. } else if (ret_key == 1) {/* help */
  68. LOG_W("Help does not support yet\n");
  69. return ret_key;
  70. } else {
  71. LOG_E("Unknown return value: %d\n", ret_key);
  72. return KEY_ESC;
  73. }
  74. }