From eaa3b9a368ce196e36ef935fe4308a0d893044d8 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 12 May 2020 11:01:46 -0500 Subject: [PATCH] Add command line option to enable i2c tools --- cli.cpp | 65 ++++++++++++++++++++++++++++++------------- main.cpp | 21 +++++++++++--- qt/OpenRGBDialog2.cpp | 6 ++-- qt/OpenRGBDialog2.h | 2 +- 4 files changed, 67 insertions(+), 27 deletions(-) diff --git a/cli.cpp b/cli.cpp index b193e941..872b7c62 100644 --- a/cli.cpp +++ b/cli.cpp @@ -422,11 +422,12 @@ bool OptionSaveProfile(std::string argument) return(true); } -bool ProcessOptions(int argc, char *argv[], Options *options) +int ProcessOptions(int argc, char *argv[], Options *options) { - int arg_index = 1; - int current_device = -1; - int current_zone = -1; + unsigned int ret_flags = 0; + int arg_index = 1; + int current_device = -1; + int current_zone = -1; options->hasDevice = false; @@ -444,10 +445,26 @@ bool ProcessOptions(int argc, char *argv[], Options *options) arg_index++; } + /*---------------------------------------------------------*\ + | --gui | + \*---------------------------------------------------------*/ + if(option == "--gui") + { + ret_flags |= 2; + } + + /*---------------------------------------------------------*\ + | --i2c-tools / --yolo | + \*---------------------------------------------------------*/ + else if(option == "--i2c-tools" || option == "--yolo") + { + ret_flags |= 4; + } + /*---------------------------------------------------------*\ | -h / --help | \*---------------------------------------------------------*/ - if(option == "--help" || option == "-h") + else if(option == "--help" || option == "-h") { OptionHelp(); exit(0); @@ -478,7 +495,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options) { if(!OptionDevice(¤t_device, argument, options)) { - return false; + return 1; } } @@ -489,7 +506,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options) { if(!OptionZone(¤t_device, ¤t_zone, argument, options)) { - return false; + return 1; } } @@ -500,7 +517,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options) { if(!OptionColor(¤t_device, ¤t_zone, argument, options)) { - return false; + return 1; } } @@ -511,7 +528,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options) { if(!OptionMode(¤t_device, argument, options)) { - return false; + return 1; } } @@ -522,7 +539,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options) { if(!OptionSize(¤t_device, ¤t_zone, argument, options)) { - return false; + return 1; } } @@ -549,7 +566,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options) else { std::cout << "Error: Invalid option: " + option << std::endl; - return false; + return 1; } arg_index++; @@ -566,16 +583,14 @@ bool ProcessOptions(int argc, char *argv[], Options *options) if(!options->devices[option_idx].hasOption) { std::cout << "Error: Device " + std::to_string(option_idx) + " specified, but neither mode nor color given" << std::endl; - return false; + return 1; } } } else { - return options->allDeviceOptions.hasOption; + return ret_flags; } - - return true; } void ApplyOptions(DeviceOptions& options) @@ -653,7 +668,7 @@ void ApplyOptions(DeviceOptions& options) } } -int cli_main(int argc, char *argv[], std::vector rgb_controllers_in, ProfileManager* profile_manager_in) +unsigned int cli_main(int argc, char *argv[], std::vector rgb_controllers_in, ProfileManager* profile_manager_in) { rgb_controllers = rgb_controllers_in; profile_manager = profile_manager_in; @@ -662,10 +677,20 @@ int cli_main(int argc, char *argv[], std::vector rgb_controller | Process the argument options | \*---------------------------------------------------------*/ Options options; - if (!ProcessOptions(argc, argv, &options)) + unsigned int ret_flags = ProcessOptions(argc, argv, &options); + switch(ret_flags) { - OptionHelp(); - return -1; + case 0: + break; + + case 1: + OptionHelp(); + exit(-1); + break; + + default: + return ret_flags; + break; } /*---------------------------------------------------------*\ @@ -704,5 +729,7 @@ int cli_main(int argc, char *argv[], std::vector rgb_controller } } + exit(0); + return 0; } diff --git a/main.cpp b/main.cpp index 3045df22..303111e6 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,7 @@ extern std::vector busses; extern std::vector rgb_controllers; // See cli.cpp -extern int cli_main(int argc, char *argv[], std::vector rgb_controllers_in, ProfileManager* profile_manager_in); +extern unsigned int cli_main(int argc, char *argv[], std::vector rgb_controllers_in, ProfileManager* profile_manager_in); /******************************************************************************************\ * * @@ -40,9 +40,22 @@ int main(int argc, char* argv[]) profile_manager.LoadSizeFromProfile("sizes.ors"); - if (argc > 1 && strcmp(argv[1], "--gui")) + unsigned int ret_flags = 0; + if(argc > 1) { - return cli_main(argc, argv, rgb_controllers, &profile_manager); + ret_flags = cli_main(argc, argv, rgb_controllers, &profile_manager); + } + + if(ret_flags && 2) + { + //GUI is enabled + } + + bool show_i2c_tools = false; + if(ret_flags && 4) + { + //I2C Tools is enabled + show_i2c_tools = true; } NetworkServer server(rgb_controllers); @@ -50,7 +63,7 @@ int main(int argc, char* argv[]) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication a(argc, argv); - Ui::OpenRGBDialog2 dlg(busses, rgb_controllers, &profile_manager, &server); + Ui::OpenRGBDialog2 dlg(busses, rgb_controllers, &profile_manager, &server, show_i2c_tools); dlg.show(); return a.exec(); diff --git a/qt/OpenRGBDialog2.cpp b/qt/OpenRGBDialog2.cpp index 39224c18..2c1d31bc 100644 --- a/qt/OpenRGBDialog2.cpp +++ b/qt/OpenRGBDialog2.cpp @@ -11,7 +11,7 @@ using namespace Ui; -OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vector& control, ProfileManager* manager, NetworkServer* server, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), network_server(server), ui(new OpenRGBDialog2Ui) +OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vector& control, ProfileManager* manager, NetworkServer* server, bool show_i2c_tools, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), profile_manager(manager), network_server(server), ui(new OpenRGBDialog2Ui) { ui->setupUi(this); @@ -203,7 +203,7 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec /*-----------------------------------------------------*\ | Show the I2C Tools page only if enabled | \*-----------------------------------------------------*/ - if(false) //TODO: SMBus Tools enable flag + if(show_i2c_tools) { OpenRGBSystemInfoPage *SMBusToolsPage = new OpenRGBSystemInfoPage(bus); ui->InformationTabBar->addTab(SMBusToolsPage, ""); @@ -235,7 +235,7 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector& bus, std::vec SoftwareTabLabel->setIndent(20); SoftwareTabLabel->setGeometry(0, 0, 200, 20); - if(false) //TODO: SMBus Tools enable flag + if(show_i2c_tools) { InformationTabBar->setTabButton(control.size() + 1, QTabBar::LeftSide, SoftwareTabLabel); } diff --git a/qt/OpenRGBDialog2.h b/qt/OpenRGBDialog2.h index 08cb9f2f..1fd62347 100644 --- a/qt/OpenRGBDialog2.h +++ b/qt/OpenRGBDialog2.h @@ -24,7 +24,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow Q_OBJECT public: - explicit OpenRGBDialog2(std::vector& bus, std::vector& control, ProfileManager* manager, NetworkServer* server, QWidget *parent = 0); + explicit OpenRGBDialog2(std::vector& bus, std::vector& control, ProfileManager* manager, NetworkServer* server, bool show_i2c_tools, QWidget *parent = 0); ~OpenRGBDialog2(); void show();