Reporting screen/laptop orientation data to userspace

10 messages, 6 authors, 2011-06-20 · open the first message on its own page

Reporting screen/laptop orientation data to userspace

From: Alberto Mardegan <hidden>
Date: 2011-05-29 07:49:26

Hi all,
  the WMI interfaces in some Lenovo Ideapad laptops provide notification
callbacks when the laptop orientation changes, reporting 4 different
values defining the new orientation.

I'd like to extend the ideapad-laptop driver with this information; but
how should it be reported to userspace? I initially thought of the input
subsystem, but I cannot find any suitable event codes; then I would
probably export it as a device under /sys, or are there better options?

Are there other devices which provide coarse orientation data to
userspace, which I might want to use as a reference?
I guess that at least some display screens have this feature.

TIA,
  Alberto

-- 
http://blog.mardy.it <- geek in un lingua international!

Re: Reporting screen/laptop orientation data to userspace

From: Bastien Nocera <hadess@hadess.net>
Date: 2011-06-03 16:02:49

On Sun, 2011-05-29 at 10:49 +0300, Alberto Mardegan wrote:
Hi all,
  the WMI interfaces in some Lenovo Ideapad laptops provide notification
callbacks when the laptop orientation changes, reporting 4 different
values defining the new orientation.

I'd like to extend the ideapad-laptop driver with this information; but
how should it be reported to userspace? I initially thought of the input
subsystem, but I cannot find any suitable event codes; then I would
probably export it as a device under /sys, or are there better options?

Are there other devices which provide coarse orientation data to
userspace, which I might want to use as a reference?
I guess that at least some display screens have this feature.
Do you also have a discrete accelerometer with that? Or you only ever
get notification through there?

If there is a discrete accelerometer, I'd drop the extra metadata, and
send an event through udev, and expect user-space to read from the
accelerometer instead.

If there isn't a discrete accelerometer, create a fake one, with some
hardcoded data based on the actual orientation of the device.

The accelerometer (whether real or fake) should show 3 axis (X/Y/Z).

As soon as it's seen some testing, I'll be showing the work I did for
GNOME support for automatic rotation based on orientation.

Cheers

Re: Reporting screen/laptop orientation data to userspace

From: Mohamed Ikbel Boulabiar <hidden>
Date: 2011-06-04 17:14:09

On Fri, Jun 3, 2011 at 5:55 PM, Bastien Nocera [off-list ref] wrote:
As soon as it's seen some testing, I'll be showing the work I did for
GNOME support for automatic rotation based on orientation.
And how you handle these events through X ?

i

Re: Reporting screen/laptop orientation data to userspace

From: Alberto Mardegan <hidden>
Date: 2011-06-06 06:54:38

On 06/03/2011 06:55 PM, Bastien Nocera wrote:
Do you also have a discrete accelerometer with that? Or you only ever
get notification through there?
There's a discrete accelerometer, but I suspect that it might be hard for its driver to get accepted into the mainline kernel, since it's directly playing with the EC I/O ports. It's this one:

https://gitorious.org/iaps/iaps/blobs/master/iaps.c

The coarse data OTOH comes via a clean WMI interface.
If there is a discrete accelerometer, I'd drop the extra metadata, and
send an event through udev, and expect user-space to read from the
accelerometer instead.
You mean, send an event through udev when the WMI interface reports that the orientation has changed, and then expect the userspace to read the values from the accelerometer?
IMHO, reporting an event with no context data, it's inefficient and ugly (because it forces the userspace to perform additional acctions in order to get the data).
If there isn't a discrete accelerometer, create a fake one, with some
hardcoded data based on the actual orientation of the device.
This could be a solution in both cases (i.e., even if a discrete accelerometer is available). But it would be nice to have some flags on the input device which tell that this accelerometer is not as precise as one could desire. Is there such a thing?
The accelerometer (whether real or fake) should show 3 axis (X/Y/Z).

As soon as it's seen some testing, I'll be showing the work I did for
GNOME support for automatic rotation based on orientation.
Do you support choosing the accelerometer device to be used?

The device that I wanted to create is actually something much simpler than an accelerometer; it would just report screen orientation. I believe that some computer screens might have something similar, detecting the screen orientation based on the angle formed between the screen base (or wall mount) and the screen panel... I would assume that if such information exists, this Lenovo Ideapad screen orientation should be reported in a similar way.

Ciao,
  Alberto

-- 
http://blog.mardy.it <-- geek in un lingua international!

Re: Reporting screen/laptop orientation data to userspace

From: Jonathan Cameron <hidden>
Date: 2011-06-06 08:35:06

On 06/06/11 07:53, Alberto Mardegan wrote:
On 06/03/2011 06:55 PM, Bastien Nocera wrote:
quoted
Do you also have a discrete accelerometer with that? Or you only ever
get notification through there?
There's a discrete accelerometer, but I suspect that it might be hard for its driver to get accepted into the mainline kernel, since it's directly playing with the EC I/O ports. It's this one:

https://gitorious.org/iaps/iaps/blobs/master/iaps.c

The coarse data OTOH comes via a clean WMI interface.
quoted
If there is a discrete accelerometer, I'd drop the extra metadata, and
send an event through udev, and expect user-space to read from the
accelerometer instead.
You mean, send an event through udev when the WMI interface reports that the orientation has changed, and then expect the userspace to read the values from the accelerometer?
IMHO, reporting an event with no context data, it's inefficient and ugly (because it forces the userspace to perform additional acctions in order to get the data).
quoted
If there isn't a discrete accelerometer, create a fake one, with some
hardcoded data based on the actual orientation of the device.
This could be a solution in both cases (i.e., even if a discrete accelerometer is available). But it would be nice to have some flags on the input device which tell that this accelerometer is not as precise as one could desire. Is there such a thing?
quoted
The accelerometer (whether real or fake) should show 3 axis (X/Y/Z).

As soon as it's seen some testing, I'll be showing the work I did for
GNOME support for automatic rotation based on orientation.
Do you support choosing the accelerometer device to be used?

The device that I wanted to create is actually something much simpler than an accelerometer; it would just report screen orientation. I believe that some computer screens might have something similar, detecting the screen orientation based on the angle formed between the screen base (or wall mount) and the screen panel... I would assume that if such information exists, this Lenovo Ideapad screen orientation should be reported in a similar way.
Just for reference, there are devices on the market which do just
orientation detection (using an accelerometer inside).  I think
the ST FC30 is an example of this. Quoting from data sheet:

"When in a steady position, it is able to detect 6
different orientations with respect to the gravity
field, with notification provided through dedicated
signal lines."

Guess that fits into what you are discussing as well.

Personally I like the convenience of a 'fake' accelerometer
output.  Devices with decent orientation detection support
are, I think, less common that unprocessed accelerometers so
best to use an interface that will work with them as well
(maybe with some smart stuff to change their threshold interrupts
to provide equivalent functionality.)

Re: Reporting screen/laptop orientation data to userspace

From: Bastien Nocera <hadess@hadess.net>
Date: 2011-06-06 17:51:12

On Mon, 2011-06-06 at 09:53 +0300, Alberto Mardegan wrote:
On 06/03/2011 06:55 PM, Bastien Nocera wrote:
quoted
Do you also have a discrete accelerometer with that? Or you only ever
get notification through there?
There's a discrete accelerometer, but I suspect that it might be hard for its 
driver to get accepted into the mainline kernel, since it's directly playing 
with the EC I/O ports. It's this one:

https://gitorious.org/iaps/iaps/blobs/master/iaps.c

The coarse data OTOH comes via a clean WMI interface.
OK.
quoted
If there is a discrete accelerometer, I'd drop the extra metadata, and
send an event through udev, and expect user-space to read from the
accelerometer instead.
You mean, send an event through udev when the WMI interface reports that the 
orientation has changed, and then expect the userspace to read the values from 
the accelerometer?
IMHO, reporting an event with no context data, it's inefficient and ugly 
(because it forces the userspace to perform additional acctions in order to get 
the data).
You'll always need to have something in user-space reading the data from
your device, somehow, kernel events don't carry any data, it just says
"foo has changed". Up to the udev rules, and user-space to check up on
it.
quoted
If there isn't a discrete accelerometer, create a fake one, with some
hardcoded data based on the actual orientation of the device.
This could be a solution in both cases (i.e., even if a discrete accelerometer 
is available). But it would be nice to have some flags on the input device which 
tell that this accelerometer is not as precise as one could desire. Is there 
such a thing?
quoted
The accelerometer (whether real or fake) should show 3 axis (X/Y/Z).

As soon as it's seen some testing, I'll be showing the work I did for
GNOME support for automatic rotation based on orientation.
Do you support choosing the accelerometer device to be used?
Nope. There's usually none, or just the one (and its children).
The device that I wanted to create is actually something much simpler than an 
accelerometer; it would just report screen orientation. I believe that some 
computer screens might have something similar, detecting the screen orientation 
based on the angle formed between the screen base (or wall mount) and the screen 
panel... I would assume that if such information exists, this Lenovo Ideapad 
screen orientation should be reported in a similar way.
Comparing it to the orientation mechanism used in some screens is a
great disservice here. There's no agreed-upon way of receiving events
about it, or how to read the current orientation. It's currently all
per-vendor undocumented gunk (topic came up recently on IRC, and the X
hackers skimmed through the interwebs to find information, there's
none).

This is the latest work I've done[1]:
http://git.kernel.org/?p=linux/hotplug/udev.git;a=commit;h=24569e24dc94a7cffb8031eb0055e8d06cbdcb72

So to support the IdeaPad, I would:
- make it export the orientation of the device in sysfs (kernel-side)
- add a rule in udev to tag that particular device with
ID_INPUT_ACCELEROMETER=1
- add a simple helper (or tweak the accelerometer one in udev) to export
the current orientation through ID_INPUT_ACCELEROMETER_ORIENTATION
- Profit

The only thing I might need to change in gnome-settings-daemon (which
just listens for events, reads the orientation, and changes the XRandR
orientation) is the subsystem used, if your device isn't in the input
subsystem.

The GNOME code lives at:
http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/orientation

Cheers

[1]: The commit message is missing, here it is:
---8<---
When an "change" event is received on an accelerometer,
open its device node, and from the value, as well as the previous
value of the property, calculate the device's new orientation,
and export it as ID_INPUT_ACCELEROMETER_ORIENTATION.
    
Possible values are:
* undefined
* normal
* bottom-up
* left-up
* right-up
    
Using a udev property means that the property is persistent across
sessions, and that new orientations can be deducted from the previous
one (it allows for a threshold for switching between opposite ends
of the orientation).
    
This system should also be extensible to devices where the accelerometer
is not available to the system (no drivers), but new orientations are
advertised through ACPI events.
---8<---

Re: Reporting screen/laptop orientation data to userspace

From: Bastien Nocera <hadess@hadess.net>
Date: 2011-06-06 17:53:53

On Sat, 2011-06-04 at 19:13 +0200, Mohamed Ikbel Boulabiar wrote:
On Fri, Jun 3, 2011 at 5:55 PM, Bastien Nocera [off-list ref] wrote:
quoted
As soon as it's seen some testing, I'll be showing the work I did for
GNOME support for automatic rotation based on orientation.
And how you handle these events through X ?
As I mentioned to Alberto, and following on from the upstream push to
udev, the only thing the code does is look for uevents coming from
ID_INPUT_ACCELEROMETER=1 devices, and read the value of
ID_INPUT_ACCELEROMETER_ORIENTATION.

Certainly much easier than my previous attempts at using X to read the
values from a floating device.

Re: Reporting screen/laptop orientation data to userspace

From: Alan Cox <hidden>
Date: 2011-06-06 18:39:51

When an "change" event is received on an accelerometer,
open its device node, and from the value, as well as the previous
value of the property, calculate the device's new orientation,
and export it as ID_INPUT_ACCELEROMETER_ORIENTATION.
    
Possible values are:
* undefined
* normal
* bottom-up
* left-up
* right-up
For quite a few of the discrete accelerometers not being used in
'joystick' mode this would make quite a sensible input interface,
at least for those that generate inputs for their transitions.

You need a couple more values though because some devices care if they
are held up/down/left/right or if they are lying flat on their front or
on their back.

Phones for example sometimes go to speakerphone if laid flat on their
back, and go into silent mode if turned over.

Alan

Re: Reporting screen/laptop orientation data to userspace

From: Pavel Machek <hidden>
Date: 2011-06-14 06:41:58

Hi!
  the WMI interfaces in some Lenovo Ideapad laptops provide notification
callbacks when the laptop orientation changes, reporting 4 different
values defining the new orientation.
Zaurus has two microswitches, indicating one of 3 configurations:

notebook, closed

notebook, open

tablet

They are exported as event/switch in the input. If possible, it would
be nice to have one interface for that, too. (And it probably should
be input,  and not fake-accelerator based; after all, there are no
accelerometers on zaurus-like systems).

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Re: Reporting screen/laptop orientation data to userspace

From: Bastien Nocera <hadess@hadess.net>
Date: 2011-06-20 14:54:09

On Mon, 2011-06-06 at 19:41 +0100, Alan Cox wrote:
quoted
When an "change" event is received on an accelerometer,
open its device node, and from the value, as well as the previous
value of the property, calculate the device's new orientation,
and export it as ID_INPUT_ACCELEROMETER_ORIENTATION.
    
Possible values are:
* undefined
* normal
* bottom-up
* left-up
* right-up
For quite a few of the discrete accelerometers not being used in
'joystick' mode this would make quite a sensible input interface,
at least for those that generate inputs for their transitions.

You need a couple more values though because some devices care if they
are held up/down/left/right or if they are lying flat on their front or
on their back.

Phones for example sometimes go to speakerphone if laid flat on their
back, and go into silent mode if turned over.
I'm not designing for phones though, and it seems to me this should be a
separate attribute anyway (and so did the people who wrote sensorfw for
MeeGo Handset).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help