libmems: Reset trigger before applying a new one

Be sure the trigger is not set before setting it. Otherwise, udev rules
with changes will fail:
udevd[13328]: Process '/usr/sbin/mems_setup --device_name=iio:device0
--sensor_kind=accel' failed with exit code 1.

Handle the case of setting a null trigger.

BUG=chromium:937916
TEST=check message is gone.

Change-Id: I6d28404cb58925626bcb7a6699b3471fa64409b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1928033
Reviewed-by: Cheng-Hao Yang <chenghaoyang@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Gwendal Grignou <gwendal@chromium.org>
Cr-Mirrored-From: https://chromium.googlesource.com/chromiumos/platform2
Cr-Mirrored-Commit: 66393e2ea2d593b5ee0080a83ffa38405a66a1d5
1 file changed
tree: 30c388676e76d85408da21679305daa1d520301e
  1. BUILD.gn
  2. export.h
  3. iio_channel.h
  4. iio_channel_impl.cc
  5. iio_channel_impl.h
  6. iio_context.h
  7. iio_context_impl.cc
  8. iio_context_impl.h
  9. iio_device.cc
  10. iio_device.h
  11. iio_device_impl.cc
  12. iio_device_impl.h
  13. libmems.pc
  14. libmems_test_support.pc
  15. OWNERS
  16. README.md
  17. test_fakes.cc
  18. test_fakes.h
README.md

Chrome OS IIO Sensor Utility Library

Project goal and motivation

This library provides a set of wrapper and test helpers around libiio.

It is meant to provide a common foundation for Chrome OS to access and interface IIO sensors, with:

  • a strong emphasis on testability;
  • readable code, with the ergonomics typical of platform2;
  • high performance.

Class hierarchy

At the root of the hierarchy, there exists the IioContext, which represents the IIO devices currently available on the system. These can be retrieved by name and inspected, via instances of IioDevice.

An IioDevice allows reading and writing attributes of an IIO device via type-safe helper APIs. It also offers support for configuring the buffer and trigger of an IIO device, which we use in order to allow the Chrome UI to read accelerometer data and support screen rotation.

An IioDevice also exposes a list of IioChannels, which can individually be enabled and disabled.

Test mocks

Useful mocks for the core classes are provided, such that a test author can focus on the logic of the unit tests and share a common testing language with other engineers working in this space. Sharing the foundation of testing IIO sensor access helps ensure that any improvement in this area can benefit all clients.