OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/accelerometer/accelerometer_reader.h" | 5 #include "chromeos/accelerometer/accelerometer_reader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_enumerator.h" | |
10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
11 #include "base/location.h" | 12 #include "base/location.h" |
12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
18 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
19 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
20 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
22 | 23 |
23 namespace chromeos { | 24 namespace chromeos { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Paths to access necessary data from the accelerometer device. | 28 // Paths to access necessary data from the accelerometer device. |
28 const base::FilePath::CharType kAccelerometerTriggerPath[] = | 29 const base::FilePath::CharType kAccelerometerTriggerPath[] = |
29 FILE_PATH_LITERAL("/sys/bus/iio/devices/trigger0/trigger_now"); | 30 FILE_PATH_LITERAL("/sys/bus/iio/devices/trigger0/trigger_now"); |
30 const base::FilePath::CharType kAccelerometerDevicePath[] = | 31 const base::FilePath::CharType kAccelerometerDevicePath[] = |
31 FILE_PATH_LITERAL("/dev/cros-ec-accel"); | 32 FILE_PATH_LITERAL("/dev/cros-ec-accel"); |
32 const base::FilePath::CharType kAccelerometerIioBasePath[] = | 33 const base::FilePath::CharType kAccelerometerIioBasePath[] = |
33 FILE_PATH_LITERAL("/sys/bus/iio/devices/"); | 34 FILE_PATH_LITERAL("/sys/bus/iio/devices/"); |
34 | 35 |
35 // File within the device in kAccelerometerIioBasePath containing the scale of | 36 // Legacy file name within the device in kAccelerometerIioBasePath containing |
36 // the accelerometers. | 37 // the scale of the accelerometers. |
37 const base::FilePath::CharType kScaleFileName[] = "in_accel_scale"; | 38 const base::FilePath::CharType kScaleFileName[] = "in_accel_scale"; |
flackr
2015/08/19 21:43:25
Can we just remove this if the scale location has
jonross
2015/08/20 20:34:13
Done.
| |
38 | 39 |
39 // This is the per source scale file in use on kernels older than 3.18. We | 40 // This is the per source scale file in use on kernels older than 3.18. We |
40 // should remove this when all devices having accelerometers are on kernel 3.18 | 41 // should remove this when all devices having accelerometers are on kernel 3.18 |
41 // or later or have been patched to use new format: http://crbug.com/510831 | 42 // or later or have been patched to use new format: http://crbug.com/510831 |
42 const base::FilePath::CharType kSourceScaleNameFormatString[] = | 43 const base::FilePath::CharType kSourceScaleNameFormatString[] = |
43 "in_accel_%s_scale"; | 44 "in_accel_%s_scale"; |
44 | 45 |
46 // File within kAccelerometerDevicePath/device* which denotes a single scale to | |
47 // be used across all axes. | |
48 const base::FilePath::CharType kAccelerometerScaleFileName[] = "scale"; | |
49 | |
50 // File within kAccelerometerDevicePath/device* which denotes the | |
51 // AccelerometerSource for the accelerometer. | |
52 const base::FilePath::CharType kAccelerometerLocationFileName[] = "location"; | |
53 | |
45 // The filename giving the path to read the scan index of each accelerometer | 54 // The filename giving the path to read the scan index of each accelerometer |
46 // axis. | 55 // axis. |
47 const char kAccelerometerScanIndexPath[] = | 56 const char kAccelerometerScanIndexPath[] = |
48 "scan_elements/in_accel_%s_%s_index"; | 57 "scan_elements/in_accel_%s_%s_index"; |
49 | 58 |
50 // The names of the accelerometers. Matches up with the enum AccelerometerSource | 59 // The names of the accelerometers. Matches up with the enum AccelerometerSource |
51 // in chromeos/accelerometer/accelerometer_types.h. | 60 // in chromeos/accelerometer/accelerometer_types.h. |
52 const char kAccelerometerNames[ACCELEROMETER_SOURCE_COUNT][5] = {"lid", "base"}; | 61 const char kAccelerometerNames[ACCELEROMETER_SOURCE_COUNT][5] = {"lid", "base"}; |
53 | 62 |
54 // The axes on each accelerometer. | 63 // The axes on each accelerometer. |
(...skipping 20 matching lines...) Expand all Loading... | |
75 // Reads |path| to the unsigned int pointed to by |value|. Returns true on | 84 // Reads |path| to the unsigned int pointed to by |value|. Returns true on |
76 // success or false on failure. | 85 // success or false on failure. |
77 bool ReadFileToInt(const base::FilePath& path, int* value) { | 86 bool ReadFileToInt(const base::FilePath& path, int* value) { |
78 std::string s; | 87 std::string s; |
79 DCHECK(value); | 88 DCHECK(value); |
80 if (!base::ReadFileToString(path, &s, kMaxAsciiUintLength)) { | 89 if (!base::ReadFileToString(path, &s, kMaxAsciiUintLength)) { |
81 return false; | 90 return false; |
82 } | 91 } |
83 base::TrimWhitespaceASCII(s, base::TRIM_ALL, &s); | 92 base::TrimWhitespaceASCII(s, base::TRIM_ALL, &s); |
84 if (!base::StringToInt(s, value)) { | 93 if (!base::StringToInt(s, value)) { |
85 LOG(ERROR) << "Failed to parse \"" << s << "\" from " << path.value(); | 94 LOG(ERROR) << "JR Failed to parse \"" << s << "\" from " << path.value(); |
flackr
2015/08/19 21:43:25
Remove JR, also as per my comment on 110 this shou
jonross
2015/08/20 20:34:13
Done.
| |
86 return false; | 95 return false; |
87 } | 96 } |
88 return true; | 97 return true; |
98 } | |
99 | |
100 // Reads |path| to the double pointed to by |value|. Returns true on success or | |
101 // false on failure. | |
102 bool ReadFileToDouble(const base::FilePath& path, double* value) { | |
103 std::string s; | |
104 DCHECK(value); | |
105 if (!base::ReadFileToString(path, &s)) { | |
106 return false; | |
107 } | |
108 base::TrimWhitespaceASCII(s, base::TRIM_ALL, &s); | |
109 if (!base::StringToDouble(s, value)) { | |
110 LOG(ERROR) << "Accelerometer Failed to parse \"" << s << "\" from " | |
flackr
2015/08/19 21:43:25
Add the type being parsed so that it's obvious fro
jonross
2015/08/20 20:34:13
Done.
| |
111 << path.value(); | |
112 return false; | |
113 } | |
114 return true; | |
89 } | 115 } |
90 | 116 |
91 } // namespace | 117 } // namespace |
92 | 118 |
93 const int AccelerometerReader::kDelayBetweenReadsMs = 100; | 119 const int AccelerometerReader::kDelayBetweenReadsMs = 100; |
94 | 120 |
95 // Work that runs on a base::TaskRunner. It determines the accelerometer | 121 // Work that runs on a base::TaskRunner. It determines the accelerometer |
96 // configuartion, and reads the data. Upon a successful read it will notify | 122 // configuartion, and reads the data. Upon a successful read it will notify |
97 // all observers. | 123 // all observers. |
98 class AccelerometerFileReader | 124 class AccelerometerFileReader |
(...skipping 30 matching lines...) Expand all Loading... | |
129 size_t length; | 155 size_t length; |
130 | 156 |
131 // Which accelerometers are present on device. | 157 // Which accelerometers are present on device. |
132 bool has[ACCELEROMETER_SOURCE_COUNT]; | 158 bool has[ACCELEROMETER_SOURCE_COUNT]; |
133 | 159 |
134 // Scale of accelerometers (i.e. raw value * scale = m/s^2). | 160 // Scale of accelerometers (i.e. raw value * scale = m/s^2). |
135 float scale[ACCELEROMETER_SOURCE_COUNT][3]; | 161 float scale[ACCELEROMETER_SOURCE_COUNT][3]; |
136 | 162 |
137 // Index of each accelerometer axis in data stream. | 163 // Index of each accelerometer axis in data stream. |
138 int index[ACCELEROMETER_SOURCE_COUNT][3]; | 164 int index[ACCELEROMETER_SOURCE_COUNT][3]; |
165 | |
166 // If true the accelerometer devices must be read from distinct files. | |
167 bool read_device_separately; | |
168 | |
169 // Length of reading per accelerometer | |
170 size_t device_length[ACCELEROMETER_SOURCE_COUNT]; | |
171 | |
172 // The path to append to |kAccelerometerDevicePath| where the accelerometer | |
173 // device resides. | |
174 base::FilePath device_path[ACCELEROMETER_SOURCE_COUNT]; | |
139 }; | 175 }; |
140 | 176 |
141 ~AccelerometerFileReader() {} | 177 ~AccelerometerFileReader() {} |
142 | 178 |
143 // Attempts to read the accelerometer data. Upon a success, converts the raw | 179 // Attempts to read the accelerometer data. Upon a success, converts the raw |
144 // reading to an AccelerometerUpdate and notifies observers. | 180 // reading to an AccelerometerUpdate and notifies observers. |
145 void ReadFileAndNotify(); | 181 void ReadFileAndNotify(); |
146 | 182 |
147 // True if Initialize completed successfully, and there is an accelerometer | 183 // True if Initialize completed successfully, and there is an accelerometer |
148 // file to read. | 184 // file to read. |
(...skipping 23 matching lines...) Expand all Loading... | |
172 | 208 |
173 void AccelerometerFileReader::Initialize( | 209 void AccelerometerFileReader::Initialize( |
174 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner) { | 210 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner) { |
175 DCHECK( | 211 DCHECK( |
176 base::SequencedWorkerPool::GetSequenceTokenForCurrentThread().IsValid()); | 212 base::SequencedWorkerPool::GetSequenceTokenForCurrentThread().IsValid()); |
177 task_runner_ = sequenced_task_runner; | 213 task_runner_ = sequenced_task_runner; |
178 | 214 |
179 // Check for accelerometer symlink which will be created by the udev rules | 215 // Check for accelerometer symlink which will be created by the udev rules |
180 // file on detecting the device. | 216 // file on detecting the device. |
181 base::FilePath device; | 217 base::FilePath device; |
182 if (!base::ReadSymbolicLink(base::FilePath(kAccelerometerDevicePath), | 218 |
183 &device)) { | 219 if (base::IsDirectoryEmpty(base::FilePath(kAccelerometerDevicePath))) { |
220 LOG(ERROR) << "Accelerometer device directory is empty at " | |
221 << kAccelerometerDevicePath; | |
184 return; | 222 return; |
185 } | 223 } |
186 | 224 |
187 if (!base::PathExists(base::FilePath(kAccelerometerTriggerPath))) { | 225 if (!base::PathExists(base::FilePath(kAccelerometerTriggerPath))) { |
188 LOG(ERROR) << "Accelerometer trigger does not exist at" | 226 LOG(ERROR) << "Accelerometer trigger does not exist at" |
189 << kAccelerometerTriggerPath; | 227 << kAccelerometerTriggerPath; |
190 return; | 228 return; |
191 } | 229 } |
192 | 230 |
193 base::FilePath iio_path(base::FilePath(kAccelerometerIioBasePath).Append( | 231 base::FileEnumerator symlink_dir(base::FilePath(kAccelerometerDevicePath), |
194 device)); | 232 false, base::FileEnumerator::FILES); |
195 | 233 for (base::FilePath name = symlink_dir.Next(); !name.empty(); |
196 // Read the scale for all axes. | 234 name = symlink_dir.Next()) { |
197 int scale_divisor = 0; | 235 base::FilePath iio_device; |
198 bool per_source_scale = | 236 if (!base::ReadSymbolicLink(name, &iio_device)) { |
199 !ReadFileToInt(iio_path.Append(kScaleFileName), &scale_divisor); | 237 LOG(ERROR) << "Accelerometer device file invalid.\n"; |
flackr
2015/08/19 21:43:25
Output name and change log message to describe exa
jonross
2015/08/20 20:34:13
Done.
| |
200 if (!per_source_scale && scale_divisor == 0) { | 238 return; |
201 LOG(ERROR) << "Accelerometer " << kScaleFileName | |
202 << "has scale of 0 and will not be used."; | |
203 return; | |
204 } | |
205 | |
206 // Read configuration of each accelerometer axis from each accelerometer from | |
207 // /sys/bus/iio/devices/iio:deviceX/. | |
208 for (size_t i = 0; i < arraysize(kAccelerometerNames); ++i) { | |
209 if (per_source_scale) { | |
210 configuration_.has[i] = false; | |
211 // Read scale of accelerometer. | |
212 std::string accelerometer_scale_path = base::StringPrintf( | |
213 kSourceScaleNameFormatString, kAccelerometerNames[i]); | |
214 if (!ReadFileToInt(iio_path.Append(accelerometer_scale_path.c_str()), | |
215 &scale_divisor)) { | |
216 continue; | |
217 } | |
218 if (scale_divisor == 0) { | |
219 LOG(ERROR) << "Accelerometer " << accelerometer_scale_path | |
220 << "has scale of 0 and will not be used."; | |
221 continue; | |
222 } | |
223 } | 239 } |
224 | 240 |
225 configuration_.has[i] = true; | 241 base::FilePath iio_path(base::FilePath(kAccelerometerIioBasePath) |
226 for (size_t j = 0; j < arraysize(kAccelerometerAxes); ++j) { | 242 .Append(iio_device.BaseName())); |
227 configuration_.scale[i][j] = kMeanGravity / scale_divisor; | 243 std::string location; |
228 std::string accelerometer_index_path = base::StringPrintf( | 244 if (base::ReadFileToString( |
229 kAccelerometerScanIndexPath, kAccelerometerAxes[j], | 245 base::FilePath(iio_path).Append(kAccelerometerLocationFileName), |
230 kAccelerometerNames[i]); | 246 &location)) { |
231 if (!ReadFileToInt(iio_path.Append(accelerometer_index_path.c_str()), | 247 configuration_.read_device_separately = true; |
232 &(configuration_.index[i][j]))) { | 248 base::TrimWhitespaceASCII(location, base::TRIM_ALL, &location); |
233 configuration_.has[i] = false; | 249 int config_index = -1; |
234 break; | 250 for (size_t j = 0; j < arraysize(kAccelerometerNames); ++j) { |
flackr
2015/08/19 21:43:25
It would probably be more clear / shorter to use s
| |
251 if (location == kAccelerometerNames[j]) { | |
252 config_index = j; | |
253 break; | |
254 } | |
235 } | 255 } |
256 | |
257 if (config_index == -1) { | |
258 LOG(ERROR) << "JR invalid location.\n"; | |
flackr
2015/08/19 21:43:25
Name the location and the file it was read from so
jonross
2015/08/20 20:34:13
Done.
| |
259 return; | |
260 } | |
261 | |
262 configuration_.device_path[config_index] = name.BaseName(); | |
263 configuration_.has[config_index] = true; | |
264 | |
265 double scale; | |
266 if (!ReadFileToDouble(iio_path.Append(kAccelerometerScaleFileName), | |
267 &scale)) { | |
268 LOG(ERROR) << "Accelerometer the scale file cannot be parsed\n"; | |
flackr
2015/08/19 21:43:24
ReadFileToDouble logs if it can't read or parse th
jonross
2015/08/20 20:34:13
Nope, missed this when refactoring readtodouble ou
| |
269 return; | |
270 } | |
271 | |
272 for (size_t j = 0; j < arraysize(kAccelerometerAxes); ++j) { | |
273 std::string accelerometer_index_path = base::StringPrintf( | |
274 "scan_elements/in_accel_%s_index", kAccelerometerAxes[j]); | |
flackr
2015/08/19 21:43:25
Use a constant.
jonross
2015/08/20 20:34:13
Done.
| |
275 if (!ReadFileToInt(iio_path.Append(accelerometer_index_path.c_str()), | |
276 &(configuration_.index[config_index][j]))) { | |
277 configuration_.has[config_index] = false; | |
278 break; | |
279 } | |
280 configuration_.scale[config_index][j] = scale; | |
flackr
2015/08/19 21:43:25
The scale file now contains a double and scales to
jonross
2015/08/20 20:34:13
Correct, this was also changed in the new kernel.
| |
281 } | |
282 configuration_.device_length[config_index] = kDataSize * 3; | |
flackr
2015/08/19 21:43:25
This looks constant.
jonross
2015/08/20 20:34:13
Done.
| |
283 if (configuration_.has[config_index]) | |
284 configuration_.count++; | |
285 } else { | |
286 // Old configuration code | |
287 LOG(ERROR) << "JR no location file\n"; | |
flackr
2015/08/19 21:43:25
I'd suggest splitting this off into functions for
jonross
2015/08/19 22:22:24
Yeah I had at first wondered if I could keep them
| |
236 } | 288 } |
237 if (configuration_.has[i]) | |
238 configuration_.count++; | |
239 } | |
240 | |
241 // Adjust the directions of accelerometers to match the AccelerometerUpdate | |
242 // type specified in chromeos/accelerometer/accelerometer_types.h. | |
243 configuration_.scale[ACCELEROMETER_SOURCE_SCREEN][0] *= -1.0f; | |
244 for (int i = 0; i < 3; ++i) { | |
245 configuration_.scale[ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD][i] *= -1.0f; | |
flackr
2015/08/19 21:43:25
Don't we still need to fix the axes' directions?
jonross
2015/08/19 22:22:24
The new values being reported are quite incorrect.
| |
246 } | 289 } |
247 | 290 |
248 // Verify indices are within bounds. | 291 // Verify indices are within bounds. |
249 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { | 292 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { |
250 if (!configuration_.has[i]) | 293 if (!configuration_.has[i]) |
251 continue; | 294 continue; |
252 for (int j = 0; j < 3; ++j) { | 295 for (int j = 0; j < 3; ++j) { |
253 if (configuration_.index[i][j] < 0 || | 296 if (configuration_.index[i][j] < 0 || |
254 configuration_.index[i][j] >= | 297 configuration_.index[i][j] >= |
255 3 * static_cast<int>(configuration_.count)) { | 298 3 * static_cast<int>(configuration_.count)) { |
256 LOG(ERROR) << "Field index for " << kAccelerometerNames[i] << " " | 299 LOG(ERROR) << "Field index for " << kAccelerometerNames[i] << " " |
257 << kAccelerometerAxes[j] << " axis out of bounds."; | 300 << kAccelerometerAxes[j] << " axis out of bounds."; |
258 return; | 301 return; |
259 } | 302 } |
260 } | 303 } |
261 } | 304 } |
262 configuration_.length = kDataSize * 3 * configuration_.count; | 305 |
306 // Legacy length | |
307 // configuration_.length = kDataSize * 3 * configuration_.count; | |
263 initialization_successful_ = true; | 308 initialization_successful_ = true; |
264 Read(); | 309 Read(); |
265 } | 310 } |
266 | 311 |
267 void AccelerometerFileReader::Read() { | 312 void AccelerometerFileReader::Read() { |
268 DCHECK( | 313 DCHECK( |
269 base::SequencedWorkerPool::GetSequenceTokenForCurrentThread().IsValid()); | 314 base::SequencedWorkerPool::GetSequenceTokenForCurrentThread().IsValid()); |
270 ReadFileAndNotify(); | 315 ReadFileAndNotify(); |
271 task_runner_->PostNonNestableDelayedTask( | 316 task_runner_->PostNonNestableDelayedTask( |
272 FROM_HERE, base::Bind(&AccelerometerFileReader::Read, this), | 317 FROM_HERE, base::Bind(&AccelerometerFileReader::Read, this), |
(...skipping 15 matching lines...) Expand all Loading... | |
288 AccelerometerReader::Observer* observer) { | 333 AccelerometerReader::Observer* observer) { |
289 observers_->RemoveObserver(observer); | 334 observers_->RemoveObserver(observer); |
290 } | 335 } |
291 | 336 |
292 void AccelerometerFileReader::ReadFileAndNotify() { | 337 void AccelerometerFileReader::ReadFileAndNotify() { |
293 DCHECK(initialization_successful_); | 338 DCHECK(initialization_successful_); |
294 char reading[kSizeOfReading]; | 339 char reading[kSizeOfReading]; |
295 | 340 |
296 // Initiate the trigger to read accelerometers simultaneously | 341 // Initiate the trigger to read accelerometers simultaneously |
297 int bytes_written = base::WriteFile( | 342 int bytes_written = base::WriteFile( |
298 base::FilePath(kAccelerometerTriggerPath), "1\n", 2); | 343 base::FilePath(kAccelerometerTriggerPath), "1\n", 2); |
flackr
2015/08/19 21:43:24
We don't need multiple triggers?
jonross
2015/08/19 22:22:24
Discussion implied only one was needed. I can add
jonross
2015/08/20 20:34:13
Confirmed with on device testing. One trigger.
| |
299 if (bytes_written < 2) { | 344 if (bytes_written < 2) { |
300 PLOG(ERROR) << "Accelerometer trigger failure: " << bytes_written; | 345 LOG(ERROR) << "JR Accelerometer trigger failure: " << bytes_written; |
301 return; | 346 return; |
302 } | 347 } |
303 | 348 |
304 // Read resulting sample from /dev/cros-ec-accel. | 349 // Read resulting sample from /dev/cros-ec-accel. |
305 int bytes_read = base::ReadFile(base::FilePath(kAccelerometerDevicePath), | 350 int bytes_read; |
306 reading, configuration_.length); | 351 update_ = new AccelerometerUpdate(); |
307 if (bytes_read < static_cast<int>(configuration_.length)) { | 352 if (!configuration_.read_device_separately) { |
308 LOG(ERROR) << "Read " << bytes_read << " byte(s), expected " | 353 bytes_read = base::ReadFile(base::FilePath(kAccelerometerDevicePath), |
309 << configuration_.length << " bytes from accelerometer"; | 354 reading, configuration_.length); |
310 return; | 355 if (bytes_read < static_cast<int>(configuration_.length)) { |
356 LOG(ERROR) << "Accelerometer Read " << bytes_read << " byte(s), expected " | |
357 << configuration_.length << " bytes from accelerometer"; | |
358 return; | |
359 } | |
360 // TODO(jonross): Legacy parsing | |
361 } else { | |
362 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { | |
363 if (!configuration_.has[i]) | |
364 continue; | |
365 bytes_read = base::ReadFile(base::FilePath(kAccelerometerDevicePath) | |
366 .Append(configuration_.device_path[i]), | |
367 reading, configuration_.device_length[i]); | |
368 if (bytes_read < static_cast<int>(configuration_.device_length[i])) { | |
369 LOG(ERROR) << "Acceleromter Read " << bytes_read | |
370 << " byte(s), expected " << configuration_.device_length[i] | |
371 << " bytes from accelerometer"; | |
372 continue; | |
373 } | |
374 | |
375 int16* values = reinterpret_cast<int16*>(reading); | |
376 update_->Set( | |
377 static_cast<AccelerometerSource>(i), | |
378 values[configuration_.index[i][0]] * configuration_.scale[i][0], | |
379 values[configuration_.index[i][1]] * configuration_.scale[i][1], | |
380 values[configuration_.index[i][2]] * configuration_.scale[i][2]); | |
381 } | |
311 } | 382 } |
312 | |
313 update_ = new AccelerometerUpdate(); | |
314 | |
315 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { | |
316 if (!configuration_.has[i]) | |
317 continue; | |
318 | |
319 int16* values = reinterpret_cast<int16*>(reading); | |
320 update_->Set( | |
321 static_cast<AccelerometerSource>(i), | |
322 values[configuration_.index[i][0]] * configuration_.scale[i][0], | |
323 values[configuration_.index[i][1]] * configuration_.scale[i][1], | |
324 values[configuration_.index[i][2]] * configuration_.scale[i][2]); | |
325 } | |
326 | |
327 observers_->Notify(FROM_HERE, | 383 observers_->Notify(FROM_HERE, |
328 &AccelerometerReader::Observer::OnAccelerometerUpdated, | 384 &AccelerometerReader::Observer::OnAccelerometerUpdated, |
329 update_); | 385 update_); |
330 } | 386 } |
331 | 387 |
332 AccelerometerFileReader::ConfigurationData::ConfigurationData() : count(0) { | 388 AccelerometerFileReader::ConfigurationData::ConfigurationData() |
389 : count(0), read_device_separately(false) { | |
333 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { | 390 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { |
334 has[i] = false; | 391 has[i] = false; |
335 for (int j = 0; j < 3; ++j) { | 392 for (int j = 0; j < 3; ++j) { |
336 scale[i][j] = 0; | 393 scale[i][j] = 0; |
337 index[i][j] = -1; | 394 index[i][j] = -1; |
338 } | 395 } |
339 } | 396 } |
340 } | 397 } |
341 | 398 |
342 AccelerometerFileReader::ConfigurationData::~ConfigurationData() { | 399 AccelerometerFileReader::ConfigurationData::~ConfigurationData() { |
(...skipping 24 matching lines...) Expand all Loading... | |
367 } | 424 } |
368 | 425 |
369 AccelerometerReader::AccelerometerReader() | 426 AccelerometerReader::AccelerometerReader() |
370 : accelerometer_file_reader_(new AccelerometerFileReader()) { | 427 : accelerometer_file_reader_(new AccelerometerFileReader()) { |
371 } | 428 } |
372 | 429 |
373 AccelerometerReader::~AccelerometerReader() { | 430 AccelerometerReader::~AccelerometerReader() { |
374 } | 431 } |
375 | 432 |
376 } // namespace chromeos | 433 } // namespace chromeos |
OLD | NEW |