Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: device/generic_sensor/public/cpp/sensor_reading.h

Issue 2865263002: Move //device/generic_sensor to be part of the internal implementation of the Device Service. (Closed)
Patch Set: code rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
6 #define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
7
8 #include "device/base/synchronization/one_writer_seqlock.h"
9 #include "device/generic_sensor/public/cpp/generic_sensor_public_export.h"
10 #include "device/generic_sensor/public/interfaces/sensor.mojom.h"
11
12 namespace device {
13
14 // This class is guarantied to have a fixed size of 64 bits on every platform.
15 // It is introduce to simplify sensors shared buffer memory calculation.
16 template <typename Data>
17 class SensorReadingField {
18 public:
19 static_assert(sizeof(Data) <= sizeof(int64_t),
20 "The field size must be <= 64 bits.");
21 SensorReadingField() = default;
22 SensorReadingField(Data value) { storage_.value = value; }
23 SensorReadingField& operator=(Data value) {
24 storage_.value = value;
25 return *this;
26 }
27 Data& value() { return storage_.value; }
28 const Data& value() const { return storage_.value; }
29
30 operator Data() const { return storage_.value; }
31
32 private:
33 union Storage {
34 int64_t unused;
35 Data value;
36 Storage() { new (&value) Data(); }
37 ~Storage() { value.~Data(); }
38 };
39 Storage storage_;
40 };
41
42 // This structure represents sensor reading data: timestamp and 4 values.
43 struct DEVICE_GENERIC_SENSOR_PUBLIC_EXPORT SensorReading {
44 SensorReading();
45 ~SensorReading();
46 SensorReading(const SensorReading& other);
47 SensorReadingField<double> timestamp;
48 constexpr static int kValuesCount = 4;
49 // AMBIENT_LIGHT:
50 // values[0]: ambient light level in SI lux units.
51 //
52 // PROXIMITY:
53 // values[0]: proximity sensor distance measured in centimeters.
54 //
55 // ACCELEROMETER:
56 // values[0]: acceleration minus Gx on the x-axis.
57 // values[1]: acceleration minus Gy on the y-axis.
58 // values[2]: acceleration minus Gz on the z-axis.
59 //
60 // LINEAR_ACCELERATION:
61 // values[0]: acceleration on the x-axis.
62 // values[1]: acceleration on the y-axis.
63 // values[2]: acceleration on the z-axis.
64 //
65 // GYROSCOPE:
66 // values[0]: angular speed around the x-axis.
67 // values[1]: angular speed around the y-axis.
68 // values[2]: angular speed around the z-axis.
69 //
70 // MAGNETOMETER:
71 // values[0]: ambient magnetic field in the x-axis in micro-Tesla (uT).
72 // values[1]: ambient magnetic field in the y-axis in micro-Tesla (uT).
73 // values[2]: ambient magnetic field in the z-axis in micro-Tesla (uT).
74 //
75 // PRESSURE:
76 // values[0]: atmospheric pressure in hPa (millibar).
77 //
78 // ABSOLUTE_ORIENTATION:
79 // values[0]: x value of a quaternion representing the orientation of the
80 // device in 3D space.
81 // values[1]: y value of a quaternion representing the orientation of the
82 // device in 3D space.
83 // values[2]: z value of a quaternion representing the orientation of the
84 // device in 3D space.
85 // values[3]: w value of a quaternion representing the orientation of the
86 // device in 3D space.
87 //
88 // RELATIVE_ORIENTATION:
89 // (Identical to ABSOLUTE_ORIENTATION except that it doesn't use the
90 // geomagnetic field.)
91 // values[0]: x value of a quaternion representing the orientation of the
92 // device in 3D space.
93 // values[1]: y value of a quaternion representing the orientation of the
94 // device in 3D space.
95 // values[2]: z value of a quaternion representing the orientation of the
96 // device in 3D space.
97 // values[3]: w value of a quaternion representing the orientation of the
98 // device in 3D space.
99 SensorReadingField<double> values[kValuesCount];
100 };
101
102 // This structure represents sensor reading buffer: sensor reading and seqlock
103 // for synchronization.
104 struct DEVICE_GENERIC_SENSOR_PUBLIC_EXPORT SensorReadingSharedBuffer {
105 SensorReadingSharedBuffer();
106 ~SensorReadingSharedBuffer();
107 SensorReadingField<OneWriterSeqLock> seqlock;
108 SensorReading reading;
109
110 // Gets the shared reading buffer offset for the given sensor type.
111 static uint64_t GetOffset(mojom::SensorType type);
112 };
113
114 } // namespace device
115
116 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/public/cpp/platform_sensor_configuration.cc ('k') | device/generic_sensor/public/cpp/sensor_reading.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698