1 // Copyright 2015 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.
5 #include "ui/chromeos/accelerometer/accelerometer_util.h"
9 #include "chromeos/accelerometer/accelerometer_types.h"
10 #include "ui/gfx/geometry/vector3d_f.h"
14 // The maximum deviation from the acceleration expected due to gravity for which
15 // the device will be considered stable: 1g.
16 const float kDeviationFromGravityThreshold
= 1.0f
;
18 // The mean acceleration due to gravity on Earth in m/s^2.
19 const float kMeanGravity
= 9.80665f
;
25 const gfx::Vector3dF
ConvertAccelerometerReadingToVector3dF(
26 const chromeos::AccelerometerReading
& reading
) {
27 return gfx::Vector3dF(reading
.x
, reading
.y
, reading
.z
);
30 bool IsAccelerometerReadingStable(const chromeos::AccelerometerUpdate
& update
,
31 chromeos::AccelerometerSource source
) {
32 return update
.has(source
) &&
33 std::abs(ConvertAccelerometerReadingToVector3dF(update
.get(source
))
35 kMeanGravity
) <= kDeviationFromGravityThreshold
;