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
|
/*
* GraphLCD plugin for the Video Disk Recorder
*
* plugin.c - main plugin class
*
* This file is released under the GNU General Public License. Refer
* to the COPYING file distributed with this package.
*
* (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online.de>
* (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de>
* (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net>
*/
#include <getopt.h>
#include <glcddrivers/config.h>
#include <glcddrivers/drivers.h>
#include "display.h"
#include "global.h"
#include "menu.h"
#include <vdr/plugin.h>
#include <ctype.h>
#if APIVERSNUM < 10503
#include "i18n.h"
#define trNOOP(_s) (_s)
#endif
static const char * kPluginName = "graphlcd";
static const char *VERSION = "0.2.0-touchcol-git";
static const char *DESCRIPTION = trNOOP("Output to graphic LCD");
static const char *MAINMENUENTRY = NULL;
static const char * kDefaultConfigFile = "/etc/graphlcd.conf";
class cPluginGraphLCD : public cPlugin
{
private:
// Add any member variables or functions you may need here.
std::string mConfigName;
std::string mDisplayName;
std::string mSkinsPath;
std::string mSkinName;
GLCD::cDriver * mLcd;
cGraphLCDDisplay * mDisplay;
public:
cPluginGraphLCD();
virtual ~cPluginGraphLCD();
virtual const char * Version() { return VERSION; }
virtual const char * Description() { return tr(DESCRIPTION); }
virtual const char * CommandLineHelp();
virtual bool ProcessArgs(int argc, char * argv[]);
virtual bool Initialize();
virtual bool Start();
virtual void Housekeeping();
virtual const char **SVDRPHelpPages(void);
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
virtual void MainThreadHook(void);
virtual const char * MainMenuEntry() { return MAINMENUENTRY; }
virtual cOsdObject * MainMenuAction();
virtual cMenuSetupPage * SetupMenu();
virtual bool SetupParse(const char * Name, const char * Value);
};
cPluginGraphLCD::cPluginGraphLCD()
: mConfigName(""),
mDisplayName(""),
mSkinsPath(""),
mSkinName(""),
mLcd(NULL),
mDisplay(NULL)
{
}
cPluginGraphLCD::~cPluginGraphLCD()
{
delete mDisplay;
if (mLcd)
mLcd->DeInit();
delete mLcd;
}
const char * cPluginGraphLCD::CommandLineHelp()
{
return " -c CFG, --config=CFG use CFG as driver config file (default is \"/etc/graphlcd.conf\")\n"
" -d DISP, --display=DISP use display DISP for output\n"
" -s SKIN, --skin=SKIN use skin SKIN (default is \"default\")\n"
" -p PATH, --skinspath=PATH use path PATH for skins (default is \"<plugin_config>/skins/\")\n";
}
bool cPluginGraphLCD::ProcessArgs(int argc, char * argv[])
{
static struct option long_options[] =
{
{"config", required_argument, NULL, 'c'},
{"display", required_argument, NULL, 'd'},
{"skinspath", required_argument, NULL, 'p'},
{"skin", required_argument, NULL, 's'},
{NULL}
};
int c;
int option_index = 0;
while ((c = getopt_long(argc, argv, "c:d:p:s:", long_options, &option_index)) != -1)
{
switch (c)
{
case 'c':
mConfigName = optarg;
break;
case 'd':
mDisplayName = optarg;
break;
case 'p':
mSkinsPath = optarg;
break;
case 's':
mSkinName = optarg;
break;
default:
return false;
}
}
return true;
}
bool cPluginGraphLCD::Initialize()
{
unsigned int displayNumber = 0;
const char * cfgDir;
#if APIVERSNUM < 10503
RegisterI18n(Phrases);
#endif
if (mConfigName.length() == 0)
{
mConfigName = kDefaultConfigFile;
isyslog("graphlcd plugin: No config file specified, using default (%s).\n", mConfigName.c_str());
}
if (GLCD::Config.Load(mConfigName) == false)
{
esyslog("graphlcd plugin: Error loading config file!\n");
return false;
}
if (GLCD::Config.driverConfigs.size() > 0)
{
if (mDisplayName.length() > 0)
{
for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++)
{
if (GLCD::Config.driverConfigs[displayNumber].name == mDisplayName)
break;
}
if (displayNumber == GLCD::Config.driverConfigs.size())
{
esyslog("graphlcd plugin: ERROR: Specified display %s not found in config file!\n", mDisplayName.c_str());
return false;
}
}
else
{
isyslog("graphlcd plugin: WARNING: No display specified, using first one (%s).\n", GLCD::Config.driverConfigs[0].name.c_str());
displayNumber = 0;
mDisplayName = GLCD::Config.driverConfigs[0].name;
}
}
else
{
esyslog("graphlcd plugin: ERROR: No displays specified in config file!\n");
return false;
}
mLcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]);
if (!mLcd)
{
esyslog("graphlcd plugin: ERROR: Failed creating display object %s\n", mDisplayName.c_str());
return false;
}
cfgDir = ConfigDirectory(kPluginName);
if (!cfgDir)
return false;
mDisplay = new cGraphLCDDisplay();
if (!mDisplay)
return false;
if (mSkinName == "")
mSkinName = "default";
if (!mDisplay->Initialise(mLcd, cfgDir, mSkinsPath, mSkinName))
return false;
return true;
}
bool cPluginGraphLCD::Start()
{
int count;
dsyslog("graphlcd plugin: waiting for display thread to get ready");
for (count = 0; count < 100 /*1200*/; count++)
{
if (mDisplay->Active())
{
dsyslog ("graphlcd plugin: display thread ready");
return true;
}
cCondWait::SleepMs(100);
}
dsyslog ("graphlcd plugin: timeout while waiting for display thread");
/* no activity after 10 secs: display is unusable */
GraphLCDSetup.PluginActive = 0;
/* don't return false, else VDR would restart itself */
return true /*false*/;
}
void cPluginGraphLCD::Housekeeping()
{
}
void cPluginGraphLCD::MainThreadHook()
{
if (mDisplay)
mDisplay->Tick();
}
const char **cPluginGraphLCD::SVDRPHelpPages(void)
{
static const char *HelpPages[] = {
"CLS Clear Display.",
"UPD Update Display.",
"OFF Switch Plugin off.",
"ON Switch Plugin on.",
"SET <key> <value> Set a key=value entry.",
"SETEXP <exp> <key> <value> Set a key=value entry which expires after <exp> secs.",
"UNSET <key> Unset (clear) entry <key>.",
"GET <key> Get value assigned to key.",
NULL
};
return HelpPages;
}
cString cPluginGraphLCD::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
std::string option = Option;
size_t firstpos = std::string::npos;
size_t secondpos = std::string::npos;
firstpos = option.find_first_of(' ');
if (firstpos != std::string::npos) {
// remove extra spaces
while ( ((firstpos+1) < option.length()) && (option[firstpos+1] == ' ') ) {
option.erase(firstpos+1, 1);
}
secondpos = option.find_first_of(' ', firstpos+1);
if (firstpos != std::string::npos) {
// remove extra spaces
while ( ((secondpos+1) < option.length()) && (option[secondpos+1] == ' ') ) {
option.erase(secondpos+1, 1);
}
}
}
if (strcasecmp(Command, "CLS") == 0) {
if (GraphLCDSetup.PluginActive == 1) {
return "Error: Plugin is active.";
} else {
mDisplay->Clear();
return "GraphLCD cleared.";
};
} else
if (strcasecmp(Command, "UPD") == 0) {
if (GraphLCDSetup.PluginActive == 0) {
return "Error: Plugin is not active.";
} else {
mDisplay->Update();
return "GraphLCD updated.";
};
} else
if (strcasecmp(Command, "OFF") == 0) {
GraphLCDSetup.PluginActive = 0;
return "GraphLCD Plugin switched off.";
} else
if (strcasecmp(Command, "ON") == 0) {
GraphLCDSetup.PluginActive = 1;
mDisplay->Update();
return "GraphLCD Plugin switched on.";
} else
if (strcasecmp(Command, "SET") == 0) {
if (firstpos != std::string::npos) {
std::string key = option.substr(0, firstpos);
if ( isalpha(key[0]) ) {
mDisplay->GetExtData()->Set(key, option.substr(firstpos+1));
return "SET ok";
}
}
return "SET requires two parameters: SET <key> <value>.";
} else
if (strcasecmp(Command, "SETEXP") == 0) {
if (secondpos != std::string::npos) {
std::string key = option.substr(firstpos+1, secondpos-firstpos-1);
std::string value = option.substr(secondpos+1);
if ( isalpha(key[0]) && isdigit(option[0]) ) {
uint32_t expsec = (uint32_t)strtoul( option.substr(0, firstpos).c_str(), NULL, 10);
mDisplay->GetExtData()->Set( key, value, expsec );
return "SETEXP ok";
}
}
return "SETEXP requires three parameters: SETEXP <exp> <key> <value>.";
} else
if (strcasecmp(Command, "UNSET") == 0) {
if (firstpos == std::string::npos) {
mDisplay->GetExtData()->Unset( option );
return "UNSET ok";
} else {
return "UNSET requires exactly one parameter: UNSET <key>.";
}
} else
if (strcasecmp(Command, "GET") == 0) {
if (firstpos == std::string::npos) {
std::string res = mDisplay->GetExtData()->Get( option );
std::string retval = "GET "; retval.append(option); retval.append(": ");
if (res != "" ) {
retval.append(res);
} else {
retval.append("(null)");
}
return retval.c_str();
} else {
return "GET requires exactly one parameter: GET <key>.";
}
}
return NULL;
}
cOsdObject * cPluginGraphLCD::MainMenuAction()
{
return NULL;
}
cMenuSetupPage * cPluginGraphLCD::SetupMenu()
{
return new cGraphLCDMenuSetup();
}
bool cPluginGraphLCD::SetupParse(const char * Name, const char * Value)
{
if (!strcasecmp(Name, "PluginActive")) GraphLCDSetup.PluginActive = atoi(Value);
else if (!strcasecmp(Name, "ShowDateTime")) GraphLCDSetup.ShowDateTime = atoi(Value);
else if (!strcasecmp(Name, "ShowChannel")) GraphLCDSetup.ShowChannel = atoi(Value);
else if (!strcasecmp(Name, "ShowChannelLogo")) GraphLCDSetup.ShowChannelLogo = atoi(Value);
else if (!strcasecmp(Name, "ShowSymbols")) GraphLCDSetup.ShowSymbols = atoi(Value);
else if (!strcasecmp(Name, "ShowProgram")) GraphLCDSetup.ShowProgram = atoi(Value);
else if (!strcasecmp(Name, "ShowTimebar")) GraphLCDSetup.ShowTimebar = atoi(Value);
else if (!strcasecmp(Name, "ShowMenu")) GraphLCDSetup.ShowMenu = atoi(Value);
else if (!strcasecmp(Name, "ShowMessages")) GraphLCDSetup.ShowMessages = atoi(Value);
else if (!strcasecmp(Name, "ShowColorButtons")) GraphLCDSetup.ShowColorButtons = atoi(Value);
else if (!strcasecmp(Name, "ShowVolume")) GraphLCDSetup.ShowVolume = atoi(Value);
else if (!strcasecmp(Name, "ShowNotRecording")) GraphLCDSetup.ShowNotRecording = atoi(Value);
else if (!strcasecmp(Name, "IdentifyReplayType")) GraphLCDSetup.IdentifyReplayType = atoi(Value);
else if (!strcasecmp(Name, "ModifyReplayString")) GraphLCDSetup.ModifyReplayString = atoi(Value);
else if (!strcasecmp(Name, "ShowReplayLogo")) GraphLCDSetup.ShowReplayLogo = atoi(Value);
else if (!strcasecmp(Name, "ScrollMode")) GraphLCDSetup.ScrollMode = atoi(Value);
else if (!strcasecmp(Name, "ScrollSpeed")) GraphLCDSetup.ScrollSpeed = atoi(Value);
else if (!strcasecmp(Name, "ScrollTime")) GraphLCDSetup.ScrollTime = atoi(Value);
else if (!strcasecmp(Name, "BrightnessActive")) GraphLCDSetup.BrightnessActive = atoi(Value);
else if (!strcasecmp(Name, "BrightnessIdle")) GraphLCDSetup.BrightnessIdle = atoi(Value);
else if (!strcasecmp(Name, "BrightnessDelay")) GraphLCDSetup.BrightnessDelay = atoi(Value);
else return false;
return true;
}
VDRPLUGINCREATOR(cPluginGraphLCD); // Don't touch this!
|