Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding K30 Support #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions K30Device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2016 Clément Vuchener
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include "K30Device.h"

K30Device::K30Device (libusb_device *dev):
CorsairDevice (dev, sizeof (K30Status))
{
}

unsigned int K30Device::getBacklightBrightness ()
{
std::vector<uint8_t> raw_status = getRawStatus ();
K30Status *status = reinterpret_cast<K30Status *> (raw_status.data ());
return status->backlight_brightness;
}

void K30Device::setBacklightBrightness (unsigned int brightness)
{
int ret;
if (brightness > 3)
brightness = 3;
ret = libusb_control_transfer (_dev, RequestOutType, SetBacklightBrightness,
brightness << 8, 0, nullptr, 0, 0);
if (ret < 0) {
throw std::runtime_error (libusb_error_name (ret));
}
}

unsigned int K30Device::getCurrentProfile ()
{
std::vector<uint8_t> raw_status = getRawStatus ();
K30Status *status = reinterpret_cast<K30Status *> (raw_status.data ());
return status->current_profile;
}

Color K30Device::getProfileColor (unsigned int profile_index)
{
throw FeatureNotSupported ();
}

void K30Device::setProfileColor (unsigned int profile_index, Color color)
{
throw FeatureNotSupported ();
}

58 changes: 58 additions & 0 deletions K30Device.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2016 Clément Vuchener
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef K30_DEVICE_H
#define K30_DEVICE_H

#include "CorsairDevice.h"

class K30Device: public CorsairDevice
{
public:
K30Device (libusb_device *dev);

virtual unsigned int getBacklightBrightness ();
virtual void setBacklightBrightness (unsigned int brightness);

virtual unsigned int getCurrentProfile ();

virtual Color getProfileColor (unsigned int profile_index);
virtual void setProfileColor (unsigned int profile_index, Color color);

private:
enum K30Request: uint8_t {
SetBacklightBrightness = 48,
SetBacklightColor = 51,
SetBacklightColorMode = 56,
SetBacklightAnimation = 49,
DoCycleAnimation = 52,
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not using most of those. Are you sure about the request codes, or is it just copied from the K40 codes?


struct K30Status {
uint8_t unk1;
uint8_t backlight_brightness;
uint8_t unk2[2];
Color color;
uint8_t current_profile;
uint8_t unk3;
uint8_t color_mode;
} __attribute__ ((packed));
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. You don't use the color parts and they looks copied from the K40 status.


#endif

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SRC= \
CorsairDevice.cpp \
K90Device.cpp \
K40Device.cpp \
K30Device.cpp \
JsonMacros.cpp \
KeyUsage.cpp \
main.cpp
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Corsair USB configuration tool
This is configuration tool for Corsair gaming keyboards using the older USB protocol (not the newer using pure HID configuration, e.g. RGB keyboards, supported by [ckb](https://github.com/ccMSC/ckb)). Currently supported devices are:
- Vengeance K90
- Raptor K40
- Raptor K30

Compilation
-----------
Expand Down
6 changes: 6 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CorsairDevice.h"
#include "K90Device.h"
#include "K40Device.h"
#include "K30Device.h"

#include "KeyUsage.h"
#include "JsonMacros.h"
Expand All @@ -42,6 +43,7 @@ constexpr uint16_t CORSAIR_VENDOR_ID = 0x1b1c;
enum ProductID: uint16_t {
CORSAIR_K90_ID = 0x1b02,
CORSAIR_K40_ID = 0x1b0e,
CORSAIR_K30_ID = 0x1b0a,
};

struct DeviceInfo {
Expand All @@ -56,6 +58,10 @@ struct DeviceInfo {
{ CORSAIR_K40_ID },
[] (libusb_device *dev) { return new K40Device (dev); }
},
{
{ CORSAIR_K30_ID },
[] (libusb_device *dev) { return new K30Device (dev); }
},
};

static const char *usage = R"(Usage: %s [options] command
Expand Down