Add command line option to enable i2c tools

This commit is contained in:
Adam Honse 2020-05-12 11:01:46 -05:00
parent 599c468de8
commit eaa3b9a368
4 changed files with 67 additions and 27 deletions

65
cli.cpp
View file

@ -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(&current_device, argument, options))
{
return false;
return 1;
}
}
@ -489,7 +506,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
{
if(!OptionZone(&current_device, &current_zone, argument, options))
{
return false;
return 1;
}
}
@ -500,7 +517,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
{
if(!OptionColor(&current_device, &current_zone, argument, options))
{
return false;
return 1;
}
}
@ -511,7 +528,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
{
if(!OptionMode(&current_device, argument, options))
{
return false;
return 1;
}
}
@ -522,7 +539,7 @@ bool ProcessOptions(int argc, char *argv[], Options *options)
{
if(!OptionSize(&current_device, &current_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<RGBController *> rgb_controllers_in, ProfileManager* profile_manager_in)
unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> 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<RGBController *> 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<RGBController *> rgb_controller
}
}
exit(0);
return 0;
}

View file

@ -22,7 +22,7 @@ extern std::vector<i2c_smbus_interface*> busses;
extern std::vector<RGBController*> rgb_controllers;
// See cli.cpp
extern int cli_main(int argc, char *argv[], std::vector<RGBController *> rgb_controllers_in, ProfileManager* profile_manager_in);
extern unsigned int cli_main(int argc, char *argv[], std::vector<RGBController *> 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();

View file

@ -11,7 +11,7 @@
using namespace Ui;
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& 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<i2c_smbus_interface *>& bus, std::vector<RGBController *>& 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<i2c_smbus_interface *>& 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<i2c_smbus_interface *>& 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);
}

View file

@ -24,7 +24,7 @@ class Ui::OpenRGBDialog2 : public QMainWindow
Q_OBJECT
public:
explicit OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, NetworkServer* server, QWidget *parent = 0);
explicit OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, ProfileManager* manager, NetworkServer* server, bool show_i2c_tools, QWidget *parent = 0);
~OpenRGBDialog2();
void show();