2019-02-12 10:30:24 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of reicast.
|
|
|
|
|
|
|
|
reicast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
reicast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with reicast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "types.h"
|
|
|
|
#include "mapping.h"
|
|
|
|
|
2020-03-28 16:58:01 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-02-12 10:30:24 +00:00
|
|
|
class GamepadDevice
|
|
|
|
{
|
|
|
|
typedef void (*input_detected_cb)(u32 code);
|
|
|
|
public:
|
2019-02-12 14:56:44 +00:00
|
|
|
const std::string& api_name() { return _api_name; }
|
|
|
|
const std::string& name() { return _name; }
|
2019-02-12 10:30:24 +00:00
|
|
|
int maple_port() { return _maple_port; }
|
|
|
|
void set_maple_port(int port) { _maple_port = port; }
|
2019-03-29 16:19:18 +00:00
|
|
|
const std::string& unique_id() { return _unique_id; }
|
2019-02-13 19:29:49 +00:00
|
|
|
virtual bool gamepad_btn_input(u32 code, bool pressed);
|
|
|
|
bool gamepad_axis_input(u32 code, int value);
|
2019-02-21 13:49:27 +00:00
|
|
|
virtual ~GamepadDevice() {}
|
|
|
|
|
2019-03-28 17:28:29 +00:00
|
|
|
void detect_btn_input(input_detected_cb button_pressed);
|
|
|
|
void detect_axis_input(input_detected_cb axis_moved);
|
2019-02-12 10:30:24 +00:00
|
|
|
void cancel_detect_input()
|
|
|
|
{
|
2020-04-17 15:55:43 +00:00
|
|
|
_input_detected = nullptr;
|
2019-02-12 10:30:24 +00:00
|
|
|
}
|
2020-03-12 15:09:05 +00:00
|
|
|
std::shared_ptr<InputMapping> get_input_mapping() { return input_mapper; }
|
2019-02-12 10:30:24 +00:00
|
|
|
void save_mapping();
|
2020-11-20 21:10:14 +00:00
|
|
|
virtual const char *get_button_name(u32 code) { return nullptr; }
|
|
|
|
virtual const char *get_axis_name(u32 code) { return nullptr; }
|
2020-03-12 15:09:05 +00:00
|
|
|
bool remappable() { return _remappable && input_mapper; }
|
2019-03-04 23:54:01 +00:00
|
|
|
virtual bool is_virtual_gamepad() { return false; }
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2019-02-22 18:23:03 +00:00
|
|
|
virtual void rumble(float power, float inclination, u32 duration_ms) {}
|
|
|
|
virtual void update_rumble() {}
|
|
|
|
bool is_rumble_enabled() { return _rumble_enabled; }
|
|
|
|
|
2019-03-29 16:19:18 +00:00
|
|
|
static void Register(std::shared_ptr<GamepadDevice> gamepad);
|
2019-02-21 13:49:27 +00:00
|
|
|
|
2019-03-29 16:19:18 +00:00
|
|
|
static void Unregister(std::shared_ptr<GamepadDevice> gamepad);
|
2019-02-21 13:49:27 +00:00
|
|
|
|
2019-02-12 10:30:24 +00:00
|
|
|
static int GetGamepadCount();
|
2019-02-21 13:49:27 +00:00
|
|
|
static std::shared_ptr<GamepadDevice> GetGamepad(int index);
|
2019-03-29 16:19:18 +00:00
|
|
|
static void SaveMaplePorts();
|
2019-02-12 10:30:24 +00:00
|
|
|
|
|
|
|
protected:
|
2019-02-13 19:29:49 +00:00
|
|
|
GamepadDevice(int maple_port, const char *api_name, bool remappable = true)
|
2020-03-12 15:09:05 +00:00
|
|
|
: _api_name(api_name), _maple_port(maple_port), _input_detected(nullptr), _remappable(remappable)
|
2019-02-13 19:29:49 +00:00
|
|
|
{
|
2019-02-12 10:30:24 +00:00
|
|
|
}
|
2020-04-17 15:55:43 +00:00
|
|
|
bool find_mapping(const char *custom_mapping = nullptr);
|
2019-02-12 10:30:24 +00:00
|
|
|
|
|
|
|
virtual void load_axis_min_max(u32 axis) {}
|
2020-11-20 21:10:14 +00:00
|
|
|
bool is_detecting_input() { return _input_detected != nullptr; }
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2019-02-12 14:56:44 +00:00
|
|
|
std::string _name;
|
2019-03-29 16:19:18 +00:00
|
|
|
std::string _unique_id = "";
|
2020-03-12 15:09:05 +00:00
|
|
|
std::shared_ptr<InputMapping> input_mapper;
|
2019-02-12 10:30:24 +00:00
|
|
|
std::map<u32, int> axis_min_values;
|
|
|
|
std::map<u32, unsigned int> axis_ranges;
|
2019-02-22 23:17:59 +00:00
|
|
|
bool _rumble_enabled = true;
|
2019-02-12 10:30:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int get_axis_min_value(u32 axis);
|
|
|
|
unsigned int get_axis_range(u32 axis);
|
2020-04-17 15:55:43 +00:00
|
|
|
std::string make_mapping_filename(bool instance = false);
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2019-02-12 14:56:44 +00:00
|
|
|
std::string _api_name;
|
2019-02-12 10:30:24 +00:00
|
|
|
int _maple_port;
|
|
|
|
bool _detecting_button = false;
|
2020-03-12 15:09:05 +00:00
|
|
|
double _detection_start_time = 0.0;
|
2019-02-12 10:30:24 +00:00
|
|
|
input_detected_cb _input_detected;
|
2019-02-13 19:29:49 +00:00
|
|
|
bool _remappable;
|
2019-02-12 10:30:24 +00:00
|
|
|
|
2019-02-21 13:49:27 +00:00
|
|
|
static std::vector<std::shared_ptr<GamepadDevice>> _gamepads;
|
2019-02-12 10:30:24 +00:00
|
|
|
static std::mutex _gamepads_mutex;
|
|
|
|
};
|
2019-06-23 10:17:24 +00:00
|
|
|
|
|
|
|
#ifdef TEST_AUTOMATION
|
|
|
|
void replay_input();
|
|
|
|
#endif
|
|
|
|
|
2020-12-02 13:40:50 +00:00
|
|
|
extern u32 kcode[4];
|
2020-03-20 15:57:50 +00:00
|
|
|
extern u8 rt[4], lt[4];
|
|
|
|
extern s8 joyx[4], joyy[4];
|
|
|
|
extern s8 joyrx[4], joyry[4];
|
2020-12-02 13:40:50 +00:00
|
|
|
|
|
|
|
void UpdateVibration(u32 port, float power, float inclination, u32 duration_ms);
|