mirror of
https://github.com/skyline-emu/skyline.git
synced 2025-01-16 21:57:56 +03:00
service: hid: Properly clear and set npad devices
This commit is contained in:
parent
cf95cfb056
commit
25b9bb00fd
@ -10,7 +10,14 @@ namespace skyline::input {
|
|||||||
: manager(manager),
|
: manager(manager),
|
||||||
section(section),
|
section(section),
|
||||||
id(id),
|
id(id),
|
||||||
updateEvent(std::make_shared<kernel::type::KEvent>(manager.state, false)) {}
|
updateEvent(std::make_shared<kernel::type::KEvent>(manager.state, false)) {
|
||||||
|
constexpr std::size_t InitializeEntryCount{19}; //!< HW initializes the first 19 entries
|
||||||
|
|
||||||
|
ResetDeviceProperties();
|
||||||
|
for (std::size_t i{}; i < InitializeEntryCount; ++i) {
|
||||||
|
WriteEmptyEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NpadDevice::Connect(NpadControllerType newType) {
|
void NpadDevice::Connect(NpadControllerType newType) {
|
||||||
if (type == newType) {
|
if (type == newType) {
|
||||||
@ -29,10 +36,11 @@ namespace skyline::input {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
section = {};
|
ResetDeviceProperties();
|
||||||
controllerInfo = nullptr;
|
controllerInfo = nullptr;
|
||||||
|
|
||||||
connectionState = {.connected = true};
|
connectionState.raw = 0;
|
||||||
|
connectionState.connected = true;
|
||||||
|
|
||||||
switch (newType) {
|
switch (newType) {
|
||||||
case NpadControllerType::ProController:
|
case NpadControllerType::ProController:
|
||||||
@ -154,8 +162,7 @@ namespace skyline::input {
|
|||||||
if (type == NpadControllerType::None)
|
if (type == NpadControllerType::None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
section = {};
|
ResetDeviceProperties();
|
||||||
globalTimestamp = 0;
|
|
||||||
|
|
||||||
index = -1;
|
index = -1;
|
||||||
partnerIndex = -1;
|
partnerIndex = -1;
|
||||||
@ -164,6 +171,7 @@ namespace skyline::input {
|
|||||||
controllerInfo = nullptr;
|
controllerInfo = nullptr;
|
||||||
|
|
||||||
updateEvent->Signal();
|
updateEvent->Signal();
|
||||||
|
WriteEmptyEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
NpadControllerInfo &NpadDevice::GetControllerInfo() {
|
NpadControllerInfo &NpadDevice::GetControllerInfo() {
|
||||||
@ -203,6 +211,36 @@ namespace skyline::input {
|
|||||||
nextEntry.status.raw = connectionState.raw;
|
nextEntry.status.raw = connectionState.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NpadDevice::WriteEmptyEntries() {
|
||||||
|
NpadControllerState emptyEntry{};
|
||||||
|
|
||||||
|
WriteNextEntry(section.fullKeyController, emptyEntry);
|
||||||
|
WriteNextEntry(section.handheldController, emptyEntry);
|
||||||
|
WriteNextEntry(section.leftController, emptyEntry);
|
||||||
|
WriteNextEntry(section.rightController, emptyEntry);
|
||||||
|
WriteNextEntry(section.palmaController, emptyEntry);
|
||||||
|
WriteNextEntry(section.dualController, emptyEntry);
|
||||||
|
WriteNextEntry(section.defaultController, emptyEntry);
|
||||||
|
|
||||||
|
globalTimestamp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NpadDevice::ResetDeviceProperties() {
|
||||||
|
// Don't reset assignment mode or ring lifo entries these values are persistent
|
||||||
|
section.header.type = NpadControllerType::None;
|
||||||
|
section.header.singleColor = {};
|
||||||
|
section.header.leftColor = {};
|
||||||
|
section.header.rightColor = {};
|
||||||
|
section.header.singleColorStatus = NpadColorReadStatus::Disconnected;
|
||||||
|
section.header.dualColorStatus = NpadColorReadStatus::Disconnected;
|
||||||
|
section.deviceType.raw = 0;
|
||||||
|
section.buttonProperties.raw = 0;
|
||||||
|
section.systemProperties.raw = 0;
|
||||||
|
section.singleBatteryLevel = NpadBatteryLevel::Empty;
|
||||||
|
section.leftBatteryLevel = NpadBatteryLevel::Empty;
|
||||||
|
section.rightBatteryLevel = NpadBatteryLevel::Empty;
|
||||||
|
}
|
||||||
|
|
||||||
void NpadDevice::UpdateSharedMemory() {
|
void NpadDevice::UpdateSharedMemory() {
|
||||||
if (!connectionState.connected)
|
if (!connectionState.connected)
|
||||||
return;
|
return;
|
||||||
|
@ -145,6 +145,16 @@ namespace skyline::input {
|
|||||||
*/
|
*/
|
||||||
void WriteNextEntry(NpadControllerInfo &info, NpadControllerState entry);
|
void WriteNextEntry(NpadControllerInfo &info, NpadControllerState entry);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes on all ring lifo buffers a new empty entry in HID Shared Memory
|
||||||
|
*/
|
||||||
|
void WriteEmptyEntries();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reverts all device properties to the default state
|
||||||
|
*/
|
||||||
|
void ResetDeviceProperties();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The NpadControllerInfo for this controller based on its type
|
* @return The NpadControllerInfo for this controller based on its type
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user