1
0
forked from drath/libratbag

libratbag api support LEDs

This commit is contained in:
Ilya Guterman
2017-02-01 01:14:31 +02:00
committed by Peter Hutterer
parent 67f1c00181
commit 3f83d5057d
14 changed files with 72 additions and 13 deletions

View File

@@ -36,6 +36,7 @@
#define ETEKCITY_PROFILE_MAX 4
#define ETEKCITY_BUTTON_MAX 10
#define ETEKCITY_NUM_DPI 6
#define ETEKCITY_LED 0
#define ETEKCITY_REPORT_ID_CONFIGURE_PROFILE 4
#define ETEKCITY_REPORT_ID_PROFILE 5
@@ -657,7 +658,8 @@ etekcity_probe(struct ratbag_device *device)
ratbag_device_init_profiles(device,
ETEKCITY_PROFILE_MAX + 1,
ETEKCITY_NUM_DPI,
ETEKCITY_BUTTON_MAX + 1);
ETEKCITY_BUTTON_MAX + 1,
ETEKCITY_LED);
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);

View File

@@ -31,6 +31,7 @@
#define GSKILL_PROFILE_MAX 5
#define GSKILL_NUM_DPI 5
#define GSKILL_BUTTON_MAX 10
#define GSKILL_NUM_LED 0
#define GSKILL_MAX_POLLING_RATE 1000
@@ -994,7 +995,7 @@ gskill_probe(struct ratbag_device *device)
drv_data->profile_count = ret;
ratbag_device_init_profiles(device, GSKILL_PROFILE_MAX, GSKILL_NUM_DPI,
GSKILL_BUTTON_MAX);
GSKILL_BUTTON_MAX, GSKILL_NUM_LED);
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_QUERY_CONFIGURATION);
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_KEY);

View File

@@ -465,7 +465,8 @@ hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device
ratbag_device_init_profiles(device,
count,
profile.num_dpi_modes,
profile.num_buttons);
profile.num_buttons,
profile.num_leds);
if (dev->profile_type != HIDPP10_PROFILE_UNKNOWN) {
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE);
@@ -584,7 +585,7 @@ hidpp10drv_probe(struct ratbag_device *device)
/* Fall back to something that every mouse has */
struct ratbag_profile *profile;
ratbag_device_init_profiles(device, 1, 1, 3);
ratbag_device_init_profiles(device, 1, 1, 3, 0);
profile = ratbag_device_get_profile(device, 0);
profile->is_active = true;
ratbag_profile_unref(profile);

View File

@@ -65,6 +65,7 @@ struct hidpp20drv_data {
unsigned int num_profiles;
unsigned int num_resolutions;
unsigned int num_buttons;
unsigned int num_leds;
};
static void
@@ -718,6 +719,7 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature)
}
case HIDPP_PAGE_COLOR_LED_EFFECTS: {
log_debug(ratbag, "device has color effects\n");
device->num_leds = drv_data->num_leds;
break;
}
case HIDPP_PAGE_ONBOARD_PROFILES: {
@@ -731,6 +733,7 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature)
drv_data->num_profiles = drv_data->profiles->num_profiles;
drv_data->num_resolutions = drv_data->profiles->num_modes;
drv_data->num_buttons = drv_data->profiles->num_buttons;
drv_data->num_leds = drv_data->profiles->num_leds;
break;
}
@@ -859,6 +862,7 @@ hidpp20drv_probe(struct ratbag_device *device)
drv_data->num_profiles = 1;
drv_data->num_resolutions = 1;
drv_data->num_buttons = 8;
drv_data->num_leds = 2;
rc = hidpp20drv_20_probe(device);
if (rc)
@@ -867,7 +871,8 @@ hidpp20drv_probe(struct ratbag_device *device)
ratbag_device_init_profiles(device,
drv_data->num_profiles,
drv_data->num_resolutions,
drv_data->num_buttons);
drv_data->num_buttons,
drv_data->num_leds);
return rc;
err:

View File

@@ -36,6 +36,7 @@
#define LOGITECH_G300_PROFILE_MAX 2
#define LOGITECH_G300_BUTTON_MAX 8
#define LOGITECH_G300_NUM_DPI 4
#define LOGITECH_G300_NUM_LED 0
#define LOGITECH_G300_REPORT_ID_SET_ACTIVE_PROFILE 0xF0
#define LOGITECH_G300_REPORT_ID_GET_ACTIVE_PROFILE 0xF1
@@ -361,7 +362,8 @@ logitech_g300_probe(struct ratbag_device *device)
ratbag_device_init_profiles(device,
LOGITECH_G300_PROFILE_MAX + 1,
LOGITECH_G300_NUM_DPI,
LOGITECH_G300_BUTTON_MAX + 1);
LOGITECH_G300_BUTTON_MAX + 1,
LOGITECH_G300_NUM_LED);
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION);
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE);

View File

@@ -36,6 +36,7 @@
#define ROCCAT_PROFILE_MAX 4
#define ROCCAT_BUTTON_MAX 23
#define ROCCAT_NUM_DPI 5
#define ROCCAT_LED_MAX 0
#define ROCCAT_MAX_RETRY_READY 10
@@ -795,7 +796,8 @@ roccat_probe(struct ratbag_device *device)
ratbag_device_init_profiles(device,
ROCCAT_PROFILE_MAX + 1,
ROCCAT_NUM_DPI,
ROCCAT_BUTTON_MAX + 1);
ROCCAT_BUTTON_MAX + 1,
ROCCAT_LED_MAX);
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);

View File

@@ -146,7 +146,8 @@ test_probe(struct ratbag_device *device, void *data)
ratbag_device_init_profiles(device,
test_device->num_profiles,
test_device->num_resolutions,
test_device->num_buttons);
test_device->num_buttons,
test_device->num_leds);
if (test_device->num_profiles > 1)
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);

View File

@@ -494,6 +494,7 @@ struct hidpp10_profile {
} buttons[PROFILE_NUM_BUTTONS];
union hidpp10_macro_data *macros[PROFILE_NUM_BUTTONS];
size_t num_buttons;
size_t num_leds;
unsigned int initialized;
};

View File

@@ -95,6 +95,7 @@ struct ratbag_device {
struct list profiles;
unsigned num_buttons;
unsigned num_leds;
void *drv_data;
@@ -334,7 +335,8 @@ int
ratbag_device_init_profiles(struct ratbag_device *device,
unsigned int num_profiles,
unsigned int num_resolutions,
unsigned int num_buttons);
unsigned int num_buttons,
unsigned int num_leds);
void
ratbag_device_set_capability(struct ratbag_device *device,

View File

@@ -30,6 +30,7 @@
#define RATBAG_TEST_MAX_PROFILES 12
#define RATBAG_TEST_MAX_BUTTONS 25
#define RATBAG_TEST_MAX_RESOLUTIONS 8
#define RATBAG_TEST_MAX_LEDS 8
struct ratbag_test_button {
enum ratbag_button_action_type type;
@@ -59,6 +60,7 @@ struct ratbag_test_device {
unsigned int num_profiles;
unsigned int num_resolutions;
unsigned int num_buttons;
unsigned int num_leds;
struct ratbag_test_profile profiles[RATBAG_TEST_MAX_PROFILES];
void (*destroyed)(struct ratbag_device *device, void *data);
void *destroyed_data;

View File

@@ -595,11 +595,20 @@ ratbag_profile_init_buttons(struct ratbag_profile *profile, unsigned int count)
return 0;
}
static int
ratbag_profile_init_leds(struct ratbag_profile *profile, unsigned int count)
{
profile->device->num_leds = count;
return 0;
}
static struct ratbag_profile *
ratbag_create_profile(struct ratbag_device *device,
unsigned int index,
unsigned int num_resolutions,
unsigned int num_buttons)
unsigned int num_buttons,
unsigned int num_leds)
{
struct ratbag_profile *profile;
unsigned i;
@@ -623,6 +632,7 @@ ratbag_create_profile(struct ratbag_device *device,
device->driver->read_profile(profile, index);
ratbag_profile_init_buttons(profile, num_buttons);
ratbag_profile_init_leds(profile, num_leds);
return profile;
}
@@ -631,12 +641,13 @@ int
ratbag_device_init_profiles(struct ratbag_device *device,
unsigned int num_profiles,
unsigned int num_resolutions,
unsigned int num_buttons)
unsigned int num_buttons,
unsigned int num_leds)
{
unsigned int i;
for (i = 0; i < num_profiles; i++) {
ratbag_create_profile(device, i, num_resolutions, num_buttons);
ratbag_create_profile(device, i, num_resolutions, num_buttons, num_leds);
}
device->num_profiles = num_profiles;
@@ -652,6 +663,9 @@ ratbag_device_init_profiles(struct ratbag_device *device,
if (num_resolutions > 1)
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION);
if (num_leds > 1)
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_LED);
return 0;
}
@@ -753,6 +767,12 @@ ratbag_device_get_num_buttons(struct ratbag_device *device)
return device->num_buttons;
}
LIBRATBAG_EXPORT unsigned int
ratbag_device_get_num_leds(struct ratbag_device *device)
{
return device->num_leds;
}
void
ratbag_device_set_capability(struct ratbag_device *device,
enum ratbag_device_capability cap)

View File

@@ -491,6 +491,11 @@ enum ratbag_device_capability {
*/
RATBAG_DEVICE_CAP_BUTTON_KEY,
/**
* The device supports assigning LED colors and effects
*/
RATBAG_DEVICE_CAP_LED,
/**
* The device supports user-defined key or button sequences.
*/
@@ -588,6 +593,17 @@ ratbag_device_get_num_profiles(struct ratbag_device *device);
unsigned int
ratbag_device_get_num_buttons(struct ratbag_device *device);
/**
* @ingroup device
*
* Return the number of LEDs available on this device.
*
* @param device A previously initialized ratbag device
* @return The number of LEDs available on this device.
*/
unsigned int
ratbag_device_get_num_leds(struct ratbag_device *device);
/**
* @ingroup profile
*

View File

@@ -45,6 +45,7 @@ global:
ratbag_log_get_priority;
ratbag_log_set_handler;
ratbag_log_set_priority;
ratbag_device_get_num_leds;
ratbag_profile_get_button;
ratbag_profile_get_num_resolutions;
ratbag_profile_get_resolution;

View File

@@ -53,6 +53,7 @@ const struct ratbag_test_device sane_device = {
.num_profiles = 3,
.num_resolutions = 3,
.num_buttons = 1,
.num_leds = 2,
.profiles = {
{
.resolutions = {
@@ -110,7 +111,7 @@ START_TEST(device_init)
{
struct ratbag *r;
struct ratbag_device *d;
int nprofiles, nbuttons;
int nprofiles, nbuttons, nleds;
struct ratbag_test_device td = sane_device;
int device_freed_count = 0;
@@ -124,6 +125,8 @@ START_TEST(device_init)
ck_assert_int_eq(nprofiles, 3);
nbuttons = ratbag_device_get_num_buttons(d);
ck_assert_int_eq(nbuttons, 1);
nleds = ratbag_device_get_num_leds(d);
ck_assert_int_eq(nleds, 2);
ratbag_device_unref(d);
ratbag_unref(r);