accelerometer_file_reader.cc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. // Copyright 2020 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. #include "ash/accelerometer/accelerometer_file_reader.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/accelerometer/accelerometer_constants.h"
  10. #include "ash/public/cpp/tablet_mode_observer.h"
  11. #include "ash/shell.h"
  12. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  13. #include "base/bind.h"
  14. #include "base/files/file_enumerator.h"
  15. #include "base/files/file_util.h"
  16. #include "base/location.h"
  17. #include "base/memory/singleton.h"
  18. #include "base/numerics/math_constants.h"
  19. #include "base/strings/string_number_conversions.h"
  20. #include "base/strings/string_util.h"
  21. #include "base/strings/stringprintf.h"
  22. #include "base/system/sys_info.h"
  23. #include "base/task/current_thread.h"
  24. #include "base/task/sequenced_task_runner.h"
  25. #include "base/task/task_runner.h"
  26. #include "base/task/task_runner_util.h"
  27. #include "base/task/task_traits.h"
  28. #include "base/task/thread_pool.h"
  29. #include "base/threading/platform_thread.h"
  30. #include "base/threading/sequenced_task_runner_handle.h"
  31. #include "base/threading/thread_task_runner_handle.h"
  32. namespace ash {
  33. namespace {
  34. // Paths to access necessary data from the accelerometer device.
  35. constexpr base::FilePath::CharType kAccelerometerDevicePath[] =
  36. FILE_PATH_LITERAL("/dev/cros-ec-accel");
  37. constexpr base::FilePath::CharType kAccelerometerIioBasePath[] =
  38. FILE_PATH_LITERAL("/sys/bus/iio/devices/");
  39. // Paths to ChromeOS EC lid angle driver.
  40. constexpr base::FilePath::CharType kECLidAngleDriverPath[] =
  41. FILE_PATH_LITERAL("/sys/bus/platform/drivers/cros-ec-lid-angle/");
  42. // Trigger created by accelerometer-init.sh to query the sensors.
  43. constexpr char kTriggerPrefix[] = "trigger";
  44. constexpr char kTriggerName[] = "sysfstrig0\n";
  45. // Sysfs entry to trigger readings.
  46. constexpr base::FilePath::CharType kTriggerNow[] = "trigger_now";
  47. // This is the per source scale file in use on kernels older than 3.18. We
  48. // should remove this when all devices having accelerometers are on kernel 3.18
  49. // or later or have been patched to use new format: http://crbug.com/510831
  50. constexpr base::FilePath::CharType kLegacyScaleNameFormatString[] =
  51. "in_accel_%s_scale";
  52. // File within kAccelerometerDevicePath/device* which denotes a single scale to
  53. // be used across all axes.
  54. constexpr base::FilePath::CharType kAccelerometerScaleFileName[] = "scale";
  55. // File within kAccelerometerDevicePath/device* which denotes the
  56. // AccelerometerSource for the accelerometer.
  57. constexpr base::FilePath::CharType kAccelerometerLocationFileName[] =
  58. "location";
  59. // The filename giving the path to read the scan index of each accelerometer
  60. // axis.
  61. constexpr char kLegacyAccelerometerScanIndexPathFormatString[] =
  62. "scan_elements/in_accel_%s_%s_index";
  63. // The filename giving the path to read the scan index of each accelerometer
  64. // when they are separate device paths.
  65. constexpr char kAccelerometerScanIndexPathFormatString[] =
  66. "scan_elements/in_accel_%s_index";
  67. // The axes on each accelerometer. The order was changed on kernel 3.18+.
  68. constexpr char kAccelerometerAxes[][2] = {"x", "y", "z"};
  69. constexpr char kLegacyAccelerometerAxes[][2] = {"y", "x", "z"};
  70. // The length required to read uint values from configuration files.
  71. constexpr size_t kMaxAsciiUintLength = 21;
  72. // The size of individual values.
  73. constexpr size_t kDataSize = 2;
  74. // The size of data in one reading of the accelerometers.
  75. constexpr int kSizeOfReading = kDataSize * kNumberOfAxes;
  76. // The time to wait between reading the accelerometer.
  77. constexpr base::TimeDelta kDelayBetweenReads = base::Milliseconds(100);
  78. // The TimeDelta before giving up on initialization. This is needed because the
  79. // sensor hub might not be online when the Initialize function is called.
  80. constexpr base::TimeDelta kInitializeTimeout = base::Seconds(5);
  81. // The time between initialization checks.
  82. constexpr base::TimeDelta kDelayBetweenInitChecks = base::Milliseconds(500);
  83. // Reads |path| to the unsigned int pointed to by |value|. Returns true on
  84. // success or false on failure.
  85. bool ReadFileToInt(const base::FilePath& path, int* value) {
  86. std::string s;
  87. DCHECK(value);
  88. if (!base::ReadFileToStringWithMaxSize(path, &s, kMaxAsciiUintLength))
  89. return false;
  90. base::TrimWhitespaceASCII(s, base::TRIM_ALL, &s);
  91. if (!base::StringToInt(s, value)) {
  92. LOG(ERROR) << "Failed to parse int \"" << s << "\" from " << path.value();
  93. return false;
  94. }
  95. return true;
  96. }
  97. // Reads |path| to the double pointed to by |value|. Returns true on success or
  98. // false on failure.
  99. bool ReadFileToDouble(const base::FilePath& path, double* value) {
  100. std::string s;
  101. DCHECK(value);
  102. if (!base::ReadFileToString(path, &s))
  103. return false;
  104. base::TrimWhitespaceASCII(s, base::TRIM_ALL, &s);
  105. if (!base::StringToDouble(s, value)) {
  106. LOG(ERROR) << "Failed to parse double \"" << s << "\" from "
  107. << path.value();
  108. return false;
  109. }
  110. return true;
  111. }
  112. } // namespace
  113. AccelerometerFileReader::AccelerometerFileReader() = default;
  114. void AccelerometerFileReader::PrepareAndInitialize() {
  115. DCHECK(base::CurrentUIThread::IsSet());
  116. DETACH_FROM_SEQUENCE(sequence_checker_);
  117. // AccelerometerReader is important for screen orientation so we need
  118. // USER_VISIBLE priority.
  119. // Use CONTINUE_ON_SHUTDOWN to avoid blocking shutdown since the datareading
  120. // could get blocked on certain devices. See https://crbug.com/1023989.
  121. blocking_task_runner_ = base::ThreadPool::CreateSequencedTaskRunner(
  122. {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
  123. base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN});
  124. initialization_state_ = State::INITIALIZING;
  125. initialization_timeout_ = base::TimeTicks::Now() + kInitializeTimeout;
  126. TryScheduleInitialize();
  127. }
  128. void AccelerometerFileReader::TriggerRead() {
  129. DCHECK(base::CurrentUIThread::IsSet());
  130. switch (initialization_state_) {
  131. case State::SUCCESS:
  132. if (GetECLidAngleDriverStatus() == ECLidAngleDriverStatus::SUPPORTED) {
  133. blocking_task_runner_->PostTask(
  134. FROM_HERE,
  135. base::BindOnce(&AccelerometerFileReader::EnableAccelerometerReading,
  136. this));
  137. }
  138. break;
  139. case State::FAILED:
  140. LOG(ERROR) << "Failed to initialize for accelerometer read.\n";
  141. break;
  142. case State::INITIALIZING:
  143. ui_task_runner_->PostNonNestableDelayedTask(
  144. FROM_HERE,
  145. base::BindOnce(&AccelerometerFileReader::TriggerRead, this),
  146. kDelayBetweenInitChecks);
  147. break;
  148. }
  149. }
  150. void AccelerometerFileReader::CancelRead() {
  151. DCHECK(base::CurrentUIThread::IsSet());
  152. if (initialization_state_ == State::SUCCESS &&
  153. GetECLidAngleDriverStatus() == ECLidAngleDriverStatus::SUPPORTED) {
  154. blocking_task_runner_->PostTask(
  155. FROM_HERE,
  156. base::BindOnce(&AccelerometerFileReader::DisableAccelerometerReading,
  157. this));
  158. }
  159. }
  160. AccelerometerFileReader::InitializationResult::InitializationResult()
  161. : initialization_state(State::INITIALIZING),
  162. ec_lid_angle_driver_status(ECLidAngleDriverStatus::UNKNOWN) {}
  163. AccelerometerFileReader::InitializationResult::~InitializationResult() =
  164. default;
  165. AccelerometerFileReader::ReadingData::ReadingData() = default;
  166. AccelerometerFileReader::ReadingData::ReadingData(const ReadingData&) = default;
  167. AccelerometerFileReader::ReadingData::~ReadingData() = default;
  168. AccelerometerFileReader::ConfigurationData::ConfigurationData() : count(0) {
  169. for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) {
  170. has[i] = false;
  171. for (int j = 0; j < 3; ++j) {
  172. scale[i][j] = 0;
  173. index[i][j] = -1;
  174. }
  175. }
  176. }
  177. AccelerometerFileReader::ConfigurationData::~ConfigurationData() = default;
  178. AccelerometerFileReader::~AccelerometerFileReader() = default;
  179. void AccelerometerFileReader::TryScheduleInitialize() {
  180. DCHECK(base::CurrentUIThread::IsSet());
  181. DCHECK(blocking_task_runner_);
  182. // Asynchronously detect and initialize the accelerometer to avoid delaying
  183. // startup.
  184. blocking_task_runner_->PostTaskAndReplyWithResult(
  185. FROM_HERE,
  186. base::BindOnce(&AccelerometerFileReader::InitializeInternal, this),
  187. base::BindOnce(
  188. &AccelerometerFileReader::SetStatesWithInitializationResult, this));
  189. }
  190. AccelerometerFileReader::InitializationResult
  191. AccelerometerFileReader::InitializeInternal() {
  192. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  193. // Log the warning/error messages only in the first initialization to prevent
  194. // spamming during the retries of initialization.
  195. static bool first_initialization_ = true;
  196. InitializationResult result;
  197. // Check for accelerometer symlink which will be created by the udev rules
  198. // file on detecting the device.
  199. if (base::IsDirectoryEmpty(base::FilePath(kAccelerometerDevicePath))) {
  200. if (base::SysInfo::IsRunningOnChromeOS()) {
  201. if (first_initialization_) {
  202. LOG(WARNING) << "Accelerometer device directory is empty at "
  203. << kAccelerometerDevicePath;
  204. }
  205. first_initialization_ = false;
  206. return result;
  207. }
  208. result.initialization_state = State::FAILED;
  209. return result;
  210. }
  211. // Find trigger to use:
  212. base::FileEnumerator trigger_dir(base::FilePath(kAccelerometerIioBasePath),
  213. false, base::FileEnumerator::DIRECTORIES);
  214. std::string prefix = kTriggerPrefix;
  215. for (base::FilePath name = trigger_dir.Next(); !name.empty();
  216. name = trigger_dir.Next()) {
  217. if (name.BaseName().value().substr(0, prefix.size()) != prefix)
  218. continue;
  219. std::string trigger_name;
  220. if (!base::ReadFileToString(name.Append("name"), &trigger_name)) {
  221. if (base::SysInfo::IsRunningOnChromeOS()) {
  222. LOG(WARNING) << "Unable to read the trigger name at " << name.value();
  223. }
  224. continue;
  225. }
  226. if (trigger_name == kTriggerName) {
  227. base::FilePath trigger_now = name.Append(kTriggerNow);
  228. if (!base::PathExists(trigger_now)) {
  229. if (base::SysInfo::IsRunningOnChromeOS()) {
  230. LOG(ERROR) << "Accelerometer trigger does not exist at "
  231. << trigger_now.value();
  232. }
  233. result.initialization_state = State::FAILED;
  234. return result;
  235. } else {
  236. configuration_.trigger_now = trigger_now;
  237. break;
  238. }
  239. }
  240. }
  241. if (configuration_.trigger_now.empty()) {
  242. if (base::SysInfo::IsRunningOnChromeOS()) {
  243. if (first_initialization_)
  244. LOG(ERROR) << "Accelerometer trigger not found";
  245. first_initialization_ = false;
  246. return result;
  247. }
  248. result.initialization_state = State::FAILED;
  249. return result;
  250. }
  251. base::FileEnumerator symlink_dir(base::FilePath(kAccelerometerDevicePath),
  252. false, base::FileEnumerator::FILES);
  253. bool legacy_cross_accel = false;
  254. for (base::FilePath name = symlink_dir.Next(); !name.empty();
  255. name = symlink_dir.Next()) {
  256. base::FilePath iio_device;
  257. if (!base::ReadSymbolicLink(name, &iio_device)) {
  258. LOG(ERROR) << "Failed to read symbolic link " << kAccelerometerDevicePath
  259. << "/" << name.MaybeAsASCII() << "\n";
  260. result.initialization_state = State::FAILED;
  261. return result;
  262. }
  263. base::FilePath iio_path(base::FilePath(kAccelerometerIioBasePath)
  264. .Append(iio_device.BaseName()));
  265. std::string location;
  266. legacy_cross_accel = !base::ReadFileToString(
  267. base::FilePath(iio_path).Append(kAccelerometerLocationFileName),
  268. &location);
  269. if (legacy_cross_accel) {
  270. if (!InitializeLegacyAccelerometers(iio_path, name)) {
  271. result.initialization_state = State::FAILED;
  272. return result;
  273. }
  274. } else {
  275. base::TrimWhitespaceASCII(location, base::TRIM_ALL, &location);
  276. if (!InitializeAccelerometer(iio_path, name, location)) {
  277. result.initialization_state = State::FAILED;
  278. return result;
  279. }
  280. }
  281. }
  282. // Verify indices are within bounds.
  283. for (int i = 0; i < ACCELEROMETER_SOURCE_COUNT; ++i) {
  284. if (!configuration_.has[i])
  285. continue;
  286. for (int j = 0; j < 3; ++j) {
  287. if (configuration_.index[i][j] < 0 ||
  288. configuration_.index[i][j] >=
  289. 3 * static_cast<int>(configuration_.count)) {
  290. const char* axis = legacy_cross_accel ? kLegacyAccelerometerAxes[j]
  291. : kAccelerometerAxes[j];
  292. LOG(ERROR) << "Field index for " << kLocationStrings[i] << " " << axis
  293. << " axis out of bounds.";
  294. result.initialization_state = State::FAILED;
  295. return result;
  296. }
  297. }
  298. }
  299. result.initialization_state = State::SUCCESS;
  300. result.ec_lid_angle_driver_status =
  301. (base::SysInfo::IsRunningOnChromeOS() &&
  302. !base::IsDirectoryEmpty(base::FilePath(kECLidAngleDriverPath)))
  303. ? ECLidAngleDriverStatus::SUPPORTED
  304. : ECLidAngleDriverStatus::NOT_SUPPORTED;
  305. return result;
  306. }
  307. void AccelerometerFileReader::SetStatesWithInitializationResult(
  308. InitializationResult result) {
  309. DCHECK(base::CurrentUIThread::IsSet());
  310. initialization_state_ = result.initialization_state;
  311. switch (initialization_state_) {
  312. case State::INITIALIZING:
  313. // If we haven't yet passed the timeout cutoff, try this again. This will
  314. // be scheduled at the same rate as reading.
  315. if (base::TimeTicks::Now() < initialization_timeout_) {
  316. ui_task_runner_->PostDelayedTask(
  317. FROM_HERE,
  318. base::BindOnce(&AccelerometerFileReader::TryScheduleInitialize,
  319. this),
  320. kDelayBetweenReads);
  321. } else {
  322. LOG(ERROR) << "Failed to initialize for accelerometer read.\n";
  323. initialization_state_ = State::FAILED;
  324. }
  325. break;
  326. case State::SUCCESS:
  327. DCHECK_NE(result.ec_lid_angle_driver_status,
  328. ECLidAngleDriverStatus::UNKNOWN);
  329. SetECLidAngleDriverStatus(result.ec_lid_angle_driver_status);
  330. if (GetECLidAngleDriverStatus() ==
  331. ECLidAngleDriverStatus::NOT_SUPPORTED) {
  332. // If ChromeOS lid angle driver is not present, start accelerometer read
  333. // and read is always on.
  334. blocking_task_runner_->PostTask(
  335. FROM_HERE,
  336. base::BindOnce(&AccelerometerFileReader::EnableAccelerometerReading,
  337. this));
  338. }
  339. break;
  340. case State::FAILED:
  341. break;
  342. default:
  343. LOG(FATAL) << "Unexpected state: "
  344. << static_cast<int>(initialization_state_);
  345. break;
  346. }
  347. }
  348. bool AccelerometerFileReader::InitializeAccelerometer(
  349. const base::FilePath& iio_path,
  350. const base::FilePath& name,
  351. const std::string& location) {
  352. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  353. size_t config_index = 0;
  354. for (; config_index < std::size(kLocationStrings); ++config_index) {
  355. if (location == kLocationStrings[config_index])
  356. break;
  357. }
  358. if (config_index >= std::size(kLocationStrings)) {
  359. LOG(ERROR) << "Unrecognized location: " << location << " for device "
  360. << name.MaybeAsASCII() << "\n";
  361. return false;
  362. }
  363. double scale;
  364. if (!ReadFileToDouble(iio_path.Append(kAccelerometerScaleFileName), &scale))
  365. return false;
  366. const int kNumberAxes = std::size(kAccelerometerAxes);
  367. for (size_t i = 0; i < kNumberAxes; ++i) {
  368. std::string accelerometer_index_path = base::StringPrintf(
  369. kAccelerometerScanIndexPathFormatString, kAccelerometerAxes[i]);
  370. if (!ReadFileToInt(iio_path.Append(accelerometer_index_path.c_str()),
  371. &(configuration_.index[config_index][i]))) {
  372. LOG(ERROR) << "Index file " << accelerometer_index_path
  373. << " could not be parsed\n";
  374. return false;
  375. }
  376. configuration_.scale[config_index][i] = scale;
  377. }
  378. configuration_.has[config_index] = true;
  379. configuration_.count++;
  380. ReadingData reading_data;
  381. reading_data.path =
  382. base::FilePath(kAccelerometerDevicePath).Append(name.BaseName());
  383. reading_data.sources.push_back(
  384. static_cast<AccelerometerSource>(config_index));
  385. configuration_.reading_data.push_back(reading_data);
  386. return true;
  387. }
  388. bool AccelerometerFileReader::InitializeLegacyAccelerometers(
  389. const base::FilePath& iio_path,
  390. const base::FilePath& name) {
  391. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  392. ReadingData reading_data;
  393. reading_data.path =
  394. base::FilePath(kAccelerometerDevicePath).Append(name.BaseName());
  395. // Read configuration of each accelerometer axis from each accelerometer from
  396. // /sys/bus/iio/devices/iio:deviceX/.
  397. for (size_t i = 0; i < std::size(kLocationStrings); ++i) {
  398. configuration_.has[i] = false;
  399. // Read scale of accelerometer.
  400. std::string accelerometer_scale_path =
  401. base::StringPrintf(kLegacyScaleNameFormatString, kLocationStrings[i]);
  402. // Read the scale for all axes.
  403. int scale_divisor = 0;
  404. if (!ReadFileToInt(iio_path.Append(accelerometer_scale_path.c_str()),
  405. &scale_divisor)) {
  406. continue;
  407. }
  408. if (scale_divisor == 0) {
  409. LOG(ERROR) << "Accelerometer " << accelerometer_scale_path
  410. << "has scale of 0 and will not be used.";
  411. continue;
  412. }
  413. configuration_.has[i] = true;
  414. for (size_t j = 0; j < std::size(kLegacyAccelerometerAxes); ++j) {
  415. configuration_.scale[i][j] = base::kMeanGravityFloat / scale_divisor;
  416. std::string accelerometer_index_path =
  417. base::StringPrintf(kLegacyAccelerometerScanIndexPathFormatString,
  418. kLegacyAccelerometerAxes[j], kLocationStrings[i]);
  419. if (!ReadFileToInt(iio_path.Append(accelerometer_index_path.c_str()),
  420. &(configuration_.index[i][j]))) {
  421. configuration_.has[i] = false;
  422. LOG(ERROR) << "Index file " << accelerometer_index_path
  423. << " could not be parsed\n";
  424. return false;
  425. }
  426. }
  427. if (configuration_.has[i]) {
  428. configuration_.count++;
  429. reading_data.sources.push_back(static_cast<AccelerometerSource>(i));
  430. }
  431. }
  432. // Adjust the directions of accelerometers to match the AccelerometerUpdate
  433. // type specified in ash/accelerometer/accelerometer_types.h.
  434. configuration_.scale[ACCELEROMETER_SOURCE_SCREEN][1] *= -1.0f;
  435. configuration_.scale[ACCELEROMETER_SOURCE_SCREEN][2] *= -1.0f;
  436. configuration_.reading_data.push_back(reading_data);
  437. return true;
  438. }
  439. void AccelerometerFileReader::EnableAccelerometerReading() {
  440. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  441. if (read_refresh_timer_.IsRunning())
  442. return;
  443. read_refresh_timer_.Start(FROM_HERE, kDelayBetweenReads, this,
  444. &AccelerometerFileReader::ReadSample);
  445. }
  446. void AccelerometerFileReader::DisableAccelerometerReading() {
  447. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  448. read_refresh_timer_.Stop();
  449. }
  450. void AccelerometerFileReader::ReadSample() {
  451. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  452. // Initiate the trigger to read accelerometers simultaneously.
  453. int bytes_written = base::WriteFile(configuration_.trigger_now, "1\n", 2);
  454. if (bytes_written < 2) {
  455. PLOG(ERROR) << "Accelerometer trigger failure: " << bytes_written;
  456. return;
  457. }
  458. // Read resulting sample from /dev/cros-ec-accel.
  459. AccelerometerUpdate update;
  460. for (auto reading_data : configuration_.reading_data) {
  461. int reading_size = reading_data.sources.size() * kSizeOfReading;
  462. DCHECK_GT(reading_size, 0);
  463. char reading[reading_size];
  464. int bytes_read = base::ReadFile(reading_data.path, reading, reading_size);
  465. if (bytes_read < reading_size) {
  466. // Dynamically throttle error logging as this can be called many times
  467. // every second if path is consistently inaccessible.
  468. static uint64_t sLogCount = 1U;
  469. static uint64_t sLogThrottle = 1U;
  470. if ((sLogCount ^ sLogThrottle) == 0) {
  471. LOG(ERROR) << "Accelerometer Read " << bytes_read
  472. << " byte(s), expected " << reading_size
  473. << " bytes from accelerometer "
  474. << reading_data.path.MaybeAsASCII();
  475. sLogThrottle *= 2U;
  476. }
  477. sLogCount++;
  478. return;
  479. }
  480. for (AccelerometerSource source : reading_data.sources) {
  481. DCHECK(configuration_.has[source]);
  482. int16_t* values = reinterpret_cast<int16_t*>(reading);
  483. update.Set(source,
  484. values[configuration_.index[source][0]] *
  485. configuration_.scale[source][0],
  486. values[configuration_.index[source][1]] *
  487. configuration_.scale[source][1],
  488. values[configuration_.index[source][2]] *
  489. configuration_.scale[source][2]);
  490. }
  491. }
  492. ui_task_runner_->PostTask(
  493. FROM_HERE,
  494. base::BindOnce(&AccelerometerFileReader::NotifyAccelerometerUpdated, this,
  495. update));
  496. }
  497. } // namespace ash