chromium/device/gamepad/dualshock4_controller.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#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 {
// Expected values for |version_number| when connected over USB and Bluetooth.
const uint16_t kDualshock4VersionUsb =;
const uint16_t kDualshock4VersionBluetooth =;

// Report IDs.
constexpr uint8_t kReportId01 =;
constexpr uint8_t kReportId05 =;
constexpr uint8_t kReportId11 =;

// Maximum in-range values for HID report fields.
const uint8_t kRumbleMagnitudeMax =;
const float kAxisMax =;
const float kDpadMax =;

// Dualshock 4 touchpad absolute dimension.
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;

// Returns the CRC32 checksum for a Dualshock4 Bluetooth output report.
// |report_data| is the report data excluding the bytes where the checksum will
// be written.
uint32_t ComputeDualshock4Checksum(base::span<const uint8_t> report_data) {}

// Scales |value| with range [0,255] to a float within [-1.0,+1.0].
static float NormalizeAxis(uint8_t value) {}

// Scales a D-pad value from a Dualshock4 report to an axis value. The D-pad
// report value has a logical range from 0 to 7, and uses an out-of-bounds value
// of 8 to indicate null input (no interaction). In-bounds values are scaled to
// the range [-1.0,+1.0]. The null input value returns +9/7 (about 1.29).
static float NormalizeDpad(uint8_t value) {}

// Scales the Dualshock4 touch absolute coordinates to a float in within the
// range [-1.0,+1.0].
float NormalizeTouch(uint32_t value, uint32_t min, uint32_t max) {}

// Reads the 12 bits coordinates given by `ds4_touch_data` into `touch`
// position.
void ReadTouchCoordinates(base::span<const uint8_t> ds4_touch_data_span,
                          GamepadTouch& touch) {}

// Reads the touchpad information given by `touchpad_data` and `touches_count`
// into `pad`.
// TODO(crbug.com/40155307): Make a member of Dualshock4Controller
template <typename Transform>
void ProcessTouchData(base::span<const TouchPadData> touchpad_data,
                      Transform& id_transform,
                      std::optional<uint32_t>& initial_touch_id,
                      Gamepad* pad) {}

// Reads the Axis and button information given by |controller_data| into
// |pad|.
void ProcessAxisButtonData(const ControllerData& controller_data,
                           Gamepad* pad) {}

}  // namespace

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;

// static
bool Dualshock4Controller::IsDualshock4(GamepadId gamepad_id) {}

// static
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() {}

}  // namespace device