summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--liblightpack/testclient.c9
-rw-r--r--lightpack.c530
-rw-r--r--lightpack.h33
-rw-r--r--osdmenu.c119
-rw-r--r--osdmenu.h8
5 files changed, 495 insertions, 204 deletions
diff --git a/liblightpack/testclient.c b/liblightpack/testclient.c
index 914c72e..76dd514 100644
--- a/liblightpack/testclient.c
+++ b/liblightpack/testclient.c
@@ -125,7 +125,16 @@ int main(void)
if( profiles != NULL )
{
printf("\tgetprofiles: %s\n", profiles);
+ printf("\tstart split\n");
+ char *tok;
+ tok = strtok(profiles, ";");
+ while( tok != NULL )
+ {
+ printf("\tprofile: %s\n", tok);
+ tok = strtok(NULL, ";");
+ }
free(profiles);
+ printf("\tend split\n");
} else
printf("\tgetprofiles error\n");
diff --git a/lightpack.c b/lightpack.c
index f5dfcaf..a955549 100644
--- a/lightpack.c
+++ b/lightpack.c
@@ -13,16 +13,15 @@ int LightpackGamma = 50;
int LightpackBrightness = 50;
int LightpackSmooth = 127;
+int LightpackProfileIndex = 0;
+
class cLibLightpack libLightpack;
// --- myMenuSetup ------------------------------------------------------------
class myMenuSetup : public cMenuSetupPage
{
private:
- int menuGroupCount;
- cStringList SwitchGroupKeyTexts;
- cStringList SwitchWithOKTexts;
- cStringList HideGroupsAtTexts;
+ cStringList Profiles;
protected:
virtual void Store()
@@ -30,6 +29,9 @@ class myMenuSetup : public cMenuSetupPage
SetupStore("Gamma", LightpackGamma);
SetupStore("Brightness", LightpackBrightness);
SetupStore("Smooth", LightpackSmooth);
+ SetupStore("ProfileIndex", LightpackProfileIndex);
+
+ SetLightpackSettings();
}
public:
~myMenuSetup()
@@ -41,7 +43,34 @@ class myMenuSetup : public cMenuSetupPage
Add(new cMenuEditIntItem(tr("Gamma"), &LightpackGamma, 0, 100));
Add(new cMenuEditIntItem(tr("Brightness"), &LightpackBrightness, 0, 100));
Add(new cMenuEditIntItem(tr("Smooth"), &LightpackSmooth, 0, 255));
+ if( libLightpack.GetProfiles( Profiles ) ) {
+ if( LightpackProfileIndex < 0 || LightpackProfileIndex > Profiles.Size() )
+ LightpackProfileIndex = 0;
+ Add(new cMenuEditStraItem(tr("Profile"), &LightpackProfileIndex, Profiles.Size(), &Profiles[0]));
+ }
+ else
+ Add(new cOsdItem(tr("can't get profiles list"), osUnknown, false));
+ }
+ void SetLightpackSettings(void)
+ {
+ cStringList Profiles;
+ if( libLightpack.GetProfiles( Profiles ) ) {
+ if( LightpackProfileIndex < 0 || LightpackProfileIndex > Profiles.Size() )
+ LightpackProfileIndex = 0;
+ if( !libLightpack.SetProfile( Profiles[LightpackProfileIndex] ) )
+ syslog(LOG_ERR, "lightpack can't set profile to %s", Profiles[LightpackProfileIndex] );
+ }
+ else
+ syslog(LOG_ERR, "lightpack can't get profile list");
+
+ if( !libLightpack.SetGamma( (double) LightpackGamma / 10.0 ) )
+ syslog(LOG_ERR, "lightpack can't set gamma");
+ if( !libLightpack.SetBrightness( LightpackBrightness ) )
+ syslog(LOG_ERR, "lightpack can't set brightness");
+ if( !libLightpack.SetSmooth( LightpackSmooth ) )
+ syslog(LOG_ERR, "lightpack can't set smooth");
}
+
};
@@ -72,14 +101,14 @@ bool cPluginLightpack::ProcessArgs(int argc, char *argv[])
bool cPluginLightpack::Initialize(void)
{
- // Initialize any background activities the plugin shall perform.
- LoadConfig();
- return true;
+ // Initialize any background activities the plugin shall perform.
+ LoadConfig();
+ SetLightpackSettings();
+ return true;
}
bool cPluginLightpack::Start(void)
{
- // Start any background activities the plugin shall perform.
return true;
}
@@ -119,17 +148,26 @@ cOsdObject *cPluginLightpack::MainMenuAction(void)
cMenuSetupPage *cPluginLightpack::SetupMenu(void)
{
return new myMenuSetup();
+ SetLightpackSettings();
}
bool cPluginLightpack::SetupParse(const char *Name, const char *Value)
{
- if(!strcmp("Gamma", Name))
+ if(!strcmp("Gamma", Name)) {
LightpackGamma = atof(Value);
- else if(!strcmp("Brightness", Name))
+ if( LightpackGamma < 0 || LightpackGamma > 100 )
+ LightpackGamma = 50;
+ } else if(!strcmp("Brightness", Name)) {
LightpackBrightness = atoi(Value);
- else if(!strcmp("Smooth", Name))
+ if( LightpackBrightness < 0 || LightpackBrightness > 100 )
+ LightpackBrightness = 50;
+ } else if(!strcmp("Smooth", Name)) {
LightpackSmooth = atoi(Value);
- else
+ if( LightpackSmooth < 0 || LightpackSmooth > 255 )
+ LightpackSmooth = 127;
+ } else if(!strcmp("ProfileIndex", Name)) {
+ LightpackProfileIndex = atoi(Value);
+ } else
return false;
return true;
}
@@ -139,17 +177,108 @@ bool cPluginLightpack::Service(const char *Id, void *Data)
// Handle custom service requests from other plugins
return false;
}
+static const char *SVDRPHelpText[] = {
+ "STATUS <ON/OFF>\n" "\040 set lightpack status\n\n"
+ " available options are\n"
+ " ON set lightpack on\n"
+ " OFF set lightpack off\n",
+ "MODE <AMBILIGHT/LAMP>\n" "\040 set lightpack mode\n\n"
+ " available options are\n"
+ " AMBILIGHT set mode to ambilight\n"
+ " LAMP set mode to lamp\n",
+ "GAMMA <value>\n" "\040 set gamma value\n\n"
+ " The value must be between 0 - 100\n"
+ " the value will be devided by 10, because prismatik handle values between 0.0 - 10.0\n",
+ "BRIGHT <value>\n" "\040 set brightness value\n\n"
+ " The value must be between 0 - 100\n",
+ "SMOOTH <value>\n" "\040 set smooth value\n\n"
+ " The value must be between 0 - 255\n",
+ "PROFILE <profile>\n" "\040 set the profile\n\n",
+ NULL
+};
const char **cPluginLightpack::SVDRPHelpPages(void)
{
- // Return help text for SVDRP commands this plugin implements
- return NULL;
+ return SVDRPHelpText;
}
cString cPluginLightpack::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
- // Process SVDRP commands this plugin implements
- return NULL;
+ if (!strcasecmp(Command, "STATUS")) {
+ if( !strcasecmp(Option, "ON")) {
+ if( libLightpack.SetStatus( true ) )
+ return "Successful set status on";
+ return cString::sprintf("Error set status on: %s", libLightpack.GetLastError() );
+ } else if( !strcasecmp(Option, "OFF")) {
+ if( libLightpack.SetStatus( false ) )
+ return "Successful set status off";
+ return cString::sprintf("Error set status off: %s", libLightpack.GetLastError() );
+ } else
+ return "Error unknown status command. Use ON/OFF";
+ } else if (!strcasecmp(Command, "MODE")) {
+ if( !strcasecmp(Option, "Ambilight")) {
+ if( libLightpack.SetMode( 1 ) )
+ return "Successful set mode to ambilight";
+ return cString::sprintf("Error set mode to ambilight: %s", libLightpack.GetLastError() );
+ } else if( !strcasecmp(Option, "Lamp")) {
+ if( libLightpack.SetMode( 2 ) )
+ return "Successful set mode to lamp";
+ return cString::sprintf("Error set mode to lamp: %s", libLightpack.GetLastError() );
+ } else
+ return "Error unknown mode command. Use AMBILIGHT/LAMP";
+ } else if (!strcasecmp(Command, "GAMMA")) {
+ int gamma = atoi(Option);
+ if( gamma >= 0 && gamma <= 100 ) {
+ if( libLightpack.SetGamma( (double) gamma / 10.0 ) )
+ return "Successful set gamma";
+ return cString::sprintf("Error set gamma: %s", libLightpack.GetLastError() );
+ }
+
+ return "Error set gamma. Value not in range. The value must be between 0 - 100!";
+ } else if (!strcasecmp(Command, "BRIGHT")) {
+ int bright = atoi(Option);
+ if( bright >= 0 && bright <= 100 ) {
+ if( libLightpack.SetBrightness( bright) )
+ return "Successful set brightness";
+ return cString::sprintf("Error set brightness: %s", libLightpack.GetLastError() );
+ }
+
+ return "Error set brightness. Value not in range. The value must be between 0 - 100!";
+ } else if (!strcasecmp(Command, "SMOOTH")) {
+ int smooth = atoi(Option);
+ if( smooth >= 0 && smooth <= 255 ) {
+ if( libLightpack.SetSmooth( smooth ) )
+ return "Successful set smooth";
+ return cString::sprintf("Error set smooth: %s", libLightpack.GetLastError() );
+ }
+
+ return "Error set smooth. Value not in range. The value must be between 0 - 255!";
+ } else if (!strcasecmp(Command, "PROFILE")) {
+ if( libLightpack.SetProfile( Option ) )
+ return "Successful set profile";
+ return cString::sprintf("Error set profile: %s", libLightpack.GetLastError() );
+ }
+ return NULL;
+}
+
+void cPluginLightpack::SetLightpackSettings(void)
+{
+ cStringList Profiles;
+ if( libLightpack.GetProfiles( Profiles ) ) {
+ if( LightpackProfileIndex < 0 || LightpackProfileIndex > Profiles.Size() )
+ LightpackProfileIndex = 0;
+ if( !libLightpack.SetProfile( Profiles[LightpackProfileIndex] ) )
+ syslog(LOG_ERR, "lightpack can't set profile to %s", Profiles[LightpackProfileIndex] );
+ }
+ else
+ syslog(LOG_ERR, "lightpack can't get profile list");
+
+ if( !libLightpack.SetGamma( (double) LightpackGamma / 10.0 ) )
+ syslog(LOG_ERR, "lightpack can't set gamma");
+ if( !libLightpack.SetBrightness( LightpackBrightness ) )
+ syslog(LOG_ERR, "lightpack can't set brightness");
+ if( !libLightpack.SetSmooth( LightpackSmooth ) )
+ syslog(LOG_ERR, "lightpack can't set smooth");
}
void cPluginLightpack::LoadConfig(void)
@@ -193,8 +322,6 @@ void cPluginLightpack::LoadConfig(void)
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)
@@ -228,6 +355,7 @@ char * cPluginLightpack::GetConfigValue(const char *Filename, const char *Settin
cLibLightpack::cLibLightpack()
{
+ LastError = "";
is_connected = false;
if( lightpack_init() == false )
is_init = false;
@@ -238,29 +366,44 @@ cLibLightpack::~cLibLightpack()
{
}
+const char* cLibLightpack::GetLastError(void)
+{
+ //syslog(LOG_ERR, "lightpack LastError: %s", *LastError);
+
+ Error = LastError;
+ LastError = "";
+ return *Error;
+}
+
bool cLibLightpack::isConnected()
{
return is_connected;
}
-int cLibLightpack::Connect(void)
+bool cLibLightpack::Connect(void)
{
- if( !is_init )
- return 1;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
int port = atoi( *Port );
- if( lightpack_connect( *Server, port) == false )
- {
- return 2;
+ if( lightpack_connect( *Server, port) == false ) {
+ LastError = "connection failed";
+ return false;
}
- if( lightpack_login(*ApiKey) != 0 )
- {
- return 3;
+ int ret = 0;
+ if( (ret = lightpack_login(*ApiKey)) != 0 ) {
+ if( ret == 1 )
+ LastError = "authentication failed, apikey wrong";
+ else
+ LastError = "authentication failed, socket error";
+ return false;
}
is_connected = true;
- return 0;
+ return true;
}
void cLibLightpack::Disconnect(void)
@@ -270,76 +413,88 @@ void cLibLightpack::Disconnect(void)
return;
lightpack_disconnect();
+ LastError = "";
}
-int cLibLightpack::SetGamma(double Value)
+bool cLibLightpack::SetGamma(double Value)
{
- if( !is_init )
- return 1;
- if( !is_connected )
- return 2;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
- int ret = 4;
char *lightret = lightpack_setgamma(Value);
- if( lightret != NULL )
- {
- syslog(LOG_ERR, "lightpack SetGamma=%s", lightret);
- if( strstr(lightret, "ok") )
- {
+ if( lightret != NULL ) {
+ if( strstr(lightret, "ok") ) {
gamma = Value;
- ret = 0;
- } else
- ret = 3;
- free(lightret);
- } else
- ret = 4;
- return ret;
+ free(lightret);
+ return true;
+ } else {
+ LastError = cString::sprintf("set failed return: %s", lightret);
+ free(lightret);
+ return false;
+ }
+ }
+ LastError = "set failed unknown error";
+ return false;
}
-int cLibLightpack::SetBrightness(int Value)
+
+bool cLibLightpack::SetBrightness(int Value)
{
- if( !is_init )
- return 1;
- if( !is_connected )
- return 2;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
- int ret = 4;
char *lightret = lightpack_setbrightness(Value);
- if( lightret != NULL )
- {
- syslog(LOG_ERR, "lightpack SetBrightness=%s", lightret);
+ if( lightret != NULL ) {
if( strstr(lightret, "ok") )
{
brightness = Value;
- ret = 0;
- } else
- ret = 3;
- free(lightret);
- } else
- ret = 4;
- return ret;
+ free(lightret);
+ return true;
+ } else {
+ LastError = cString::sprintf("set failed return: %s", lightret);
+ free(lightret);
+ return false;
+ }
+ }
+ LastError = "set failed unknown error";
+ return false;
}
-int cLibLightpack::SetSmooth(int Value)
-{
- if( !is_init )
- return 1;
- if( !is_connected )
- return 2;
- int ret = 4;
+bool cLibLightpack::SetSmooth(int Value)
+{
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
char *lightret = lightpack_setsmooth(Value);
- if( lightret != NULL )
- {
- syslog(LOG_ERR, "lightpack SetSmooth=%s", lightret);
- if( strstr(lightret, "ok") )
- {
+ if( lightret != NULL ) {
+ if( strstr(lightret, "ok") ) {
smooth = Value;
- ret = 0;
- } else
- ret = 3;
- free(lightret);
- } else
- ret = 4;
- return ret;
+ free(lightret);
+ return true;
+ } else {
+ LastError = cString::sprintf("set failed return: %s", lightret);
+ free(lightret);
+ return false;
+ }
+ }
+ LastError = "set failed unknown error";
+ return false;
}
double cLibLightpack::GetGamma(void)
@@ -355,123 +510,218 @@ int cLibLightpack::GetSmooth(void)
return smooth;
}
-int cLibLightpack::SetStatus(bool Value)
+bool cLibLightpack::SetStatus(bool Value)
{
- if( !is_init )
- return 1;
- if( !is_connected )
- return 2;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
- 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;
+ if( lightret != NULL ) {
+ if( strstr(lightret, "ok") ) {
+ free(lightret);
+ return true;
+ } else {
+ LastError = cString::sprintf("set failed return: %s", lightret);
+ free(lightret);
+ return false;
+ }
+ }
+ LastError = "set failed unknown error";
+ return false;
}
-int cLibLightpack::SetMode(int Value)
+bool cLibLightpack::SetMode(int Value)
{
- if( !is_init )
- return 1;
- if( !is_connected )
- return 2;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
- int ret = 4;
char *lightret = NULL;
if( Value == 1)
lightret = lightpack_setmode("ambilight");
else if( Value == 2 )
lightret = lightpack_setmode("moodlamp");
- else
- return ret;
+ else {
+ LastError = "wrong mode";
+ return false;
+ }
- if( lightret != NULL )
- {
- if( strstr(lightret, "ok") )
- {
- ret = 0;
- } else
- ret = 3;
- free(lightret);
- } else
- ret = 4;
- return ret;
+ if( lightret != NULL ) {
+ if( strstr(lightret, "ok") ) {
+ free(lightret);
+ return true;
+ } else {
+ free(lightret);
+ LastError = cString::sprintf("set failed return: %s", lightret);
+ return false;
+ }
+ }
+ LastError = "set failed unknown error";
+ return false;
+}
+
+bool cLibLightpack::SetProfile(cString Profile)
+{
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
+
+ char *lightret = NULL;
+ lightret = lightpack_setprofile(*Profile);
+ if( lightret != NULL ) {
+ if( strstr(lightret, "ok") ) {
+ free(lightret);
+ return true;
+ } else {
+ LastError = cString::sprintf("set failed return: %s", lightret);
+ free(lightret);
+ return false;
+ }
+ }
+ LastError = "set failed unknown error";
+ return false;
}
int cLibLightpack::GetStatus(void)
{
+ if( !is_init ) {
+ LastError = "not initialized";
+ return 0;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return 0;
+ }
int ret = 0;
char *status = lightpack_getstatus();
- if( status != NULL )
- {
+ if( status != NULL ) {
if( strstr(status, "on") )
ret = 1;
- else
+ else
ret = 2;
free(status);
- } else
+ } else {
+ LastError = "set failed unknown error";
ret = 0;
+ }
return ret;
}
int cLibLightpack::GetMode(void)
{
+ if( !is_init ) {
+ LastError = "not initialized";
+ return 0;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return 0;
+ }
int ret = 0;
char *mode = lightpack_getmode();
- if( mode != NULL )
- {
+ if( mode != NULL ) {
if( strstr(mode, "ambilight") )
ret = 1;
else
ret = 2;
free(mode);
- } else
+ } else {
+ LastError = "set failed unknown error";
ret = 0;
+ }
return ret;
}
-double cLibLightpack::GetFps(void)
+bool cLibLightpack::GetFps(double &Fps)
{
- double ret = -1;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
char *fps = lightpack_getmode();
- if( fps != NULL )
- {
- ret = atof(fps);
+ if( fps != NULL ) {
+ Fps = atof(fps);
free(fps);
- } else
- ret = -1;
+ return true;
+ }
+ LastError = "set failed unknown error";
- return ret;
+ return false;
}
-int cLibLightpack::GetProfile(cString &Profile)
+bool cLibLightpack::GetProfile(cString &Profile)
{
- int ret = 0;
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
char *profile = lightpack_getprofile();
- if( profile != NULL )
- {
+ if( profile != NULL ) {
Profile = strdup(profile);
- ret = 1;
free(profile);
- } else
- ret = 0;
+ return true;
+ }
+ LastError = "set failed unknown error";
- return ret;
+ return false;
+}
+
+bool cLibLightpack::GetProfiles(cStringList &Profiles)
+{
+ if( !is_init ) {
+ LastError = "not initialized";
+ return false;
+ }
+ if( !is_connected ) {
+ if( !Connect() )
+ return false;
+ }
+ char *profiles = lightpack_getprofiles();
+ if( profiles != NULL ) {
+ char *tok;
+ tok = strtok(profiles, ";");
+ while( tok != NULL )
+ {
+ Profiles.Append( strdup(tok) );
+ tok = strtok(NULL, ";");
+ }
+ free(profiles);
+ return true;
+ }
+ LastError = "set failed unknown error";
+
+ return false;
}
VDRPLUGINCREATOR(cPluginLightpack); // Don't touch this!
diff --git a/lightpack.h b/lightpack.h
index 4f3811b..3a36097 100644
--- a/lightpack.h
+++ b/lightpack.h
@@ -26,14 +26,17 @@ extern int LightpackGamma;
extern int LightpackBrightness;
extern int LightpackSmooth;
+extern int LightpackProfileIndex;
+
extern class cLibLightpack libLightpack;
class cPluginLightpack : public cPlugin {
private:
// Add any member variables or functions you may need here.
- void LoadConfig(void);
- char * GetConfigValue(const char *Filename, const char *Setting);
+ void SetLightpackSettings(void);
+ void LoadConfig(void);
+ char * GetConfigValue(const char *Filename, const char *Setting);
public:
cPluginLightpack(void);
virtual ~cPluginLightpack();
@@ -65,6 +68,10 @@ class cLibLightpack {
double gamma;
int brightness;
int smooth;
+
+ cString Error;
+ cString LastError;
+
public:
cLibLightpack();
~cLibLightpack();
@@ -73,23 +80,28 @@ public:
cString Port;
cString ApiKey;
- int Connect(void);
+ const char* GetLastError(void);
+
+ bool Connect(void);
bool isConnected(void);
void Disconnect(void);
- int SetGamma(double Value);
- int SetBrightness(int Value);
- int SetSmooth(int Value);
+ bool SetGamma(double Value);
+ bool SetBrightness(int Value);
+ bool SetSmooth(int Value);
- int SetStatus(bool Value);
+ bool SetStatus(bool Value);
// 1 = Ambilight
// 2 = Lamp
- int SetMode(int Value);
+ bool SetMode(int Value);
+
+ bool SetProfile(cString Profile);
double GetGamma(void);
int GetBrightness(void);
int GetSmooth(void);
+
// 0 = Error
// 1 = On
@@ -101,9 +113,10 @@ public:
// 2 = Lamp
int GetMode(void);
- int GetProfile(cString &Profile);
+ bool GetProfile(cString &Profile);
+ bool GetProfiles(cStringList &Profiles);
- double GetFps(void);
+ bool GetFps(double &Fps);
};
#endif
diff --git a/osdmenu.c b/osdmenu.c
index f484666..1cabd1b 100644
--- a/osdmenu.c
+++ b/osdmenu.c
@@ -3,27 +3,32 @@
myOsdMenu::myOsdMenu() : cOsdMenu("Lightpack", 32)
{
- LastGamma = LightpackGamma;
- LastBrightness = LightpackBrightness;
- LastSmooth = LightpackSmooth;
-
- int ret = libLightpack.Connect();
- if( ret == 0 ) {
+ Gamma = LastGamma = LightpackGamma;
+ Brightness = LastBrightness = LightpackBrightness;
+ Smooth = LastSmooth = LightpackSmooth;
+ ProfileIndex = LastProfileIndex = LightpackProfileIndex;
+
+ if( libLightpack.Connect() ) {
Add(new cOsdItem(tr("Appearance"), osUnknown, false));
- Add(new cMenuEditIntItem(tr("Gamma"), &LightpackGamma, 0, 100));
- Add(new cMenuEditIntItem(tr("Brightness"), &LightpackBrightness));
- Add(new cMenuEditIntItem(tr("Smooth"), &LightpackSmooth));
+ Add(new cMenuEditIntItem(tr("Gamma"), &Gamma, 0, 100));
+ Add(new cMenuEditIntItem(tr("Brightness"), &Brightness));
+ Add(new cMenuEditIntItem(tr("Smooth"), &Smooth));
+ if( libLightpack.GetProfiles( Profiles ) ) {
+ cString Profile;
+ libLightpack.GetProfile( Profile );
+ ProfileIndex = LastProfileIndex = Profiles.Find( *Profile );
+ if( ProfileIndex < 0 || ProfileIndex > Profiles.Size() )
+ ProfileIndex = 0;
+ Add(new cMenuEditStraItem(tr("Profile"), &ProfileIndex, Profiles.Size(), &Profiles[0]));
+ }
+ else
+ Add(new cOsdItem(tr("can't get profiles list"), osUnknown, false));
MySetHelp();
- } else if( ret == 1 ) {
+ } else {
Add(new cOsdItem(tr("Lightpack not available"), osUnknown, false));
- Add(new cOsdItem(tr("init error"), osUnknown, false));
- } else if( ret == 2 ) {
- Add(new cOsdItem(tr("Lightpack not available"), osUnknown, false));
- Add(new cOsdItem(tr("connect error (Server/Port wrong? Prismatik running?)"), osUnknown, false));
- } else if( ret == 3 ) {
- Add(new cOsdItem(tr("Lightpack not available"), osUnknown, false));
- Add(new cOsdItem(tr("login error (ApiKey wrong?)"), osUnknown, false));
+ cString Error = libLightpack.GetLastError();
+ Add(new cOsdItem(*Error, osUnknown, false));
}
Display();
@@ -39,16 +44,16 @@ void myOsdMenu::MySetHelp()
else if( LastMode == 2 )
SetHelp(tr("Stop"), tr("Ambilight"), NULL, NULL);
else
- Skins.Message(mtError, tr("can't get lightpack mode"));
+ Skins.Message(mtError, libLightpack.GetLastError() );
} else if( LastStatus == 2 ) {
if( LastMode == 1 )
SetHelp(tr("Start"), tr("Lamp"), NULL, NULL);
else if( LastMode == 2 )
SetHelp(tr("Start"), tr("Ambilight"), NULL, NULL);
else
- Skins.Message(mtError, tr("can't get lightpack mode"));
+ Skins.Message(mtError, libLightpack.GetLastError() );
} else
- Skins.Message(mtError, tr("can't get lightpack status"));
+ Skins.Message(mtError, libLightpack.GetLastError() );
}
myOsdMenu::~myOsdMenu()
@@ -62,37 +67,49 @@ eOSState myOsdMenu::ProcessKey(eKeys Key)
if( !libLightpack.isConnected() )
return state;
- int lightRet = 0;
-
- if( LastGamma != LightpackGamma )
+ if( LastGamma != Gamma )
{
- lightRet = libLightpack.SetGamma( (double) LightpackGamma / 10.0);
- if( lightRet == 0 )
- LastGamma = LightpackGamma;
+
+ if( libLightpack.SetGamma( (double) Gamma / 10.0) )
+ LastGamma = Gamma;
else {
- LightpackGamma = LastGamma;
- Skins.Message(mtError, tr("lightpack error"));
+ Gamma = LastGamma;
+ Skins.Message(mtError, libLightpack.GetLastError() );
}
}
- if( LastBrightness != LightpackBrightness )
+ if( LastBrightness != Brightness )
{
- lightRet = libLightpack.SetBrightness(LightpackBrightness);
- if( lightRet == 0 )
- LastBrightness = LightpackBrightness;
+ if( libLightpack.SetBrightness(Brightness) )
+ LastBrightness = Brightness;
else {
- LightpackBrightness = LastBrightness;
- Skins.Message(mtError, tr("lightpack error"));
+ Brightness = LastBrightness;
+ Skins.Message(mtError, libLightpack.GetLastError() );
}
}
- if( LastSmooth != LightpackSmooth )
+ if( LastSmooth != Smooth )
{
- lightRet = libLightpack.SetSmooth(LightpackSmooth);
- if( lightRet == 0 )
- LastSmooth = LightpackSmooth;
+ if( libLightpack.SetSmooth(Smooth) )
+ LastSmooth = Smooth;
else {
- LightpackSmooth = LastSmooth;
- Skins.Message(mtError, tr("lightpack error"));
+ Smooth = LastSmooth;
+ Skins.Message(mtError, libLightpack.GetLastError() );
+ }
+ }
+ if( LastProfileIndex != ProfileIndex )
+ {
+ cStringList Profiles;
+ if( libLightpack.GetProfiles( Profiles ) ) {
+ if( ProfileIndex < 0 || ProfileIndex > Profiles.Size() )
+ ProfileIndex = 0;
+ if( libLightpack.SetProfile( Profiles[ProfileIndex] ) )
+ LastProfileIndex = ProfileIndex;
+ else {
+ ProfileIndex = LastProfileIndex;
+ Skins.Message(mtError, libLightpack.GetLastError() );
+ }
}
+ else
+ Skins.Message(mtError, libLightpack.GetLastError() );
}
switch(Key)
@@ -100,26 +117,23 @@ eOSState myOsdMenu::ProcessKey(eKeys Key)
case kRed:
LastStatus = libLightpack.GetStatus();
if( LastStatus == 1 ) {
- lightRet = libLightpack.SetStatus( false );
- if( lightRet > 0 )
- Skins.Message(mtError, tr("lightpack error"));
+
+ if( !libLightpack.SetStatus( false ) )
+ Skins.Message(mtError, libLightpack.GetLastError() );
} else if( LastStatus == 2 ) {
- lightRet = libLightpack.SetStatus( true );
- if( lightRet > 0 )
- Skins.Message(mtError, tr("lightpack error"));
+ if( !libLightpack.SetStatus( true ) )
+ Skins.Message(mtError, libLightpack.GetLastError() );
}
MySetHelp();
break;
case kGreen:
LastMode = libLightpack.GetMode();
if( LastMode == 1 ) {
- lightRet = libLightpack.SetMode( 2 );
- if( lightRet > 0 )
- Skins.Message(mtError, tr("lightpack error"));
+ if( !libLightpack.SetMode( 2 ) )
+ Skins.Message(mtError, libLightpack.GetLastError() );
} else if( LastMode == 2 ) {
- lightRet = libLightpack.SetMode( 1 );
- if( lightRet > 0 )
- Skins.Message(mtError, tr("lightpack error"));
+ if( !libLightpack.SetMode( 1 ) )
+ Skins.Message(mtError, libLightpack.GetLastError() );
}
MySetHelp();
break;
@@ -130,6 +144,5 @@ eOSState myOsdMenu::ProcessKey(eKeys Key)
default:
break;
}
- //syslog(LOG_ERR, "lightpack Gamma=%d Brightness=%d Smooth=%d", LightpackGamma, LightpackBrightness, LightpackSmooth);
return state;
}
diff --git a/osdmenu.h b/osdmenu.h
index 5c8163b..9169dc0 100644
--- a/osdmenu.h
+++ b/osdmenu.h
@@ -7,8 +7,14 @@
class myOsdMenu : public cOsdMenu
{
private:
+ int Gamma, Brightness, Smooth;
+ int ProfileIndex;
+
int LastGamma, LastBrightness, LastSmooth;
int LastStatus, LastMode;
+ int LastProfileIndex;
+
+ cStringList Profiles;
void MySetHelp(void);
public:
@@ -19,4 +25,4 @@ public:
};
-#endif \ No newline at end of file
+#endif