#ifndef DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_
#define DEVICE_GAMEPAD_PUBLIC_CPP_GAMEPAD_H_
#include <stddef.h>
#include <cstdint>
#include <string>
#include <limits>
#include "base/component_export.h"
namespace device {
#pragma pack(push, 4)
class GamepadButton {
public:
static constexpr float kDefaultButtonPressedThreshold = 30.f / 255.f;
GamepadButton() = default;
GamepadButton(bool pressed, bool touched, double value)
: used(true), pressed(pressed), touched(touched), value(value) {}
bool operator==(const GamepadButton& other) const {
return this->used == other.used && this->pressed == other.pressed &&
this->touched == other.touched && this->value == other.value;
}
bool used{false};
bool pressed{false};
bool touched{false};
double value{0.0};
};
enum class GamepadHapticActuatorType {
kVibration = 0,
kDualRumble = 1,
kTriggerRumble = 2
};
enum class GamepadHapticEffectType { kDualRumble = 0 };
enum class GamepadHapticsResult {
kError = 0,
kComplete = 1,
kPreempted = 2,
kInvalidParameter = 3,
kNotSupported = 4
};
struct GamepadTouch {
uint32_t touch_id = 0;
uint8_t surface_id = 0;
bool has_surface_dimensions = false;
float x = 0.0f;
float y = 0.0f;
uint32_t surface_width;
uint32_t surface_height;
};
class GamepadHapticActuator {
public:
static constexpr double kMaxEffectDurationMillis = 5000.0;
GamepadHapticActuator() : not_null(false) {}
bool not_null;
GamepadHapticActuatorType type;
};
class GamepadEffectParameters {
public:
double duration;
double start_delay;
double strong_magnitude;
double weak_magnitude;
};
class GamepadVector {
public:
GamepadVector() : not_null(false) {}
bool not_null;
float x, y, z;
};
class GamepadQuaternion {
public:
GamepadQuaternion() : not_null(false) {}
bool not_null;
float x, y, z, w;
};
class GamepadPose {
public:
GamepadPose() : not_null(false) {}
bool not_null;
bool has_orientation;
bool has_position;
GamepadQuaternion orientation;
GamepadVector position;
GamepadVector angular_velocity;
GamepadVector linear_velocity;
GamepadVector angular_acceleration;
GamepadVector linear_acceleration;
};
enum class GamepadMapping { kNone = 0, kStandard = 1, kXrStandard = 2 };
enum class GamepadHand { kNone = 0, kLeft = 1, kRight = 2 };
class COMPONENT_EXPORT(GAMEPAD_PUBLIC) Gamepad {
public:
static constexpr size_t kIdLengthCap = 128;
static constexpr size_t kAxesLengthCap = 16;
static constexpr size_t kButtonsLengthCap = 32;
static constexpr size_t kTouchEventsLengthCap = 8;
Gamepad();
Gamepad(const Gamepad& other);
Gamepad& operator=(const Gamepad& other);
void SetID(const std::u16string& src);
bool connected;
char16_t id[kIdLengthCap];
int64_t timestamp;
unsigned axes_length;
uint32_t axes_used;
static_assert(Gamepad::kAxesLengthCap <=
std::numeric_limits<uint32_t>::digits,
"axes_used is not large enough");
double axes[kAxesLengthCap];
unsigned buttons_length;
GamepadButton buttons[kButtonsLengthCap];
uint32_t touch_events_length;
bool supports_touch_events_ = false;
GamepadTouch touch_events[kTouchEventsLengthCap];
GamepadHapticActuator vibration_actuator;
GamepadMapping mapping;
GamepadPose pose;
GamepadHand hand;
unsigned display_id;
bool is_xr = false;
};
#pragma pack(pop)
}
#endif