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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/******************************************************************************
* Copyright (C) 2018 Alejandro Colomar Andrés *
* SPDX-License-Identifier: GPL-2.0-only *
******************************************************************************/
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
#include "vision-artificial/user/iface.h"
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <alx/base/stdio.h>
#include "vision-artificial/image/iface.h"
#include "vision-artificial/user/tui.h"
/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
#define TITLE_SIZE (80)
/******************************************************************************
******* enums ****************************************************************
******************************************************************************/
/******************************************************************************
******* structs / unions *****************************************************
******************************************************************************/
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
struct User_Iface_Log user_iface_log;
/******************************************************************************
******* static functions (prototypes) ****************************************
******************************************************************************/
static void user_iface_act (int action);
static void user_iface_show_ocr (void);
/******************************************************************************
******* global functions *****************************************************
******************************************************************************/
void user_iface_init (void)
{
user_iface_log.len = 0;
user_iface_log.pos = -1;
user_tui_init();
}
void user_iface_cleanup (void)
{
user_tui_cleanup();
fflush(stdout);
}
void user_iface (void)
{
char title[TITLE_SIZE];
char subtitle[TITLE_SIZE];
int user_action;
snprintf(title, TITLE_SIZE, "Title");
snprintf(subtitle, TITLE_SIZE, "Subtitle");
do {
img_iface_show_img();
user_action = user_tui(title, subtitle);
user_iface_act(user_action);
} while (user_action != USER_IFACE_ACT_QUIT);
}
void user_iface_show_log (const char *restrict title,
const char *restrict subtitle)
{
user_tui_show_log(title, subtitle);
}
void user_iface_fname (const char *restrict filepath,
char *restrict filename)
{
user_tui_fname(filepath, filename);
}
double user_iface_getdbl (double m, double def, double M,
const char *restrict title,
const char *restrict help)
{
return user_tui_getint(m, def, M, title, help);
}
int user_iface_getint (double m, int64_t def, double M,
const char *restrict title,
const char *restrict help)
{
return user_tui_getdbl(m, def, M, title, help);
}
void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg)
{
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s",
msg);
user_iface_log.lvl[user_iface_log.len] = lvl;
user_iface_log.len++;
}
const char *user_iface_log_read (void)
{
user_iface_log.pos++;
for (; user_iface_log.pos < user_iface_log.len; user_iface_log.pos++) {
if (user_iface_log.lvl[user_iface_log.pos] <=
user_iface_log.visible) {
break;
}
}
if (user_iface_log.pos == user_iface_log.len)
return NULL;
return &user_iface_log.line[user_iface_log.pos][0];
}
/******************************************************************************
******* static functions (definitions) ***************************************
******************************************************************************/
static void user_iface_act (int action)
{
if (action & USER_IFACE_ACT_USRI) {
switch (action) {
case USER_IFACE_ACT_SHOW_OCR:
user_iface_show_ocr();
break;
case USER_IFACE_ACT_QUIT:
/* do nothing */
break;
}
} else {
img_iface_act(action);
}
}
static void user_iface_show_ocr (void)
{
user_tui_show_ocr();
}
/******************************************************************************
******* end of file **********************************************************
******************************************************************************/
|