Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
e56b1b69b7 | |||
56bff126d2 |
@ -281,10 +281,10 @@ static_assert(sizeof(ProcessorState) == 0xE20, "ProcessorState is an invalid siz
|
||||
|
||||
// This is nn::irsensor::detail::DeviceFormat
|
||||
struct DeviceFormat {
|
||||
Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Unconnected};
|
||||
Core::IrSensor::IrCameraStatus camera_status{Core::IrSensor::IrCameraStatus::Available};
|
||||
Core::IrSensor::IrCameraInternalStatus camera_internal_status{
|
||||
Core::IrSensor::IrCameraInternalStatus::Ready};
|
||||
Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::None};
|
||||
Core::IrSensor::IrCameraInternalStatus::Stopped};
|
||||
Core::IrSensor::IrSensorMode mode{Core::IrSensor::IrSensorMode::ImageTransferProcessor};
|
||||
ProcessorState state{};
|
||||
};
|
||||
static_assert(sizeof(DeviceFormat) == 0xE30, "DeviceFormat is an invalid size");
|
||||
|
@ -296,7 +296,7 @@ void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) {
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle);
|
||||
MakeProcessor<TeraPluginProcessor>(parameters.camera_handle, device);
|
||||
MakeProcessorWithCoreContext<TeraPluginProcessor>(parameters.camera_handle, device);
|
||||
auto& image_transfer_processor =
|
||||
GetProcessor<TeraPluginProcessor>(parameters.camera_handle);
|
||||
image_transfer_processor.SetConfig(parameters.processor_config);
|
||||
|
@ -1,29 +1,103 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "core/hid/emulated_controller.h"
|
||||
#include "core/hid/hid_core.h"
|
||||
#include "core/hle/service/hid/irsensor/tera_plugin_processor.h"
|
||||
|
||||
namespace Service::IRS {
|
||||
TeraPluginProcessor::TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format)
|
||||
: device(device_format) {
|
||||
TeraPluginProcessor::TeraPluginProcessor(Core::HID::HIDCore& hid_core_,
|
||||
Core::IrSensor::DeviceFormat& device_format,
|
||||
std::size_t npad_index)
|
||||
: device{device_format} {
|
||||
npad_device = hid_core_.GetEmulatedControllerByIndex(npad_index);
|
||||
|
||||
device.mode = Core::IrSensor::IrSensorMode::TeraPluginProcessor;
|
||||
device.camera_status = Core::IrSensor::IrCameraStatus::Unconnected;
|
||||
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Stopped;
|
||||
|
||||
shared_memory = std::construct_at(
|
||||
reinterpret_cast<TeraSharedMemory*>(&device_format.state.processor_raw_data));
|
||||
|
||||
Core::HID::ControllerUpdateCallback engine_callback{
|
||||
.on_change = [this](Core::HID::ControllerTriggerType type) { OnControllerUpdate(type); },
|
||||
.is_npad_service = true,
|
||||
};
|
||||
callback_key = npad_device->SetCallback(engine_callback);
|
||||
}
|
||||
|
||||
TeraPluginProcessor::~TeraPluginProcessor() = default;
|
||||
TeraPluginProcessor::~TeraPluginProcessor() {
|
||||
npad_device->DeleteCallback(callback_key);
|
||||
};
|
||||
|
||||
void TeraPluginProcessor::StartProcessor() {}
|
||||
void TeraPluginProcessor::StartProcessor() {
|
||||
device.camera_status = Core::IrSensor::IrCameraStatus::Available;
|
||||
device.camera_internal_status = Core::IrSensor::IrCameraInternalStatus::Ready;
|
||||
}
|
||||
|
||||
void TeraPluginProcessor::SuspendProcessor() {}
|
||||
|
||||
void TeraPluginProcessor::StopProcessor() {}
|
||||
|
||||
void TeraPluginProcessor::OnControllerUpdate(Core::HID::ControllerTriggerType type) {
|
||||
if (type != Core::HID::ControllerTriggerType::IrSensor) {
|
||||
return;
|
||||
}
|
||||
|
||||
next_state = {};
|
||||
const auto camera_data = npad_device->GetCamera();
|
||||
auto filtered_image = camera_data.data;
|
||||
|
||||
memcpy(next_state.data.data(), filtered_image.data(), GetDataSize(format));
|
||||
|
||||
// These 4 bytes seem to control the brightness of a image
|
||||
next_state.data[0] = 1;
|
||||
next_state.data[1] = 2;
|
||||
next_state.data[2] = 0xde;
|
||||
next_state.data[3] = 0x07;
|
||||
|
||||
// Data from HW
|
||||
/* next_state.data = {
|
||||
0x01, 0x02, 0xde, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x48, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x13, 0x13, 0x00, 0x00, 0x06, 0x00, 0xc0, 0x28,
|
||||
0x00, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x3c, 0x00, 0x05, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x20, 0xa8, 0x09, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04,
|
||||
0x12, 0x41, 0x00, 0x00, 0x13, 0x86, 0x02, 0x00, 0x00, 0x00, 0x1e, 0xc0, 0x02, 0x00, 0x00, 0x00,
|
||||
0x40, 0x0f, 0x00, 0x00, 0x00, 0x30, 0xcd, 0x34, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x10, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x02, 0x00, 0x00, 0x80, 0xf3, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x36, 0x08, 0x04, 0x60, 0x02, 0x00, 0x76, 0x80, 0x09, 0x00, 0x00, 0x88, 0xd1,
|
||||
0x20, 0x00, 0x00, 0x00, 0x65, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x80, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x28, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x40, 0x01, 0x68, 0x00, 0x00, 0x00,
|
||||
0x80, 0xf2, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x04, 0x80, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x06, 0x00,
|
||||
0x00, 0x00, 0x04, 0xa0, 0x57, 0x02, 0x04, 0x40, 0x51, 0x02, 0x00, 0x40, 0xc1, 0x01, 0x00, 0x50,
|
||||
0x86, 0x02, 0x00, 0x50, 0x0d, 0x04, 0x00, 0xb0, 0x05, 0x00, 0x00, 0x50, 0x04, 0x00, 0x00, 0xb0,
|
||||
0x09, 0x00, 0x00, 0xb0, 0x01, 0xc0, 0x06, 0xc0, 0x0e, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x20,
|
||||
0x01, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x20, 0x05, 0x00, 0x00, 0x80,
|
||||
0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x86, 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00,
|
||||
};*/
|
||||
next_state.sampling_number = camera_data.sample;
|
||||
next_state.timestamp = next_state.sampling_number + 131;
|
||||
next_state.ambient_noise_level = Core::IrSensor::CameraAmbientNoiseLevel::Low;
|
||||
|
||||
shared_memory->tera_lifo.WriteNextEntry(next_state);
|
||||
|
||||
if (!IsProcessorActive()) {
|
||||
StartProcessor();
|
||||
}
|
||||
}
|
||||
void TeraPluginProcessor::SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config) {
|
||||
current_config.mode = config.mode;
|
||||
current_config.unknown_1 = config.unknown_1;
|
||||
current_config.unknown_2 = config.unknown_2;
|
||||
current_config.unknown_3 = config.unknown_3;
|
||||
|
||||
LOG_ERROR(Service_IRS, "{} {} {} {}", config.mode, config.unknown_1, config.unknown_2,
|
||||
config.unknown_3);
|
||||
npad_device->SetCameraFormat(format);
|
||||
}
|
||||
|
||||
} // namespace Service::IRS
|
||||
|
@ -3,15 +3,21 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hid/irs_types.h"
|
||||
#include "core/hle/service/hid/irs_ring_lifo.h"
|
||||
#include "core/hle/service/hid/irsensor/processor_base.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedController;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Service::IRS {
|
||||
class TeraPluginProcessor final : public ProcessorBase {
|
||||
public:
|
||||
explicit TeraPluginProcessor(Core::IrSensor::DeviceFormat& device_format);
|
||||
explicit TeraPluginProcessor(Core::HID::HIDCore& hid_core_,
|
||||
Core::IrSensor::DeviceFormat& device_format,
|
||||
std::size_t npad_index);
|
||||
~TeraPluginProcessor() override;
|
||||
|
||||
// Called when the processor is initialized
|
||||
@ -27,6 +33,10 @@ public:
|
||||
void SetConfig(Core::IrSensor::PackedTeraPluginProcessorConfig config);
|
||||
|
||||
private:
|
||||
static constexpr auto format = Core::IrSensor::ImageTransferProcessorFormat::Size20x15;
|
||||
static constexpr std::size_t width = 40;
|
||||
static constexpr std::size_t height = 30;
|
||||
|
||||
// This is nn::irsensor::TeraPluginProcessorConfig
|
||||
struct TeraPluginProcessorConfig {
|
||||
u8 mode;
|
||||
@ -46,8 +56,22 @@ private:
|
||||
static_assert(sizeof(TeraPluginProcessorState) == 0x140,
|
||||
"TeraPluginProcessorState is an invalid size");
|
||||
|
||||
struct TeraSharedMemory {
|
||||
Service::IRS::Lifo<TeraPluginProcessorState, 6> tera_lifo;
|
||||
static_assert(sizeof(tera_lifo) == 0x790, "tera_lifo is an invalid size");
|
||||
INSERT_PADDING_WORDS(0x1A4);
|
||||
};
|
||||
static_assert(sizeof(TeraSharedMemory) == 0xE20, "TeraSharedMemory is an invalid size");
|
||||
|
||||
void OnControllerUpdate(Core::HID::ControllerTriggerType type);
|
||||
|
||||
TeraSharedMemory* shared_memory = nullptr;
|
||||
TeraPluginProcessorState next_state{};
|
||||
|
||||
TeraPluginProcessorConfig current_config{};
|
||||
Core::IrSensor::DeviceFormat& device;
|
||||
Core::HID::EmulatedController* npad_device;
|
||||
int callback_key{};
|
||||
};
|
||||
|
||||
} // namespace Service::IRS
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,13 @@ using SDL_JoystickID = s32;
|
||||
|
||||
namespace InputCommon {
|
||||
|
||||
class SDLJoystick;
|
||||
|
||||
using ButtonBindings =
|
||||
std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerButton>, 18>;
|
||||
using ZButtonBindings =
|
||||
std::array<std::pair<Settings::NativeButton::Values, SDL_GameControllerAxis>, 2>;
|
||||
|
||||
class SDLDriver : public InputEngine {
|
||||
public:
|
||||
/// Initializes and registers SDL device factories
|
||||
@ -34,12 +41,15 @@ public:
|
||||
/// Handle SDL_Events for joysticks from SDL_PollEvent
|
||||
void HandleGameControllerEvent(const SDL_Event& event);
|
||||
|
||||
bool IsStickInverted(const Common::ParamPackage& params) override;
|
||||
/// Get the nth joystick with the corresponding GUID
|
||||
std::shared_ptr<SDLJoystick> GetSDLJoystickBySDLID(SDL_JoystickID sdl_id);
|
||||
|
||||
bool IsVibrationEnabled(const PadIdentifier& identifier) override;
|
||||
|
||||
Common::Input::VibrationError SetVibration(
|
||||
const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
|
||||
/**
|
||||
* Check how many identical joysticks (by guid) were connected before the one with sdl_id and so
|
||||
* tie it to a SDLJoystick with the same guid and that port
|
||||
*/
|
||||
std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const Common::UUID& guid, int port);
|
||||
std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port);
|
||||
|
||||
std::vector<Common::ParamPackage> GetInputDevices() const override;
|
||||
|
||||
@ -51,43 +61,75 @@ public:
|
||||
std::string GetHatButtonName(u8 direction_value) const override;
|
||||
u8 GetHatButtonId(const std::string& direction_name) const override;
|
||||
|
||||
bool IsStickInverted(const Common::ParamPackage& params) override;
|
||||
|
||||
Common::Input::DriverResult SetVibration(
|
||||
const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
|
||||
|
||||
bool IsVibrationEnabled(const PadIdentifier& identifier) override;
|
||||
|
||||
private:
|
||||
struct VibrationRequest {
|
||||
PadIdentifier identifier;
|
||||
Common::Input::VibrationStatus vibration;
|
||||
};
|
||||
|
||||
struct JoystickID {
|
||||
int sdl_index;
|
||||
bool has_rumble;
|
||||
PadIdentifier identifier;
|
||||
};
|
||||
|
||||
std::shared_ptr<JoystickID> GetSDLJoystickBySDLID(SDL_JoystickID sdl_id);
|
||||
|
||||
void InitJoystick(int joystick_index);
|
||||
void CloseJoystick(int joystick_index);
|
||||
void CloseJoystick(SDL_Joystick* sdl_joystick);
|
||||
|
||||
/// Needs to be called before SDL_QuitSubSystem.
|
||||
void CloseJoysticks();
|
||||
|
||||
void UpdateControllerStatus(u32 event, int joystick_index, int index, int value);
|
||||
|
||||
Common::Input::BatteryLevel GetBatteryLevel(int value);
|
||||
|
||||
/// Takes all vibrations from the queue and sends the command to the controller
|
||||
void SendVibrations();
|
||||
|
||||
/// Map of GUID of a list of corresponding virtual Joysticks
|
||||
std::unordered_map<Common::UUID, std::vector<std::shared_ptr<JoystickID>>> joystick_map;
|
||||
std::mutex joystick_map_mutex;
|
||||
Common::ParamPackage BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
|
||||
s32 axis, float value = 0.1f) const;
|
||||
Common::ParamPackage BuildButtonParamPackageForButton(int port, const Common::UUID& guid,
|
||||
s32 button) const;
|
||||
|
||||
std::atomic<bool> initialized = false;
|
||||
Common::ParamPackage BuildHatParamPackageForButton(int port, const Common::UUID& guid, s32 hat,
|
||||
u8 value) const;
|
||||
|
||||
Common::ParamPackage BuildMotionParam(int port, const Common::UUID& guid) const;
|
||||
|
||||
Common::ParamPackage BuildParamPackageForBinding(
|
||||
int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const;
|
||||
|
||||
Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x,
|
||||
int axis_y, float offset_x,
|
||||
float offset_y) const;
|
||||
|
||||
/// Returns the default button bindings list for generic controllers
|
||||
ButtonBindings GetDefaultButtonBinding() const;
|
||||
|
||||
/// Returns the default button bindings list for nintendo controllers
|
||||
ButtonBindings GetNintendoButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const;
|
||||
|
||||
/// Returns the button mappings from a single controller
|
||||
ButtonMapping GetSingleControllerMapping(const std::shared_ptr<SDLJoystick>& joystick,
|
||||
const ButtonBindings& switch_to_sdl_button,
|
||||
const ZButtonBindings& switch_to_sdl_axis) const;
|
||||
|
||||
/// Returns the button mappings from two different controllers
|
||||
ButtonMapping GetDualControllerMapping(const std::shared_ptr<SDLJoystick>& joystick,
|
||||
const std::shared_ptr<SDLJoystick>& joystick2,
|
||||
const ButtonBindings& switch_to_sdl_button,
|
||||
const ZButtonBindings& switch_to_sdl_axis) const;
|
||||
|
||||
/// Returns true if the button is on the left joycon
|
||||
bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const;
|
||||
|
||||
/// Queue of vibration request to controllers
|
||||
Common::SPSCQueue<VibrationRequest> vibration_queue;
|
||||
|
||||
/// Thread that handles request from the vibration queue
|
||||
/// Map of GUID of a list of corresponding virtual Joysticks
|
||||
std::unordered_map<Common::UUID, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
|
||||
std::mutex joystick_map_mutex;
|
||||
|
||||
bool start_thread = false;
|
||||
std::atomic<bool> initialized = false;
|
||||
|
||||
std::thread vibration_thread;
|
||||
};
|
||||
} // namespace InputCommon
|
||||
|
Reference in New Issue
Block a user