From eee8f23fcedc78a9a40ac7ad9ef7fe72e7388b1e Mon Sep 17 00:00:00 2001 From: cathery Date: Mon, 12 Apr 2021 10:59:40 +0300 Subject: [PATCH] Update dependencies for 12.0.0 FW support --- README.md | 2 +- source/AppletCompanion/source/main.cpp | 37 ++++++----- .../SwitchAbstractedPadHandler.cpp | 56 ++++++++-------- source/ControllerSwitch/SwitchHDLHandler.cpp | 66 +++++++++---------- source/ControllerSwitch/SwitchHDLHandler.h | 2 +- .../SwitchVirtualGamepadHandler.h | 4 +- source/Sysmodule/source/psc_module.cpp | 4 +- source/libstratosphere | 2 +- 8 files changed, 88 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 982247d..a6f4d13 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Instead, clone the repository **recursively** using any git client you have. (Gi Like all other switch projects, you need to have [devkitA64](https://switchbrew.org/wiki/Setting_up_Development_Environment) set up on your system. -This project uses libnx version **3.3.0**. +For compatibility with the Atmosphere-libs dependency, this project currently uses a version of libnx at commit **[0d32a2c](https://github.com/switchbrew/libnx/commit/0d32a2c0d5343fe212a0957420d285c0ef44fb36)**. Clone the repository, checkout to that commit, and run `make install` to set it up. If you have **Visual Studio Code**, you can open the project as a folder and run the build tasks from inside the program. It also has Intellisense configured for switch development, if you have DEVKITPRO correctly defined in your environment variables. Handy! diff --git a/source/AppletCompanion/source/main.cpp b/source/AppletCompanion/source/main.cpp index 9e3ddd8..2634896 100644 --- a/source/AppletCompanion/source/main.cpp +++ b/source/AppletCompanion/source/main.cpp @@ -3,22 +3,25 @@ int main() { - consoleInit(NULL); - - printf("Hello\n"); - - while(appletMainLoop()) - { - hidScanInput(); - u64 kDown = 0; - for (u8 controller = 0; controller < 10; controller++) - kDown |= hidKeysDown(static_cast(controller)); - - if (kDown & KEY_PLUS || kDown & KEY_B) - break; - consoleUpdate(NULL); - } + consoleInit(NULL); - consoleExit(NULL); - return 0; + padConfigureInput(8, HidNpadStyleSet_NpadStandard); + PadState pad; + padInitializeAny(&pad); + hidSetNpadHandheldActivationMode(HidNpadHandheldActivationMode_Single); + + printf("Hello\n"); + + while (appletMainLoop()) + { + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + + if (kDown & HidNpadButton_Plus || kDown & HidNpadButton_B) + break; + consoleUpdate(NULL); + } + + consoleExit(NULL); + return 0; } \ No newline at end of file diff --git a/source/ControllerSwitch/SwitchAbstractedPadHandler.cpp b/source/ControllerSwitch/SwitchAbstractedPadHandler.cpp index 836a623..10c9e01 100644 --- a/source/ControllerSwitch/SwitchAbstractedPadHandler.cpp +++ b/source/ControllerSwitch/SwitchAbstractedPadHandler.cpp @@ -73,9 +73,9 @@ Result SwitchAbstractedPadHandler::InitAbstractedPadState() m_state = {0}; m_abstractedPadID = getUniqueId(); m_state.type = BIT(0); - m_state.npadInterfaceType = NpadInterfaceType_USB; + m_state.npadInterfaceType = HidNpadInterfaceType_USB; m_state.flags = 0xff; - m_state.state.batteryCharge = 4; + m_state.state.battery_level = 4; ControllerConfig *config = GetController()->GetConfig(); m_state.singleColorBody = config->bodyColor.rgbaValue; m_state.singleColorButtons = config->buttonsColor.rgbaValue; @@ -96,31 +96,31 @@ Result SwitchAbstractedPadHandler::ExitAbstractedPadState() void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData &data) { m_state.state.buttons = 0; - m_state.state.buttons |= (data.buttons[0] ? KEY_X : 0); - m_state.state.buttons |= (data.buttons[1] ? KEY_A : 0); - m_state.state.buttons |= (data.buttons[2] ? KEY_B : 0); - m_state.state.buttons |= (data.buttons[3] ? KEY_Y : 0); + m_state.state.buttons |= (data.buttons[0] ? HidNpadButton_X : 0); + m_state.state.buttons |= (data.buttons[1] ? HidNpadButton_A : 0); + m_state.state.buttons |= (data.buttons[2] ? HidNpadButton_B : 0); + m_state.state.buttons |= (data.buttons[3] ? HidNpadButton_Y : 0); - m_state.state.buttons |= (data.buttons[4] ? KEY_LSTICK : 0); - m_state.state.buttons |= (data.buttons[5] ? KEY_RSTICK : 0); + m_state.state.buttons |= (data.buttons[4] ? HidNpadButton_StickL : 0); + m_state.state.buttons |= (data.buttons[5] ? HidNpadButton_StickR : 0); - m_state.state.buttons |= (data.buttons[6] ? KEY_L : 0); - m_state.state.buttons |= (data.buttons[7] ? KEY_R : 0); + m_state.state.buttons |= (data.buttons[6] ? HidNpadButton_L : 0); + m_state.state.buttons |= (data.buttons[7] ? HidNpadButton_R : 0); - m_state.state.buttons |= (data.buttons[8] ? KEY_ZL : 0); - m_state.state.buttons |= (data.buttons[9] ? KEY_ZR : 0); + m_state.state.buttons |= (data.buttons[8] ? HidNpadButton_ZL : 0); + m_state.state.buttons |= (data.buttons[9] ? HidNpadButton_ZR : 0); - m_state.state.buttons |= (data.buttons[10] ? KEY_MINUS : 0); - m_state.state.buttons |= (data.buttons[11] ? KEY_PLUS : 0); + m_state.state.buttons |= (data.buttons[10] ? HidNpadButton_Minus : 0); + m_state.state.buttons |= (data.buttons[11] ? HidNpadButton_Plus : 0); ControllerConfig *config = GetController()->GetConfig(); if (config && config->swapDPADandLSTICK) { - m_state.state.buttons |= ((data.sticks[0].axis_y > 0.5f) ? KEY_DUP : 0); - m_state.state.buttons |= ((data.sticks[0].axis_x > 0.5f) ? KEY_DRIGHT : 0); - m_state.state.buttons |= ((data.sticks[0].axis_y < -0.5f) ? KEY_DDOWN : 0); - m_state.state.buttons |= ((data.sticks[0].axis_x < -0.5f) ? KEY_DLEFT : 0); + m_state.state.buttons |= ((data.sticks[0].axis_y > 0.5f) ? HidNpadButton_Up : 0); + m_state.state.buttons |= ((data.sticks[0].axis_x > 0.5f) ? HidNpadButton_Right : 0); + m_state.state.buttons |= ((data.sticks[0].axis_y < -0.5f) ? HidNpadButton_Down : 0); + m_state.state.buttons |= ((data.sticks[0].axis_x < -0.5f) ? HidNpadButton_Left : 0); float daxis_x{}, daxis_y{}; @@ -129,22 +129,22 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData daxis_y += data.buttons[14] ? -1.0f : 0.0f; //DDOWN daxis_x += data.buttons[15] ? -1.0f : 0.0f; //DLEFT - ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_state.state.joysticks[JOYSTICK_LEFT].dx, &m_state.state.joysticks[JOYSTICK_LEFT].dy); + ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_state.state.analog_stick_l.x, &m_state.state.analog_stick_l.y); } else { - m_state.state.buttons |= (data.buttons[12] ? KEY_DUP : 0); - m_state.state.buttons |= (data.buttons[13] ? KEY_DRIGHT : 0); - m_state.state.buttons |= (data.buttons[14] ? KEY_DDOWN : 0); - m_state.state.buttons |= (data.buttons[15] ? KEY_DLEFT : 0); + m_state.state.buttons |= (data.buttons[12] ? HidNpadButton_Up : 0); + m_state.state.buttons |= (data.buttons[13] ? HidNpadButton_Right : 0); + m_state.state.buttons |= (data.buttons[14] ? HidNpadButton_Down : 0); + m_state.state.buttons |= (data.buttons[15] ? HidNpadButton_Left : 0); - ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_state.state.joysticks[JOYSTICK_LEFT].dx, &m_state.state.joysticks[JOYSTICK_LEFT].dy); + ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_state.state.analog_stick_l.x, &m_state.state.analog_stick_l.y); } - ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_state.state.joysticks[JOYSTICK_RIGHT].dx, &m_state.state.joysticks[JOYSTICK_RIGHT].dy); + ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_state.state.analog_stick_r.x, &m_state.state.analog_stick_r.y); - m_state.state.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0); - m_state.state.buttons |= (data.buttons[17] ? KEY_HOME : 0); + m_state.state.buttons |= (data.buttons[16] ? HiddbgNpadButton_Capture : 0); + m_state.state.buttons |= (data.buttons[17] ? HiddbgNpadButton_Home : 0); } Result SwitchAbstractedPadHandler::UpdateAbstractedState() @@ -174,7 +174,7 @@ void SwitchAbstractedPadHandler::UpdateOutput() { Result rc; HidVibrationValue value; - rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value); + rc = hidGetActualVibrationValue(m_vibrationDeviceHandle, &value); if (R_SUCCEEDED(rc)) GetController()->SetRumble(static_cast(value.amp_high * 255.0f), static_cast(value.amp_low * 255.0f)); } diff --git a/source/ControllerSwitch/SwitchHDLHandler.cpp b/source/ControllerSwitch/SwitchHDLHandler.cpp index 3d21079..f4fa601 100644 --- a/source/ControllerSwitch/SwitchHDLHandler.cpp +++ b/source/ControllerSwitch/SwitchHDLHandler.cpp @@ -48,13 +48,13 @@ void SwitchHDLHandler::Exit() Result SwitchHDLHandler::InitHdlState() { - m_hdlHandle = 0; + m_hdlHandle = {0}; m_deviceInfo = {0}; m_hdlState = {0}; // Set the controller type to Pro-Controller, and set the npadInterfaceType. m_deviceInfo.deviceType = HidDeviceType_FullKey15; - m_deviceInfo.npadInterfaceType = NpadInterfaceType_USB; + m_deviceInfo.npadInterfaceType = HidNpadInterfaceType_USB; // Set the controller colors. The grip colors are for Pro-Controller on [9.0.0+]. ControllerConfig *config = m_controller->GetConfig(); m_deviceInfo.singleColorBody = config->bodyColor.rgbaValue; @@ -62,11 +62,11 @@ Result SwitchHDLHandler::InitHdlState() m_deviceInfo.colorLeftGrip = config->leftGripColor.rgbaValue; m_deviceInfo.colorRightGrip = config->rightGripColor.rgbaValue; - m_hdlState.batteryCharge = 4; // Set battery charge to full. - m_hdlState.joysticks[JOYSTICK_LEFT].dx = 0x1234; - m_hdlState.joysticks[JOYSTICK_LEFT].dy = -0x1234; - m_hdlState.joysticks[JOYSTICK_RIGHT].dx = 0x5678; - m_hdlState.joysticks[JOYSTICK_RIGHT].dy = -0x5678; + m_hdlState.battery_level = 4; // Set battery charge to full. + m_hdlState.analog_stick_l.x = 0x1234; + m_hdlState.analog_stick_l.y = -0x1234; + m_hdlState.analog_stick_r.x = 0x5678; + m_hdlState.analog_stick_r.y = -0x5678; if (m_controller->IsControllerActive()) return hiddbgAttachHdlsVirtualDevice(&m_hdlHandle, &m_deviceInfo); @@ -98,31 +98,31 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data) // we convert the input packet into switch-specific button states m_hdlState.buttons = 0; - m_hdlState.buttons |= (data.buttons[0] ? KEY_X : 0); - m_hdlState.buttons |= (data.buttons[1] ? KEY_A : 0); - m_hdlState.buttons |= (data.buttons[2] ? KEY_B : 0); - m_hdlState.buttons |= (data.buttons[3] ? KEY_Y : 0); + m_hdlState.buttons |= (data.buttons[0] ? HidNpadButton_X : 0); + m_hdlState.buttons |= (data.buttons[1] ? HidNpadButton_A : 0); + m_hdlState.buttons |= (data.buttons[2] ? HidNpadButton_B : 0); + m_hdlState.buttons |= (data.buttons[3] ? HidNpadButton_Y : 0); - m_hdlState.buttons |= (data.buttons[4] ? KEY_LSTICK : 0); - m_hdlState.buttons |= (data.buttons[5] ? KEY_RSTICK : 0); + m_hdlState.buttons |= (data.buttons[4] ? HidNpadButton_StickL : 0); + m_hdlState.buttons |= (data.buttons[5] ? HidNpadButton_StickR : 0); - m_hdlState.buttons |= (data.buttons[6] ? KEY_L : 0); - m_hdlState.buttons |= (data.buttons[7] ? KEY_R : 0); + m_hdlState.buttons |= (data.buttons[6] ? HidNpadButton_L : 0); + m_hdlState.buttons |= (data.buttons[7] ? HidNpadButton_R : 0); - m_hdlState.buttons |= (data.buttons[8] ? KEY_ZL : 0); - m_hdlState.buttons |= (data.buttons[9] ? KEY_ZR : 0); + m_hdlState.buttons |= (data.buttons[8] ? HidNpadButton_ZL : 0); + m_hdlState.buttons |= (data.buttons[9] ? HidNpadButton_ZR : 0); - m_hdlState.buttons |= (data.buttons[10] ? KEY_MINUS : 0); - m_hdlState.buttons |= (data.buttons[11] ? KEY_PLUS : 0); + m_hdlState.buttons |= (data.buttons[10] ? HidNpadButton_Minus : 0); + m_hdlState.buttons |= (data.buttons[11] ? HidNpadButton_Plus : 0); ControllerConfig *config = m_controller->GetConfig(); if (config && config->swapDPADandLSTICK) { - m_hdlState.buttons |= ((data.sticks[0].axis_y > 0.5f) ? KEY_DUP : 0); - m_hdlState.buttons |= ((data.sticks[0].axis_x > 0.5f) ? KEY_DRIGHT : 0); - m_hdlState.buttons |= ((data.sticks[0].axis_y < -0.5f) ? KEY_DDOWN : 0); - m_hdlState.buttons |= ((data.sticks[0].axis_x < -0.5f) ? KEY_DLEFT : 0); + m_hdlState.buttons |= ((data.sticks[0].axis_y > 0.5f) ? HidNpadButton_Up : 0); + m_hdlState.buttons |= ((data.sticks[0].axis_x > 0.5f) ? HidNpadButton_Right : 0); + m_hdlState.buttons |= ((data.sticks[0].axis_y < -0.5f) ? HidNpadButton_Down : 0); + m_hdlState.buttons |= ((data.sticks[0].axis_x < -0.5f) ? HidNpadButton_Left : 0); float daxis_x{}, daxis_y{}; @@ -139,22 +139,22 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data) daxis_x *= ratio; daxis_y *= ratio; - ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_hdlState.joysticks[JOYSTICK_LEFT].dx, &m_hdlState.joysticks[JOYSTICK_LEFT].dy); + ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_hdlState.analog_stick_l.x, &m_hdlState.analog_stick_l.y); } else { - m_hdlState.buttons |= (data.buttons[12] ? KEY_DUP : 0); - m_hdlState.buttons |= (data.buttons[13] ? KEY_DRIGHT : 0); - m_hdlState.buttons |= (data.buttons[14] ? KEY_DDOWN : 0); - m_hdlState.buttons |= (data.buttons[15] ? KEY_DLEFT : 0); + m_hdlState.buttons |= (data.buttons[12] ? HidNpadButton_Up : 0); + m_hdlState.buttons |= (data.buttons[13] ? HidNpadButton_Right : 0); + m_hdlState.buttons |= (data.buttons[14] ? HidNpadButton_Down : 0); + m_hdlState.buttons |= (data.buttons[15] ? HidNpadButton_Left : 0); - ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_LEFT].dx, &m_hdlState.joysticks[JOYSTICK_LEFT].dy); + ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_hdlState.analog_stick_l.x, &m_hdlState.analog_stick_l.y); } - ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_RIGHT].dx, &m_hdlState.joysticks[JOYSTICK_RIGHT].dy); + ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.analog_stick_r.x, &m_hdlState.analog_stick_r.y); - m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0); - m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0); + m_hdlState.buttons |= (data.buttons[16] ? HiddbgNpadButton_Capture : 0); + m_hdlState.buttons |= (data.buttons[17] ? HiddbgNpadButton_Home : 0); } void SwitchHDLHandler::UpdateInput() @@ -190,7 +190,7 @@ void SwitchHDLHandler::UpdateOutput() { Result rc; HidVibrationValue value; - rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value); + rc = hidGetActualVibrationValue(m_vibrationDeviceHandle, &value); if (R_SUCCEEDED(rc)) m_controller->SetRumble(static_cast(value.amp_high * 255.0f), static_cast(value.amp_low * 255.0f)); } diff --git a/source/ControllerSwitch/SwitchHDLHandler.h b/source/ControllerSwitch/SwitchHDLHandler.h index a828ced..872126a 100644 --- a/source/ControllerSwitch/SwitchHDLHandler.h +++ b/source/ControllerSwitch/SwitchHDLHandler.h @@ -8,7 +8,7 @@ class SwitchHDLHandler : public SwitchVirtualGamepadHandler { private: - u64 m_hdlHandle; + HiddbgHdlsHandle m_hdlHandle; HiddbgHdlsDeviceInfo m_deviceInfo; HiddbgHdlsState m_hdlState; diff --git a/source/ControllerSwitch/SwitchVirtualGamepadHandler.h b/source/ControllerSwitch/SwitchVirtualGamepadHandler.h index 9400edd..1344ac5 100644 --- a/source/ControllerSwitch/SwitchVirtualGamepadHandler.h +++ b/source/ControllerSwitch/SwitchVirtualGamepadHandler.h @@ -7,7 +7,7 @@ class SwitchVirtualGamepadHandler { protected: - u32 m_vibrationDeviceHandle; + HidVibrationDeviceHandle m_vibrationDeviceHandle; std::unique_ptr m_controller; alignas(ams::os::ThreadStackAlignment) u8 input_thread_stack[0x1000]; @@ -52,5 +52,5 @@ public: //Get the raw controller pointer inline IController *GetController() { return m_controller.get(); } - inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; } + inline HidVibrationDeviceHandle *GetVibrationHandle() { return &m_vibrationDeviceHandle; } }; \ No newline at end of file diff --git a/source/Sysmodule/source/psc_module.cpp b/source/Sysmodule/source/psc_module.cpp index b82480c..9583112 100644 --- a/source/Sysmodule/source/psc_module.cpp +++ b/source/Sysmodule/source/psc_module.cpp @@ -11,7 +11,7 @@ namespace syscon::psc { PscPmModule pscModule; Waiter pscModuleWaiter; - const uint16_t dependencies[] = {PscPmModuleId_Fs}; + const uint32_t dependencies[] = {PscPmModuleId_Fs}; //Thread to check for psc:pm state change (console waking up/going to sleep) void PscThreadFunc(void *arg); @@ -53,7 +53,7 @@ namespace syscon::psc } // namespace Result Initialize() { - R_TRY(pscmGetPmModule(&pscModule, PscPmModuleId(126), dependencies, sizeof(dependencies) / sizeof(uint16_t), true)); + R_TRY(pscmGetPmModule(&pscModule, PscPmModuleId(126), dependencies, sizeof(dependencies) / sizeof(uint32_t), true)); pscModuleWaiter = waiterForEvent(&pscModule.event); is_psc_thread_running = true; R_ABORT_UNLESS(threadCreate(&g_psc_thread, &PscThreadFunc, nullptr, psc_thread_stack, sizeof(psc_thread_stack), 0x2C, -2)); diff --git a/source/libstratosphere b/source/libstratosphere index 797dfa7..44279db 160000 --- a/source/libstratosphere +++ b/source/libstratosphere @@ -1 +1 @@ -Subproject commit 797dfa782e85173652d017de38066f9a5c88622a +Subproject commit 44279dbac4cce6413faf5b44bd790b23aa323083