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 #include "modules/sensor/GyroscopeReading.h" | |
6 | |
7 #include "modules/sensor/GyroscopeReadingInit.h" | |
8 #include "wtf/CurrentTime.h" | |
9 | |
10 namespace blink { | |
11 | |
12 namespace { | |
13 device::SensorReading ToReadingData(const GyroscopeReadingInit& init) { | |
14 device::SensorReading result; | |
15 result.timestamp = WTF::monotonicallyIncreasingTime(); | |
16 if (init.hasX()) | |
17 result.values[0] = init.x(); | |
18 if (init.hasY()) | |
19 result.values[1] = init.y(); | |
20 if (init.hasZ()) | |
21 result.values[2] = init.z(); | |
22 return result; | |
23 } | |
24 } // namespace | |
25 | |
26 GyroscopeReading::GyroscopeReading(const GyroscopeReadingInit& init) | |
27 : SensorReading(ToReadingData(init)) {} | |
28 | |
29 GyroscopeReading::GyroscopeReading(const device::SensorReading& data) | |
30 : SensorReading(data) {} | |
31 | |
32 GyroscopeReading::~GyroscopeReading() = default; | |
33 | |
34 double GyroscopeReading::x() const { | |
35 return data().values[0]; | |
36 } | |
37 | |
38 double GyroscopeReading::y() const { | |
39 return data().values[1]; | |
40 } | |
41 | |
42 double GyroscopeReading::z() const { | |
43 return data().values[2]; | |
44 } | |
45 | |
46 bool GyroscopeReading::isReadingUpdated( | |
47 const device::SensorReading& previous) const { | |
48 return previous.values[0] != x() || previous.values[1] != y() || | |
49 previous.values[2] != z(); | |
50 } | |
51 | |
52 DEFINE_TRACE(GyroscopeReading) { | |
53 SensorReading::trace(visitor); | |
54 } | |
55 | |
56 } // namespace blink | |
OLD | NEW |