Gnome input devices manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
ginput/drivers/razer/razer.c

106 lines
2.2 KiB

#include "razer.h"
static uint8_t compute_crc(void* report)
{
uint8_t* r = report;
uint8_t crc = 0;
for(size_t i = 2; i < REPORT_SIZE - sizeof(report_footer_t); i++)
{
crc ^= r[i];
}
return crc;
}
static int send_command(libusb_device_handle* hand, uint8_t command_class, uint8_t command, uint8_t size, void* report)
{
report_header_t* head = report;
head->report_size = size;
head->command_class = command_class;
head->command_id = command;
report_footer_t* footer = report + REPORT_SIZE - sizeof(report_footer_t);
footer->crc = compute_crc(report);
// Send command
int res = libusb_control_transfer(hand,
0x21, // request type
0x09, // request (SET_REPORT)
0x300, // wValue (FEATURE << 8 | REPORT(0))
0x0, // wIndex = 0x0 : interface
report,
REPORT_SIZE, // wLength = 90
0 /* timeout*/);
if(res <= 0) return res;
// Wait for the mouse to catch the report
usleep(100);
// Get response report
res = libusb_control_transfer(hand,
0xa1, // request type
0x01, // request (GET_REPORT)
0x300, // wValue (FEATURE << 8 | REPORT(0))
0x0, // wIndex = 0x0 : interface
report,
REPORT_SIZE, // wLength = 90
0);
return res;
}
void driver_init(void) {}
uint32_t driver_getkey(void)
{
static int count = 0;
count++;
// Register ALL razer compatible devices
uint16_t id = 0;
switch(count)
{
case 1:
id = VIPER_MINI_PRODUCT_ID;
break;
default:
id = 0;
}
if(id == 0) return 0;
return (VENDOR_ID << 16) | id;
}
char* driver_get_name(void* handle)
{
libusb_device* dev = handle;
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(dev, &desc);
switch(desc.idProduct)
{
case VIPER_MINI_PRODUCT_ID:
return VIPER_MINI_NAME;
default:
return "Unknown Razer mice";
}
}
char* driver_get_image(void* handle)
{
libusb_device* dev = handle;
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(dev, &desc);
switch(desc.idProduct)
{
case VIPER_MINI_PRODUCT_ID:
return VIPER_MINI_IMAGE;
default:
return "";
}
}