dialog_event_subscribe_action_channel.c 3.4 KB

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