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

Unified Diff: ui/events/ozone/evdev/gamepad_event_converter_evdev.h

Issue 2805793002: ozone: evdev: Add gamepad support (Closed)
Patch Set: Support Gamepad in Ozone. Created 3 years, 7 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: ui/events/ozone/evdev/gamepad_event_converter_evdev.h
diff --git a/ui/events/ozone/evdev/gamepad_event_converter_evdev.h b/ui/events/ozone/evdev/gamepad_event_converter_evdev.h
new file mode 100644
index 0000000000000000000000000000000000000000..d8d1e619a6a96ca30b4bf074146f41efd01abf13
--- /dev/null
+++ b/ui/events/ozone/evdev/gamepad_event_converter_evdev.h
@@ -0,0 +1,90 @@
+// Copyright 2017 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 UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_
+#define UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_
+
+#include <vector>
+
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "ui/events/devices/input_device.h"
+#include "ui/events/event.h"
+#include "ui/events/ozone/evdev/event_converter_evdev.h"
+#include "ui/events/ozone/evdev/event_device_info.h"
+#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
+#include "ui/events/ozone/evdev/scoped_input_device.h"
+#include "ui/events/ozone/gamepad/gamepad_mapping.h"
+#include "ui/events/ozone/gamepad/webgamepad_constants.h"
+
+struct input_event;
+
+namespace ui {
+
+class DeviceEventDispatcherEvdev;
+
+class EVENTS_OZONE_EVDEV_EXPORT GamepadEventConverterEvdev
+ : public EventConverterEvdev {
+ public:
+ GamepadEventConverterEvdev(ScopedInputDevice fd,
+ base::FilePath path,
+ int id,
+ const EventDeviceInfo& info,
+ DeviceEventDispatcherEvdev* dispatcher);
+
+ ~GamepadEventConverterEvdev() override;
+
+ // EventConverterEvdev:
+ void OnFileCanReadWithoutBlocking(int fd) override;
+ bool HasGamepad() const override;
+ void OnDisabled() override;
+
+ // This function processes one input_event from evdev.
+ void ProcessEvent(const struct input_event& input,
+ const base::TimeTicks& timestamp);
+
+ private:
+ // This function releases all the keys and resets all the axises.
+ void ResetGamepad();
+
+ // This function reads current gamepad status and resyncs the gamepad.
+ void ResyncGamepad();
+
+ void OnButtonChange(unsigned int code,
+ double value,
+ const base::TimeTicks& timestamp);
+ void OnAbsChange(unsigned int code,
+ double value,
+ const base::TimeTicks& timestamp);
+ void OnSync(const base::TimeTicks& timestamp);
+
+ // Sometimes, we want to drop abs values, when we do so, we no longer want to
+ // send gamepad frame event when we see next sync. This flag is set to false
+ // when each frame is sent. It is set to true when Btn or Abs event is sent.
+ bool will_send_frame_;
+
+ // Internal representation of all axis information.
+ class AxisInfos;
+ AxisInfos* axis_infos_;
spang 2017/05/05 15:37:43 Why is this a pointer? You should be able to put t
jkwang 2017/05/05 21:32:57 Putting array here means we need a declaration of
+
+ // These values keeps the state of previous hat.
+ bool last_hat_left_press_;
+ bool last_hat_right_press_;
+ bool last_hat_up_press_;
+ bool last_hat_down_press_;
+
+ GamepadMapper mapper_;
+
+ // Input device file descriptor.
+ ScopedInputDevice input_device_fd_;
+
+ // Callbacks for dispatching events.
+ DeviceEventDispatcherEvdev* dispatcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(GamepadEventConverterEvdev);
+};
+
+} // namespace ui
+
+#endif // UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_

Powered by Google App Engine
This is Rietveld 408576698