diff options
Diffstat (limited to 'drivers/hid/hid-roccat-kone.c')
-rw-r--r-- | drivers/hid/hid-roccat-kone.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index 2b8f3a3..e2072af 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -37,6 +37,21 @@ static uint profile_numbers[5] = {0, 1, 2, 3, 4}; +static void kone_profile_activated(struct kone_device *kone, uint new_profile) +{ + kone->actual_profile = new_profile; + kone->actual_dpi = kone->profiles[new_profile - 1].startup_dpi; +} + +static void kone_profile_report(struct kone_device *kone, uint new_profile) +{ + struct kone_roccat_report roccat_report; + roccat_report.event = kone_mouse_event_switch_profile; + roccat_report.value = new_profile; + roccat_report.key = 0; + roccat_report_event(kone->chrdev_minor, (uint8_t *)&roccat_report); +} + static int kone_receive(struct usb_device *usb_dev, uint usb_command, void *data, uint size) { @@ -283,7 +298,7 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, container_of(kobj, struct device, kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); - int retval = 0, difference; + int retval = 0, difference, old_profile; /* I need to get my data in one piece */ if (off != 0 || count != sizeof(struct kone_settings)) @@ -294,21 +309,20 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, if (difference) { retval = kone_set_settings(usb_dev, (struct kone_settings const *)buf); - if (!retval) - memcpy(&kone->settings, buf, - sizeof(struct kone_settings)); - } - mutex_unlock(&kone->kone_lock); + if (retval) { + mutex_unlock(&kone->kone_lock); + return retval; + } - if (retval) - return retval; + old_profile = kone->settings.startup_profile; + memcpy(&kone->settings, buf, sizeof(struct kone_settings)); - /* - * If we get here, treat settings as okay and update actual values - * according to startup_profile - */ - kone->actual_profile = kone->settings.startup_profile; - kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi; + kone_profile_activated(kone, kone->settings.startup_profile); + + if (kone->settings.startup_profile != old_profile) + kone_profile_report(kone, kone->settings.startup_profile); + } + mutex_unlock(&kone->kone_lock); return sizeof(struct kone_settings); } @@ -501,6 +515,8 @@ static ssize_t kone_sysfs_set_tcu(struct device *dev, goto exit_no_settings; goto exit_unlock; } + /* calibration resets profile */ + kone_profile_activated(kone, kone->settings.startup_profile); } retval = size; @@ -544,16 +560,16 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev, kone_set_settings_checksum(&kone->settings); retval = kone_set_settings(usb_dev, &kone->settings); - - mutex_unlock(&kone->kone_lock); - - if (retval) + if (retval) { + mutex_unlock(&kone->kone_lock); return retval; + } /* changing the startup profile immediately activates this profile */ - kone->actual_profile = new_startup_profile; - kone->actual_dpi = kone->profiles[kone->actual_profile - 1].startup_dpi; + kone_profile_activated(kone, new_startup_profile); + kone_profile_report(kone, new_startup_profile); + mutex_unlock(&kone->kone_lock); return size; } @@ -665,8 +681,7 @@ static int kone_init_kone_device_struct(struct usb_device *usb_dev, if (retval) return retval; - kone->actual_profile = kone->settings.startup_profile; - kone->actual_dpi = kone->profiles[kone->actual_profile].startup_dpi; + kone_profile_activated(kone, kone->settings.startup_profile); return 0; } @@ -776,10 +791,10 @@ static void kone_keep_values_up_to_date(struct kone_device *kone, { switch (event->event) { case kone_mouse_event_switch_profile: + kone->actual_dpi = kone->profiles[event->value - 1]. + startup_dpi; case kone_mouse_event_osd_profile: kone->actual_profile = event->value; - kone->actual_dpi = kone->profiles[kone->actual_profile - 1]. - startup_dpi; break; case kone_mouse_event_switch_dpi: case kone_mouse_event_osd_dpi: |