| 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_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // File within the device in kAccelerometerIioBasePath containing the scale of | 33 // File within the device in kAccelerometerIioBasePath containing the scale of |
| 34 // the accelerometers. | 34 // the accelerometers. |
| 35 const base::FilePath::CharType kScaleNameFormatString[] = "in_accel_%s_scale"; | 35 const base::FilePath::CharType kScaleNameFormatString[] = "in_accel_%s_scale"; |
| 36 | 36 |
| 37 // The filename giving the path to read the scan index of each accelerometer | 37 // The filename giving the path to read the scan index of each accelerometer |
| 38 // axis. | 38 // axis. |
| 39 const char kAccelerometerScanIndexPath[] = | 39 const char kAccelerometerScanIndexPath[] = |
| 40 "scan_elements/in_accel_%s_%s_index"; | 40 "scan_elements/in_accel_%s_%s_index"; |
| 41 | 41 |
| 42 // The names of the accelerometers. Matches up with the enum AccelerometerSource | 42 // The names of the accelerometers. Matches up with the enum AccelerometerSource |
| 43 // in ui/accelerometer/accelerometer_types.h. | 43 // in chromeos/accelerometer/accelerometer_types.h. |
| 44 const char kAccelerometerNames[ACCELEROMETER_SOURCE_COUNT][5] = {"lid", "base"}; | 44 const char kAccelerometerNames[ACCELEROMETER_SOURCE_COUNT][5] = {"lid", "base"}; |
| 45 | 45 |
| 46 // The axes on each accelerometer. | 46 // The axes on each accelerometer. |
| 47 const char kAccelerometerAxes[][2] = {"y", "x", "z"}; | 47 const char kAccelerometerAxes[][2] = {"y", "x", "z"}; |
| 48 | 48 |
| 49 // The length required to read uint values from configuration files. | 49 // The length required to read uint values from configuration files. |
| 50 const size_t kMaxAsciiUintLength = 21; | 50 const size_t kMaxAsciiUintLength = 21; |
| 51 | 51 |
| 52 // The size of individual values. | 52 // The size of individual values. |
| 53 const size_t kDataSize = 2; | 53 const size_t kDataSize = 2; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 kAccelerometerScanIndexPath, kAccelerometerAxes[j], | 113 kAccelerometerScanIndexPath, kAccelerometerAxes[j], |
| 114 kAccelerometerNames[i]); | 114 kAccelerometerNames[i]); |
| 115 if (!ReadFileToInt(iio_path.Append(accelerometer_index_path.c_str()), | 115 if (!ReadFileToInt(iio_path.Append(accelerometer_index_path.c_str()), |
| 116 &(configuration->data.index[i][j]))) { | 116 &(configuration->data.index[i][j]))) { |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Adjust the directions of accelerometers to match the AccelerometerUpdate | 122 // Adjust the directions of accelerometers to match the AccelerometerUpdate |
| 123 // type specified in ui/accelerometer/accelerometer_types.h. | 123 // type specified in chromeos/accelerometer/accelerometer_types.h. |
| 124 configuration->data.scale[ACCELEROMETER_SOURCE_SCREEN][0] *= -1.0f; | 124 configuration->data.scale[ACCELEROMETER_SOURCE_SCREEN][0] *= -1.0f; |
| 125 for (int i = 0; i < 3; ++i) { | 125 for (int i = 0; i < 3; ++i) { |
| 126 configuration->data.scale[ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD][i] *= | 126 configuration->data.scale[ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD][i] *= |
| 127 -1.0f; | 127 -1.0f; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Verify indices are within bounds. | 130 // Verify indices are within bounds. |
| 131 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { | 131 for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) { |
| 132 if (!configuration->data.has[i]) | 132 if (!configuration->data.has[i]) |
| 133 continue; | 133 continue; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 // Trigger another read after the current sampling delay. | 264 // Trigger another read after the current sampling delay. |
| 265 base::MessageLoop::current()->PostDelayedTask( | 265 base::MessageLoop::current()->PostDelayedTask( |
| 266 FROM_HERE, | 266 FROM_HERE, |
| 267 base::Bind(&AccelerometerReader::TriggerRead, | 267 base::Bind(&AccelerometerReader::TriggerRead, |
| 268 weak_factory_.GetWeakPtr()), | 268 weak_factory_.GetWeakPtr()), |
| 269 base::TimeDelta::FromMilliseconds(kDelayBetweenReadsMs)); | 269 base::TimeDelta::FromMilliseconds(kDelayBetweenReadsMs)); |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace chromeos | 272 } // namespace chromeos |
| OLD | NEW |