dialog_event_subscribe_action_camera.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <camera_app_spec.h>
  20. #include <csi_camera_platform_spec.h>
  21. #include <camera_string.h>
  22. #include "param.h"
  23. #include "app_dialogs.h"
  24. extern cams_t *cam_session;
  25. static int add_event_actions(camera_event_action_union_t *event_action)
  26. {
  27. int count = 0;
  28. const camera_app_bitmasks_t *bitmasks =
  29. camera_app_get_bitmask_array(CAMERA_APP_BITMAKS_CAMERA_EVENT_ACTION);
  30. LOG_D("bitmasks->count=%d\n", bitmasks->count);
  31. if (bitmasks == NULL) {
  32. LOG_E("Can't get camera's action support list\n");
  33. return count;
  34. }
  35. LOG_D("camera.action=0x%08x\n", event_action->camera.action);
  36. switch (event_action->camera.event) {
  37. case CSI_CAMERA_EVENT_WARNING:
  38. case CSI_CAMERA_EVENT_ERROR:
  39. case CSI_CAMERA_EVENT_SENSOR_FIRST_IMAGE_ARRIVE:
  40. case CSI_CAMERA_EVENT_ISP_3A_ADJUST_READY:
  41. for (int i = 0; i < bitmasks->count; i++) {
  42. csi_camera_event_id_e loop_action = bitmasks->bitmask[i];
  43. bool action_set = (event_action->camera.action & loop_action) != 0;
  44. const char *item_name = camera_string_camera_action(loop_action);
  45. item_make("\t%-16s(0x%08x)", item_name, loop_action);
  46. LOG_D("\t%-16s(0x%08x)\n", item_name, loop_action);
  47. item_set_tag(action_set ? '*' : ' ');
  48. item_set_int(loop_action);
  49. }
  50. break;
  51. }
  52. }
  53. int dialog_event_subscribe_action_camera(camera_event_action_union_t *event_action)
  54. {
  55. int ret_key = KEY_ESC;
  56. if (event_action == NULL) {
  57. LOG_W("event_action is NULL\n");
  58. return KEY_ESC;
  59. }
  60. char *title = "Set Camera Event Action(s)";
  61. char *prompt = "Select the Camera event then config the action(s)";
  62. int item_pos = 0;
  63. int list_count = 0;
  64. again:
  65. item_reset();
  66. item_make("%-32s","Subscribe");
  67. if (event_action->camera.subscribed == false) {
  68. item_set_tag(' ');
  69. } else {
  70. item_set_tag('*');
  71. list_count = add_event_actions(event_action);
  72. }
  73. int list_height = MIN(list_count + 8, 24);
  74. ret_key = dialog_checkbox(
  75. title, prompt,
  76. CHECKLIST_HEIGTH_MIN + list_height + 2,
  77. WIN_COLS - CHECKLIST_WIDTH_MIN - 32,
  78. list_height, item_pos);
  79. LOG_D("dialog_checkbox() ret_key=%d\n", ret_key);
  80. if (ret_key == KEY_ESC) {
  81. return KEY_ESC;
  82. } else if (ret_key == 0) {/* select */
  83. item_pos = item_n();
  84. LOG_D("item_pos=%d\n", item_pos);
  85. if (item_pos == 0) { // 1st item, which indicate whether register actions
  86. if (item_tag() == ' ') {
  87. event_action->camera.subscribed = true;
  88. goto again;
  89. } else {
  90. event_action->camera.subscribed = false;
  91. goto again;
  92. }
  93. } else { // other item, which indicate whether register actions
  94. camera_action_e cur_action = item_int();
  95. if (item_tag() == ' ') {
  96. event_action->camera.action |= cur_action;
  97. item_set_tag('*');
  98. } else {
  99. event_action->camera.action &= ~cur_action;
  100. item_set_tag(' ');
  101. }
  102. LOG_D("camera.action=0x%08x\n", event_action->camera.action);
  103. }
  104. goto again;
  105. return ret_key;
  106. } else if (ret_key == 1) {/* Return */
  107. return ret_key;
  108. } else if (ret_key == 2) {/* Help */
  109. LOG_W("Help does not support yet\n");
  110. return ret_key;
  111. } else {
  112. LOG_E("Unknown return value: %d\n", ret_key);
  113. return KEY_ESC;
  114. }
  115. }