mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-02 08:25:07 +01:00
HID: use AnalogDevice
This commit is contained in:
parent
1d1329af23
commit
70420272ca
@ -100,4 +100,11 @@ std::unique_ptr<InputDeviceType> CreateDevice(const std::string& params) {
|
|||||||
*/
|
*/
|
||||||
using ButtonDevice = InputDevice<bool>;
|
using ButtonDevice = InputDevice<bool>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An analog device is an input device that returns a tuple of x and y coordinates as status. The
|
||||||
|
* coordinates are within the unit circle. x+ is defined as right direction, and y+ is defined as up
|
||||||
|
* direction
|
||||||
|
*/
|
||||||
|
using AnalogDevice = InputDevice<std::tuple<float, float>>;
|
||||||
|
|
||||||
} // namespace Input
|
} // namespace Input
|
||||||
|
@ -51,6 +51,7 @@ constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE_ARM11 / 101;
|
|||||||
static std::atomic<bool> is_device_reload_pending;
|
static std::atomic<bool> is_device_reload_pending;
|
||||||
static std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
|
static std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
|
||||||
buttons;
|
buttons;
|
||||||
|
static std::unique_ptr<Input::AnalogDevice> circle_pad;
|
||||||
|
|
||||||
static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
|
static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
|
||||||
// 30 degree and 60 degree are angular thresholds for directions
|
// 30 degree and 60 degree are angular thresholds for directions
|
||||||
@ -86,12 +87,15 @@ static void LoadInputDevices() {
|
|||||||
std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
|
std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
|
||||||
Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
|
Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
|
||||||
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
|
buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
|
||||||
|
circle_pad = Input::CreateDevice<Input::AnalogDevice>(
|
||||||
|
Settings::values.analogs[Settings::NativeAnalog::CirclePad]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UnloadInputDevices() {
|
static void UnloadInputDevices() {
|
||||||
for (auto& button : buttons) {
|
for (auto& button : buttons) {
|
||||||
button.reset();
|
button.reset();
|
||||||
}
|
}
|
||||||
|
circle_pad.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdatePadCallback(u64 userdata, int cycles_late) {
|
static void UpdatePadCallback(u64 userdata, int cycles_late) {
|
||||||
@ -116,8 +120,11 @@ static void UpdatePadCallback(u64 userdata, int cycles_late) {
|
|||||||
state.select.Assign(buttons[Select - BUTTON_HID_BEGIN]->GetStatus());
|
state.select.Assign(buttons[Select - BUTTON_HID_BEGIN]->GetStatus());
|
||||||
|
|
||||||
// Get current circle pad position and update circle pad direction
|
// Get current circle pad position and update circle pad direction
|
||||||
s16 circle_pad_x, circle_pad_y;
|
float circle_pad_x_f, circle_pad_y_f;
|
||||||
std::tie(circle_pad_x, circle_pad_y) = VideoCore::g_emu_window->GetCirclePadState();
|
std::tie(circle_pad_x_f, circle_pad_y_f) = circle_pad->GetStatus();
|
||||||
|
constexpr int MAX_CIRCLEPAD_POS = 0x9C; // Max value for a circle pad position
|
||||||
|
s16 circle_pad_x = static_cast<s16>(circle_pad_x_f * MAX_CIRCLEPAD_POS);
|
||||||
|
s16 circle_pad_y = static_cast<s16>(circle_pad_y_f * MAX_CIRCLEPAD_POS);
|
||||||
state.hex |= GetCirclePadDirectionState(circle_pad_x, circle_pad_y).hex;
|
state.hex |= GetCirclePadDirectionState(circle_pad_x, circle_pad_y).hex;
|
||||||
|
|
||||||
mem->pad.current_state.hex = state.hex;
|
mem->pad.current_state.hex = state.hex;
|
||||||
|
@ -111,6 +111,19 @@ static const std::array<const char*, NumButtons> mapping = {{
|
|||||||
}};
|
}};
|
||||||
} // namespace NativeButton
|
} // namespace NativeButton
|
||||||
|
|
||||||
|
namespace NativeAnalog {
|
||||||
|
enum Values {
|
||||||
|
CirclePad,
|
||||||
|
CStick,
|
||||||
|
|
||||||
|
NumAnalogs,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const std::array<const char*, NumAnalogs> mapping = {{
|
||||||
|
"circle_pad", "c_stick",
|
||||||
|
}};
|
||||||
|
} // namespace NumAnalog
|
||||||
|
|
||||||
struct Values {
|
struct Values {
|
||||||
// CheckNew3DS
|
// CheckNew3DS
|
||||||
bool is_new_3ds;
|
bool is_new_3ds;
|
||||||
@ -120,6 +133,7 @@ struct Values {
|
|||||||
float pad_circle_modifier_scale;
|
float pad_circle_modifier_scale;
|
||||||
|
|
||||||
std::array<std::string, NativeButton::NumButtons> buttons;
|
std::array<std::string, NativeButton::NumButtons> buttons;
|
||||||
|
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
bool use_cpu_jit;
|
bool use_cpu_jit;
|
||||||
|
Loading…
Reference in New Issue
Block a user