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

Side by Side Diff: content/browser/device_sensors/sensor_manager_chromeos.cc

Issue 1306453003: Update AccelerometerReader to support separate iio devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missed tests Created 5 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/device_sensors/sensor_manager_chromeos.h" 5 #include "content/browser/device_sensors/sensor_manager_chromeos.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "chromeos/accelerometer/accelerometer_reader.h" 9 #include "chromeos/accelerometer/accelerometer_reader.h"
10 #include "chromeos/accelerometer/accelerometer_types.h" 10 #include "chromeos/accelerometer/accelerometer_types.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 motion_buffer_->seqlock.WriteEnd(); 133 motion_buffer_->seqlock.WriteEnd();
134 } 134 }
135 135
136 void SensorManagerChromeOS::GenerateOrientationEvent(double x, 136 void SensorManagerChromeOS::GenerateOrientationEvent(double x,
137 double y, 137 double y,
138 double z) { 138 double z) {
139 if (!orientation_buffer_) 139 if (!orientation_buffer_)
140 return; 140 return;
141 141
142 // Create a unit vector for trigonometry 142 // Create a unit vector for trigonometry
143 // TODO(jonross): Stop reversing signs for vector components once 143 gfx::Vector3dF data(x, y, z);
144 // accelerometer values have been fixed. crbug.com/431391
145 // Ternaries are to remove -0.0f which gives incorrect trigonometrical
146 // results.
147 gfx::Vector3dF data(x, y ? -y : 0.0f, z ? -z : 0.0f);
148 data.Scale(1.0f / data.Length()); 144 data.Scale(1.0f / data.Length());
149 145
150 // Transform accelerometer to W3C angles, using the Z-X-Y Eulerangles matrix. 146 // Transform accelerometer to W3C angles, using the Z-X-Y Eulerangles matrix.
151 // x = sin(gamma) 147 // x = sin(gamma)
152 // y = -cos(gamma) * sin(beta) 148 // y = -cos(gamma) * sin(beta)
153 // z = cos(beta) * cos(gamma) 149 // z = cos(beta) * cos(gamma)
154 // With only accelerometer alpha cannot be provided. 150 // With only accelerometer alpha cannot be provided.
155 double beta = kRad2deg * atan2(data.y(), data.z()); 151 double beta = kRad2deg * atan2(data.y(), data.z());
156 double gamma = kRad2deg * asin(data.x()); 152 double gamma = kRad2deg * asin(-data.x());
157 153
158 // Convert beta and gamma to fit the intervals in the specification. Beta is 154 // Convert beta and gamma to fit the intervals in the specification. Beta is
159 // [-180, 180) and gamma is [-90, 90). 155 // [-180, 180) and gamma is [-90, 90).
160 if (beta >= 180.0f) 156 if (beta >= 180.0f)
161 beta = -180.0f; 157 beta = -180.0f;
162 if (gamma >= 90.0f) 158 if (gamma >= 90.0f)
163 gamma = -90.0f; 159 gamma = -90.0f;
164 orientation_buffer_->seqlock.WriteBegin(); 160 orientation_buffer_->seqlock.WriteBegin();
165 orientation_buffer_->data.beta = beta; 161 orientation_buffer_->data.beta = beta;
166 orientation_buffer_->data.hasBeta = true; 162 orientation_buffer_->data.hasBeta = true;
167 orientation_buffer_->data.gamma = gamma; 163 orientation_buffer_->data.gamma = gamma;
168 orientation_buffer_->data.hasGamma = true; 164 orientation_buffer_->data.hasGamma = true;
169 orientation_buffer_->data.allAvailableSensorsAreActive = true; 165 orientation_buffer_->data.allAvailableSensorsAreActive = true;
170 orientation_buffer_->seqlock.WriteEnd(); 166 orientation_buffer_->seqlock.WriteEnd();
171 } 167 }
172 168
173 } // namespace content 169 } // namespace content
OLDNEW
« no previous file with comments | « chromeos/accelerometer/accelerometer_reader.cc ('k') | content/browser/device_sensors/sensor_manager_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698