Brad Parker
9 years ago
commit
0d1d44c559
4 changed files with 136 additions and 0 deletions
@ -0,0 +1,62 @@ |
|||
#include "keyboard.h" |
|||
#include <iostream> |
|||
#include <QTimer> |
|||
#include <QCoreApplication> |
|||
|
|||
#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<unsigned int>(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<unsigned int>(region); |
|||
buf[4] = static_cast<unsigned int>(color); |
|||
buf[5] = static_cast<unsigned int>(intensity); |
|||
buf[6] = 0; |
|||
buf[7] = 236; |
|||
|
|||
hid_send_feature_report(m_dev, buf, BUFSIZ); |
|||
} |
|||
|
@ -0,0 +1,53 @@ |
|||
#ifndef __KEYBOARD_H |
|||
#define __KEYBOARD_H |
|||
|
|||
#include <QObject> |
|||
#include <hidapi/hidapi.h> |
|||
|
|||
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
|
@ -0,0 +1,16 @@ |
|||
#include <QCoreApplication> |
|||
#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();
|
|||
} |
|||
|
@ -0,0 +1,5 @@ |
|||
QT -= gui |
|||
SOURCES += main.cpp keyboard.cpp |
|||
HEADERS += keyboard.h |
|||
|
|||
unix:LIBS += -lhidapi-libusb |
Loading…
Reference in new issue