wireless driver interface, g-wolves implementation
This commit is contained in:
		@@ -49,9 +49,11 @@ int driver_mouse_angle_snap_get(void* handle, bool* output);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
* Wireless driver
 | 
					* Wireless driver
 | 
				
			||||||
* - Battery (state + amount)
 | 
					* - Battery (state + level)
 | 
				
			||||||
* - Connection type (usb 2.4/bluetooth/wired)
 | 
					* - Connection type (wired/wireless)
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					int driver_wireless_battery_state_get(void* handle, int* battery_level, bool* charging);
 | 
				
			||||||
 | 
					int driver_wireless_connection_type_get(void* handle, bool* output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
#include "g-wolves.h"
 | 
					#include "g-wolves.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define DEVICE_WIRELESS(handle) (driver_get_capacity(handle) & DEVICE_CAPACITY_WIRELESS)
 | 
					#define DEVICE_WIRELESS(handle) (is_connection_wireless(handle))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int send_command(libusb_device_handle* hand, uint8_t command, uint8_t size, void* report, bool wireless)
 | 
					static int send_command(libusb_device_handle* hand, uint8_t command, uint8_t size, void* report, bool wireless)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -86,10 +86,13 @@ device_capacity_t driver_get_capacity(void* handle)
 | 
				
			|||||||
    uint8_t wireless = 0;
 | 
					    uint8_t wireless = 0;
 | 
				
			||||||
    switch(desc.idProduct)
 | 
					    switch(desc.idProduct)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        case HTX_4K_PRODUCT_ID_WIRED:
 | 
				
			||||||
        case HTX_4K_PRODUCT_ID_WIRELESS:
 | 
					        case HTX_4K_PRODUCT_ID_WIRELESS:
 | 
				
			||||||
 | 
					        case HTS_PLUS_4K_PRODUCT_ID_WIRED:
 | 
				
			||||||
        case HTS_PLUS_4K_PRODUCT_ID_WIRELESS:
 | 
					        case HTS_PLUS_4K_PRODUCT_ID_WIRELESS:
 | 
				
			||||||
 | 
					        case HSK_PRO_ACE_PRODUCT_ID_WIRED:
 | 
				
			||||||
        case HSK_PRO_ACE_PRODUCT_ID_WIRELESS:
 | 
					        case HSK_PRO_ACE_PRODUCT_ID_WIRELESS:
 | 
				
			||||||
            wireless = 1;
 | 
					            wireless = DEVICE_CAPACITY_WIRELESS;
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -147,6 +150,24 @@ char* driver_get_image(void* handle)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool is_connection_wireless(void* handle)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    libusb_device* dev = handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct libusb_device_descriptor desc;
 | 
				
			||||||
 | 
					    libusb_get_device_descriptor(dev, &desc);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    switch(desc.idProduct)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        case HTX_4K_PRODUCT_ID_WIRELESS:
 | 
				
			||||||
 | 
					        case HTS_PLUS_4K_PRODUCT_ID_WIRELESS:
 | 
				
			||||||
 | 
					        case HSK_PRO_ACE_PRODUCT_ID_WIRELESS:
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int driver_mouse_dpi_get(void* handle, struct MOUSE_DPI_LEVELS* output)
 | 
					int driver_mouse_dpi_get(void* handle, struct MOUSE_DPI_LEVELS* output)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    libusb_device* dev = handle;
 | 
					    libusb_device* dev = handle;
 | 
				
			||||||
@@ -229,3 +250,34 @@ int driver_mouse_angle_snap_get(void* handle, bool* output)
 | 
				
			|||||||
    libusb_close(hand);
 | 
					    libusb_close(hand);
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int driver_wireless_connection_type_get(void* handle, bool* output)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    *output = is_connection_wireless(handle);
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int driver_wireless_battery_state_get(void* handle, int* battery_level, bool* charging)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    libusb_device* dev = handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Prepare usb device for transfer
 | 
				
			||||||
 | 
					    libusb_device_handle* hand;
 | 
				
			||||||
 | 
					    int openres = libusb_open(dev, &hand);
 | 
				
			||||||
 | 
					    if(openres) return -1;
 | 
				
			||||||
 | 
					    libusb_detach_kernel_driver(hand, 0x2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Send command
 | 
				
			||||||
 | 
					    struct REPORT_BATTERY report = {0};
 | 
				
			||||||
 | 
					    int res = send_command(hand, COMMAND_BATTERY, REPORT_BATTERY_SIZE, &report, DEVICE_WIRELESS(handle));
 | 
				
			||||||
 | 
					    if(res <= 0) return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Format output values
 | 
				
			||||||
 | 
					    *battery_level = report.battery_level;
 | 
				
			||||||
 | 
					    *charging = report.battery_status;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // Close and return
 | 
				
			||||||
 | 
					    libusb_attach_kernel_driver(hand, 0x2);
 | 
				
			||||||
 | 
					    libusb_close(hand);
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,5 +41,8 @@ int driver_mouse_dpi_get(void* handle, struct MOUSE_DPI_LEVELS* output);
 | 
				
			|||||||
int driver_mouse_motion_sync_get(void* handle, bool* output);
 | 
					int driver_mouse_motion_sync_get(void* handle, bool* output);
 | 
				
			||||||
int driver_mouse_angle_snap_get(void* handle, bool* output);
 | 
					int driver_mouse_angle_snap_get(void* handle, bool* output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Wireless drivers */
 | 
				
			||||||
 | 
					int driver_wireless_battery_state_get(void* handle, int* battery_level, bool* charging);
 | 
				
			||||||
 | 
					int driver_wireless_connection_type_get(void* handle, bool* output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
		Reference in New Issue
	
	Block a user