From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Andreas Bergmeier <abergmeier@gmx.net>
Cc: linux-input@vger.kernel.org,
USB mailing list <linux-usb@vger.kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
Jiri Kosina <jikos@kernel.org>,
linux-leds@vger.kernel.org,
Nestor Lopez Casado <nlopezcasad@logitech.com>
Subject: Re: Litra Glow on Linux
Date: Mon, 31 Oct 2022 09:30:47 +0000 [thread overview]
Message-ID: <CAO-hwJJGAWkhZgGeLBruqCoskY5PBP-STs4kh-P6fBvpuSgpUw@mail.gmail.com> (raw)
In-Reply-To: <CABfF9mNrMx2BzU5tbBeapY15M4Ls_5xYBGfVB=Up5TJu=eWCcg@mail.gmail.com>
[adding linux-leds in Cc]
On Sat, Oct 29, 2022 at 9:21 AM Andreas Bergmeier <abergmeier@gmx.net> wrote:
>
> Sorry, another set of questions - seems like I am a bit dense.
>
> On Thu, 27 Oct 2022 at 11:44, Benjamin Tissoires
> <benjamin.tissoires@redhat.com> wrote:
> > It's just Logitech's common HID protocol. The advantage is that if
> > Logitech reuses the feature on a different hardware, we won't have to
> > implement anything new in the kernel.
> Started implementing some illumination code but will take a while
> until I figure out the driver I think.
>
> > But from where you are now, you should probably be able to implement
> > the basic on/off feature by looking at the function 0x1000 in the
> > hid-logitech-hidpp code:
> > - you need define a few macros for your functionality (the class, the
> > commands, the events)
> So my approach would be to identify the GLOW device and then at some
> later point create the
> illumination state and from there only handle common illumination.
For identifying the GLOW device you should be adding an id in the
table of hid-logitech-hidpp, with a driver data that tells the driver
to look for 0x1990.
>
> > - you need to add a hook in connect_event to register the led class
> > device that will hook on to the actual LED of the device
> I did read all the LED specs/headers that I could find and from what I
> have seen all you can currently do with this interface is control
> brightness. There seems to be no way of controlling the Color
> temperature, though.
Leds can be multicolor. See drivers/hid/hid-playstation.c for an example.
So I think you should be able to give a color to the LED that can be
controlled as a separate channel, different from the brightness. The
LEDs folks will know better.
> So either this then would have to be exposed as a special device or
> get handled entirely in userspace.
> The latter seems to work against "implementing illumination handling
> once in driver and reusing it".
I would rather have it handled as a standard LED class, a colored LED
one. There might be a special structure for colored LEDs, and if not
you should probably be able to use a multi-color led with just one
color channel.
>
> > [0] https://pwr-solaar.github.io/Solaar
> > [1] https://github.com/pwr-Solaar/Solaar/blob/master/docs/hidpp-documentation.txt
> Thanks. Never would have found the specs on my own.
> That said - I read x1990 spec and tried to access getIllumination from
> userspace.
Oh, good point, Nestor added that spec back in May :)
Thanks, Nestor!
> The spec seems a bit vague for my limited experience level.
> For example I have not yet figured out what the communication (bytes)
> difference between _getIllumination()_ and _illuminationChangedEvent_
> is.
> What seems to work is accessing events:
>
> So I tried:
> ```c
>
> #define LONG_REPORT_ID 0x11
>
> struct hiddev_usage_ref_multi multi;
> memset(&multi, 0, sizeof(multi));
> multi.uref.report_type = HID_REPORT_TYPE_INPUT;
> multi.uref.report_id = LONG_REPORT_ID;
> multi.uref.field_index = 0x0;
> multi.uref.usage_index = 0x03;
> multi.uref.usage_code = 0xff430002;
> multi.num_values = 1;
>
> if (ioctl(fd, HIDIOCGUSAGES, &multi) < 0)
> {
> perror("HIDIOCGUSAGES getIllumination");
> return -11;
> }
>
> printf("VALUE: %0x\n", multi.values[0]);
>
> ```
> Which seems to report the illumination state until I press another
> hardware button. So this seems to access the last event, which seems
> to be _illuminationChangedEvent_ in my case.
> No idea currently how to get _getIllumination_ to work.
IIRC, HIDIOCGUSAGES doesn't do anything with the device, you are
querying the kernel of its current state. Which explains why you are
not getting the current state, but the previous known state.
What you need to do, is actually emit a command to the device
(completely untested, of course):
---
#define APPLICATION_ID 0x06 // can be anything between 0x01 and 0xF,
0x1 being the ID from the kernel
#define HIDPP_1990_GET_ILLUMINATION 0x00
#define HIDPP_1990_SET_ILLUMINATION 0x10
#define ....
unsigned char cmd = HIDPP_1990_GET_ILLUMINATION | APPLICATION_ID;
unsigned char buf[20] = {0x11, 0xff, 0x04}; // HIDPP ID, DEVICE INDEX,
FEATURE INDEX in the feature table
buf[3] = cmd;
write(fd, buf, sizeof(buf));
memset(buf, sizeof(buf), 0);
while (buf[3] != cmd)
read(fd, buf, sizeof(buf));
printf("VALUE: %0x\n", buf[4]);
---
It is important to set an application id so you can differentiate your
requests from the events (the application ID from an event is always
0).
With that in mind, you should now be able to understand why you had to
send {0x11, 0xff, 0x04, 0x10, 0x01} to set the illumination. And
again, for being sure you can get the feedback you should use 0x16 as
the fourth byte here, so you can detect your answer.
I hope it makes more sense now.
Cheers,
Benjamin
next prev parent reply other threads:[~2022-10-31 9:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 15:17 Litra Glow on Linux Alan Stern
2022-10-19 15:48 ` Bastien Nocera
2022-10-19 15:49 ` Bastien Nocera
2022-10-19 19:40 ` Andreas Bergmeier
2022-10-20 18:22 ` Andreas Bergmeier
2022-10-22 12:42 ` Andreas Bergmeier
2022-10-25 7:46 ` Benjamin Tissoires
2022-10-26 20:49 ` Andreas Bergmeier
2022-10-27 9:45 ` Benjamin Tissoires
2022-10-29 8:21 ` Andreas Bergmeier
2022-10-31 9:30 ` Benjamin Tissoires [this message]
2022-11-04 7:45 ` Andreas Bergmeier
2022-11-04 11:40 ` Pavel Machek
2022-11-09 20:27 ` Andreas Bergmeier
2022-11-10 3:29 ` Andreas Bergmeier
2022-11-10 9:22 ` Benjamin Tissoires
2022-11-10 12:24 ` Andreas Bergmeier
2022-11-10 13:39 ` Benjamin Tissoires
2022-11-19 20:18 ` Andreas Bergmeier
2022-11-27 11:04 ` Andreas Bergmeier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAO-hwJJGAWkhZgGeLBruqCoskY5PBP-STs4kh-P6fBvpuSgpUw@mail.gmail.com \
--to=benjamin.tissoires@redhat.com \
--cc=abergmeier@gmx.net \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nlopezcasad@logitech.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).