1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next min version: 2
// NOTE: This mojom exists in two places and must be kept in sync:
// Chromium: //chromeos/components/sensors/mojom/
// Chrome OS: src/platform2/iioservice/mojo/
// Note: Other repos downstream of Chromium might also use this mojom.
// Example: A backwards-compatible mojom change (and corresponding
// implementation change) can be made in Chrome OS first, then replicated to the
// clients (Chromium, other downstream repos) later.
module chromeos.sensors.mojom;
const string kScale = "scale";
const string kSamplingFrequencyAvailable = "sampling_frequency_available";
const string kLocation = "location";
const string kLabel = "label";
// The attribute name to get the device name in SensorDevice::GetAttributes.
const string kDeviceName = "name";
// The attribute name to get the device's syspath in
// SensorDevice::GetAttributes, which can be used to match up iio devices and
// external devices, like external tablets.
// For example, if device 0 has the iio path to the syspath with symbolic link:
// /sys/bus/iio/devices/iio:device0 ->
// ../../../devices/pci0000:00/0000:00:13.0/.../HID-SENSOR-200083.20.auto/iio:device0
// , /sys/devices/pci0000:00/0000:00:13.0/.../HID-SENSOR-200083.20.auto/iio:device0
// will be returned.
const string kSysPath = "syspath";
// Only available for SAR sensors, needed to determine the antenna type
// (wifi/lte).
const string kDevlink = "devlink";
const string kLocationBase = "base";
const string kLocationLid = "lid";
const string kLocationCamera = "camera";
const string kLabelBase = "accel-base";
const string kLabelLid = "accel-display";
// As Mojo doesn't support const arrays of strings and char, and also axes are
// trivial, let Sensor clients append the axes.
// Supported axes: {"x", "y", "z"}. Ex: "accel_x".
const string kAccelerometerChannel = "accel";
const string kGyroscopeChannel = "anglvel";
const string kMagnetometerChannel = "magn";
const string kGravityChannel = "gravity";
// The light sensor may have not only channel "illuminance", but three color
// channels: illuminance_red, illuminance_green, and illuminance_blue.
const string kLightChannel = "illuminance";
const string kPressureChannel = "pressure";
const string kTimestampChannel = "timestamp";
[Stable, Extensible]
enum DeviceType {
[Default] NONE = 0, // invalid device type
ACCEL = 1,
ANGLVEL = 2,
LIGHT = 3,
COUNT = 4,
MAGN = 5,
ANGL = 6,
BARO = 7,
ACCEL_UNCALIBRATED = 8,
ANGLVEL_UNCALIBRATED = 9,
MAGN_UNCALIBRATED = 10,
GRAVITY = 11,
};
[Stable, Extensible]
enum ObserverErrorType {
[Default] ALREADY_STARTED = 0,
SET_FREQUENCY_IO_FAILED = 1,
FREQUENCY_INVALID = 2,
NO_ENABLED_CHANNELS = 3,
GET_FD_FAILED = 4,
READ_FAILED = 5,
READ_TIMEOUT = 6,
};
[Stable, Extensible]
enum SensorServiceDisconnectReason {
// iioservice has crashed. The clients should reset all current usages and
// wait for its reconnection.
[Default] IIOSERVICE_CRASHED = 0,
// iioservice is shutting down.
IIOSERVICE_SHUTDOWN = 1,
// iioservice is resetting because chrome has stopped.
CHROME_STOPPED = 2,
};
// SensorService, an interface to search and get SensorDevices. A User can get
// multiple isolated SensorDevices for one physical device, if it wants
// different frequencies of that device's samples.
//
// Next method ID: 4
[Stable]
interface SensorService {
// Gets device ids as a vector of int given the device's type. Only devices
// with id having "iio:device" as the prefix would be available.
// Gets an empty vector if no device can be found.
GetDeviceIds@0(DeviceType type) => (array<int32> iio_device_ids);
// Gets all device ids and their types. Only devices with id having
// "iio:device" as the prefix would be available. For combo sensors, there are
// multiple types in the array of types.
// Gets an empty vector if no device can be found.
GetAllDeviceIds@1() => (map<int32, array<DeviceType>> iio_device_ids_types);
// Creates a new Mojo channel to the iioservice as an isolated client. Upon
// successfully binding of |device_request|, the caller will have an
// established Mojo channel to iioservice.
// If failed, the request won't be bound and will be destroyed directly.
GetDevice@2(int32 iio_device_id,
pending_receiver<SensorDevice> device_request);
// Registers a SensorServiceNewDevicesObserver to iioservice. Users will get
// notified when new devices are added and visible to iioservice.
RegisterNewDevicesObserver
@3(pending_remote<SensorServiceNewDevicesObserver> observer);
};
// The disconnect reasons of SensorDevice and SensorDeviceSamplesObserver.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
[Stable, Extensible]
enum SensorDeviceDisconnectReason {
// iioservice has crashed. The clients should reset all current usages and
// wait for its reconnection.
[Default] IIOSERVICE_CRASHED = 0,
// The sensor device is removed from iioservice. This should only happen on
// the hot pluggable device.
DEVICE_REMOVED = 1,
};
// SensorDevice, an interface sending requests for a physical device
// (libiio:iio_device). It is an isolated client in iioservice's point of view.
//
// Next method ID: 9
[Stable]
interface SensorDevice {
// Sets |timeout| in milliseconds for I/O operations, mainly for reading
// samples. Sets |timeout| as 0 to specify that no timeout should occur.
// Default: 5000 milliseconds.
SetTimeout@0(uint32 timeout);
// Gets the |attr_names| attributes of this device into |values| as strings.
// When an attribute cannot be read, its value in |values| is set to null.
// |values| and |attr_names| always have the same size.
// Device name (|kDeviceName|) is also an attribute that can be requested.
GetAttributes@1(array<string> attr_names) => (array<string?> values);
// Sets the frequency in Hz of the device before starting to read samples.
// If no frequency or an invalid frequency is set, an
// ObserverErrorType::FREQUENCY_INVALID error will occur after calling
// |StartReadingSamples|.
// After starting to read samples, the client can set the frequency to 0 to
// pause the reading, and set a valid frequency later to resume the reading.
// |result_freq| would be the frequency set by iioservice for the client.
SetFrequency@2(double frequency) => (double result_freq);
// Starts reading samples with the frequency set by |SetFrequency|. Samples or
// errors will be pushed to the observer. It's the user's responsibility to
// keep |observer| active while reading.
StartReadingSamples@3(pending_remote<SensorDeviceSamplesObserver> observer);
// Stops reading samples in this device. Reading can be restarted by calling
// |StartReadingSamples| again.
StopReadingSamples@4();
// Gets all channels' ids as a vector of string. The ids are ordered and the
// user should use the indices of channels to send further requests and
// receive samples.
GetAllChannelIds@5() => (array<string> iio_chn_ids);
// Sets channels' enabled status to |en| with channel indices
// |iio_chn_indices|. Returns an array of channel indices |failed_indices| if
// there are some invalid or duplicate indices.
SetChannelsEnabled @6(array<int32> iio_chn_indices, bool en)
=> (array<int32> failed_indices);
// Returns an array of bool indicating if channels are enabled.
GetChannelsEnabled@7(array<int32> iio_chn_indices) => (array<bool> enabled);
// Gets the |attr_name| attribute of channels as a group into |values| in
// string.
// Returns std::nullopt if the attribute in the channel cannot be read.
GetChannelsAttributes@8(array<int32> iio_chn_indices, string attr_name)
=> (array<string?> values);
};
// One observer is created to track one specific device's samples, using
// SensorDevice::StartReadingSamples to register the observer.
//
// Next method ID: 2
[Stable]
interface SensorDeviceSamplesObserver {
// |sample| arrives and is sent to the client as a map from iio_chn_indices to
// data (64 bit integer).
OnSampleUpdated@0(map<int32, int64> sample);
// An error occurs and is sent to the client as an enum type.
OnErrorOccurred@1(ObserverErrorType type);
};
// One observer is created to track new sensors updated to iioservice, using
// SensorService::RegisterNewDevicesObserver to register the observer.
//
// Next method ID: 1
[Stable]
interface SensorServiceNewDevicesObserver {
// A new IIO device with |iio_device_id| and |types| is added and visible to
// iioservice. Sensor clients can get access to this device with the id.
OnNewDeviceAdded@0(int32 iio_device_id, array<DeviceType> types);
};
|