Skip to content

Commit

Permalink
add extended help info and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Parker committed Sep 11, 2015
1 parent f5601e1 commit 7e8cf24
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ This program can change the colors on your MSI steelseries keyboard. The keyboar

Prerequisites (tested on Ubuntu 14.04 only):

Qt 5
Qt 5.2 or later (Ubuntu includes Qt 5.2.1)
libhidapi-dev
libhidapi-libusb0

To build:
Expand Down
85 changes: 85 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,95 @@
*/

#include <QCoreApplication>
#include <QCommandLineParser>
#include <iostream>
#include "keyboard.h"

enum CommandLineParseResult
{
CommandLineOk,
CommandLineError,
CommandLineVersionRequested,
CommandLineHelpRequested
};


CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *errorMessage) {
QCommandLineOption helpOption = parser.addHelpOption();
QCommandLineOption versionOption = parser.addVersionOption();

QCommandLineOption mode(QStringList() << "m" << "mode", "set color mode: normal, gaming, breathe, demo, wave");
QCommandLineOption color(QStringList() << "c" << "color", "set a color using the format: region,color,intensity");

parser.addOption(mode);
parser.addOption(color);

if(!parser.parse(QCoreApplication::arguments())) {
*errorMessage = parser.errorText();
return CommandLineError;
}

if(parser.isSet(versionOption))
return CommandLineVersionRequested;

if(parser.isSet(helpOption))
return CommandLineHelpRequested;

return CommandLineOk;
}

int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
app.setApplicationName("msi-keyboard");
app.setApplicationVersion("1.0");

QCommandLineParser parser;
parser.setApplicationDescription("Keyboard color changer for MSI steelseries keyboards");

QString errorMessage;

switch(parseCommandLine(parser, &errorMessage)) {
case CommandLineOk:
break;
case CommandLineError:
fputs(qPrintable(errorMessage), stderr);
fputs("\n\n", stderr);
fputs(qPrintable(parser.helpText()), stderr);
return 1;
case CommandLineVersionRequested:
printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
qPrintable(QCoreApplication::applicationVersion()));
return 0;
case CommandLineHelpRequested:
{
std::cout << qPrintable(parser.helpText()) << std::endl;

QStringList regions = QStringList() << "left" << "middle" << "right";
QStringList colors = QStringList() << "off" << "red" << "orange" << "yellow" << "green" << "sky" << "blue" << "purple" << "white";
QStringList intensities = QStringList() << "high" << "medium" << "low" << "light";

QString colorHelp = QString(R"(Available regions:
%1
Available colors:
%2
Available intensities:
%3
Example:
%4
)").arg(regions.join('\n')).arg(colors.join('\n')).arg(intensities.join('\n')).arg(QString(argv[0]) + " -m normal -c left,red,high -c middle,purple,high -c right,sky,high");

std::cout << qPrintable(colorHelp) << std::endl;

return 0;
}
}

Keyboard k;
k.setMode(MODE_NORMAL);
Expand Down
2 changes: 2 additions & 0 deletions msi-keyboard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ QT -= gui
SOURCES += main.cpp keyboard.cpp
HEADERS += keyboard.h

QMAKE_CXXFLAGS += -std=c++11

unix:LIBS += -lhidapi-libusb

0 comments on commit 7e8cf24

Please sign in to comment.