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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
/*
* iMON LCD plugin for VDR (C++)
*
* (C) 2009 Andreas Brachold <vdr07 AT deltab de>
*
* This iMON LCD plugin is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, version 3 of the License.
*
* See the files README and COPYING for details.
*
*/
#include <vdr/plugin.h>
#include <getopt.h>
#include <string.h>
#include "imon.h"
#include "watch.h"
#include "status.h"
#include "setup.h"
static const char *VERSION = "0.0.2";
static const char *DEFAULT_LCDDEVICE = "/dev/lcd0";
class cPluginImonlcd : public cPlugin {
private:
ciMonStatusMonitor *statusMonitor;
char* m_szDevice;
ciMonWatch m_dev;
eProtocol m_Protocol;
bool m_bSuspend;
char* m_szIconHelpPage;
protected:
bool resume();
bool suspend();
const char* SVDRPCommandOn(const char *Option, int &ReplyCode);
const char* SVDRPCommandOff(const char *Option, int &ReplyCode);
const char* SVDRPCommandIcon(const char *Option, int &ReplyCode);
public:
cPluginImonlcd(void);
virtual ~cPluginImonlcd();
virtual const char *Version(void) { return VERSION; }
virtual const char *Description(void) { return tr("Control a iMON LCD"); }
virtual const char *CommandLineHelp(void);
virtual bool ProcessArgs(int argc, char *argv[]);
virtual bool Initialize(void);
virtual bool Start(void);
virtual void Stop(void);
virtual void Housekeeping(void);
virtual void MainThreadHook(void);
virtual cString Active(void);
virtual time_t WakeupTime(void);
virtual const char *MainMenuEntry(void) { return NULL; }
virtual cOsdObject *MainMenuAction(void);
virtual cMenuSetupPage *SetupMenu(void);
virtual bool SetupParse(const char *Name, const char *Value);
virtual bool Service(const char *Id, void *Data = NULL);
virtual const char **SVDRPHelpPages(void);
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
};
cPluginImonlcd::cPluginImonlcd(void)
: m_Protocol(ePROTOCOL_0038)
{
m_bSuspend = true;
statusMonitor = NULL;
m_szDevice = NULL;
m_szIconHelpPage = NULL;
}
cPluginImonlcd::~cPluginImonlcd()
{
//Cleanup if'nt throw housekeeping
if(statusMonitor) {
delete statusMonitor;
statusMonitor = NULL;
}
if(m_szDevice) {
free(m_szDevice);
m_szDevice = NULL;
}
if(m_szIconHelpPage) {
free(m_szIconHelpPage);
m_szIconHelpPage = NULL;
}
}
const char *cPluginImonlcd::CommandLineHelp(void)
{
// Return a string that describes all known command line options.
return
" -d DEV, --device=DEV sets the lcd-device to other device than /dev/lcd0\n"
" -p MODE, --protocol=MODE sets the protocol of lcd-device\n"
" '0038' For LCD with ID 15c2:0038 SoundGraph Inc (default)\n"
" 'ffdc' For LCD with ID 15c2:ffdc SoundGraph Inc\n";
}
bool cPluginImonlcd::ProcessArgs(int argc, char *argv[])
{
static struct option long_options[] =
{
{ "device", required_argument, NULL, 'd'},
{ "protocol", required_argument, NULL, 'p'},
{ NULL}
};
int c;
int option_index = 0;
while ((c = getopt_long(argc, argv, "d:p:", long_options, &option_index)) != -1)
{
switch (c)
{
case 'd':
{
if(m_szDevice) {
free(m_szDevice);
m_szDevice = NULL;
}
m_szDevice = strdup(optarg);
break;
}
case 'p':
{
if(strcasecmp(optarg,"0038") == 0) {
m_Protocol = ePROTOCOL_0038;
} else if(strcasecmp(optarg,"ffdc") == 0) {
m_Protocol = ePROTOCOL_FFDC;
}
break;
}
default:
return false;
}
}
if (NULL == m_szDevice)
{
// neither Device given:
// => set "/dev/lcd0" it to default
m_szDevice = strdup(DEFAULT_LCDDEVICE);
}
return true;
}
bool cPluginImonlcd::Initialize(void)
{
// Initialize any background activities the plugin shall perform.
return true;
}
bool cPluginImonlcd::resume() {
if(m_bSuspend
&& NULL != m_szDevice
&& 0 == m_dev.open(m_szDevice,m_Protocol)) {
m_bSuspend = false;
return true;
}
return false;
}
bool cPluginImonlcd::suspend() {
if(!m_bSuspend) {
m_dev.close();
m_bSuspend = true;
return true;
}
return false;
}
bool cPluginImonlcd::Start(void)
{
if(resume()) {
statusMonitor = new ciMonStatusMonitor(&m_dev);
if(NULL == statusMonitor){
esyslog("iMonLCD: can't create ciMonStatusMonitor!");
return (false);
}
}
return true;
}
void cPluginImonlcd::Stop(void)
{
if(statusMonitor) {
delete statusMonitor;
statusMonitor = NULL;
}
m_dev.close();
if(m_szDevice) {
free(m_szDevice);
m_szDevice = NULL;
}
}
void cPluginImonlcd::Housekeeping(void)
{
// Perform any cleanup or other regular tasks.
}
void cPluginImonlcd::MainThreadHook(void)
{
// Perform actions in the context of the main program thread.
// WARNING: Use with great care - see PLUGINS.html!
}
cString cPluginImonlcd::Active(void)
{
// Return a message string if shutdown should be postponed
return NULL;
}
time_t cPluginImonlcd::WakeupTime(void)
{
// Return custom wakeup time for shutdown script
return 0;
}
cOsdObject *cPluginImonlcd::MainMenuAction(void)
{
return NULL;
}
cMenuSetupPage *cPluginImonlcd::SetupMenu(void)
{
return new ciMonMenuSetup(&m_dev);
}
bool cPluginImonlcd::SetupParse(const char *szName, const char *szValue)
{
return theSetup.SetupParse(szName,szValue);
}
bool cPluginImonlcd::Service(const char *Id, void *Data)
{
// Handle custom service requests from other plugins
return false;
}
const char* cPluginImonlcd::SVDRPCommandOn(const char *Option, int &ReplyCode)
{
if(!m_bSuspend) {
ReplyCode=251;
return "driver already resumed";
}
if(resume()) {
ReplyCode=250;
return "driver resumed";
} else {
ReplyCode=554;
return "driver could not resumed";
}
}
const char* cPluginImonlcd::SVDRPCommandOff(const char *Option, int &ReplyCode)
{
if(suspend()) {
ReplyCode=250;
return "driver suspended";
} else {
ReplyCode=251;
return "driver already suspended";
}
}
static const struct {
unsigned int nIcon;
const char* szIcon;
} icontable[] = {
{ eIconTopMusic , "Music" },
{ eIconTopMovie , "Movie" },
{ eIconTopPhoto , "Photo" },
{ eIconTopDVD , "DVD" },
{ eIconTopTV , "TopTV" },
{ eIconTopWeb , "Web" },
{ eIconTopNews , "News" },
{ eIconSpeakerL , "SpeakerL" },
{ eIconSpeakerR , "SpeakerR" },
{ eIconSpeakerLR , "SpeakerLR" },
{ eIconSpeaker51 , "Speaker51" },
{ eIconSpeaker71 , "Speaker71" },
{ eIconSPDIF , "SPDIF" },
{ eIconMute , "MUTE" },
{ eIconDiscSpin|eIconDiscRunSpin|eIconDiscEllispe , "DISC" },
{ eIconTV , "TV" },
{ eIconHDTV , "HDTV" },
{ eIconSRC , "SRC" },
{ eIconSRC1 , "SRC1" },
{ eIconSRC2 , "SRC2" },
{ eIconFIT , "FIT" },
{ eIconBL_MPG , "MPG" },
{ eIconBL_DIVX , "DIVX" },
{ eIconBL_XVID , "XVID" },
{ eIconBL_WMV , "WMV" },
{ eIconBM_MPG , "MPGA" },
{ eIconBM_AC3 , "AC3" },
{ eIconBM_DTS , "DTS" },
{ eIconBM_WMA , "WMAA" },
{ eIconBR_MP3 , "MP3" },
{ eIconBR_OGG , "OGG" },
{ eIconBR_WMA , "WMA" },
{ eIconBR_WAV , "WAV" },
{ eIconVolume , "VOL" },
{ eIconTime , "TIME" },
{ eIconAlarm , "ALARM" },
{ eIconRecording , "REC" },
{ eIconRepeat , "REP" },
{ eIconShuffle , "SFL" }
};
const char* cPluginImonlcd::SVDRPCommandIcon(const char *Option, int &ReplyCode)
{
if(m_bSuspend) {
ReplyCode=251;
return "driver suspended";
}
if( Option && strlen(Option) < 256) {
char* request = strdup(Option);
char* cmd = NULL;
if( request ) {
char* tmp = request;
eIconState m = eIconStateQuery;
cmd = strtok_r(request, " ", &tmp);
if(cmd) {
char* param = strtok_r(0, " ", &tmp);
if(param) {
if(!strcasecmp(param,"ON")) {
m = eIconStateOn;
} else if(!strcasecmp(param,"OFF")) {
m = eIconStateOff;
} else if(!strcasecmp(param,"AUTO")) {
m = eIconStateAuto;
} else {
ReplyCode=501;
free(request);
return "unknown icon state";
}
}
}
ReplyCode=501;
const char* szReplay = "unknown icon title";
if(cmd) {
unsigned int i;
for(i = 0; i < (sizeof(icontable)/sizeof(*icontable));++i)
{
if(0 == strcasecmp(cmd,icontable[i].szIcon))
{
eIconState r = m_dev.ForceIcon(icontable[i].nIcon, m);
switch(r) {
case eIconStateAuto:
ReplyCode=250;
szReplay = "icon state 'auto'";
break;
case eIconStateOn:
ReplyCode=251;
szReplay = "icon state 'on'";
break;
case eIconStateOff:
ReplyCode=252;
szReplay = "icon state 'off'";
break;
default:
break;
}
break;
}
}
}
free(request);
return szReplay;
}
}
ReplyCode=501;
return "wrong parameter";
}
cString cPluginImonlcd::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
ReplyCode=501;
const char* szReplay = "unknown command";
if(!strcasecmp(Command, "ON")) {
szReplay = SVDRPCommandOn(Option,ReplyCode);
} else if(!strcasecmp(Command, "OFF")) {
szReplay = SVDRPCommandOff(Option,ReplyCode);
} else if(!strcasecmp(Command, "ICON")) {
szReplay = SVDRPCommandIcon(Option,ReplyCode);
}
dsyslog("iMonLCD: SVDRP %s %s - %d (%s)", Command, Option, ReplyCode, szReplay);
return szReplay;
}
const char **cPluginImonlcd::SVDRPHelpPages(void)
{
if(!m_szIconHelpPage) {
unsigned int i,l,k;
for(i = 0,l = 0, k = (sizeof(icontable)/sizeof(*icontable)); i < k;++i) {
l += strlen(icontable[i].szIcon);
l += 2;
}
l += 80;
m_szIconHelpPage = (char*) calloc(l + 1,1);
if(m_szIconHelpPage) {
strncat(m_szIconHelpPage, "ICON [name] [on|off|auto]\n Force state of icon. Names of icons are:", l);
for(i = 0; i < k;++i) {
if((i % 7) == 0) {
strncat(m_szIconHelpPage, "\n ", l - (strlen(m_szIconHelpPage) + 5));
} else {
strncat(m_szIconHelpPage, ",", l - (strlen(m_szIconHelpPage) + 1));
}
strncat(m_szIconHelpPage, icontable[i].szIcon,
l - (strlen(m_szIconHelpPage) + strlen(icontable[i].szIcon)));
}
}
}
// Return help text for SVDRP commands this plugin implements
static const char *HelpPages[] = {
"ON\n"
" Resume driver of display.\n",
"OFF\n"
" Suspend driver of display.\n",
"ICON [name] [on|off|auto]\n"
" Force state of icon.\n",
NULL
};
if(m_szIconHelpPage)
HelpPages[2] = m_szIconHelpPage;
return HelpPages;
}
VDRPLUGINCREATOR(cPluginImonlcd); // Don't touch this!
|