diff --git a/makefile b/makefile index 6a24c9b..24826e8 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,6 @@ CC=g++ CFLAGS=-Wall -O2 -std=gnu++11 +LIBUSB_INC?=-I/usr/include/libusb-1.0 LDFLAGS=-lusb-1.0 PROGN=g810-led @@ -7,11 +8,11 @@ PROGN=g810-led all: bin/$(PROGN) -bin/$(PROGN): src/main.cpp src/classes/*.cpp +bin/$(PROGN): src/main.cpp src/classes/*.cpp src/classes/*.h @mkdir -p bin - $(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS) + $(CC) $(CFLAGS) $(LIBUSB_INC) -o $@ $^ $(LDFLAGS) -debug: CFLAGS += -g +debug: CFLAGS += -g -Wextra -pedantic debug: bin/$(PROGN) clean: diff --git a/src/classes/Keyboard.cpp b/src/classes/Keyboard.cpp index 5544788..f2400a5 100644 --- a/src/classes/Keyboard.cpp +++ b/src/classes/Keyboard.cpp @@ -21,7 +21,20 @@ bool Keyboard::attach() { int pid = 0; for(ssize_t i = 0; i < cnt; i++) { libusb_device *device = devs[i]; - libusb_device_descriptor desc = {0}; + libusb_device_descriptor desc = {0, // bLength + 0, // bDescriptorType + 0, // bcdUSB + 0, // bDeviceClass + 0, // bDeviceSubClass + 0, // bDeviceProtocol + 0, // bMaxPacketSize0 + 0, // idVendor + 0, // idProduct + 0, // bcdDevice + 0, // iManufacturer + 0, // iProduct + 0, // iSerialNumber + 0}; // bNumConfigurations libusb_get_device_descriptor(device, &desc); if (desc.idVendor == 0x046d) { if (desc.idProduct == 0xc331) { pid = desc.idProduct; break; } // G810 spectrum @@ -476,7 +489,7 @@ bool Keyboard::parseColor(std::string color, KeyColors &colors) { return true; } -bool Keyboard::sendDataInternal(unsigned char *data, int data_size) { +bool Keyboard::sendDataInternal(unsigned char *data, uint16_t data_size) { if (m_isAttached == false) return false; int r; if (data_size > 20) r = libusb_control_transfer(dev_handle, 0x21, 0x09, 0x0212, 1, data, data_size, 2000); @@ -589,17 +602,15 @@ bool Keyboard::populateAddressGroupInternal(KeyAddressGroup addressGroup, unsign return true; } -bool Keyboard::setKeysInternal(KeyAddressGroup addressGroup, KeyValue keyValues[], int keyValueCount) { +bool Keyboard::setKeysInternal(KeyAddressGroup addressGroup, KeyValue keyValues[], size_t keyValueCount) { bool retval = false; - unsigned char *data; int data_size; - int maxKeyValueCount = 0; if (addressGroup == KeyAddressGroup::logo) data_size = 20; else data_size = 64; - data = new unsigned char[data_size]; + unsigned char *data = new unsigned char[data_size]; + const size_t maxKeyValueCount = (data_size - 8) / 4; populateAddressGroupInternal(addressGroup, data); - maxKeyValueCount = (data_size - 8) / 4; - for(int i = 0; i < maxKeyValueCount; i++) { + for(size_t i = 0; i < maxKeyValueCount; i++) { if (i < keyValueCount) { data[8 + i * 4 + 0] = keyValues[i].key.id; data[8 + i * 4 + 1] = keyValues[i].colors.red; @@ -671,24 +682,24 @@ bool Keyboard::setKey(Key key, KeyColors colors) { return setKey(keyValue); } -bool Keyboard::setKeys(KeyValue keyValue[], int keyValueCount) { - int maxLogoKeys = 5; - int logoCount = 0; +bool Keyboard::setKeys(KeyValue keyValue[], size_t keyValueCount) { + const size_t maxLogoKeys = 5; + const size_t maxIndicatorsKeys = 25; + const size_t maxMultimediaKeys = 25; + const size_t maxKeys = 200; + const size_t maxGKeys = 25; + size_t logoCount = 0; + size_t indicatorsCount = 0; + size_t multimediaCount = 0; + size_t keysCount = 0; + size_t gkeysCount = 0; KeyValue logo[maxLogoKeys]; - int maxIndicatorsKeys = 25; - int indicatorsCount = 0; KeyValue indicators[maxIndicatorsKeys]; - int maxMultimediaKeys = 25; - int multimediaCount = 0; KeyValue multimedia[maxMultimediaKeys]; - int maxKeys = 200; - int keysCount = 0; KeyValue keys[maxKeys]; - int maxGKeys = 25; - int gkeysCount = 0; KeyValue gkeys[maxGKeys]; - for (int i = 0; i < keyValueCount; i++) { + for (size_t i = 0; i < keyValueCount; i++) { if(keyValue[i].key.addressGroup == KeyAddressGroup::logo && logoCount <= maxLogoKeys) { logo[logoCount] = keyValue[i]; logoCount++; @@ -714,11 +725,11 @@ bool Keyboard::setKeys(KeyValue keyValue[], int keyValueCount) { if (multimediaCount > 0) setKeysInternal(KeyAddressGroup::multimedia, multimedia, multimediaCount); if (keysCount > 0) { - int maxKeyValueCount = 14; - for (int i = 0; i < keysCount; i = i + maxKeyValueCount) { + const size_t maxKeyValueCount = 14; + for (size_t i = 0; i < keysCount; i = i + maxKeyValueCount) { KeyValue keysBlock[maxKeyValueCount]; - int keysBlockCount = 0; - for (int j = 0; j < maxKeyValueCount; j++) { + size_t keysBlockCount = 0; + for (size_t j = 0; j < maxKeyValueCount; j++) { if((i + j) < keysCount ) { keysBlock[j] = keys[i + j]; keysBlockCount++; diff --git a/src/classes/Keyboard.h b/src/classes/Keyboard.h index aa0f60f..a2b563e 100644 --- a/src/classes/Keyboard.h +++ b/src/classes/Keyboard.h @@ -2,7 +2,7 @@ #define DEF_KEYBOARD #include -#include "/usr/include/libusb-1.0/libusb.h" +#include class Keyboard { @@ -32,8 +32,8 @@ class Keyboard { }; enum class KeyGroup { logo, indicators, multimedia, fkeys, modifiers, arrows, numeric, functions, keys, gkeys}; - struct KeyColors { char red; char green; char blue; }; - struct KeyAddress { KeyAddressGroup addressGroup; char id; }; + struct KeyColors { uint8_t red; uint8_t green; uint8_t blue; }; + struct KeyAddress { KeyAddressGroup addressGroup; uint8_t id; }; struct KeyValue { KeyAddress key; KeyColors colors; }; bool isAttached(); @@ -48,7 +48,7 @@ class Keyboard { bool setPowerOnEffect(PowerOnEffect powerOnEffect); bool setKey(KeyValue keyValue); bool setKey(Key key, KeyColors colors); - bool setKeys(KeyValue keyValue[], int keyValueCount); + bool setKeys(KeyValue keyValue[], size_t keyValueCount); bool setAllKeys(KeyColors colors); bool setGroupKeys(KeyGroup keyGroup, KeyColors colors); @@ -63,8 +63,8 @@ class Keyboard { libusb_context *ctx = NULL; bool populateAddressGroupInternal(KeyAddressGroup addressGroup, unsigned char *data); - bool sendDataInternal(unsigned char *data, int data_size); - bool setKeysInternal(KeyAddressGroup addressGroup, KeyValue keyValues[], int keyValueCount); + bool sendDataInternal(unsigned char *data, uint16_t data_size); + bool setKeysInternal(KeyAddressGroup addressGroup, KeyValue keyValues[], size_t keyValueCount); }; diff --git a/wireshark_dumps/g810-spectrum/README.md b/wireshark_dumps/g810-spectrum/README.md new file mode 100644 index 0000000..5316549 --- /dev/null +++ b/wireshark_dumps/g810-spectrum/README.md @@ -0,0 +1,26 @@ +# Description of each wireshark dump found in this folder +=== + +Sets effect to 'breathing' with color rgb(252,253,254) at the highest level the slider bar offers. Noticed that the full cycle of updates after switching to the profile (which was done through linking a profile to Notepad++ and letting logitech automatically send the profile once) is around 1 second for fullspeed, 5 seconds for midspeed, and a long 10 seconds for nospeed. + +`g810-effect-to-breathing-252-253-254-fullspeed.pcapng +`g810-effect-to-breathing-252-253-254-midspeed.pcapng +`g810-effect-to-breathing-252-253-254-nospeed.pcapng + +Sets effect to 'key press' with pressed color rgb(3,2,1) and background color rgb(252,253,254) with slider at lowest speed + +`g810-effect-to-keypress-3-2-1_252-253-254-nospeed.pcapng + +Idle g810 capture, was getting periodic updates without having anything interesting going on. Not sure why + +`g810-idle.pcapng + +Sets key color of 'a' / 'rcntrl' to rgb(252,253,254) + +`g810-set-a-to-252-253-254.pcapng +`g810-set-rcntrl-to-252-253-254.pcapng + +Sets effect to 'fixedcolor' - believe this was also at rgb(252,253,254). The second one includes going to the window and back, where it loads the profile and then reloads the former profile. + +`g810-switches-to-fixedcolor-effect.pcapng +`g810-switches-to-from-fixedcolor-effect.pcapng diff --git a/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-fullspeed.pcapng b/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-fullspeed.pcapng new file mode 100644 index 0000000..6f02103 Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-fullspeed.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-midspeed.pcapng b/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-midspeed.pcapng new file mode 100644 index 0000000..c5c4b97 Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-midspeed.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-nospeed.pcapng b/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-nospeed.pcapng new file mode 100644 index 0000000..e74ee6b Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-effect-to-breathing-252-253-254-nospeed.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-effect-to-keypress-3-2-1_252-253-254-nospeed.pcapng b/wireshark_dumps/g810-spectrum/g810-effect-to-keypress-3-2-1_252-253-254-nospeed.pcapng new file mode 100644 index 0000000..03986f5 Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-effect-to-keypress-3-2-1_252-253-254-nospeed.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-idle.pcapng b/wireshark_dumps/g810-spectrum/g810-idle.pcapng new file mode 100644 index 0000000..b38822f Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-idle.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-set-a-to-252-253-254.pcapng b/wireshark_dumps/g810-spectrum/g810-set-a-to-252-253-254.pcapng new file mode 100644 index 0000000..31f9f87 Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-set-a-to-252-253-254.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-set-rcntrl-to-252-253-254.pcapng b/wireshark_dumps/g810-spectrum/g810-set-rcntrl-to-252-253-254.pcapng new file mode 100644 index 0000000..aa848d1 Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-set-rcntrl-to-252-253-254.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-switches-to-fixedcolor-effect.pcapng b/wireshark_dumps/g810-spectrum/g810-switches-to-fixedcolor-effect.pcapng new file mode 100644 index 0000000..caa928c Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-switches-to-fixedcolor-effect.pcapng differ diff --git a/wireshark_dumps/g810-spectrum/g810-switches-to-from-fixedcolor-effect.pcapng b/wireshark_dumps/g810-spectrum/g810-switches-to-from-fixedcolor-effect.pcapng new file mode 100644 index 0000000..12f3023 Binary files /dev/null and b/wireshark_dumps/g810-spectrum/g810-switches-to-from-fixedcolor-effect.pcapng differ