pax_global_header00006660000000000000000000000064126756260360014527gustar00rootroot0000000000000052 comment=37e341350c2799305aad4c4b3800e4f0626cc5eb msi-keyboard-1.1/000077500000000000000000000000001267562603600137565ustar00rootroot00000000000000msi-keyboard-1.1/99-msi.rules000066400000000000000000000001211267562603600160530ustar00rootroot00000000000000SUBSYSTEM=="usb", ATTRS{idVendor}=="1770", ATTRS{idProduct}=="ff00", MODE="0666" msi-keyboard-1.1/COPYING000066400000000000000000000027321267562603600150150ustar00rootroot00000000000000Copyright (c) 2015, Brad Parker All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. msi-keyboard-1.1/README000066400000000000000000000035131267562603600146400ustar00rootroot00000000000000This program can change the colors on your MSI steelseries keyboard. The keyboards have 3 regions that can have different colors for each one. Prerequisites (tested on Ubuntu 14.04 only): Qt 5.2 or later (Ubuntu includes Qt 5.2.1) libhidapi-dev libhidapi-libusb0 To build: qmake make Make sure to copy 99-msi.rules to /etc/udev/rules.d unless you want to run the program as root. Requires a reboot or maybe just a reload of udev rules to work correctly. To use: Usage: ./msi-keyboard [options] Keyboard color changer for MSI steelseries keyboards Options: -h, --help Displays this help. -v, --version Displays version information. -m, --mode set color mode: normal, gaming, breathe, demo, wave -c, --color set a color using the format: region,color,intensity Available regions: left middle right Available colors: off red orange yellow green sky blue purple white Available intensities: high medium low light Example: ./msi-keyboard -m normal -c left,red,high -c middle,purple,high -c right,sky,high Licensing: This program is licensed as 3-clause BSD, terms are available in the COPYING file. Based on a nodejs version of msi-keyboard by Steve Lacy of wearefractal.com: Copyright (c) 2013 | Steve Lacy slacy.me | Fractal wearefractal.com contact@wearefractal.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. msi-keyboard-1.1/keyboard.cpp000066400000000000000000000023551267562603600162670ustar00rootroot00000000000000/* keyboard.cpp (C) Copyright 2015, Brad Parker All rights reserved. License: 3-clause BSD. See COPYING */ #include "keyboard.h" #include #include #include #define BUFSIZE 8 Keyboard::Keyboard() : m_dev(NULL) { m_dev = hid_open(0x1770, 0xff00, 0); if(!m_dev) { std::cout << "cannot open usb device" << std::endl; QTimer::singleShot(0, qApp, SLOT(quit())); return; } } Keyboard::~Keyboard() { if(m_dev) { hid_close(m_dev); //std::cout << "closed usb device" << std::endl; } } void Keyboard::setMode(Mode mode) { if(!m_dev) return; unsigned char buf[BUFSIZE] = {0}; buf[0] = 1; buf[1] = 2; buf[2] = 65; buf[3] = static_cast(mode); buf[4] = 0; buf[5] = 0; buf[6] = 0; buf[7] = 236; hid_send_feature_report(m_dev, buf, BUFSIZE); } void Keyboard::setColor(Region region, Color color, Intensity intensity) { if(!m_dev) return; unsigned char buf[BUFSIZE] = {0}; buf[0] = 1; buf[1] = 2; buf[2] = 66; buf[3] = static_cast(region); buf[4] = static_cast(color); buf[5] = static_cast(intensity); buf[6] = 0; buf[7] = 236; hid_send_feature_report(m_dev, buf, BUFSIZE); } msi-keyboard-1.1/keyboard.h000066400000000000000000000016251267562603600157330ustar00rootroot00000000000000/* keyboard.h (C) Copyright 2015, Brad Parker All rights reserved. License: 3-clause BSD. See COPYING */ #ifndef __KEYBOARD_H #define __KEYBOARD_H #include #include enum Mode { MODE_NORMAL = 1, MODE_GAMING = 2, MODE_BREATHE = 3, MODE_DEMO = 4, MODE_WAVE = 5 }; enum Region { REGION_LEFT = 1, REGION_MIDDLE = 2, REGION_RIGHT = 3 }; enum Color { COLOR_OFF = 0, COLOR_RED = 1, COLOR_ORANGE = 2, COLOR_YELLOW = 3, COLOR_GREEN = 4, COLOR_SKY = 5, COLOR_BLUE = 6, COLOR_PURPLE = 7, COLOR_WHITE = 8 }; enum Intensity { INTENSITY_HIGH = 0, INTENSITY_MEDIUM = 1, INTENSITY_LOW = 2, INTENSITY_LIGHT = 3 }; class Keyboard : public QObject { Q_OBJECT public: Keyboard(); ~Keyboard(); void setMode(Mode mode); void setColor(Region region, Color color, Intensity intensity); private: hid_device *m_dev; }; #endif // __KEYBOARD_H msi-keyboard-1.1/main.cpp000066400000000000000000000132051267562603600154070ustar00rootroot00000000000000/* main.cpp (C) Copyright 2015, Brad Parker All rights reserved. License: 3-clause BSD. See COPYING */ #include #include #include #include "keyboard.h" enum CommandLineParseResult { CommandLineOk, CommandLineError, CommandLineVersionRequested, CommandLineHelpRequested }; struct ColorOption { ColorOption() : region(REGION_LEFT) ,color(COLOR_RED) ,intensity(INTENSITY_HIGH) {} Region region; Color color; Intensity intensity; }; struct KeyboardOptions { KeyboardOptions() : modeOption(MODE_NORMAL) ,colorOptions() ,modeSet(false) ,colorSet(false) {} Mode modeOption; QList colorOptions; bool modeSet; bool colorSet; void setMode(QString mode) { if(mode == "normal") { modeOption = MODE_NORMAL; } if(mode == "gaming") { modeOption = MODE_GAMING; } if(mode == "breathe") { modeOption = MODE_BREATHE; } if(mode == "demo") { modeOption = MODE_DEMO; } if(mode == "wave") { modeOption = MODE_WAVE; } modeSet = true; } void setColor(QString colorString) { QStringList fields = colorString.split(','); if(fields.count() != 3) { std::cerr << "invalid color selection" << std::endl; qApp->quit(); return; } QString region = fields.at(0); QString color = fields.at(1); QString intensity = fields.at(2); ColorOption *colorOption = new ColorOption; if(region == "left") colorOption->region = REGION_LEFT; if(region == "middle") colorOption->region = REGION_MIDDLE; if(region == "right") colorOption->region = REGION_RIGHT; if(color == "off") colorOption->color = COLOR_OFF; if(color == "red") colorOption->color = COLOR_RED; if(color == "orange") colorOption->color = COLOR_ORANGE; if(color == "yellow") colorOption->color = COLOR_YELLOW; if(color == "green") colorOption->color = COLOR_GREEN; if(color == "sky") colorOption->color = COLOR_SKY; if(color == "blue") colorOption->color = COLOR_BLUE; if(color == "purple") colorOption->color = COLOR_PURPLE; if(color == "white") colorOption->color = COLOR_WHITE; if(intensity == "high") colorOption->intensity = INTENSITY_HIGH; if(intensity == "medium") colorOption->intensity = INTENSITY_MEDIUM; if(intensity == "low") colorOption->intensity = INTENSITY_LOW; if(intensity == "light") colorOption->intensity = INTENSITY_LIGHT; colorSet = true; colorOptions.append(colorOption); } }; CommandLineParseResult parseCommandLine(QCommandLineParser &parser, KeyboardOptions *keyboardOptions, QString *errorMessage) { QCommandLineOption helpOption = parser.addHelpOption(); QCommandLineOption versionOption = parser.addVersionOption(); QCommandLineOption mode(QStringList() << "m" << "mode", "set color : normal, gaming, breathe, demo, wave", "mode"); QCommandLineOption color(QStringList() << "c" << "color", "set a using the format: region,color,intensity", "color"); 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; if(parser.isSet(mode)) { keyboardOptions->setMode(parser.value(mode)); } if(parser.isSet(color)) { foreach(const QString &colorValue, parser.values(color)) { keyboardOptions->setColor(colorValue); } } 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; KeyboardOptions keyboardOptions; switch(parseCommandLine(parser, &keyboardOptions, &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; } } if(!keyboardOptions.modeSet || !keyboardOptions.colorSet) { std::cerr << "Please set a mode as well as at least one color region to change." << std::endl; return 1; }else{ Keyboard k; if(keyboardOptions.colorSet) { for(int i = 0; i < keyboardOptions.colorOptions.count(); ++i) { ColorOption *colorOption = keyboardOptions.colorOptions.at(i); k.setColor(colorOption->region, colorOption->color, colorOption->intensity); } } if(keyboardOptions.modeSet) { k.setMode(keyboardOptions.modeOption); } } return 0; } msi-keyboard-1.1/msi-keyboard.pro000066400000000000000000000006521267562603600170710ustar00rootroot00000000000000# msi-keyboard.pro # (C) Copyright 2015, Brad Parker # All rights reserved. # License: 3-clause BSD. See COPYING QT -= gui SOURCES += main.cpp keyboard.cpp HEADERS += keyboard.h QMAKE_CXXFLAGS += -std=c++11 QMAKE_LFLAGS += -Wl,--no-undefined packagesExist(hidapi-libusb) { unix:LIBS += -lhidapi-libusb } else { packagesExist(hidapi) { unix:LIBS += -lhidapi } else { unix:LIBS += -lhidapi-libusb } }