forked from drath/libratbag
add implemention of ratbag_set_active_profile
It's a 2 callback combo in the driver. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -126,6 +126,23 @@ etekcity_current_profile(struct ratbag *ratbag)
|
||||
return buf[2];
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_set_current_profile(struct ratbag *ratbag, unsigned int index)
|
||||
{
|
||||
__u8 buf[] = {ETEKCITY_REPORT_ID_PROFILE, 0x03, index};
|
||||
int ret;
|
||||
|
||||
if (index > ETEKCITY_PROFILE_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
ret = ratbag_hidraw_raw_request(ratbag, buf[0], buf, sizeof(buf),
|
||||
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
|
||||
|
||||
msleep(100);
|
||||
|
||||
return ret == sizeof(buf) ? 0 : ret;
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_set_config_profile(struct ratbag *ratbag, __u8 profile, __u8 type)
|
||||
{
|
||||
@@ -182,6 +199,12 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_write_profile(struct ratbag_profile *profile)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_probe(struct ratbag *ratbag, const struct ratbag_id id)
|
||||
{
|
||||
@@ -238,6 +261,8 @@ struct ratbag_driver etekcity_driver = {
|
||||
.table_ids = etekcity_table,
|
||||
.probe = etekcity_probe,
|
||||
.read_profile = etekcity_read_profile,
|
||||
.write_profile = etekcity_write_profile,
|
||||
.get_active_profile = etekcity_current_profile,
|
||||
.set_active_profile = etekcity_set_current_profile,
|
||||
.has_capability = etekcity_has_capability,
|
||||
};
|
||||
|
||||
@@ -67,7 +67,9 @@ struct ratbag_driver {
|
||||
|
||||
int (*probe)(struct ratbag *ratbag, const struct ratbag_id id);
|
||||
void (*read_profile)(struct ratbag_profile *profile, unsigned int index);
|
||||
int (*write_profile)(struct ratbag_profile *profile);
|
||||
int (*get_active_profile)(struct ratbag *ratbag);
|
||||
int (*set_active_profile)(struct ratbag *ratbag, unsigned int index);
|
||||
int (*has_capability)(const struct ratbag *ratbag, enum ratbag_capability cap);
|
||||
|
||||
/* private */
|
||||
|
||||
@@ -481,3 +481,18 @@ ratbag_has_capability(const struct ratbag *ratbag, enum ratbag_capability cap)
|
||||
assert(ratbag->driver->has_capability);
|
||||
return ratbag->driver->has_capability(ratbag, cap);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_set_active_profile(struct ratbag *ratbag,
|
||||
struct ratbag_profile *profile)
|
||||
{
|
||||
int rc;
|
||||
|
||||
assert(ratbag->driver->write_profile);
|
||||
rc = ratbag->driver->write_profile(profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
assert(ratbag->driver->set_active_profile);
|
||||
return ratbag->driver->set_active_profile(ratbag, profile->index);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ global:
|
||||
ratbag_get_profile_by_index;
|
||||
ratbag_has_capability;
|
||||
ratbag_new_from_fd;
|
||||
ratbag_set_active_profile;
|
||||
ratbag_profile_ref;
|
||||
ratbag_profile_unref;
|
||||
ratbag_unref;
|
||||
|
||||
@@ -82,10 +82,14 @@ main(int argc, char **argv)
|
||||
|
||||
fprintf(stderr, "Opened '%s' (%s).\n", ratbag_get_name(rb), path);
|
||||
|
||||
profile = ratbag_get_profile_by_index(rb, 0);
|
||||
ratbag_set_active_profile(rb, profile);
|
||||
profile = ratbag_profile_unref(profile);
|
||||
|
||||
profile = ratbag_get_active_profile(rb);
|
||||
profile = ratbag_profile_unref(profile);
|
||||
|
||||
out:
|
||||
profile = ratbag_profile_unref(profile);
|
||||
rb = ratbag_unref(rb);
|
||||
libratbag_unref(libratbag);
|
||||
close(fd);
|
||||
|
||||
Reference in New Issue
Block a user