chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2018 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-08-24 15:57:49 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
2021-09-21 00:33:19 +02:00
|
|
|
|
2019-08-24 15:57:49 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/thread.h"
|
2021-09-21 00:33:19 +02:00
|
|
|
#include "input_common/input_engine.h"
|
2019-08-24 15:57:49 +02:00
|
|
|
|
|
|
|
namespace InputCommon::CemuhookUDP {
|
|
|
|
|
|
|
|
class Socket;
|
|
|
|
|
|
|
|
namespace Response {
|
2022-01-17 17:44:13 +01:00
|
|
|
enum class Battery : u8;
|
2019-08-24 15:57:49 +02:00
|
|
|
struct PadData;
|
|
|
|
struct PortInfo;
|
2021-01-01 19:32:29 +01:00
|
|
|
struct TouchPad;
|
2021-01-03 05:04:50 +01:00
|
|
|
struct Version;
|
2019-08-24 15:57:49 +02:00
|
|
|
} // namespace Response
|
|
|
|
|
2020-09-05 04:35:42 +02:00
|
|
|
enum class PadTouch {
|
|
|
|
Click,
|
|
|
|
Undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UDPPadStatus {
|
2020-11-18 05:16:29 +01:00
|
|
|
std::string host{"127.0.0.1"};
|
|
|
|
u16 port{26760};
|
|
|
|
std::size_t pad_index{};
|
2020-09-05 04:35:42 +02:00
|
|
|
};
|
|
|
|
|
2019-08-24 15:57:49 +02:00
|
|
|
struct DeviceStatus {
|
|
|
|
std::mutex update_mutex;
|
|
|
|
|
|
|
|
// calibration data for scaling the device's touch area to 3ds
|
|
|
|
struct CalibrationData {
|
2019-11-03 07:04:28 +01:00
|
|
|
u16 min_x{};
|
|
|
|
u16 min_y{};
|
|
|
|
u16 max_x{};
|
|
|
|
u16 max_y{};
|
2019-08-24 15:57:49 +02:00
|
|
|
};
|
|
|
|
std::optional<CalibrationData> touch_calibration;
|
|
|
|
};
|
|
|
|
|
2021-09-21 00:33:19 +02:00
|
|
|
/**
|
|
|
|
* A button device factory representing a keyboard. It receives keyboard events and forward them
|
|
|
|
* to all button devices it created.
|
|
|
|
*/
|
2021-12-13 15:05:23 +01:00
|
|
|
class UDPClient final : public InputEngine {
|
2019-08-24 15:57:49 +02:00
|
|
|
public:
|
2021-12-13 15:05:23 +01:00
|
|
|
explicit UDPClient(std::string input_engine_);
|
|
|
|
~UDPClient() override;
|
2020-09-05 04:35:42 +02:00
|
|
|
|
2020-11-18 05:16:29 +01:00
|
|
|
void ReloadSockets();
|
2019-08-24 15:57:49 +02:00
|
|
|
|
2021-11-26 22:45:37 +01:00
|
|
|
/// Used for automapping features
|
|
|
|
std::vector<Common::ParamPackage> GetInputDevices() const override;
|
|
|
|
ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override;
|
|
|
|
AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;
|
|
|
|
MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override;
|
|
|
|
Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
|
|
|
|
|
2022-03-04 18:47:13 +01:00
|
|
|
bool IsStickInverted(const Common::ParamPackage& params) override;
|
|
|
|
|
2019-08-24 15:57:49 +02:00
|
|
|
private:
|
2021-11-26 22:45:37 +01:00
|
|
|
enum class PadButton {
|
|
|
|
Undefined = 0x0000,
|
|
|
|
Share = 0x0001,
|
|
|
|
L3 = 0x0002,
|
|
|
|
R3 = 0x0004,
|
|
|
|
Options = 0x0008,
|
|
|
|
Up = 0x0010,
|
|
|
|
Right = 0x0020,
|
|
|
|
Down = 0x0040,
|
|
|
|
Left = 0x0080,
|
|
|
|
L2 = 0x0100,
|
|
|
|
R2 = 0x0200,
|
|
|
|
L1 = 0x0400,
|
|
|
|
R1 = 0x0800,
|
|
|
|
Triangle = 0x1000,
|
|
|
|
Circle = 0x2000,
|
|
|
|
Cross = 0x4000,
|
|
|
|
Square = 0x8000,
|
|
|
|
Touch1 = 0x10000,
|
2022-01-30 16:15:29 +01:00
|
|
|
Touch2 = 0x20000,
|
|
|
|
Home = 0x40000,
|
|
|
|
TouchHardPress = 0x80000,
|
2021-11-26 22:45:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class PadAxes : u8 {
|
|
|
|
LeftStickX,
|
|
|
|
LeftStickY,
|
|
|
|
RightStickX,
|
|
|
|
RightStickY,
|
|
|
|
AnalogLeft,
|
|
|
|
AnalogDown,
|
|
|
|
AnalogRight,
|
|
|
|
AnalogUp,
|
|
|
|
AnalogSquare,
|
|
|
|
AnalogCross,
|
|
|
|
AnalogCircle,
|
|
|
|
AnalogTriangle,
|
|
|
|
AnalogR1,
|
|
|
|
AnalogL1,
|
|
|
|
AnalogR2,
|
|
|
|
AnalogL3,
|
|
|
|
AnalogR3,
|
|
|
|
Touch1X,
|
|
|
|
Touch1Y,
|
|
|
|
Touch2X,
|
|
|
|
Touch2Y,
|
|
|
|
Undefined,
|
|
|
|
};
|
|
|
|
|
2021-03-30 19:42:05 +02:00
|
|
|
struct PadData {
|
2020-11-18 05:16:29 +01:00
|
|
|
std::size_t pad_index{};
|
2021-03-30 19:42:05 +02:00
|
|
|
bool connected{};
|
2020-09-05 04:35:42 +02:00
|
|
|
DeviceStatus status;
|
2020-11-18 05:16:29 +01:00
|
|
|
u64 packet_sequence{};
|
2020-09-05 04:35:42 +02:00
|
|
|
|
2021-03-30 19:42:05 +02:00
|
|
|
std::chrono::time_point<std::chrono::steady_clock> last_update;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ClientConnection {
|
|
|
|
ClientConnection();
|
|
|
|
~ClientConnection();
|
2022-02-05 18:35:39 +01:00
|
|
|
Common::UUID uuid{"00000000-0000-0000-0000-00007F000001"};
|
2021-03-30 19:42:05 +02:00
|
|
|
std::string host{"127.0.0.1"};
|
|
|
|
u16 port{26760};
|
|
|
|
s8 active{-1};
|
|
|
|
std::unique_ptr<Socket> socket;
|
|
|
|
std::thread thread;
|
2020-09-05 04:35:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// For shutting down, clear all data, join all threads, release usb
|
|
|
|
void Reset();
|
|
|
|
|
2020-11-18 05:16:29 +01:00
|
|
|
// Translates configuration to client number
|
2021-03-30 19:42:05 +02:00
|
|
|
std::size_t GetClientNumber(std::string_view host, u16 port) const;
|
2020-11-18 05:16:29 +01:00
|
|
|
|
2022-01-17 17:44:13 +01:00
|
|
|
// Translates UDP battery level to input engine battery level
|
2022-02-07 01:20:12 +01:00
|
|
|
Common::Input::BatteryLevel GetBatteryLevel(Response::Battery battery) const;
|
2022-01-17 17:44:13 +01:00
|
|
|
|
2019-08-24 15:57:49 +02:00
|
|
|
void OnVersion(Response::Version);
|
|
|
|
void OnPortInfo(Response::PortInfo);
|
2020-11-18 05:16:29 +01:00
|
|
|
void OnPadData(Response::PadData, std::size_t client);
|
2021-03-30 19:42:05 +02:00
|
|
|
void StartCommunication(std::size_t client, const std::string& host, u16 port);
|
2022-01-24 16:58:22 +01:00
|
|
|
PadIdentifier GetPadIdentifier(std::size_t pad_index) const;
|
2022-02-05 18:35:39 +01:00
|
|
|
Common::UUID GetHostUUID(const std::string& host) const;
|
2019-08-24 15:57:49 +02:00
|
|
|
|
2021-11-26 22:45:37 +01:00
|
|
|
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
|
|
|
|
|
2020-11-18 05:16:29 +01:00
|
|
|
// Allocate clients for 8 udp servers
|
2021-03-30 19:42:05 +02:00
|
|
|
static constexpr std::size_t MAX_UDP_CLIENTS = 8;
|
|
|
|
static constexpr std::size_t PADS_PER_CLIENT = 4;
|
|
|
|
std::array<PadData, MAX_UDP_CLIENTS * PADS_PER_CLIENT> pads{};
|
|
|
|
std::array<ClientConnection, MAX_UDP_CLIENTS> clients{};
|
2019-08-24 15:57:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// An async job allowing configuration of the touchpad calibration.
|
|
|
|
class CalibrationConfigurationJob {
|
|
|
|
public:
|
|
|
|
enum class Status {
|
|
|
|
Initialized,
|
|
|
|
Ready,
|
|
|
|
Stage1Completed,
|
|
|
|
Completed,
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Constructs and starts the job with the specified parameter.
|
|
|
|
*
|
|
|
|
* @param status_callback Callback for job status updates
|
|
|
|
* @param data_callback Called when calibration data is ready
|
|
|
|
*/
|
2021-03-30 19:42:05 +02:00
|
|
|
explicit CalibrationConfigurationJob(const std::string& host, u16 port,
|
2021-02-27 16:26:33 +01:00
|
|
|
std::function<void(Status)> status_callback,
|
2019-08-24 15:57:49 +02:00
|
|
|
std::function<void(u16, u16, u16, u16)> data_callback);
|
|
|
|
~CalibrationConfigurationJob();
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Common::Event complete_event;
|
|
|
|
};
|
|
|
|
|
2021-03-30 19:42:05 +02:00
|
|
|
void TestCommunication(const std::string& host, u16 port,
|
2020-10-16 12:22:26 +02:00
|
|
|
const std::function<void()>& success_callback,
|
|
|
|
const std::function<void()>& failure_callback);
|
2019-08-24 15:57:49 +02:00
|
|
|
|
|
|
|
} // namespace InputCommon::CemuhookUDP
|