hc
2024-03-22 ac5f19e89dcbd5c7428fcc78a0d407c887564466
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "sample_comm.h"
 
int uapi_usage_show(uapi_case_t* uapi_list)
{
  int case_i = 0;
 
  if (!uapi_list) {
    return -1;
  }
 
  CLEAR();
  printf("Usage <key>:\n");
 
  while (1) {
    if (!uapi_list[case_i].desc) {
      break;
    }
 
    if (uapi_list[case_i].desc) {
      printf("\t\t%c) %s.\n", '0' + case_i, uapi_list[case_i].desc);
    }
 
    case_i++;
  }
 
  return 0;
}
 
int uapi_list_count(uapi_case_t* uapi_list)
{
  int case_i = 0;
  while (1) {
    if (!uapi_list[case_i].desc) {
      break;
    }
    case_i++;
  }
 
  return case_i;
}
 
int uapi_process_loop(const rk_aiq_sys_ctx_t* ctx, uapi_case_t* uapi_list)
{
  int key = -1;
  int max_key = -1;
 
  max_key = uapi_list_count(uapi_list);
 
  uapi_usage_show(uapi_list);
 
  do {
    printf("\t please press the key: ");
    key = getchar();
    while (key == '\n' || key == '\r')
      key = getchar();
    printf("\n");
 
    if (key == 'h') {
      uapi_usage_show(uapi_list);
      continue;
    }
 
    if (key - '0' > max_key) {
      printf("\t invalid input key:[%c]\n", key);
      continue;
    }
 
    if (!uapi_list[key - '0'].func) {
      printf("\t invalid function for key:[%c]\n", key);
      continue;
    }
 
    uapi_list[key - '0'].func(ctx);
 
  } while (key != 'q' && key != 'Q');
 
  return XCAM_RETURN_NO_ERROR;
}