Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 module device.sensors; | |
|
Ken Rockot(use gerrit already)
2016/06/28 16:18:29
See note in other mojom file about module names
shalamov
2016/06/29 15:02:17
Done.
| |
| 6 | |
| 7 // Types of supported sensors | |
| 8 enum SensorType { | |
| 9 FIRST = 1, | |
| 10 AMBIENT_LIGHT = FIRST, | |
| 11 PROXIMITY, | |
| 12 LINEAR_ACCELERATION, | |
| 13 GYROSCOPE, | |
| 14 PRESSURE, | |
| 15 LAST = PRESSURE // Note: LAST is also equal to the types count. | |
| 16 }; | |
| 17 | |
| 18 // Reporting mode supported by the Sensor. | |
| 19 // ON_CHANGE - client will be notified through OnSensorReadingChanged() signal | |
| 20 // whenever sensor reading is changed. | |
| 21 // CONTINUOUS - sensor will continuously update its reading with frequency | |
| 22 // specified in SensorConfiguration.frequency. | |
| 23 // OnSensorReadingChanged() signal is not sent to the client for | |
| 24 // sensors with CONTINUOUS reporting mode. | |
| 25 enum ReportingMode { | |
| 26 ON_CHANGE, | |
| 27 CONTINUOUS | |
| 28 }; | |
| 29 | |
| 30 enum Result { | |
| 31 SUCCESS, | |
| 32 FAILURE | |
| 33 }; | |
| 34 | |
| 35 // Sensor reading buffer is putting fields of 64-bit floating point type in the | |
|
Ken Rockot(use gerrit already)
2016/06/28 16:18:29
This description could be clearer and doesn't real
shalamov
2016/06/29 15:02:17
Done.
| |
| 36 // following order: | |
| 37 // 1) timestamp | |
| 38 // 2) sensor reading fields | |
| 39 | |
| 40 // Total count of fields in sensor reading (timestamp, values[3]) | |
| 41 const uint8 kSensorReadingFieldsCount = 4; | |
| 42 | |
| 43 // Size of a single sensor reading field in bytes. | |
| 44 const uint8 kSensorReadingFieldSize = 8; | |
| 45 | |
| 46 struct SensorConfiguration { | |
| 47 // Frequency in Hz | |
| 48 double frequency; | |
| 49 // TODO(shalamov): Add map<string, union> for sensor specific configuration. | |
| 50 }; | |
| 51 | |
| 52 // Interface for controlling the Sensor. | |
| 53 interface Sensor { | |
| 54 // Sets SensorClient interface that is used to notify client when sensor | |
| 55 // reading is changed (only for sensors with ReportingMode::ON_CHANGE), or | |
| 56 // when error is raised by Sensor interface implementation. | |
| 57 SetClient(SensorClient client); | |
| 58 | |
| 59 // Requests sensor to start reading sensor data with specified | |
| 60 // SensorConfiguration. Returns SUCCESS on success, FAILURE otherwise. | |
| 61 Start(SensorConfiguration configuration) => (Result result); | |
| 62 | |
| 63 // Requests sensor to stop reading sensor data for specified | |
| 64 // SensorConfiguration. Returns SUCCESS on success, FAILURE otherwiseS. | |
| 65 Stop(SensorConfiguration configuration) => (Result result); | |
|
Ken Rockot(use gerrit already)
2016/06/28 16:18:29
How is an implementation supposed to disambiguate
shalamov
2016/06/29 15:02:17
We don't need to know anything about monitoring in
| |
| 66 }; | |
| 67 | |
| 68 // Interface that client of the Sensor interface must implement to observe | |
| 69 // sensor reading changes and error conditions. | |
| 70 interface SensorClient { | |
| 71 // Signals SensorClient when there is an error. | |
| 72 OnSensorError(); | |
|
Ken Rockot(use gerrit already)
2016/06/28 16:18:29
I think this pattern ("On" method naming) has been
shalamov
2016/06/29 15:02:17
Done.
| |
| 73 | |
| 74 // Signals SensorClient when reading has been changed (only for sensors with | |
| 75 // ReportingMode::ON_CHANGE). | |
| 76 OnSensorReadingChanged(); | |
| 77 }; | |
| OLD | NEW |