mirror of
				https://github.com/MatMoul/g810-led.git
				synced 2025-11-03 02:24:23 +00:00 
			
		
		
		
	Initial support for G403 mouse
Tested only with libusb version No support for effects, no support for persistent storage. It might come later. To switch the wheel color: ./bin/g810-led -k logo 00ff00 To switch the logo color: ./bin/g810-led -k logo2 00ff00 To switch both leds color: ./bin/g810-led -g logo 00ff00 or ./bin/g810-led -a 00ff00
This commit is contained in:
		
							parent
							
								
									1b480ae4c2
								
							
						
					
					
						commit
						ecdb2d364b
					
				@ -290,8 +290,13 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(libusb_kernel_driver_active(m_hidHandle, 1) == 1) {
 | 
			
		||||
			if(libusb_detach_kernel_driver(m_hidHandle, 1) != 0) {
 | 
			
		||||
		if (currentDevice.model == KeyboardModel::g403)
 | 
			
		||||
			m_Interface = 2;
 | 
			
		||||
		else
 | 
			
		||||
			m_Interface = 1;
 | 
			
		||||
 | 
			
		||||
		if(libusb_kernel_driver_active(m_hidHandle, m_Interface) == 1) {
 | 
			
		||||
			if(libusb_detach_kernel_driver(m_hidHandle, m_Interface) != 0) {
 | 
			
		||||
				libusb_exit(m_ctx);
 | 
			
		||||
				m_ctx = NULL;
 | 
			
		||||
				return false;
 | 
			
		||||
@ -299,9 +304,9 @@ bool LedKeyboard::open(uint16_t vendorID, uint16_t productID, string serial) {
 | 
			
		||||
			m_isKernellDetached = true;
 | 
			
		||||
		}
 | 
			
		||||
			
 | 
			
		||||
		if(libusb_claim_interface(m_hidHandle, 1) < 0) {
 | 
			
		||||
		if(libusb_claim_interface(m_hidHandle, m_Interface) < 0) {
 | 
			
		||||
			if(m_isKernellDetached==true) {
 | 
			
		||||
				libusb_attach_kernel_driver(m_hidHandle, 1);
 | 
			
		||||
				libusb_attach_kernel_driver(m_hidHandle, m_Interface);
 | 
			
		||||
				m_isKernellDetached = false;
 | 
			
		||||
			}
 | 
			
		||||
			libusb_exit(m_ctx);
 | 
			
		||||
@ -331,9 +336,9 @@ bool LedKeyboard::close() {
 | 
			
		||||
		return true;
 | 
			
		||||
	#elif defined(libusb)
 | 
			
		||||
		if (m_hidHandle == NULL) return true;
 | 
			
		||||
		if(libusb_release_interface(m_hidHandle, 1) != 0) return false;
 | 
			
		||||
		if(libusb_release_interface(m_hidHandle, m_Interface) != 0) return false;
 | 
			
		||||
		if(m_isKernellDetached==true) {
 | 
			
		||||
			libusb_attach_kernel_driver(m_hidHandle, 1);
 | 
			
		||||
			libusb_attach_kernel_driver(m_hidHandle, m_Interface);
 | 
			
		||||
			m_isKernellDetached = false;
 | 
			
		||||
		}
 | 
			
		||||
		libusb_close(m_hidHandle);
 | 
			
		||||
@ -356,7 +361,8 @@ bool LedKeyboard::commit() {
 | 
			
		||||
	switch (currentDevice.model) {
 | 
			
		||||
		case KeyboardModel::g213:
 | 
			
		||||
		case KeyboardModel::g413:
 | 
			
		||||
			return true; // Keyboard is non-transactional
 | 
			
		||||
		case KeyboardModel::g403:
 | 
			
		||||
			return true; // Device is non-transactional
 | 
			
		||||
		case KeyboardModel::g410:
 | 
			
		||||
		case KeyboardModel::g610:
 | 
			
		||||
		case KeyboardModel::g810:
 | 
			
		||||
@ -397,6 +403,7 @@ bool LedKeyboard::setKeys(KeyValueArray keyValues) {
 | 
			
		||||
					case LedKeyboard::KeyboardModel::g610:
 | 
			
		||||
					case LedKeyboard::KeyboardModel::g810:
 | 
			
		||||
					case LedKeyboard::KeyboardModel::gpro:
 | 
			
		||||
					case LedKeyboard::KeyboardModel::g403:
 | 
			
		||||
						if (SortedKeys[0].size() <= 1 && keyValues[i].key == LedKeyboard::Key::logo)
 | 
			
		||||
							SortedKeys[0].push_back(keyValues[i]);
 | 
			
		||||
						break;
 | 
			
		||||
@ -490,6 +497,15 @@ bool LedKeyboard::setKeys(KeyValueArray keyValues) {
 | 
			
		||||
					
 | 
			
		||||
					for (uint8_t i = 0; i < maxKeyCount; i++) {
 | 
			
		||||
						if (gi + i < SortedKeys[kag].size()) {
 | 
			
		||||
							if (currentDevice.model == LedKeyboard::KeyboardModel::g403) {
 | 
			
		||||
								data.push_back(static_cast<uint8_t>(
 | 
			
		||||
									static_cast<uint16_t>(SortedKeys[kag][gi+i].key) & 0x00ff) - 1);
 | 
			
		||||
								data.push_back(0x01);
 | 
			
		||||
								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);
 | 
			
		||||
								data.push_back(0x02);
 | 
			
		||||
							} else {
 | 
			
		||||
								data.push_back(static_cast<uint8_t>(
 | 
			
		||||
									static_cast<uint16_t>(SortedKeys[kag][gi+i].key) & 0x00ff));
 | 
			
		||||
								data.push_back(SortedKeys[kag][gi+i].color.red);
 | 
			
		||||
@ -497,6 +513,7 @@ bool LedKeyboard::setKeys(KeyValueArray keyValues) {
 | 
			
		||||
								data.push_back(SortedKeys[kag][gi+i].color.blue);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					data.resize(data_size, 0x00);
 | 
			
		||||
					
 | 
			
		||||
@ -830,19 +847,25 @@ bool LedKeyboard::sendDataInternal(byte_buffer_t &data) {
 | 
			
		||||
			return true;
 | 
			
		||||
		#elif defined(libusb)
 | 
			
		||||
			if (! m_isOpen) return false;
 | 
			
		||||
			if (data.size() > 20) {
 | 
			
		||||
				if(libusb_control_transfer(m_hidHandle, 0x21, 0x09, 0x0212, 1, 
 | 
			
		||||
 | 
			
		||||
			uint16_t wValue;
 | 
			
		||||
			unsigned char endpoint = 0x82;
 | 
			
		||||
 | 
			
		||||
			if (data.size() > 20)
 | 
			
		||||
				wValue = 0x0212;
 | 
			
		||||
			else if (data.size() < 20) {
 | 
			
		||||
				wValue = 0x0210;
 | 
			
		||||
				endpoint = 0x83;
 | 
			
		||||
			} else
 | 
			
		||||
				wValue = 0x0211;
 | 
			
		||||
 | 
			
		||||
			if(libusb_control_transfer(m_hidHandle, 0x21, 0x09, wValue, m_Interface,
 | 
			
		||||
					const_cast<unsigned char*>(data.data()), data.size(), 2000) < 0)
 | 
			
		||||
				return false;
 | 
			
		||||
			} else {
 | 
			
		||||
				if(libusb_control_transfer(m_hidHandle, 0x21, 0x09, 0x0211, 1, 
 | 
			
		||||
						const_cast<unsigned char*>(data.data()), data.size(), 2000) < 0)
 | 
			
		||||
					return false;
 | 
			
		||||
			}
 | 
			
		||||
			usleep(1000);
 | 
			
		||||
			unsigned char buffer[64];
 | 
			
		||||
			int len = 0;
 | 
			
		||||
			libusb_interrupt_transfer(m_hidHandle, 0x82, buffer, sizeof(buffer), &len, 1);
 | 
			
		||||
			libusb_interrupt_transfer(m_hidHandle, endpoint, buffer, sizeof(buffer), &len, 1);
 | 
			
		||||
			return true;
 | 
			
		||||
		#endif
 | 
			
		||||
	}
 | 
			
		||||
@ -886,6 +909,8 @@ LedKeyboard::byte_buffer_t LedKeyboard::getKeyGroupAddress(LedKeyboard::KeyAddre
 | 
			
		||||
					return { 0x12, 0xff, 0x0f, 0x3d, 0x00, 0x01, 0x00, 0x0e };
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case KeyboardModel::g403:
 | 
			
		||||
			return { 0x11, 0x01, 0x18, 0x3a };
 | 
			
		||||
		default:
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,9 @@ class LedKeyboard {
 | 
			
		||||
			{ 0x46d, 0xc337, (u_int16_t)KeyboardModel::g810 },
 | 
			
		||||
			{ 0x46d, 0xc32b, (u_int16_t)KeyboardModel::g910 },
 | 
			
		||||
			{ 0x46d, 0xc335, (u_int16_t)KeyboardModel::g910 },
 | 
			
		||||
			{ 0x46d, 0xc339, (u_int16_t)KeyboardModel::gpro }
 | 
			
		||||
			{ 0x46d, 0xc339, (u_int16_t)KeyboardModel::gpro },
 | 
			
		||||
			{ 0x46d, 0xc082, (u_int16_t)KeyboardModel::g403 },
 | 
			
		||||
			{ 0x46d, 0xc539, (u_int16_t)KeyboardModel::g403 }
 | 
			
		||||
		};
 | 
			
		||||
		
 | 
			
		||||
		enum class KeyboardModel : uint8_t {
 | 
			
		||||
@ -48,7 +50,8 @@ class LedKeyboard {
 | 
			
		||||
			g610,
 | 
			
		||||
			g810,
 | 
			
		||||
			g910,
 | 
			
		||||
			gpro
 | 
			
		||||
			gpro,
 | 
			
		||||
			g403
 | 
			
		||||
		};
 | 
			
		||||
		enum class StartupMode : uint8_t {
 | 
			
		||||
			wave = 0x01,
 | 
			
		||||
@ -206,11 +209,12 @@ class LedKeyboard {
 | 
			
		||||
		DeviceInfo currentDevice;
 | 
			
		||||
		
 | 
			
		||||
		#if defined(hidapi)
 | 
			
		||||
			hid_device *m_hidHandle;
 | 
			
		||||
			hid_device *m_hidHandle = NULL;
 | 
			
		||||
		#elif defined(libusb)
 | 
			
		||||
			bool m_isKernellDetached = false;
 | 
			
		||||
			libusb_device_handle *m_hidHandle;
 | 
			
		||||
			libusb_device_handle *m_hidHandle = NULL;
 | 
			
		||||
			libusb_context *m_ctx = NULL;
 | 
			
		||||
			int m_Interface;
 | 
			
		||||
		#endif
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user