static int test_probe(struct ratbag_device *device, const struct ratbag_id id) { struct ratbag_test_device *test_device; assert(id.id.bustype == 0x00); assert(id.id.vendor == 0x00); assert(id.id.product == 0x00); assert(id.id.version == 0x00); assert(id.test_device != NULL); test_device = id.test_device; ratbag_set_drv_data(device, test_device); ratbag_device_init_profiles(device, test_device->num_profiles, test_device->num_buttons); return 0; }
static int hidpp20drv_probe(struct ratbag_device *device) { int rc; struct hidpp20drv_data *drv_data; struct hidpp_device base; struct hidpp20_device *dev; const char *prop; int device_idx = HIDPP_RECEIVER_IDX; int nread = 0; rc = ratbag_find_hidraw(device, hidpp20drv_test_hidraw); if (rc) return rc; drv_data = zalloc(sizeof(*drv_data)); ratbag_set_drv_data(device, drv_data); hidpp_device_init(&base, device->hidraw.fd); hidpp_device_set_log_handler(&base, hidpp20_log, HIDPP_LOG_PRIORITY_RAW, device); prop = ratbag_device_get_udev_property(device, "RATBAG_HIDPP20_INDEX"); if (prop) { sscanf(prop, "%d%n", &device_idx, &nread); if (!nread || (prop[nread]) != '\0' || device_idx < 0) { log_error(device->ratbag, "Error parsing RATBAG_HIDPP20_INDEX: '%s' for %s\n", prop, device->name); device_idx = HIDPP_RECEIVER_IDX; } } /* In the general case, we can treat all devices as wired devices * here. If we talk to the correct hidraw device the kernel adjusts * the device index for us, so even for unifying receiver devices * we can just use 0xff as device index. * * If there is a special need like for G900, we can pass a * udev prop RATBAG_HIDPP20_INDEX. */ dev = hidpp20_device_new(&base, device_idx); if (!dev) { rc = -ENODEV; goto err; } drv_data->dev = dev; log_debug(device->ratbag, "'%s' is using protocol v%d.%d\n", ratbag_device_get_name(device), dev->proto_major, dev->proto_minor); /* add some defaults that will be overwritten by the device */ drv_data->num_profiles = 1; drv_data->num_resolutions = 1; drv_data->num_buttons = 8; rc = hidpp20drv_20_probe(device); if (rc) goto err; ratbag_device_init_profiles(device, drv_data->num_profiles, drv_data->num_resolutions, drv_data->num_buttons); return rc; err: hidpp20drv_remove(device); return rc; }