summaryrefslogtreecommitdiffstats
path: root/src/dbg.h
blob: 42d654195f2e4f8cc69dc993dce2e6d545704fc8 (plain) (blame)
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
/******************************************************************************
 *	Copyright (C) 2020	Alejandro Colomar Andrés		      *
 *	SPDX-License-Identifier:	GPL-2.0-only			      *
 ******************************************************************************/


/******************************************************************************
 ******* include guard ********************************************************
 ******************************************************************************/
#pragma once	/* dbg.h */


/******************************************************************************
 ******* headers **************************************************************
 ******************************************************************************/
#include <stdbool.h>

#define ALX_NO_PREFIX
#include <libalx/base/errno.h>
#include <libalx/base/stdio.h>
#include <libalx/extra/cv/cv.h>


/******************************************************************************
 ******* macro ****************************************************************
 ******************************************************************************/
#define DBG			3
#define DBG_SHOW_WAIT		0
#define DBG_SHOWTIME(dbg)	(					\
{									\
	int	tm_;							\
									\
	switch (dbg) {							\
	case 0:								\
		tm_	= 500;						\
		break;							\
	case 1:								\
		tm_	= 300;						\
		break;							\
	case 2:								\
		tm_	= 200;						\
		break;							\
	case 3:								\
		tm_	= 100;						\
		break;							\
	case 4:								\
		tm_	= 30;						\
		break;							\
	}								\
									\
	if (DBG_SHOW_WAIT)						\
		tm_	= -1;						\
									\
	tm_;								\
}									\
)

#if defined(DBG)
#define dbg_show(dbg, img)		do				\
{									\
									\
	if (dbg <= DBG) {						\
		alx_cv_imshow(img, "dbg", DBG_SHOWTIME(dbg));		\
	}								\
} while (0);

#define dbg_printf(dbg, fmt, ...)	do				\
{									\
									\
	if (dbg <= DBG) {						\
		printf(fmt, ##__VA_ARGS__);				\
	}								\
} while (0);

#define dbg_update_win()		do				\
{									\
									\
	if (DBG) {							\
		alx_cv_destroy_all_windows();				\
		alx_cv_named_window("dbg", ALX_CV_WINDOW_NORMAL);	\
	}								\
} while (0);
#else
#define dbg_show(dbg, img)	do {} while (0);
#define dbg_update_win()	do {} while (0);
#endif	/* defined(DBG) */


/******************************************************************************
 ******* enum *****************************************************************
 ******************************************************************************/


/******************************************************************************
 ******* struct / union *******************************************************
 ******************************************************************************/


/******************************************************************************
 ******* prototypes ***********************************************************
 ******************************************************************************/


/******************************************************************************
 ******* inline ***************************************************************
 ******************************************************************************/


/******************************************************************************
 ******* end of file **********************************************************
 ******************************************************************************/