1
0
mirror of https://github.com/MatMoul/g810-led.git synced 2024-12-23 01:06:11 +00:00

g815 basic support

This commit is contained in:
MatMoul 2020-04-26 18:36:18 +02:00
parent b6051dfe8a
commit 3cea57cf4b

View File

@ -19,6 +19,7 @@
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
#include <map>
#if defined(hidapi) #if defined(hidapi)
#include <locale> #include <locale>
@ -402,172 +403,167 @@ bool LedKeyboard::setKeys(KeyValueArray keyValues) {
bool retval = true; bool retval = true;
vector<vector<KeyValue>> SortedKeys = { vector<vector<KeyValue>> SortedKeys;
{}, // Logo AddressGroup map<int32_t, vector<KeyValue>> KeyByColors;
{}, // Indicators AddressGroup map<int32_t, vector<KeyValue>>::iterator KeyByColorsIterator;
{}, // Multimedia AddressGroup const uint8_t maxKeyPerColor = 13;
{}, // GKeys AddressGroup
{} // Keys AddressGroup
};
for (uint8_t i = 0; i < keyValues.size(); i++) {
switch(static_cast<LedKeyboard::KeyAddressGroup>(static_cast<uint16_t>(keyValues[i].key) >> 8 )) {
case LedKeyboard::KeyAddressGroup::logo:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g610:
case LedKeyboard::KeyboardModel::g810:
case LedKeyboard::KeyboardModel::g815:
case LedKeyboard::KeyboardModel::gpro:
if (SortedKeys[0].size() <= 1 && keyValues[i].key == LedKeyboard::Key::logo)
SortedKeys[0].push_back(keyValues[i]);
break;
case LedKeyboard::KeyboardModel::g910:
if (SortedKeys[0].size() <= 2) SortedKeys[0].push_back(keyValues[i]);
break;
default:
break;
}
break;
case LedKeyboard::KeyAddressGroup::indicators:
if (SortedKeys[1].size() <= 5) SortedKeys[1].push_back(keyValues[i]);
break;
case LedKeyboard::KeyAddressGroup::multimedia:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g610:
case LedKeyboard::KeyboardModel::g810:
case LedKeyboard::KeyboardModel::gpro:
if (SortedKeys[2].size() <= 5) SortedKeys[2].push_back(keyValues[i]);
break;
case LedKeyboard::KeyboardModel::g815:
if (SortedKeys[2].size() <= 4) SortedKeys[2].push_back(keyValues[i]);
break;
default:
break;
}
break;
case LedKeyboard::KeyAddressGroup::gkeys:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g815:
if (SortedKeys[3].size() <= 4) SortedKeys[3].push_back(keyValues[i]);
break;
case LedKeyboard::KeyboardModel::g910:
if (SortedKeys[3].size() <= 9) SortedKeys[3].push_back(keyValues[i]);
break;
default:
break;
}
break;
case LedKeyboard::KeyAddressGroup::keys:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g513:
case LedKeyboard::KeyboardModel::g610:
case LedKeyboard::KeyboardModel::g810:
case LedKeyboard::KeyboardModel::g815:
case LedKeyboard::KeyboardModel::g910:
case LedKeyboard::KeyboardModel::gpro:
if (SortedKeys[4].size() <= 120) SortedKeys[4].push_back(keyValues[i]);
break;
case LedKeyboard::KeyboardModel::g410:
if (SortedKeys[4].size() <= 120)
if (keyValues[i].key < LedKeyboard::Key::num_lock ||
keyValues[i].key > LedKeyboard::Key::num_dot)
SortedKeys[4].push_back(keyValues[i]);
break;
default:
break;
}
break;
}
}
switch (currentDevice.model) { switch (currentDevice.model) {
case KeyboardModel::g815: case KeyboardModel::g815:
for (uint8_t kag = 0; kag < 5; kag++) { for (uint8_t i = 0; i < keyValues.size(); i++) {
if (SortedKeys[kag].size() > 0) { uint32_t colorkey = static_cast<uint32_t>(keyValues[i].color.red | keyValues[i].color.green << 8 | keyValues[i].color.blue << 16 );
if (KeyByColors.count(colorkey) == 0) KeyByColors.insert(pair<uint32_t, vector<KeyValue>>(colorkey, {}));
KeyByColors[colorkey].push_back(keyValues[i]);
}
for (auto& x: KeyByColors) {
if (x.second.size() > 0) {
uint8_t gi = 0; uint8_t gi = 0;
while (gi < SortedKeys[kag].size()) { while (gi < x.second.size()) {
size_t data_size = 20; size_t data_size = 20;
byte_buffer_t data = {}; byte_buffer_t data = { 0x11, 0xff, 0x10, 0x6c };
uint8_t keyaddoffset = 0; // Temporary solution data.push_back(x.second[0].color.red);
uint8_t keyremoveoffset = 0; // Temporary solution data.push_back(x.second[0].color.green);
switch (kag) { data.push_back(x.second[0].color.blue);
case 0: for (uint8_t i = 0; i < maxKeyPerColor; i++) {
data = getKeyGroupAddress(LedKeyboard::KeyAddressGroup::logo); if (gi + i < x.second.size()) {
keyaddoffset = 0xd1; switch (x.second[gi+i].key) {
break; case Key::logo2:
case 1: case Key::game:
data = getKeyGroupAddress(LedKeyboard::KeyAddressGroup::indicators); case Key::caps:
keyaddoffset = 0x98; case Key::scroll:
break; case Key::num:
case 2: case Key::stop:
data = getKeyGroupAddress(LedKeyboard::KeyAddressGroup::multimedia); case Key::g6:
break; case Key::g7:
case 3: case Key::g8:
data = getKeyGroupAddress(LedKeyboard::KeyAddressGroup::gkeys); case Key::g9:
keyaddoffset = 0xb3; break;
break; case Key::play:
case 4: data.push_back(0x9b);
data = getKeyGroupAddress(LedKeyboard::KeyAddressGroup::keys); break;
keyremoveoffset = 0x03; case Key::mute:
break; data.push_back(0x9c);
} break;
case Key::next:
//const uint8_t maxKeyCount = (data_size - 8) / 4; data.push_back(0x9d);
//const uint8_t maxKeyCount = 4; break;
const uint8_t maxKeyCount = 1; // Temporary solution case Key::prev:
data.push_back(0x9e);
if (data.size() > 0) { break;
case Key::ctrl_left:
for (uint8_t i = 0; i < maxKeyCount; i++) { case Key::shift_left:
if (gi + i < SortedKeys[kag].size()) { case Key::alt_left:
switch (SortedKeys[kag][gi+i].key) { // Temporary solution case Key::win_left:
case Key::play: case Key::ctrl_right:
data.push_back(0x9b); case Key::shift_right:
break; case Key::alt_right:
case Key::mute: case Key::win_right:
data.push_back(0x9c); data.push_back((static_cast<uint8_t>(x.second[gi+i].key) & 0x00ff) - 0x78);
break; break;
case Key::next: default:
data.push_back(0x9d); switch (static_cast<KeyAddressGroup>((static_cast<uint16_t>(x.second[gi+i].key) & 0xff00) / 0xff)) {
break; case KeyAddressGroup::logo:
case Key::prev: data.push_back((static_cast<uint8_t>(x.second[gi+i].key) & 0x00ff) + 0xd1);
data.push_back(0x9e); break;
break; case KeyAddressGroup::indicators:
case Key::ctrl_left: data.push_back((static_cast<uint8_t>(x.second[gi+i].key) & 0x00ff) + 0x98);
case Key::shift_left: break;
case Key::alt_left: case KeyAddressGroup::gkeys:
case Key::win_left: data.push_back((static_cast<uint8_t>(x.second[gi+i].key) & 0x00ff) + 0xb3);
case Key::ctrl_right: break;
case Key::shift_right: case KeyAddressGroup::keys:
case Key::alt_right: data.push_back((static_cast<uint8_t>(x.second[gi+i].key) & 0x00ff) - 0x03);
case Key::win_right: break;
data.push_back(static_cast<uint8_t>( default:
static_cast<uint16_t>(SortedKeys[kag][gi+i].key) & 0x00ff) - 0x78); break;
break; }
default:
data.push_back(static_cast<uint8_t>(
static_cast<uint16_t>(SortedKeys[kag][gi+i].key) & 0x00ff) + keyaddoffset - keyremoveoffset);
}
data.push_back(SortedKeys[kag][gi+i].color.red);
data.push_back(SortedKeys[kag][gi+i].color.green);
data.push_back(SortedKeys[kag][gi+i].color.blue);
} }
} }
if (data.size() < data_size) data.push_back(0xff);
data.resize(data_size, 0x00);
if (retval) retval = sendDataInternal(data);
else sendDataInternal(data);
} }
gi = gi + maxKeyCount; if (data.size() < data_size) data.push_back(0xff);
data.resize(data_size, 0x00);
if (retval) retval = sendDataInternal(data);
else sendDataInternal(data);
gi = gi + maxKeyPerColor;
} }
} }
} }
break; break;
default: default:
SortedKeys = {
{}, // Logo AddressGroup
{}, // Indicators AddressGroup
{}, // Multimedia AddressGroup
{}, // GKeys AddressGroup
{} // Keys AddressGroup
};
for (uint8_t i = 0; i < keyValues.size(); i++) {
switch(static_cast<LedKeyboard::KeyAddressGroup>(static_cast<uint16_t>(keyValues[i].key) >> 8 )) {
case LedKeyboard::KeyAddressGroup::logo:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g610:
case LedKeyboard::KeyboardModel::g810:
case LedKeyboard::KeyboardModel::gpro:
if (SortedKeys[0].size() <= 1 && keyValues[i].key == LedKeyboard::Key::logo)
SortedKeys[0].push_back(keyValues[i]);
break;
case LedKeyboard::KeyboardModel::g910:
if (SortedKeys[0].size() <= 2) SortedKeys[0].push_back(keyValues[i]);
break;
default:
break;
}
break;
case LedKeyboard::KeyAddressGroup::indicators:
if (SortedKeys[1].size() <= 5) SortedKeys[1].push_back(keyValues[i]);
break;
case LedKeyboard::KeyAddressGroup::multimedia:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g610:
case LedKeyboard::KeyboardModel::g810:
case LedKeyboard::KeyboardModel::gpro:
if (SortedKeys[2].size() <= 5) SortedKeys[2].push_back(keyValues[i]);
break;
default:
break;
}
break;
case LedKeyboard::KeyAddressGroup::gkeys:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g910:
if (SortedKeys[3].size() <= 9) SortedKeys[3].push_back(keyValues[i]);
break;
default:
break;
}
break;
case LedKeyboard::KeyAddressGroup::keys:
switch (currentDevice.model) {
case LedKeyboard::KeyboardModel::g513:
case LedKeyboard::KeyboardModel::g610:
case LedKeyboard::KeyboardModel::g810:
case LedKeyboard::KeyboardModel::g910:
case LedKeyboard::KeyboardModel::gpro:
if (SortedKeys[4].size() <= 120) SortedKeys[4].push_back(keyValues[i]);
break;
case LedKeyboard::KeyboardModel::g410:
if (SortedKeys[4].size() <= 120)
if (keyValues[i].key < LedKeyboard::Key::num_lock ||
keyValues[i].key > LedKeyboard::Key::num_dot)
SortedKeys[4].push_back(keyValues[i]);
break;
default:
break;
}
break;
}
}
for (uint8_t kag = 0; kag < 5; kag++) { for (uint8_t kag = 0; kag < 5; kag++) {
if (SortedKeys[kag].size() > 0) { if (SortedKeys[kag].size() > 0) {