#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "device/gamepad/dualshock4_controller.h"
#include <algorithm>
#include <array>
#include "base/containers/span.h"
#include "base/metrics/crc32.h"
#include "base/numerics/safe_conversions.h"
#include "device/gamepad/gamepad_data_fetcher.h"
#include "device/gamepad/gamepad_id_list.h"
#include "device/gamepad/hid_writer.h"
#include "device/gamepad/public/cpp/gamepad_features.h"
namespace device {
namespace {
const uint16_t kDualshock4VersionUsb = …;
const uint16_t kDualshock4VersionBluetooth = …;
constexpr uint8_t kReportId01 = …;
constexpr uint8_t kReportId05 = …;
constexpr uint8_t kReportId11 = …;
const uint8_t kRumbleMagnitudeMax = …;
const float kAxisMax = …;
const float kDpadMax = …;
constexpr uint16_t kTouchDimensionX = …;
constexpr uint16_t kTouchDimensionY = …;
struct ControllerData { … } ABSL_ATTRIBUTE_PACKED;
static_assert …;
struct TouchData { … };
static_assert …;
struct TouchPadData { … };
static_assert …;
struct Dualshock4InputReportUsb { … };
static_assert …;
struct Dualshock4InputReportBluetooth { … } ABSL_ATTRIBUTE_PACKED;
static_assert …;
uint32_t ComputeDualshock4Checksum(base::span<const uint8_t> report_data) { … }
static float NormalizeAxis(uint8_t value) { … }
static float NormalizeDpad(uint8_t value) { … }
float NormalizeTouch(uint32_t value, uint32_t min, uint32_t max) { … }
void ReadTouchCoordinates(base::span<const uint8_t> ds4_touch_data_span,
GamepadTouch& touch) { … }
template <typename Transform>
void ProcessTouchData(base::span<const TouchPadData> touchpad_data,
Transform& id_transform,
std::optional<uint32_t>& initial_touch_id,
Gamepad* pad) { … }
void ProcessAxisButtonData(const ControllerData& controller_data,
Gamepad* pad) { … }
}
template <typename ExtendedType, typename BaseType>
ExtendedType
Dualshock4Controller::ExtendedCounter<ExtendedType, BaseType>::operator()(
BaseType num,
ExtendedCounter const* other) { … }
Dualshock4Controller::Dualshock4Controller(GamepadId gamepad_id,
GamepadBusType bus_type,
std::unique_ptr<HidWriter> writer)
: … { … }
Dualshock4Controller::~Dualshock4Controller() = default;
bool Dualshock4Controller::IsDualshock4(GamepadId gamepad_id) { … }
GamepadBusType Dualshock4Controller::BusTypeFromVersionNumber(
uint32_t version_number) { … }
void Dualshock4Controller::DoShutdown() { … }
bool Dualshock4Controller::ProcessInputReport(uint8_t report_id,
base::span<const uint8_t> report,
Gamepad* pad,
bool ignore_button_axis,
bool is_multitouch_enabled) { … }
void Dualshock4Controller::SetVibration(
mojom::GamepadEffectParametersPtr params) { … }
void Dualshock4Controller::SetVibrationUsb(double strong_magnitude,
double weak_magnitude) { … }
void Dualshock4Controller::SetVibrationBluetooth(double strong_magnitude,
double weak_magnitude) { … }
base::WeakPtr<AbstractHapticGamepad> Dualshock4Controller::GetWeakPtr() { … }
}