commit 0d1d44c5595f7575bf9ec3bfe3994a696e79b0e0 Author: Brad Parker Date: Sun Aug 16 22:40:11 2015 -0400 initial commit diff --git a/keyboard.cpp b/keyboard.cpp new file mode 100644 index 0000000..b2f31f7 --- /dev/null +++ b/keyboard.cpp @@ -0,0 +1,62 @@ +#include "keyboard.h" +#include +#include +#include + +#define BUFSIZ 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[BUFSIZ] = {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, BUFSIZ); +} + +void Keyboard::setColor(Region region, Color color, Intensity intensity) { + if(!m_dev) + return; + + unsigned char buf[BUFSIZ] = {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, BUFSIZ); +} + diff --git a/keyboard.h b/keyboard.h new file mode 100644 index 0000000..22b0146 --- /dev/null +++ b/keyboard.h @@ -0,0 +1,53 @@ +#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 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..1785d91 --- /dev/null +++ b/main.cpp @@ -0,0 +1,16 @@ +#include +#include "keyboard.h" + +int main(int argc, char *argv[]) { + QCoreApplication app(argc, argv); + + Keyboard k; + k.setMode(MODE_NORMAL); + k.setColor(REGION_LEFT, COLOR_RED, INTENSITY_HIGH); + k.setColor(REGION_MIDDLE, COLOR_PURPLE, INTENSITY_HIGH); + k.setColor(REGION_RIGHT, COLOR_SKY, INTENSITY_HIGH); + + return 0; + //return app.exec(); +} + diff --git a/msi-bp.pro b/msi-bp.pro new file mode 100644 index 0000000..8c5967c --- /dev/null +++ b/msi-bp.pro @@ -0,0 +1,5 @@ +QT -= gui +SOURCES += main.cpp keyboard.cpp +HEADERS += keyboard.h + +unix:LIBS += -lhidapi-libusb