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

Unified Diff: chromeos/accelerometer/accelerometer_reader.h

Issue 200643005: Read and expose accelerometer values from cros-ec-accel trigger. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments, update to use udev symlink to determine device name. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/accelerometer/accelerometer_reader.h
diff --git a/chromeos/accelerometer/accelerometer_reader.h b/chromeos/accelerometer/accelerometer_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..dc4e5de3fe1c32176d3861a26c732437ae1c2c40
--- /dev/null
+++ b/chromeos/accelerometer/accelerometer_reader.h
@@ -0,0 +1,78 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
+#define CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
+
+#include <vector>
+
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "chromeos/chromeos_export.h"
+#include "ui/gfx/geometry/vector3d_f.h"
+
+namespace chromeos {
+
+// An interface to receive data from the AccelerometerReader.
+class AccelerometerDelegate {
Daniel Erat 2014/03/26 22:26:14 maybe move this be a public internal class of Acce
flackr 2014/03/27 15:21:07 Done.
+ public:
+ virtual void OnAccelerometerRead(const gfx::Vector3dF& base,
+ const gfx::Vector3dF& lid) = 0;
+};
+
+// Reads an accelerometer device and reports data back to an
+// AccelerometerDelegate.
+class CHROMEOS_EXPORT AccelerometerReader {
+ public:
+ AccelerometerReader(AccelerometerDelegate* delegate);
Daniel Erat 2014/03/26 22:26:14 nit: explicit
flackr 2014/03/27 15:21:07 Done.
+ virtual ~AccelerometerReader();
Daniel Erat 2014/03/26 22:26:14 nit: don't need virtual
flackr 2014/03/27 15:21:07 Done.
+
+ private:
+ // Detects and reads configuration of the accelerometer device.
+ bool Initialize();
+
+ // Dispatched when initialization is complete. |success| is true if an
+ // accelerometer was detected and all configuration paramaters read.
Daniel Erat 2014/03/26 22:26:14 nit: s/paramaters/parameters/
flackr 2014/03/27 15:21:07 Done.
+ void OnInitialized(bool success);
+
+ // Triggers an asynchronous read from the accelerometer, signalling
+ // OnDataRead with the result of the read.
+ void TriggerRead();
+
+ // Triggers the accelerometer and reads the sampled values. Returns true if
+ // successful, in which case base_accelerometer_ and lid_accelerometer_
+ // contain the current values.
+ bool ReadAccelerometer();
+
+ // If |success|, notifies the delegate_ with the new readings. Triggers
Daniel Erat 2014/03/26 22:26:14 nit: s/delegate_/|delegate_|/ (also in other comme
flackr 2014/03/27 15:21:07 Done.
+ // another read from the accelerometer at the current sampling rate.
+ void OnDataRead(bool success);
+
+ // A weak pointer to the delegate to send accelerometer readings to.
+ AccelerometerDelegate* delegate_;
+
+ // True after Initialize has run if an accelerometer sensor exists.
+ bool has_accelerometer_;
+
+ // The index of each axis of each accelerometer.
+ std::vector<unsigned int> accelerometer_index_;
+
+ // The scale of the base and lid accelerometers.
+ unsigned int accelerometer_base_scale_;
+ unsigned int accelerometer_lid_scale_;
+
+ // The last reading from the base accelerometer.
+ gfx::Vector3dF base_accelerometer_;
Daniel Erat 2014/03/26 22:26:14 nit: base_reading_? base_value_?
flackr 2014/03/27 15:21:07 Done.
+
+ // The last reading from the lid accelerometer.
+ gfx::Vector3dF lid_accelerometer_;
Daniel Erat 2014/03/26 22:26:14 nit: lid_reading_? lid_value_?
flackr 2014/03/27 15:21:07 Done.
+
+ base::WeakPtrFactory<AccelerometerReader> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AccelerometerReader);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_

Powered by Google App Engine
This is Rietveld 408576698