1 Commits

Author SHA1 Message Date
f30cd6e6d8 props 2024-02-02 12:19:30 -06:00
9 changed files with 73 additions and 38 deletions

View File

@ -45,7 +45,7 @@ Result NpadAbstractBatteryHandler::DecrementRefCounter() {
return ResultSuccess; return ResultSuccess;
} }
Result NpadAbstractBatteryHandler::UpdateBatteryState(u64 aruid) { Result NpadAbstractBatteryHandler::ActivateBattery(u64 aruid) {
const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId()); const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId());
AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid); AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (aruid_data == nullptr) { if (aruid_data == nullptr) {

View File

@ -25,7 +25,7 @@ public:
Result IncrementRefCounter(); Result IncrementRefCounter();
Result DecrementRefCounter(); Result DecrementRefCounter();
Result UpdateBatteryState(u64 aruid); Result ActivateBattery(u64 aruid);
void UpdateBatteryState(); void UpdateBatteryState();
bool GetNewBatteryState(); bool GetNewBatteryState();
void UpdateCoreBatteryState(); void UpdateCoreBatteryState();

View File

@ -176,16 +176,16 @@ Result AbstractPad::Deactivate() {
return ResultSuccess; return ResultSuccess;
} }
Result AbstractPad::ActivateNpad(u64 aruid) { Result AbstractPad::Activate(u64 aruid) {
Result result = ResultSuccess; Result result = ResultSuccess;
if (result.IsSuccess()) { if (result.IsSuccess()) {
result = properties_handler.ActivateNpadUnknown0x88(aruid); result = properties_handler.Activate(aruid);
} }
if (result.IsSuccess()) { if (result.IsSuccess()) {
result = sixaxis_handler.UpdateSixAxisState2(aruid); result = sixaxis_handler.ActivateSixAxis(aruid);
} }
if (result.IsSuccess()) { if (result.IsSuccess()) {
result = battery_handler.UpdateBatteryState(aruid); result = battery_handler.ActivateBattery(aruid);
} }
return result; return result;
} }
@ -253,10 +253,15 @@ void AbstractPad::UpdateInterfaceType() {
if (interface_type != properties_handler.GetInterfaceType()) { if (interface_type != properties_handler.GetInterfaceType()) {
Update(); Update();
} }
properties_handler.UpdateAThingIfNeeded();
//button_handler.UpdateButtonState(false);
//sixaxis_handler.UpdateSixAxisState();
battery_handler.UpdateBatteryState(); battery_handler.UpdateBatteryState();
//led_handler.UpdateLedState();
} }
void AbstractPad::Update() { void AbstractPad::Update() {
properties_handler.UpdateProperties();
properties_handler.UpdateDeviceType(); properties_handler.UpdateDeviceType();
led_handler.SetNpadLedHandlerLedPattern(); led_handler.SetNpadLedHandlerLedPattern();
vibration_handler.UpdateVibrationState(); vibration_handler.UpdateVibrationState();

View File

@ -62,7 +62,7 @@ public:
Result Activate(); Result Activate();
Result Deactivate(); Result Deactivate();
Result ActivateNpad(u64 aruid); Result Activate(u64 aruid);
NpadAbstractedPadHolder* GetAbstractedPadHolder(); NpadAbstractedPadHolder* GetAbstractedPadHolder();
NpadAbstractPropertiesHandler* GetAbstractPropertiesHandler(); NpadAbstractPropertiesHandler* GetAbstractPropertiesHandler();

View File

@ -108,7 +108,7 @@ Result NpadAbstractPropertiesHandler::DecrementRefCounter() {
return ResultSuccess; return ResultSuccess;
} }
Result NpadAbstractPropertiesHandler::ActivateNpadUnknown0x88(u64 aruid) { Result NpadAbstractPropertiesHandler::Activate(u64 aruid) {
const auto npad_index = NpadIdTypeToIndex(npad_id_type); const auto npad_index = NpadIdTypeToIndex(npad_id_type);
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) { for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid_index); auto* data = applet_resource_holder->applet_resource->GetAruidData(aruid_index);
@ -123,6 +123,11 @@ Result NpadAbstractPropertiesHandler::ActivateNpadUnknown0x88(u64 aruid) {
void NpadAbstractPropertiesHandler::UpdateDeviceType() { void NpadAbstractPropertiesHandler::UpdateDeviceType() {
// TODO // TODO
UpdateDeviceColor();
//...
UpdateFooterAttributes();
UpdateAthingOrTwo();
} }
void NpadAbstractPropertiesHandler::UpdateDeviceColor() { void NpadAbstractPropertiesHandler::UpdateDeviceColor() {
@ -133,6 +138,10 @@ void NpadAbstractPropertiesHandler::UpdateFooterAttributes() {
// TODO // TODO
} }
void NpadAbstractPropertiesHandler::UpdateAthingOrTwo() {
// TODO
}
void NpadAbstractPropertiesHandler::UpdateAllDeviceProperties() { void NpadAbstractPropertiesHandler::UpdateAllDeviceProperties() {
const auto npad_index = NpadIdTypeToIndex(npad_id_type); const auto npad_index = NpadIdTypeToIndex(npad_id_type);
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) { for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
@ -145,7 +154,11 @@ void NpadAbstractPropertiesHandler::UpdateAllDeviceProperties() {
} }
} }
Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetFullkeyInterfaceType() { void NpadAbstractPropertiesHandler::GetFiel28() const {
return fiel28;
}
Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetFullkeyInterfaceType() const {
std::array<IAbstractedPad*, 5> abstract_pads{}; std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads); const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
@ -158,7 +171,7 @@ Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetFullkeyInterfaceT
continue; continue;
} }
if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) { if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) {
// Abort ASSERT_MSG(false, "Invalid interface type");
continue; continue;
} }
return abstract_pad->interface_type; return abstract_pad->interface_type;
@ -167,7 +180,7 @@ Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetFullkeyInterfaceT
return Core::HID::NpadInterfaceType::None; return Core::HID::NpadInterfaceType::None;
} }
Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetInterfaceType() { Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetInterfaceType() const {
std::array<IAbstractedPad*, 5> abstract_pads{}; std::array<IAbstractedPad*, 5> abstract_pads{};
const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads); const std::size_t count = abstract_pad_holder->GetAbstractedPads(abstract_pads);
@ -180,7 +193,7 @@ Core::HID::NpadInterfaceType NpadAbstractPropertiesHandler::GetInterfaceType() {
continue; continue;
} }
if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) { if (abstract_pad->interface_type >= Core::HID::NpadInterfaceType::Embedded) {
// Abort ASSERT_MSG(false, "Invalid interface type");
continue; continue;
} }
return abstract_pad->interface_type; return abstract_pad->interface_type;
@ -284,6 +297,17 @@ Result NpadAbstractPropertiesHandler::GetNpadFullKeyGripColor(
return ResultNpadIsNotProController; return ResultNpadIsNotProController;
} }
void NpadAbstractPropertiesHandler::UpdateAThingIfNeeded() {
if (!needs_to_update_a_thing_or_two) {
return;
}
UpdateAthingOrTwo();
}
void NpadAbstractPropertiesHandler::UpdateProperties() {
}
void NpadAbstractPropertiesHandler::GetNpadLeftRightInterfaceType( void NpadAbstractPropertiesHandler::GetNpadLeftRightInterfaceType(
Core::HID::NpadInterfaceType& out_left_interface, Core::HID::NpadInterfaceType& out_left_interface,
Core::HID::NpadInterfaceType& out_right_interface) const { Core::HID::NpadInterfaceType& out_right_interface) const {

View File

@ -37,15 +37,17 @@ public:
Result IncrementRefCounter(); Result IncrementRefCounter();
Result DecrementRefCounter(); Result DecrementRefCounter();
Result ActivateNpadUnknown0x88(u64 aruid); Result Activate(u64 aruid);
void UpdateDeviceType(); void UpdateDeviceType();
void UpdateDeviceColor(); void UpdateDeviceColor();
void UpdateFooterAttributes(); void UpdateFooterAttributes();
void UpdateAthingOrTwo();
void UpdateAllDeviceProperties(); void UpdateAllDeviceProperties();
Core::HID::NpadInterfaceType GetFullkeyInterfaceType(); u32 GetFiel28()const;
Core::HID::NpadInterfaceType GetInterfaceType(); Core::HID::NpadInterfaceType GetFullkeyInterfaceType() const;
Core::HID::NpadInterfaceType GetInterfaceType() const;
Core::HID::NpadStyleSet GetStyleSet(u64 aruid); Core::HID::NpadStyleSet GetStyleSet(u64 aruid);
std::size_t GetAbstractedPadsWithStyleTag(std::span<IAbstractedPad*> list, std::size_t GetAbstractedPadsWithStyleTag(std::span<IAbstractedPad*> list,
@ -63,6 +65,9 @@ public:
Result GetNpadFullKeyGripColor(Core::HID::NpadColor& main_color, Result GetNpadFullKeyGripColor(Core::HID::NpadColor& main_color,
Core::HID::NpadColor& sub_color) const; Core::HID::NpadColor& sub_color) const;
void UpdateAThingIfNeeded();
void UpdateProperties();
void GetNpadLeftRightInterfaceType(Core::HID::NpadInterfaceType& param_2, void GetNpadLeftRightInterfaceType(Core::HID::NpadInterfaceType& param_2,
Core::HID::NpadInterfaceType& param_3) const; Core::HID::NpadInterfaceType& param_3) const;

View File

@ -79,7 +79,7 @@ Result NpadAbstractSixAxisHandler::UpdateSixAxisState(u64 aruid) {
return ResultSuccess; return ResultSuccess;
} }
Result NpadAbstractSixAxisHandler::UpdateSixAxisState2(u64 aruid) { Result NpadAbstractSixAxisHandler::ActivateSixAxis(u64 aruid) {
const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId()); const auto npad_index = NpadIdTypeToIndex(properties_handler->GetNpadId());
AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid); AruidData* aruid_data = applet_resource_holder->applet_resource->GetAruidData(aruid);
if (aruid_data == nullptr) { if (aruid_data == nullptr) {

View File

@ -32,7 +32,7 @@ public:
Result UpdateSixAxisState(); Result UpdateSixAxisState();
Result UpdateSixAxisState(u64 aruid); Result UpdateSixAxisState(u64 aruid);
Result UpdateSixAxisState2(u64 aruid); Result ActivateSixAxis(u64 aruid);
private: private:
void UpdateSixaxisInternalState(NpadSharedMemoryEntry& npad_entry, u64 aruid, void UpdateSixaxisInternalState(NpadSharedMemoryEntry& npad_entry, u64 aruid,

View File

@ -42,7 +42,6 @@ NPad::NPad(Core::HID::HIDCore& hid_core_, KernelHelpers::ServiceContext& service
} }
for (std::size_t i = 0; i < abstracted_pads.size(); ++i) { for (std::size_t i = 0; i < abstracted_pads.size(); ++i) {
abstracted_pads[i] = AbstractPad{}; abstracted_pads[i] = AbstractPad{};
abstracted_pads[i].SetNpadId(IndexToNpadIdType(i));
} }
} }
@ -63,7 +62,24 @@ Result NPad::Activate() {
if (ref_counter == 0) { if (ref_counter == 0) {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
// TODO: Activate handlers and AbstractedPad // TODO: Initialize handlers
Result result = ResultSuccess;
std::size_t abstract_index;
for (abstract_index = 0; abstract_index < abstracted_pads.size() && result.IsSuccess();
++abstract_index) {
abstracted_pads[abstract_index].SetNpadId(IndexToNpadIdType(abstract_index));
result = abstracted_pads[abstract_index].Activate();
}
if (result.IsSuccess()) {
ref_counter++;
return ResultSuccess;
}
for (std::size_t i = 0; i < abstract_index; ++i) {
abstracted_pads[i].Deactivate();
}
} }
ref_counter++; ref_counter++;
@ -86,27 +102,12 @@ Result NPad::Activate(u64 aruid) {
controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state; controller.shared_memory = &data->shared_memory_format->npad.npad_entry[i].internal_state;
} }
// Prefill controller buffers Result result = ResultSuccess;
for (auto& controller : controller_data[aruid_index]) { for (std::size_t i = 0; i < abstracted_pads.size() && result.IsSuccess(); ++i) {
auto* npad = controller.shared_memory; result = abstracted_pads[i].Activate(aruid);
npad->fullkey_color = {
.attribute = ColorAttribute::NoController,
.fullkey = {},
};
npad->joycon_color = {
.attribute = ColorAttribute::NoController,
.left = {},
.right = {},
};
// HW seems to initialize the first 19 entries
for (std::size_t i = 0; i < 19; ++i) {
WriteEmptyEntry(npad);
}
controller.is_active = true;
} }
return ResultSuccess; return result;
} }
Result NPad::ActivateNpadResource() { Result NPad::ActivateNpadResource() {