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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
/*
* lightpack.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id$
*/
#include "lightpack.h"
#include "liblightpack.h"
// Gamma = Gamma * 10
int LightpackGamma = 50;
int LightpackBrightness = 50;
int LightpackSmooth = 127;
class cLibLightpack libLightpack;
// --- myMenuSetup ------------------------------------------------------------
class myMenuSetup : public cMenuSetupPage
{
private:
int menuGroupCount;
cStringList SwitchGroupKeyTexts;
cStringList SwitchWithOKTexts;
cStringList HideGroupsAtTexts;
protected:
virtual void Store()
{
SetupStore("Gamma", LightpackGamma);
SetupStore("Brightness", LightpackBrightness);
SetupStore("Smooth", LightpackSmooth);
}
public:
~myMenuSetup()
{
}
myMenuSetup()
{
Add(new cOsdItem(tr("Appearance"), osUnknown, false));
Add(new cMenuEditIntItem(tr("Gamma"), &LightpackGamma, 0, 100));
Add(new cMenuEditIntItem(tr("Brightness"), &LightpackBrightness, 0, 100));
Add(new cMenuEditIntItem(tr("Smooth"), &LightpackSmooth, 0, 255));
}
};
cPluginLightpack::cPluginLightpack(void)
{
// Initialize any member variables here.
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
}
cPluginLightpack::~cPluginLightpack()
{
// Clean up after yourself!
}
const char *cPluginLightpack::CommandLineHelp(void)
{
// Return a string that describes all known command line options.
return NULL;
}
bool cPluginLightpack::ProcessArgs(int argc, char *argv[])
{
// Implement command line argument processing here if applicable.
return true;
}
bool cPluginLightpack::Initialize(void)
{
// Initialize any background activities the plugin shall perform.
LoadConfig();
return true;
}
bool cPluginLightpack::Start(void)
{
// Start any background activities the plugin shall perform.
return true;
}
void cPluginLightpack::Stop(void)
{
// Stop any background activities the plugin is performing.
}
void cPluginLightpack::Housekeeping(void)
{
// Perform any cleanup or other regular tasks.
}
void cPluginLightpack::MainThreadHook(void)
{
// Perform actions in the context of the main program thread.
// WARNING: Use with great care - see PLUGINS.html!
}
cString cPluginLightpack::Active(void)
{
// Return a message string if shutdown should be postponed
return NULL;
}
time_t cPluginLightpack::WakeupTime(void)
{
// Return custom wakeup time for shutdown script
return 0;
}
cOsdObject *cPluginLightpack::MainMenuAction(void)
{
return new myOsdMenu();
}
cMenuSetupPage *cPluginLightpack::SetupMenu(void)
{
return new myMenuSetup();
}
bool cPluginLightpack::SetupParse(const char *Name, const char *Value)
{
if(!strcmp("Gamma", Name))
LightpackGamma = atof(Value);
else if(!strcmp("Brightness", Name))
LightpackBrightness = atoi(Value);
else if(!strcmp("Smooth", Name))
LightpackSmooth = atoi(Value);
else
return false;
return true;
}
bool cPluginLightpack::Service(const char *Id, void *Data)
{
// Handle custom service requests from other plugins
return false;
}
const char **cPluginLightpack::SVDRPHelpPages(void)
{
// Return help text for SVDRP commands this plugin implements
return NULL;
}
cString cPluginLightpack::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
// Process SVDRP commands this plugin implements
return NULL;
}
void cPluginLightpack::LoadConfig(void)
{
cString ConfigDir;
cString ConfigFile;
FILE *fp;
ConfigDir = ConfigDirectory("lightpack");
ConfigFile = AddDirectory(ConfigDir, "lightpack.conf");
fp = fopen( *ConfigFile, "r");
if( !fp )
{
fp = fopen(ConfigFile, "w");
fprintf(fp, "server=127.0.0.1\n");
fprintf(fp, "port=3636\n");
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
char confFile[256];
sprintf(confFile, "%s/.Prismatik/main.conf", homedir);
char *ApiKey = GetConfigValue(confFile, "AuthKey");
if( ApiKey )
{
fprintf(fp, "apikey=%s\n", ApiKey);
free(ApiKey);
} else
fprintf(fp, "apikey=[APIKEY]\n");
fclose(fp);
fp = fopen(ConfigFile, "r");
if( !fp )
{
syslog(LOG_ERR, "lightpack can't open configfile: %s!", (const char*)ConfigFile);
return;
}
}
fclose(fp);
libLightpack.Server = GetConfigValue(ConfigFile, "server");
libLightpack.Port = GetConfigValue(ConfigFile, "port");
libLightpack.ApiKey = GetConfigValue(ConfigFile, "apikey");
syslog(LOG_ERR, "lightpack server=%s port=%s apikey=%s", *libLightpack.Server, *libLightpack.Port, *libLightpack.ApiKey);
}
char * cPluginLightpack::GetConfigValue(const char *Filename, const char *Setting)
{
char *Value;
Value = (char*) malloc( sizeof(char) * 1024);
char setting[1024];
FILE *fp;
fp = fopen(Filename, "r");
if( fp != NULL )
{
char *line = NULL;
size_t len = 0;
ssize_t read;
while( (read = getline(&line, &len, fp)) != -1 ) {
if( sscanf(line, "%[^=]=%s", setting, Value) == 2 ) {
if( !strcmp(setting, Setting) ) {
free(line);
return Value;
}
}
}
if (line)
free(line);
}
return NULL;
}
cLibLightpack::cLibLightpack()
{
is_connected = false;
if( lightpack_init() == false )
is_init = false;
else
is_init = true;
}
cLibLightpack::~cLibLightpack()
{
}
bool cLibLightpack::isConnected()
{
return is_connected;
}
int cLibLightpack::Connect(void)
{
if( !is_init )
return 1;
int port = atoi( *Port );
if( lightpack_connect( *Server, port) == false )
{
return 2;
}
if( lightpack_login(*ApiKey) != 0 )
{
return 3;
}
is_connected = true;
return 0;
}
void cLibLightpack::Disconnect(void)
{
is_connected = false;
if( !is_init )
return;
lightpack_disconnect();
}
int cLibLightpack::SetGamma(double Value)
{
if( !is_init )
return 1;
if( !is_connected )
return 2;
int ret = 4;
char *lightret = lightpack_setgamma(Value);
if( lightret != NULL )
{
syslog(LOG_ERR, "lightpack SetGamma=%s", lightret);
if( strstr(lightret, "ok") )
{
gamma = Value;
ret = 0;
} else
ret = 3;
free(lightret);
} else
ret = 4;
return ret;
}
int cLibLightpack::SetBrightness(int Value)
{
if( !is_init )
return 1;
if( !is_connected )
return 2;
int ret = 4;
char *lightret = lightpack_setbrightness(Value);
if( lightret != NULL )
{
syslog(LOG_ERR, "lightpack SetBrightness=%s", lightret);
if( strstr(lightret, "ok") )
{
brightness = Value;
ret = 0;
} else
ret = 3;
free(lightret);
} else
ret = 4;
return ret;
}
int cLibLightpack::SetSmooth(int Value)
{
if( !is_init )
return 1;
if( !is_connected )
return 2;
int ret = 4;
char *lightret = lightpack_setsmooth(Value);
if( lightret != NULL )
{
syslog(LOG_ERR, "lightpack SetSmooth=%s", lightret);
if( strstr(lightret, "ok") )
{
smooth = Value;
ret = 0;
} else
ret = 3;
free(lightret);
} else
ret = 4;
return ret;
}
double cLibLightpack::GetGamma(void)
{
return gamma;
}
int cLibLightpack::GetBrightness(void)
{
return brightness;
}
int cLibLightpack::GetSmooth(void)
{
return smooth;
}
int cLibLightpack::SetStatus(bool Value)
{
if( !is_init )
return 1;
if( !is_connected )
return 2;
int ret = 4;
char *lightret = NULL;
if( Value )
lightret = lightpack_setstatus("on");
else
lightret = lightpack_setstatus("off");
if( lightret != NULL )
{
if( strstr(lightret, "ok") )
{
ret = 0;
} else
ret = 3;
free(lightret);
} else
ret = 4;
return ret;
}
int cLibLightpack::SetMode(int Value)
{
if( !is_init )
return 1;
if( !is_connected )
return 2;
int ret = 4;
char *lightret = NULL;
if( Value == 1)
lightret = lightpack_setmode("ambilight");
else if( Value == 2 )
lightret = lightpack_setmode("moodlamp");
else
return ret;
if( lightret != NULL )
{
if( strstr(lightret, "ok") )
{
ret = 0;
} else
ret = 3;
free(lightret);
} else
ret = 4;
return ret;
}
int cLibLightpack::GetStatus(void)
{
int ret = 0;
char *status = lightpack_getstatus();
if( status != NULL )
{
if( strstr(status, "on") )
ret = 1;
else
ret = 2;
free(status);
} else
ret = 0;
return ret;
}
int cLibLightpack::GetMode(void)
{
int ret = 0;
char *mode = lightpack_getmode();
if( mode != NULL )
{
if( strstr(mode, "ambilight") )
ret = 1;
else
ret = 2;
free(mode);
} else
ret = 0;
return ret;
}
double cLibLightpack::GetFps(void)
{
double ret = -1;
char *fps = lightpack_getmode();
if( fps != NULL )
{
ret = atof(fps);
free(fps);
} else
ret = -1;
return ret;
}
int cLibLightpack::GetProfile(cString &Profile)
{
int ret = 0;
char *profile = lightpack_getprofile();
if( profile != NULL )
{
Profile = strdup(profile);
ret = 1;
free(profile);
} else
ret = 0;
return ret;
}
VDRPLUGINCREATOR(cPluginLightpack); // Don't touch this!
|