-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathncurses_present.cpp
More file actions
147 lines (132 loc) · 2.84 KB
/
Copy pathncurses_present.cpp
File metadata and controls
147 lines (132 loc) · 2.84 KB
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
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/dvb/frontend.h>
#include "color.h"
/*
* File role: low-level ncurses presentation helpers.
*
* Provides bounded percentage bars plus FE_GET_INFO/status presentation used
* by the frontend view layer.
*/
#include "ncurses_present.h"
// Draw a percentage bar whose total width is controlled by the caller.
void linebar(int proc, int len) {
if (len < 7)
len = 7;
if (proc > 100)
proc = 100;
if (proc < 0)
proc = 0;
int inner_len = len - 3;
printw(" [");
YELLOW_BOLD_ON;
for (int i = 1; i <= inner_len; i++) {
if ((float)proc >= (((float)i / (float)inner_len) * 100))
printw("=");
else
printw(" ");
}
YELLOW_BOLD_OFF;
printw("]");
}
// Render static frontend information returned by FE_GET_INFO.
void print_info(const char *text, dvb_frontend_info fe_info) {
DESC_COL_ON;
printw("%s ", text);
DESC_COL_OFF;
DESC_COLL_ON;
printw("TYPE: ");
DESC_COLL_OFF;
DESC_VALL_ON;
switch (fe_info.type) {
case FE_QPSK:
printw("QPSK ");
break;
case FE_QAM:
printw("QAM ");
break;
case FE_OFDM:
printw("OFDM ");
break;
case FE_ATSC:
printw("ATSC ");
break;
}
DESC_VALL_OFF;
DESC_COLL_ON;
printw("NAME: ");
DESC_COLL_OFF;
DESC_VALL_ON;
printw("%s ", fe_info.name);
DESC_VALL_OFF;
}
// Render frontend lock/status flags with highlighted active flags.
void print_status(const char *text, fe_status_t status) {
DESC_COL_ON;
printw("%s ", text);
DESC_COL_OFF;
if (status & FE_HAS_SIGNAL) {
DESC_VAL_ON;
printw("*SIGNAL* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" SIGNAL ");
DESC_VALL_OFF;
}
if (status & FE_HAS_CARRIER) {
DESC_VAL_ON;
printw("*CARRIER* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" CARRIER ");
DESC_VALL_OFF;
}
if (status & FE_HAS_VITERBI) {
DESC_VAL_ON;
printw("*VITERBI* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" VITERBI ");
DESC_VALL_OFF;
}
if (status & FE_HAS_SYNC) {
DESC_VAL_ON;
printw("*SYNC* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" SYNC ");
DESC_VALL_OFF;
}
if (status & FE_HAS_LOCK) {
DESC_VAL_ON;
printw("*LOCK* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" LOCK ");
DESC_VALL_OFF;
}
if (status & FE_TIMEDOUT) {
DESC_VAL_ON;
printw("*TIMEDOUT* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" TIMEDOUT ");
DESC_VALL_OFF;
}
if (status & FE_REINIT) {
DESC_VAL_ON;
printw("*REINIT* ");
DESC_VAL_OFF;
} else {
DESC_VALL_ON;
printw(" REINIT ");
DESC_VALL_OFF;
}
}