mirror of
https://github.com/switchbrew/switch-examples.git
synced 2025-06-21 05:12:40 +02:00
Updated vibration example.
This commit is contained in:
parent
0ee7945bec
commit
c04241827f
@ -4,7 +4,6 @@
|
||||
#include <switch.h>
|
||||
|
||||
//Example for HID vibration/rumble.
|
||||
//TODO: Why doesn't this vibrate, even though no errors are returned?
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@ -12,21 +11,24 @@ int main(int argc, char **argv)
|
||||
Result rc = 0, rc2 = 0;
|
||||
|
||||
HidVibrationValue VibrationValue;
|
||||
HidVibrationValue VibrationValue_stop;
|
||||
|
||||
gfxInitDefault();
|
||||
consoleInit(NULL);
|
||||
|
||||
printf("Press PLUS to exit.\n");
|
||||
|
||||
rc = hidInitializeVibrationDevice(&VibrationDeviceHandle, CONTROLLER_PLAYER_1, LAYOUT_DEFAULT);//3-10 works
|
||||
rc = hidInitializeVibrationDevice(&VibrationDeviceHandle, CONTROLLER_PLAYER_1, LAYOUT_DEFAULT);
|
||||
printf("hidInitializeVibrationDevice() returned: 0x%x\n", rc);
|
||||
|
||||
if (R_SUCCEEDED(rc)) printf("Press A to vibrate.\n");
|
||||
|
||||
VibrationValue.values[0] = -0.5f;
|
||||
VibrationValue.values[1] = -0.5f;
|
||||
VibrationValue.values[2] = -0.5f;
|
||||
VibrationValue.values[3] = -0.5f;
|
||||
VibrationValue.values[0] = 10.0f;
|
||||
VibrationValue.values[1] = 10.0f;
|
||||
VibrationValue.values[2] = 10.0f;
|
||||
VibrationValue.values[3] = 10.0f;
|
||||
|
||||
memset(&VibrationValue_stop, 0, sizeof(HidVibrationValue));
|
||||
|
||||
// Main loop
|
||||
while(appletMainLoop())
|
||||
@ -36,13 +38,25 @@ int main(int argc, char **argv)
|
||||
|
||||
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
|
||||
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
u32 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
|
||||
u32 kUp = hidKeysUp(CONTROLLER_P1_AUTO);
|
||||
|
||||
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
|
||||
|
||||
if (R_SUCCEEDED(rc) && (kDown & KEY_A))
|
||||
if (R_SUCCEEDED(rc) && (kHeld & KEY_R))
|
||||
{
|
||||
rc2 = hidSendVibrationValue(&VibrationDeviceHandle, &VibrationValue);
|
||||
printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
|
||||
rc2 = hidSendVibrationValue(&VibrationDeviceHandle, &VibrationValue);//This is really only needed when sending a new VibrationValue.
|
||||
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
|
||||
|
||||
if (kDown & KEY_A) VibrationValue.values[0]+= 1.0f;
|
||||
if (kDown & KEY_B) VibrationValue.values[1]+= 5.0f;
|
||||
if (kDown & KEY_X) VibrationValue.values[2]+= 10.0f;
|
||||
if (kDown & KEY_Y) VibrationValue.values[3]+= 12.0f;
|
||||
}
|
||||
else if(kUp & KEY_R)//Stop vibration.
|
||||
{
|
||||
rc2 = hidSendVibrationValue(&VibrationDeviceHandle, &VibrationValue_stop);
|
||||
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
|
||||
}
|
||||
|
||||
gfxFlushBuffers();
|
||||
|
Loading…
Reference in New Issue
Block a user