dialog_camera_property_integer.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_int"
  17. #include <syslog.h>
  18. #include <camera_manager.h>
  19. #include "param.h"
  20. #include "app_dialogs.h"
  21. extern cams_t *cam_session;
  22. extern char dialog_input_result[MAX_LEN + 1];
  23. int dialog_camera_property_integer(csi_camera_property_description_s *property)
  24. {
  25. int ret_key = KEY_ESC;
  26. if (property == NULL) {
  27. LOG_W("property is NULL\n");
  28. return KEY_ESC;
  29. }
  30. char title[64];
  31. snprintf(title, sizeof(title), "Camera %s setting", property->name);
  32. char prompt[64];
  33. snprintf(prompt, sizeof(prompt), "value range should be: [%d, %d], step %d",
  34. property->minimum, property->maximum, property->step);
  35. char str_value[32];
  36. snprintf(str_value, sizeof(str_value), "%d", property->value.int_value);
  37. again:
  38. curs_set(1);
  39. ret_key = dialog_inputbox(title, prompt, 10, 50, str_value);
  40. curs_set(0);
  41. if (ret_key == KEY_ESC || ret_key == 1)
  42. return KEY_ESC;
  43. /* can't be empty */
  44. if (strlen(dialog_input_result) == 0) {
  45. goto again;
  46. }
  47. /* value check, reset if invalid */
  48. int value = atoi(dialog_input_result);
  49. if (value < property->minimum || value > property->maximum ||
  50. ((value - property->minimum) % property->step != 0)) {
  51. LOG_W("%s\n", prompt);
  52. goto again;
  53. }
  54. /* accept value, set into property */
  55. property->value.int_value = value;
  56. return 0;
  57. }