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