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

Unified Diff: athena/system/orientation_controller.cc

Issue 576113002: Reland "Use chromeos accelerometer reader and support only lid accelerometer. (patchset #3 id:60001… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile. Created 6 years, 3 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
« no previous file with comments | « athena/system/orientation_controller.h ('k') | athena/system/system_ui_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: athena/system/orientation_controller.cc
diff --git a/athena/system/orientation_controller.cc b/athena/system/orientation_controller.cc
index a4dfa1ce87997bd4a53ed11ec83d97cc4c625ce8..93d0bf10023ec850f1f47670847efee5e4a0c184 100644
--- a/athena/system/orientation_controller.cc
+++ b/athena/system/orientation_controller.cc
@@ -14,112 +14,34 @@ namespace athena {
namespace {
-// Path of the socket which the sensor daemon creates.
-const char kSocketPath[] = "/dev/sensors/orientation";
-
// Threshold after which to rotate in a given direction.
const int kGravityThreshold = 6.0f;
-// Minimum delay before triggering another orientation change.
-const int kOrientationChangeDelayNS = 500000000;
-
-enum SensorType {
- SENSOR_ACCELEROMETER,
- SENSOR_LIGHT,
- SENSOR_PROXIMITY
-};
-
-// A sensor event from the device.
-struct DeviceSensorEvent {
- // The type of event from the SensorType enum above.
- int32_t type;
-
- // The time in nanoseconds at which the event happened.
- int64_t timestamp;
-
- union {
- // Accelerometer X,Y,Z values in SI units (m/s^2) including gravity.
- // The orientation is described at
- // http://www.html5rocks.com/en/tutorials/device/orientation/.
- float data[3];
-
- // Ambient (room) temperature in degrees Celcius.
- float temperature;
-
- // Proximity sensor distance in centimeters.
- float distance;
-
- // Ambient light level in SI lux units.
- float light;
- };
-};
-
} // namespace
-OrientationController::OrientationController()
- : DeviceSocketListener(kSocketPath, sizeof(DeviceSensorEvent)),
- last_orientation_change_time_(0),
- shutdown_(false) {
- CHECK(base::MessageLoopForUI::current());
- ui_task_runner_ = base::MessageLoopForUI::current()->task_runner();
+OrientationController::OrientationController() {
}
void OrientationController::InitWith(
- scoped_refptr<base::TaskRunner> file_task_runner) {
- file_task_runner_ = file_task_runner;
- file_task_runner->PostTask(
- FROM_HERE,
- base::Bind(&OrientationController::WatchForSocketPathOnFILE, this));
+ scoped_refptr<base::TaskRunner> blocking_task_runner) {
+ accelerometer_reader_.reset(
+ new chromeos::AccelerometerReader(blocking_task_runner, this));
}
OrientationController::~OrientationController() {
}
void OrientationController::Shutdown() {
- CHECK(file_task_runner_.get());
- StopListening();
- file_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&OrientationController::ShutdownOnFILE, this));
-}
-
-void OrientationController::ShutdownOnFILE() {
- shutdown_ = true;
- watcher_.reset();
+ accelerometer_reader_.reset();
}
-void OrientationController::WatchForSocketPathOnFILE() {
- CHECK(base::MessageLoopForIO::current());
- if (base::PathExists(base::FilePath(kSocketPath))) {
- ui_task_runner_->PostTask(FROM_HERE,
- base::Bind(&OrientationController::StartListening, this));
- } else {
- watcher_.reset(new base::FilePathWatcher);
- watcher_->Watch(
- base::FilePath(kSocketPath),
- false,
- base::Bind(&OrientationController::OnFilePathChangedOnFILE, this));
- }
-}
-
-void OrientationController::OnFilePathChangedOnFILE(const base::FilePath& path,
- bool error) {
- watcher_.reset();
- if (error || shutdown_)
+void OrientationController::HandleAccelerometerUpdate(
+ const ui::AccelerometerUpdate& update) {
+ if (!update.has(ui::ACCELEROMETER_SOURCE_SCREEN))
return;
- ui_task_runner_->PostTask(FROM_HERE,
- base::Bind(&OrientationController::StartListening, this));
-}
-
-void OrientationController::OnDataAvailableOnFILE(const void* data) {
- const DeviceSensorEvent* event =
- static_cast<const DeviceSensorEvent*>(data);
- if (event->type != SENSOR_ACCELEROMETER)
- return;
-
- float gravity_x = event->data[0];
- float gravity_y = event->data[1];
+ float gravity_x = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).x();
+ float gravity_y = update.get(ui::ACCELEROMETER_SOURCE_SCREEN).y();
gfx::Display::Rotation rotation;
if (gravity_x < -kGravityThreshold) {
rotation = gfx::Display::ROTATE_270;
@@ -134,24 +56,11 @@ void OrientationController::OnDataAvailableOnFILE(const void* data) {
return;
}
- if (rotation == current_rotation_ ||
- event->timestamp - last_orientation_change_time_ <
- kOrientationChangeDelayNS) {
+ if (rotation == current_rotation_)
return;
- }
- last_orientation_change_time_ = event->timestamp;
current_rotation_ = rotation;
- ui_task_runner_->PostTask(FROM_HERE,
- base::Bind(&OrientationController::RotateOnUI, this, rotation));
-}
-
-void OrientationController::RotateOnUI(gfx::Display::Rotation rotation) {
- ScreenManager* screen_manager = ScreenManager::Get();
- // Since this is called from the FILE thread, the screen manager may no longer
- // exist.
- if (screen_manager)
- screen_manager->SetRotation(rotation);
+ ScreenManager::Get()->SetRotation(rotation);
}
} // namespace athena
« no previous file with comments | « athena/system/orientation_controller.h ('k') | athena/system/system_ui_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698