| 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..1b923724d1c02aa46ee9347de1c9d0a70fe20bb9
|
| --- /dev/null
|
| +++ b/chromeos/accelerometer/accelerometer_reader.h
|
| @@ -0,0 +1,84 @@
|
| +// 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 {
|
| +
|
| +// Reads an accelerometer device and reports data back to an
|
| +// AccelerometerDelegate.
|
| +class CHROMEOS_EXPORT AccelerometerReader {
|
| + public:
|
| + // An interface to receive data from the AccelerometerReader.
|
| + class Delegate {
|
| + public:
|
| + virtual void HandleAccelerometerReading(const gfx::Vector3dF& base,
|
| + const gfx::Vector3dF& lid) = 0;
|
| + };
|
| +
|
| + explicit AccelerometerReader(Delegate* delegate);
|
| + ~AccelerometerReader();
|
| +
|
| + private:
|
| + // Detects and reads configuration of the accelerometer device.
|
| + void Initialize();
|
| +
|
| + // Dispatched when initialization is complete. |has_accelerometer_| is true if
|
| + // an accelerometer was detected and all configuration parameters read.
|
| + void OnInitialized();
|
| +
|
| + // Triggers an asynchronous read from the accelerometer, signalling
|
| + // OnDataRead with |read_sucess_| set to true if the read was successful.
|
| + void TriggerRead();
|
| +
|
| + // Triggers the accelerometer and reads the sampled values. Sets
|
| + // |read_success_| to true and |base_reading_| and |lid_reading_| to the
|
| + // read values if successful.
|
| + void ReadAccelerometer();
|
| +
|
| + // If |read_success_|, notifies the |delegate_| with the new readings.
|
| + // Triggers another read from the accelerometer at the current sampling rate.
|
| + void OnDataRead();
|
| +
|
| + // A weak pointer to the delegate to send accelerometer readings to.
|
| + Delegate* 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_;
|
| +
|
| + // Set to false before triggering a read. If the read is successful, set to
|
| + // true by ReadAccelerometer.
|
| + bool read_success_;
|
| +
|
| + // The last readings from the base and lid accelerometers. DO NOT directly
|
| + // read these as they are updated from the blocking thread pool. Instead,
|
| + // only use the values as passed to the |delegate_|.
|
| + // TODO(flackr): Pass the values back from the blocking thread pool to avoid
|
| + // the potential for them to be read while they're being updated.
|
| + gfx::Vector3dF base_reading_;
|
| + gfx::Vector3dF lid_reading_;
|
| +
|
| + base::WeakPtrFactory<AccelerometerReader> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AccelerometerReader);
|
| +};
|
| +
|
| +} // namespace chromeos
|
| +
|
| +#endif // CHROMEOS_ACCELEROMETER_ACCELEROMETER_READER_H_
|
|
|