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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/*
* interface.c: Abstract user interface layer
*
* See the main source file 'osm.c' for copyright information and
* how to reach the author.
*
* $Id: interface.c 1.1 2000/02/19 13:36:48 kls Exp $
*/
#include "interface.h"
#include <ncurses.h>
#include <unistd.h>
#include "dvbapi.h"
#include "remote.h"
#ifndef DEBUG_REMOTE
cRcIo RcIo("/dev/ttyS1");//XXX
#endif
WINDOW *window;
cInterface Interface;
cInterface::cInterface(void)
{
open = 0;
cols[0] = 0;
#ifdef DEBUG_OSD
initscr();
keypad(stdscr, TRUE);
nonl();
cbreak();
noecho();
leaveok(stdscr, TRUE);
window = stdscr;
#else
#endif
}
void cInterface::Init(void)
{
#ifndef DEBUG_REMOTE
RcIo.SetCode(Keys.code, Keys.address);
#endif
}
void cInterface::Open(void)
{
if (!open++) {
#ifdef DEBUG_OSD
#else
//TODO
DvbOsdOpen(100, 100, 500, 400);
#endif
}
}
void cInterface::Close(void)
{
if (!--open) {
#ifdef DEBUG_OSD
#else
//TODO
DvbOsdClose();
#endif
}
}
unsigned int cInterface::GetCh(void)
{
#ifdef DEBUG_REMOTE
return getch();
#else
#ifdef DEBUG_OSD
wrefresh(window);//XXX
#endif
unsigned int Command;
return RcIo.GetCommand(&Command) ? Command : 0;
#endif
}
eKeys cInterface::GetKey(void)
{
return Keys.Get(GetCh());
}
void cInterface::Clear(void)
{
if (open) {
#ifdef DEBUG_OSD
wclear(window);
#else
//TODO
DvbOsdClear();
#endif
}
}
void cInterface::SetCols(int *c)
{
for (int i = 0; i < MaxCols; i++) {
cols[i] = *c++;
if (cols[i] == 0)
break;
}
}
void cInterface::Write(int x, int y, char *s)
{
if (open) {
#ifdef DEBUG_OSD
wmove(window, y, x); // ncurses wants 'y' before 'x'!
waddstr(window, s);
#else
DvbOsdText(x * DvbOsdCharWidth, y * DvbOsdLineHeight, s);
#endif
}
}
void cInterface::WriteText(int x, int y, char *s, bool Current)
{
if (open) {
#ifdef DEBUG_OSD
wmove(window, y, x); // ncurses wants 'y' before 'x'!
wclrtoeol(window);//XXX
#else
//TODO
DvbOsdClrEol(x * DvbOsdCharWidth, y);//XXX
#endif
Write(x, y, Current ? "*" : " ");
x++;
int col = 0;
for (;;) {
char *t = strchr(s, '\t');
char *p = s;
char buf[1000];
if (t && col < MaxCols && cols[col] > 0) {
unsigned int n = t - s;
if (n >= sizeof(buf))
n = sizeof(buf) - 1;
strncpy(buf, s, n);
buf[n] = 0;
p = buf;
s = t + 1;
}
Write(x, y, p);
if (p == s)
break;
x += cols[col++];
}
}
}
void cInterface::Info(char *s)
{
Open();
isyslog(LOG_ERR, s);
WriteText(0, 11, s);//TODO
#ifdef DEBUG_OSD
wrefresh(window);//XXX
#endif
sleep(1);
WriteText(0, 11, "");//TODO
#ifdef DEBUG_OSD
wrefresh(window);//XXX
#endif
Close();
}
void cInterface::Error(char *s)
{
Open();
esyslog(LOG_ERR, s);
WriteText(0, 12, s);//TODO
#ifdef DEBUG_OSD
wrefresh(window);//XXX
#endif
sleep(1);
WriteText(0, 12, "");//TODO
#ifdef DEBUG_OSD
wrefresh(window);//XXX
#endif
Close();
}
void cInterface::QueryKeys(void)
{
Keys.Clear();
WriteText(1, 1, "Learning Remote Control Keys");
WriteText(1, 3, "Phase 1: Detecting RC code type");
WriteText(1, 5, "Press any key on the RC unit");
#ifndef DEBUG_REMOTE
unsigned char Code = 0;
unsigned short Address;
#endif
for (;;) {
#ifdef DEBUG_REMOTE
if (GetCh())
break;
#else
//TODO on screen display...
if (RcIo.DetectCode(&Code, &Address)) {
Keys.code = Code;
Keys.address = Address;
WriteText(1, 5, "RC code detected!");
WriteText(1, 6, "Do not press any key...");
RcIo.Flush(3);
WriteText(1, 5, "");
WriteText(1, 6, "");
break;
}
#endif
}
WriteText(1, 3, "Phase 2: Learning specific key codes");
tKey *k = Keys.keys;
while (k->type != kNone) {
char *Prompt;
asprintf(&Prompt, "Press key for '%s'", k->name);
WriteText(1, 5, Prompt);
delete Prompt;
for (;;) {
unsigned int ch = GetCh();
if (ch != 0) {
switch (Keys.Get(ch)) {
case kUp: if (k > Keys.keys) {
k--;
break;
}
case kDown: if (k > Keys.keys + 1) {
WriteText(1, 5, "Press 'Up' to confirm");
WriteText(1, 6, "Press 'Down' to continue");
WriteText(1, 7, "");
WriteText(1, 8, "");
for (;;) {
eKeys key = GetKey();
if (key == kUp) {
Clear();
return;
}
else if (key == kDown) {
WriteText(1, 6, "");
break;
}
}
break;
}
case kNone: k->code = ch;
k++;
break;
default: break;
}
break;
}
}
if (k > Keys.keys)
WriteText(1, 7, "(press 'Up' to go back)");
else
WriteText(1, 7, "");
if (k > Keys.keys + 1)
WriteText(1, 8, "(press 'Down' to end key definition)");
else
WriteText(1, 8, "");
}
}
void cInterface::LearnKeys(void)
{
isyslog(LOG_INFO, "learning keys");
for (;;) {
Clear();
QueryKeys();
Clear();
WriteText(1, 1, "Learning Remote Control Keys");
WriteText(1, 3, "Phase 3: Saving key codes");
WriteText(1, 5, "Press 'Up' to save, 'Down' to cancel");
for (;;) {
eKeys key = GetKey();
if (key == kUp) {
Keys.Save();
Clear();
return;
}
else if (key == kDown) {
Keys.Load();
Clear();
return;
}
}
}
}
void cInterface::DisplayChannel(int Number, char *Name)
{
//TODO
#ifndef DEBUG_REMOTE
RcIo.Number(Number);
#endif
}
|