Skip to contentSkip to conversation

Reporting screen/laptop orientation data to userspace

DISCUSSION Alberto Mardegan 6 participants 10 messages May 29, 2011 – Jun 20, 2011 HID

lore
Share & tools
lore
#0 lore raw

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

Signature · 1 line
http://blog.mardy.it <- geek in un lingua international!
#1 lore raw
Quoted 5 lines · Alberto Mardegan

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.

Quoted 8 lines

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

#2 lore raw
Quoted 3 lines · Bastien Nocera

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

#3 lore raw
Quoted 6 lines · Mohamed Ikbel Boulabiar
Quoted 3 lines · Bastien Nocera

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.

#4 lore raw
In reply to Bastien Nocera
Quoted 2 lines · Bastien Nocera

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 3 lines

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 2 lines

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 4 lines

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

Signature · 1 line
http://blog.mardy.it <-- geek in un lingua international!
#5 lore raw
Quoted 22 lines · Alberto Mardegan
Quoted 2 lines · Bastien Nocera

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 3 lines

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 2 lines

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 8 lines
Quoted 4 lines

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.)

#6 lore raw
In reply to Alberto Mardegan
Quoted 11 lines · Alberto Mardegan
Quoted 2 lines · Bastien Nocera

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 10 lines
Quoted 3 lines

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 8 lines
Quoted 2 lines

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 6 lines
Quoted 4 lines

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).

Quoted 6 lines

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<---

#7 lore raw
Quoted 11 lines

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

#8 lore raw
Quoted 16 lines · Alan Cox
Quoted 11 lines

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.

Quoted 6 lines

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).

#9 lore raw
In reply to Alberto Mardegan

Hi!

Quoted 3 lines

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).

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