mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 01:06:11 +00:00
Add native effect support
This commit is contained in:
parent
5a2bff5225
commit
3b13f247b5
@ -491,6 +491,13 @@ bool Keyboard::parseColor(std::string color, KeyColors &colors) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Keyboard::parseSpeed(std::string speed, uint8_t &speedValue) {
|
||||
if (speed.length() == 1) speed = speed + "0";
|
||||
if (speed.length() != 2) return false;
|
||||
speedValue = std::stoul("0x"+speed, nullptr, 16);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Keyboard::sendDataInternal(unsigned char *data, uint16_t data_size) {
|
||||
if (m_isAttached == false) return false;
|
||||
int r;
|
||||
@ -849,34 +856,6 @@ bool Keyboard::setFXColor(KeyColors colors) {
|
||||
int data_size = 20;
|
||||
unsigned char *data = new unsigned char[data_size];
|
||||
|
||||
// Indicators
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
data[2] = 0x0c; // Base address
|
||||
data[3] = 0x4c; // Base address
|
||||
data[4] = 0x00; // Base address
|
||||
data[5] = 0x40; // Base address
|
||||
|
||||
data[6] = colors.red;
|
||||
data[7] = colors.green;
|
||||
data[8] = colors.blue;
|
||||
|
||||
for(int i = 9; i < data_size; i++) data[i] = 0x00;
|
||||
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
data[2] = 0x0c; // Base address
|
||||
data[3] = 0x5c; // Base address
|
||||
|
||||
for(int i = 4; i < data_size; i++) data[i] = 0x00;
|
||||
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
|
||||
|
||||
// Keys
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
@ -884,17 +863,13 @@ bool Keyboard::setFXColor(KeyColors colors) {
|
||||
data[3] = 0x3c; // Base address
|
||||
data[4] = 0x00; // Base address
|
||||
data[5] = 0x01; // Base address
|
||||
|
||||
data[6] = colors.red;
|
||||
data[7] = colors.green;
|
||||
data[8] = colors.blue;
|
||||
data[9] = 0x02;
|
||||
|
||||
for(int i = 10; i < data_size; i++) data[i] = 0x00;
|
||||
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
|
||||
// Logo
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
@ -902,17 +877,103 @@ bool Keyboard::setFXColor(KeyColors colors) {
|
||||
data[3] = 0x3c; // Base address
|
||||
data[4] = 0x01; // Base address
|
||||
data[5] = 0x01; // Base address
|
||||
|
||||
data[6] = colors.red;
|
||||
data[7] = colors.green;
|
||||
data[8] = colors.blue;
|
||||
data[9] = 0x02;
|
||||
|
||||
for(int i = 10; i < data_size; i++) data[i] = 0x00;
|
||||
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
|
||||
delete[] data;
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool Keyboard::setFXBreathing(KeyColors colors, uint8_t speed) {
|
||||
bool retval = false;
|
||||
int data_size = 20;
|
||||
unsigned char *data = new unsigned char[data_size];
|
||||
|
||||
// Keys
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
data[2] = 0x0d; // Base address
|
||||
data[3] = 0x3c; // Base address
|
||||
data[4] = 0x00; // Base address
|
||||
data[5] = 0x02; // Base address
|
||||
data[6] = colors.red;
|
||||
data[7] = colors.green;
|
||||
data[8] = colors.blue;
|
||||
data[9] = speed; // Speed
|
||||
data[10] = 0x10; // ???
|
||||
data[11] = 0x00;
|
||||
data[12] = 0x64;
|
||||
for(int i = 13; i < data_size; i++) data[i] = 0x00;
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
// Logo
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
data[2] = 0x0d; // Base address
|
||||
data[3] = 0x3c; // Base address
|
||||
data[4] = 0x01; // Base address
|
||||
data[5] = 0x02; // Base address
|
||||
data[6] = colors.red;
|
||||
data[7] = colors.green;
|
||||
data[8] = colors.blue;
|
||||
data[9] = speed; // Speed
|
||||
data[10] = 0x10; // ???
|
||||
data[11] = 0x00;
|
||||
data[12] = 0x64;
|
||||
for(int i = 13; i < data_size; i++) data[i] = 0x00;
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
delete[] data;
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool Keyboard::setFXColorCycle(uint8_t speed) {
|
||||
bool retval = false;
|
||||
int data_size = 20;
|
||||
unsigned char *data = new unsigned char[data_size];
|
||||
|
||||
// Keys
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
data[2] = 0x0d; // Base address
|
||||
data[3] = 0x3c; // Base address
|
||||
data[4] = 0x00; // Base address
|
||||
data[5] = 0x03; // Base address
|
||||
data[6] = 0x00;
|
||||
data[7] = 0x00;
|
||||
data[8] = 0x00;
|
||||
data[9] = 0x00;
|
||||
data[10] = 0x00;
|
||||
data[11] = speed; // Speed
|
||||
data[12] = 0x00; // ???
|
||||
data[13] = 0x00;
|
||||
data[14] = 0x64;
|
||||
for(int i = 15; i < data_size; i++) data[i] = 0x00;
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
// Logo
|
||||
data[0] = 0x11; // Base address
|
||||
data[1] = 0xff; // Base address
|
||||
data[2] = 0x0d; // Base address
|
||||
data[3] = 0x3c; // Base address
|
||||
data[4] = 0x01; // Base address
|
||||
data[5] = 0x03; // Base address
|
||||
data[6] = 0x00;
|
||||
data[7] = 0x00;
|
||||
data[8] = 0x00;
|
||||
data[9] = 0x00;
|
||||
data[10] = 0x00;
|
||||
data[11] = speed; // Speed
|
||||
data[12] = 0x00; // ???
|
||||
data[13] = 0x00;
|
||||
data[14] = 0x64;
|
||||
for(int i = 15; i < data_size; i++) data[i] = 0x00;
|
||||
retval = sendDataInternal(data, data_size);
|
||||
|
||||
delete[] data;
|
||||
return retval;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ class Keyboard {
|
||||
bool parseKey(std::string key, KeyAddress &keyAddress);
|
||||
bool parseKeyGroup(std::string key, KeyGroup &keyGroup);
|
||||
bool parseColor(std::string color, KeyColors &colors);
|
||||
bool parseSpeed(std::string speed, uint8_t &speedValue);
|
||||
bool setPowerOnEffect(PowerOnEffect powerOnEffect);
|
||||
bool setKey(KeyValue keyValue);
|
||||
bool setKey(Key key, KeyColors colors);
|
||||
@ -52,6 +53,8 @@ class Keyboard {
|
||||
bool setAllKeys(KeyColors colors);
|
||||
bool setGroupKeys(KeyGroup keyGroup, KeyColors colors);
|
||||
bool setFXColor(KeyColors colors);
|
||||
bool setFXBreathing(KeyColors colors, uint8_t speed);
|
||||
bool setFXColorCycle(uint8_t speed);
|
||||
|
||||
|
||||
private:
|
||||
|
84
src/main.cpp
84
src/main.cpp
@ -10,34 +10,40 @@ void usage() {
|
||||
cout<<appname<<" Usages :\n";
|
||||
cout<<"-----------------\n";
|
||||
cout<<"\n";
|
||||
cout<<" -s effect :\t\tSet keyboard startup effect\n";
|
||||
cout<<" -s effect :\t\t\tSet keyboard startup effect\n";
|
||||
cout<<"\n";
|
||||
cout<<" -a color :\t\tSet all keys\n";
|
||||
cout<<" -g group, color :\tSet a group of keys\n";
|
||||
cout<<" -k key, color :\tSet a key\n";
|
||||
cout<<" -a color :\t\t\tSet all keys\n";
|
||||
cout<<" -g group, color :\t\tSet a group of keys\n";
|
||||
cout<<" -k key, color :\t\tSet a key\n";
|
||||
cout<<"\n";
|
||||
cout<<" -an color :\t\tSet all keys without commit\n";
|
||||
cout<<" -gn group, color :\tSet a group of keys without commit\n";
|
||||
cout<<" -kn key, color :\tSet a key without commit\n";
|
||||
cout<<" -an color :\t\t\tSet all keys without commit\n";
|
||||
cout<<" -gn group, color :\t\tSet a group of keys without commit\n";
|
||||
cout<<" -kn key, color :\t\tSet a key without commit\n";
|
||||
cout<<"\n";
|
||||
cout<<" -c :\t\t\tCommit changes\n";
|
||||
cout<<" -c :\t\t\t\tCommit changes\n";
|
||||
cout<<"\n";
|
||||
cout<<" -p profilefile :\tLoad a profile\n";
|
||||
cout<<" -fx-color color :\t\tSet static color effect\n";
|
||||
cout<<" -fx-breathing color, speed :\tSet breathing effect\n";
|
||||
cout<<" -fx-cycle speed :\t\tSet color cycle effect\n";
|
||||
cout<<"\n";
|
||||
cout<<" -h | --help :\t\tthis help message\n";
|
||||
cout<<" -lk | --list-keys :\tList keys in groups\n";
|
||||
cout<<" -p profilefile :\t\tLoad a profile\n";
|
||||
cout<<"\n";
|
||||
cout<<"color formats :\t\tRRGGBB (hex value for red, green and blue)\n";
|
||||
cout<<" -h | --help :\t\t\tthis help message\n";
|
||||
cout<<" -lk | --list-keys :\t\tList keys in groups\n";
|
||||
cout<<"\n";
|
||||
cout<<"effect values :\t\trainbow, color\n";
|
||||
cout<<"key values :\t\tabc... 123... and other\n";
|
||||
cout<<"group values :\t\tlogo, indicators, fkeys, modifiers, multimedia, arrows, numeric, functions, keys, gkeys\n";
|
||||
cout<<"color formats :\t\t\tRRGGBB (hex value for red, green and blue)\n";
|
||||
cout<<"speed formats :\t\t\tSS (hex value for speed)\n";
|
||||
cout<<"\n";
|
||||
cout<<"effect values :\t\t\trainbow, color\n";
|
||||
cout<<"key values :\t\t\tabc... 123... and other\n";
|
||||
cout<<"group values :\t\t\tlogo, indicators, fkeys, modifiers, multimedia, arrows, numeric, functions, keys, gkeys\n";
|
||||
cout<<"\n";
|
||||
cout<<"sample :\n";
|
||||
cout<<appname<<" -k logo ff0000\n";
|
||||
cout<<appname<<" -a 00ff00\n";
|
||||
cout<<appname<<" -g fkeys ff00ff\n";
|
||||
cout<<appname<<" -s color\n";
|
||||
cout<<appname<<" -fx-cycle 10\n";
|
||||
}
|
||||
|
||||
void listkeys() {
|
||||
@ -204,6 +210,10 @@ int setFXColor(string color) {
|
||||
Keyboard lg_kbd;
|
||||
Keyboard::KeyColors colors;
|
||||
if (lg_kbd.parseColor(color, colors) == true) {
|
||||
lg_kbd.attach();
|
||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||
lg_kbd.commit();
|
||||
lg_kbd.detach();
|
||||
lg_kbd.attach();
|
||||
lg_kbd.setFXColor(colors);
|
||||
lg_kbd.detach();
|
||||
@ -212,6 +222,48 @@ int setFXColor(string color) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setFXBreathing(string color, string speed) {
|
||||
Keyboard lg_kbd;
|
||||
Keyboard::KeyColors colors;
|
||||
uint8_t speedValue;
|
||||
if (lg_kbd.parseColor(color, colors) == true) {
|
||||
if (lg_kbd.parseSpeed(speed, speedValue) == true) {
|
||||
lg_kbd.attach();
|
||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||
lg_kbd.commit();
|
||||
lg_kbd.detach();
|
||||
lg_kbd.attach();
|
||||
lg_kbd.setFXBreathing(colors, speedValue);
|
||||
lg_kbd.detach();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int setFXColorCycle(string speed) {
|
||||
Keyboard lg_kbd;
|
||||
Keyboard::KeyColors colors;
|
||||
uint8_t speedValue;
|
||||
if (lg_kbd.parseSpeed(speed, speedValue) == true) {
|
||||
colors.red = 0xff;
|
||||
colors.green = 0xff;
|
||||
colors.blue = 0xff;
|
||||
lg_kbd.attach();
|
||||
lg_kbd.setGroupKeys(Keyboard::KeyGroup::indicators, colors);
|
||||
lg_kbd.commit();
|
||||
lg_kbd.detach();
|
||||
lg_kbd.attach();
|
||||
lg_kbd.setFXColorCycle(speedValue);
|
||||
lg_kbd.detach();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int loadProfile(string profileFile) {
|
||||
ifstream file;
|
||||
|
||||
@ -317,6 +369,8 @@ int main(int argc, char *argv[]) {
|
||||
else if (argCmd == "-c" && argc == 2) return commit();
|
||||
else if (argCmd == "-p" && argc == 3) return loadProfile(argv[2]);
|
||||
else if (argCmd == "-fx-color" && argc == 3) return setFXColor(argv[2]);
|
||||
else if (argCmd == "-fx-breathing" && argc == 4) return setFXBreathing(argv[2], argv[3]);
|
||||
else if (argCmd == "-fx-cycle" && argc == 3) return setFXColorCycle(argv[2]);
|
||||
}
|
||||
usage();
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user