From 0a7ee97e081a1433a3710bd67aefa94e8db2485a Mon Sep 17 00:00:00 2001 From: TangoCash Date: Sun, 29 Dec 2019 23:46:52 +0100 Subject: [PATCH] make driver selectable for graphlcd Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/cd00832423b7a488387af300a8b9fe71354275c3 Author: TangoCash Date: 2019-12-29 (Sun, 29 Dec 2019) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- data/locale/deutsch.locale | 1 + data/locale/english.locale | 1 + src/driver/nglcd.cpp | 17 +++++++++++++++- src/driver/nglcd.h | 2 ++ src/gui/glcdsetup.cpp | 41 ++++++++++++++++++++++++++++++++++++++ src/gui/glcdsetup.h | 1 + src/neutrino.cpp | 2 ++ src/system/locals.h | 1 + src/system/locals_intern.h | 1 + src/system/settings.h | 3 +++ 10 files changed, 69 insertions(+), 1 deletion(-) diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index 24c08cc0e..752b76959 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -878,6 +878,7 @@ glcd.color.dark_blue Dunkelblau glcd.color.purple Purple glcd.color.mint Mint glcd.color.golden Golden +glcd.display Display-Typ glcd.enable GraphLCD aktiv glcd.font Schrift glcd.head GraphLCD-Unterstützung diff --git a/data/locale/english.locale b/data/locale/english.locale index 007e04420..23a6b0183 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -878,6 +878,7 @@ glcd.color.dark_blue Dark Blue glcd.color.purple Purple glcd.color.mint Mint glcd.color.golden Golden +glcd.display Display type glcd.enable GraphLCD enabled glcd.font Font glcd.head GraphLCD-Support diff --git a/src/driver/nglcd.cpp b/src/driver/nglcd.cpp index 7cbb3fbe5..f7d15220f 100644 --- a/src/driver/nglcd.cpp +++ b/src/driver/nglcd.cpp @@ -562,7 +562,11 @@ void nGLCD::Run(void) break; int warmUp = 10; - lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[0].id, &GLCD::Config.driverConfigs[0]); + + if ((g_settings.glcd_selected_config < 0) || (g_settings.glcd_selected_config > GetConfigSize() - 1)) + g_settings.glcd_selected_config = 0; + + lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[g_settings.glcd_selected_config].id, &GLCD::Config.driverConfigs[g_settings.glcd_selected_config]); if (!lcd) { #ifdef GLCD_DEBUG fprintf(stderr, "CreateDriver failed.\n"); @@ -959,3 +963,14 @@ int nGLCD::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t /* data */) return messages_return::unhandled; } +int nGLCD::GetConfigSize() +{ + return (int) GLCD::Config.driverConfigs.size(); +} + +std::string nGLCD::GetConfigName(int driver) +{ + if ((driver < 0) || (driver > GetConfigSize() - 1)) + driver = 0; + return GLCD::Config.driverConfigs[driver].name; +} diff --git a/src/driver/nglcd.h b/src/driver/nglcd.h index 7936319c7..309445684 100644 --- a/src/driver/nglcd.h +++ b/src/driver/nglcd.h @@ -130,6 +130,8 @@ class nGLCD static void Exit(); static void Blit(); static void SetBrightness(unsigned int b); + int GetConfigSize(); + std::string GetConfigName(int); void UpdateBrightness(); int handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data); }; diff --git a/src/gui/glcdsetup.cpp b/src/gui/glcdsetup.cpp index 4ac2025d8..ef8814999 100644 --- a/src/gui/glcdsetup.cpp +++ b/src/gui/glcdsetup.cpp @@ -123,6 +123,13 @@ int GLCD_Menu::exec(CMenuTarget* parent, const std::string & actionKey) nglcd->Rescan(); return res; } + if(actionKey == "select_driver") { + if(parent) + parent->hide(); + GLCD_Menu_Select_Driver(); + nglcd->Exit(); + return res; + } if(actionKey == "select_font") { if(parent) parent->hide(); @@ -220,6 +227,9 @@ void GLCD_Menu::GLCD_Menu_Settings() m.addItem(new CMenuOptionChooser(LOCALE_GLCD_ENABLE, &g_settings.glcd_enable, OPTIONS_OFF0_ON1_OPTIONS, OPTIONS_OFF0_ON1_OPTION_COUNT, true, this)); + + m.addItem(new CMenuForwarder(LOCALE_GLCD_DISPLAY, (nGLCD::getInstance()->GetConfigSize() > 1), + nGLCD::getInstance()->GetConfigName(g_settings.glcd_selected_config).c_str(), this, "select_driver")); int shortcut = 1; m.addItem(GenericMenuSeparatorLine); m.addItem(new CMenuOptionChooser(LOCALE_GLCD_SELECT_FG, &color_fg, @@ -271,3 +281,34 @@ void GLCD_Menu::GLCD_Menu_Settings() nGLCD::getInstance()->StandbyMode(false); m.hide(); } + +void GLCD_Menu::GLCD_Menu_Select_Driver() +{ + int select = 0; + + if (nGLCD::getInstance()->GetConfigSize() > 1) + { + CMenuWidget *m = new CMenuWidget(LOCALE_GLCD_HEAD, NEUTRINO_ICON_SETTINGS); + CMenuSelectorTarget * selector = new CMenuSelectorTarget(&select); + + // we don't show introitems, so we add a separator for a smoother view + m->addItem(GenericMenuSeparator); + + CMenuForwarder* mf; + for (int i = 0; i != nGLCD::getInstance()->GetConfigSize() - 1; i++) + { + mf = new CMenuForwarder(nGLCD::getInstance()->GetConfigName(i), true, NULL, selector,to_string(i).c_str()); + m->addItem(mf); + } + + m->enableSaveScreen(); + m->exec(NULL, ""); + + if (!m->gotAction()) + return; + + delete selector; + m->hide(); + } + g_settings.glcd_selected_config = select; +} diff --git a/src/gui/glcdsetup.h b/src/gui/glcdsetup.h index aa587517e..b9cb9c0ab 100644 --- a/src/gui/glcdsetup.h +++ b/src/gui/glcdsetup.h @@ -36,6 +36,7 @@ class GLCD_Menu : public CMenuTarget, public CChangeObserver int width; int selected; static int color2index(uint32_t color); + void GLCD_Menu_Select_Driver(); public: static uint32_t index2color(int i); GLCD_Menu(); diff --git a/src/neutrino.cpp b/src/neutrino.cpp index eef0a1548..d4ea862ca 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -693,6 +693,7 @@ int CNeutrinoApp::loadSetup(const char * fname) #else g_settings.glcd_scroll_speed = configfile.getInt32("glcd_scroll_speed", 5); #endif + g_settings.glcd_selected_config = configfile.getInt32("glcd_selected_config", 0); #endif //personalize @@ -1635,6 +1636,7 @@ void CNeutrinoApp::saveSetup(const char * fname) configfile.setInt32("glcd_brightness", g_settings.glcd_brightness); configfile.setInt32("glcd_brightness_standby", g_settings.glcd_brightness_standby); configfile.setInt32("glcd_scroll_speed", g_settings.glcd_scroll_speed); + configfile.setInt32("glcd_selected_config", g_settings.glcd_selected_config); #endif //personalize diff --git a/src/system/locals.h b/src/system/locals.h index 26224ecd4..9e7586c5f 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -905,6 +905,7 @@ typedef enum LOCALE_GLCD_COLOR_PURPLE, LOCALE_GLCD_COLOR_MINT, LOCALE_GLCD_COLOR_GOLDEN, + LOCALE_GLCD_DISPLAY, LOCALE_GLCD_ENABLE, LOCALE_GLCD_FONT, LOCALE_GLCD_HEAD, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 9af03174e..7693860a5 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -905,6 +905,7 @@ const char * locale_real_names[] = "glcd.color.purple", "glcd.color.mint", "glcd.color.golden", + "glcd.display", "glcd.enable", "glcd.font", "glcd.head", diff --git a/src/system/settings.h b/src/system/settings.h index 64aeb0457..540a50d31 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -798,6 +798,7 @@ struct SNeutrinoSettings int infoClockSeconds; int infoClockBackground; +#ifdef ENABLE_GRAPHLCD // graphlcd int glcd_enable; uint32_t glcd_color_fg; @@ -817,6 +818,8 @@ struct SNeutrinoSettings int glcd_brightness; int glcd_brightness_standby; int glcd_scroll_speed; + int glcd_selected_config; +#endif // lcd4linux int lcd4l_support;