mirror of
https://github.com/MatMoul/g810-led.git
synced 2026-05-21 14:27:41 +00:00
Initial work to add G213 support
Currently supported:
- G213 by region {1..5}
- Standard FX calls
- Startup behavior
- Help and command-line app support
resolves MatMoul/g810-led#69
Signed-off-by: Kevin Pearson <pearson.kevin.m@gmail.com>
This commit is contained in:
committed by
Kevin Pearson
parent
1f0458ea4f
commit
793aa0d557
@@ -55,6 +55,7 @@ setup:
|
||||
$(DESTDIR)/etc/$(PROGN)/samples \
|
||||
$(DESTDIR)/etc/udev/rules.d
|
||||
@cp bin/$(PROGN) $(DESTDIR)/usr/bin
|
||||
@test -s $(DESTDIR)/usr/bin/g213-led || ln -s /usr/bin/$(PROGN) $(DESTDIR)/usr/bin/g213-led
|
||||
@test -s $(DESTDIR)/usr/bin/g410-led || ln -s /usr/bin/$(PROGN) $(DESTDIR)/usr/bin/g410-led
|
||||
@test -s $(DESTDIR)/usr/bin/g610-led || ln -s /usr/bin/$(PROGN) $(DESTDIR)/usr/bin/g610-led
|
||||
@test -s $(DESTDIR)/usr/bin/g910-led || ln -s /usr/bin/$(PROGN) $(DESTDIR)/usr/bin/g910-led
|
||||
@@ -99,6 +100,7 @@ uninstall:
|
||||
systemctl daemon-reload && \
|
||||
rm -R /etc/$(PROGN)
|
||||
|
||||
@rm /usr/bin/g213-led
|
||||
@rm /usr/bin/g410-led
|
||||
@rm /usr/bin/g610-led
|
||||
@rm /usr/bin/g910-led
|
||||
|
||||
+50
-11
@@ -231,6 +231,8 @@ LedKeyboard::KeyboardModel LedKeyboard::getKeyboardModel() {
|
||||
bool LedKeyboard::commit() {
|
||||
byte_buffer_t data;
|
||||
switch (m_keyboardModel) {
|
||||
case KeyboardModel::g213:
|
||||
break; // Keyboard is non-transactional
|
||||
case KeyboardModel::g410:
|
||||
case KeyboardModel::g610:
|
||||
case KeyboardModel::g810:
|
||||
@@ -430,17 +432,32 @@ bool LedKeyboard::setGroupKeys(KeyGroup keyGroup, LedKeyboard::Color color) {
|
||||
|
||||
bool LedKeyboard::setAllKeys(LedKeyboard::Color color) {
|
||||
KeyValueArray keyValues;
|
||||
for (uint8_t i = 0; i < keyGroupLogo.size(); i++) keyValues.push_back({keyGroupLogo[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupIndicators.size(); i++) keyValues.push_back({keyGroupIndicators[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupMultimedia.size(); i++) keyValues.push_back({keyGroupMultimedia[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupGKeys.size(); i++) keyValues.push_back({keyGroupGKeys[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupFKeys.size(); i++) keyValues.push_back({keyGroupFKeys[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupFunctions.size(); i++) keyValues.push_back({keyGroupFunctions[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupArrows.size(); i++) keyValues.push_back({keyGroupArrows[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupNumeric.size(); i++) keyValues.push_back({keyGroupNumeric[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupModifiers.size(); i++) keyValues.push_back({keyGroupModifiers[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupKeys.size(); i++) keyValues.push_back({keyGroupKeys[i], color});
|
||||
return setKeys(keyValues);
|
||||
|
||||
switch (m_keyboardModel) {
|
||||
case KeyboardModel::g213:
|
||||
for (uint8_t rIndex=0x01; rIndex <= 0x05; rIndex++) {
|
||||
if (! setRegion(rIndex,color)) return false;
|
||||
}
|
||||
return true;
|
||||
case KeyboardModel::g410:
|
||||
case KeyboardModel::g610:
|
||||
case KeyboardModel::g810:
|
||||
case KeyboardModel::g910:
|
||||
for (uint8_t i = 0; i < keyGroupLogo.size(); i++) keyValues.push_back({keyGroupLogo[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupIndicators.size(); i++) keyValues.push_back({keyGroupIndicators[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupMultimedia.size(); i++) keyValues.push_back({keyGroupMultimedia[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupGKeys.size(); i++) keyValues.push_back({keyGroupGKeys[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupFKeys.size(); i++) keyValues.push_back({keyGroupFKeys[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupFunctions.size(); i++) keyValues.push_back({keyGroupFunctions[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupArrows.size(); i++) keyValues.push_back({keyGroupArrows[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupNumeric.size(); i++) keyValues.push_back({keyGroupNumeric[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupModifiers.size(); i++) keyValues.push_back({keyGroupModifiers[i], color});
|
||||
for (uint8_t i = 0; i < keyGroupKeys.size(); i++) keyValues.push_back({keyGroupKeys[i], color});
|
||||
return setKeys(keyValues);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -510,10 +527,25 @@ bool LedKeyboard::setGKeysMode(uint8_t value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LedKeyboard::setRegion(uint8_t region, LedKeyboard::Color color) {
|
||||
LedKeyboard::byte_buffer_t data;
|
||||
switch (m_keyboardModel) {
|
||||
case KeyboardModel::g213:
|
||||
data = {0x11, 0xff, 0x0c, 0x3a, region, 0x01, color.red, color.green, color.blue };
|
||||
data.resize(20,0x00);
|
||||
return sendDataInternal(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LedKeyboard::setStartupMode(StartupMode startupMode) {
|
||||
byte_buffer_t data;
|
||||
switch (m_keyboardModel) {
|
||||
case KeyboardModel::g213:
|
||||
case KeyboardModel::g410:
|
||||
case KeyboardModel::g610:
|
||||
case KeyboardModel::g810:
|
||||
@@ -535,6 +567,11 @@ bool LedKeyboard::setNativeEffect(NativeEffect effect, NativeEffectPart part, ui
|
||||
uint8_t protocolByte = 0;
|
||||
|
||||
switch (m_keyboardModel) {
|
||||
case KeyboardModel::g213:
|
||||
protocolByte = 0x0c;
|
||||
|
||||
if (part == NativeEffectPart::logo) return false; //Does not have logo component
|
||||
break;
|
||||
case KeyboardModel::g410:
|
||||
case KeyboardModel::g610: // Unconfirmed
|
||||
case KeyboardModel::g810:
|
||||
@@ -653,6 +690,8 @@ bool LedKeyboard::sendDataInternal(byte_buffer_t &data) {
|
||||
|
||||
LedKeyboard::byte_buffer_t LedKeyboard::getKeyGroupAddress(LedKeyboard::KeyAddressGroup keyAddressGroup) {
|
||||
switch (m_keyboardModel) {
|
||||
case KeyboardModel::g213:
|
||||
return {}; // Device doesn't support per-key setting
|
||||
case KeyboardModel::g410:
|
||||
case KeyboardModel::g610:
|
||||
case KeyboardModel::g810:
|
||||
|
||||
@@ -17,6 +17,7 @@ class LedKeyboard {
|
||||
private:
|
||||
|
||||
const std::vector<std::vector<uint16_t>> SupportedKeyboards = {
|
||||
{ 0x46d, 0xc336, (u_int16_t)KeyboardModel::g213 },
|
||||
{ 0x46d, 0xc330, (u_int16_t)KeyboardModel::g410 },
|
||||
{ 0x46d, 0xc333, (u_int16_t)KeyboardModel::g610 },
|
||||
{ 0x46d, 0xc338, (u_int16_t)KeyboardModel::g610 },
|
||||
@@ -40,6 +41,7 @@ class LedKeyboard {
|
||||
|
||||
enum class KeyboardModel : uint8_t {
|
||||
unknown = 0x00,
|
||||
g213,
|
||||
g410,
|
||||
g610,
|
||||
g810,
|
||||
@@ -144,6 +146,7 @@ class LedKeyboard {
|
||||
bool setMNKey(uint8_t value);
|
||||
bool setGKeysMode(uint8_t value);
|
||||
|
||||
bool setRegion(uint8_t region, Color color);
|
||||
bool setStartupMode(StartupMode startupMode);
|
||||
|
||||
bool setNativeEffect(NativeEffect effect, NativeEffectPart part, uint8_t speed, Color color);
|
||||
|
||||
@@ -19,6 +19,10 @@ namespace help {
|
||||
cout<<" -a {color}\t\t\t\tSet all keys color"<<endl;
|
||||
cout<<" -g {keygroup} {color}\t\t\tSet key group color"<<endl;
|
||||
cout<<" -k {key} {color}\t\t\tSet key color"<<endl;
|
||||
if (cmdName == "g213-led")
|
||||
{
|
||||
cout<<" -r {region} {color}\t\t\tSet the color of a region for a region-based keyboard"<<endl;
|
||||
}
|
||||
if (cmdName == "g910-led") {
|
||||
cout<<" -mr {value}\t\t\t\tSet MR key (0-1)"<<endl;
|
||||
cout<<" -mn {value}\t\t\t\tSet MN key (0-7) (M1=1, M2=2, M3=4) (M1+M2=3, M1+M3=5, ...)"<<endl;
|
||||
@@ -50,6 +54,10 @@ namespace help {
|
||||
cout<<"color formats :\t\t\t\tII (hex value for intensity)"<<endl;
|
||||
else
|
||||
cout<<"color formats :\t\t\t\tRRGGBB (hex value for red, green and blue)"<<endl;
|
||||
if (cmdName == "g213-led")
|
||||
{
|
||||
cout<<"region formats :\t\t\tRN (integer value for region, 1 to 5)"<<endl;
|
||||
}
|
||||
cout<<"speed formats :\t\t\t\tSS (hex value for speed 01 to ff)"<<endl;
|
||||
cout<<""<<endl;
|
||||
cout<<"key values :\t\t\t\tabc... 123... and other (use --help-keys for more detail)"<<endl;
|
||||
|
||||
@@ -70,6 +70,15 @@ int setGKeysMode(LedKeyboard &kbd, std::string arg2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setRegion(LedKeyboard &kbd, std::string arg2, std::string arg3) {
|
||||
uint8_t region = 0;
|
||||
LedKeyboard::Color color;
|
||||
|
||||
if (! utils::parseColor(arg3, color)) return 1;
|
||||
if (! utils::parseUInt8(arg2, region)) return 1;
|
||||
if (kbd.setRegion(region,color)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setFX(LedKeyboard &kbd, std::string arg2, std::string arg3, std::string arg4, std::string arg5 = "") {
|
||||
LedKeyboard::NativeEffect effect;
|
||||
@@ -238,6 +247,7 @@ int main(int argc, char **argv) {
|
||||
else if (argc > 2 && arg == "-an") return setAllKeys(kbd, argv[2], false);
|
||||
else if (argc > 3 && arg == "-gn") return setGroupKeys(kbd, argv[2], argv[3], false);
|
||||
else if (argc > 3 && arg == "-kn") return setKey(kbd, argv[2], argv[3], false);
|
||||
else if (argc > 3 && arg == "-r") return setRegion(kbd, argv[2], argv[3]);
|
||||
|
||||
else if (argc > 2 && arg == "-gkm") return setGKeysMode(kbd, argv[2]);
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user