Skip to content

Commit

Permalink
Update dependencies for 12.0.0 FW support
Browse files Browse the repository at this point in the history
  • Loading branch information
cathery committed Apr 12, 2021
1 parent 28f9ce9 commit eee8f23
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 85 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
37 changes: 20 additions & 17 deletions source/AppletCompanion/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HidControllerID>(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;
}
56 changes: 28 additions & 28 deletions source/ControllerSwitch/SwitchAbstractedPadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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{};

Expand All @@ -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()
Expand Down Expand Up @@ -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<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
}
Expand Down
66 changes: 33 additions & 33 deletions source/ControllerSwitch/SwitchHDLHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ 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;
m_deviceInfo.singleColorButtons = config->buttonsColor.rgbaValue;
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);
Expand Down Expand Up @@ -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{};

Expand All @@ -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()
Expand Down Expand Up @@ -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<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
}
Expand Down
2 changes: 1 addition & 1 deletion source/ControllerSwitch/SwitchHDLHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SwitchHDLHandler : public SwitchVirtualGamepadHandler
{
private:
u64 m_hdlHandle;
HiddbgHdlsHandle m_hdlHandle;
HiddbgHdlsDeviceInfo m_deviceInfo;
HiddbgHdlsState m_hdlState;

Expand Down
4 changes: 2 additions & 2 deletions source/ControllerSwitch/SwitchVirtualGamepadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class SwitchVirtualGamepadHandler
{
protected:
u32 m_vibrationDeviceHandle;
HidVibrationDeviceHandle m_vibrationDeviceHandle;
std::unique_ptr<IController> m_controller;

alignas(ams::os::ThreadStackAlignment) u8 input_thread_stack[0x1000];
Expand Down Expand Up @@ -52,5 +52,5 @@ class SwitchVirtualGamepadHandler

//Get the raw controller pointer
inline IController *GetController() { return m_controller.get(); }
inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
inline HidVibrationDeviceHandle *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
};
4 changes: 2 additions & 2 deletions source/Sysmodule/source/psc_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion source/libstratosphere
Submodule libstratosphere updated 1485 files

0 comments on commit eee8f23

Please sign in to comment.