mirror of
https://github.com/switchbrew/switch-examples.git
synced 2025-06-21 05:12:40 +02:00
hid/sevensixaxis: Updated for hid-refactor.
This commit is contained in:
parent
5a42b4766b
commit
29484f5c06
@ -1,18 +1,34 @@
|
|||||||
#include <string.h>
|
// Include the most common headers from the C standard library
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Include the main libnx system header, for Switch development
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
// This example shows how to use the SevenSixAxisSensor. Official sw usually only uses this while VrMode is active. See also the vrmode example.
|
// This example shows how to use the SevenSixAxisSensor. Official sw usually only uses this while VrMode is active. See also the vrmode example.
|
||||||
// See also libnx hid.h.
|
// See also libnx hid.h.
|
||||||
// SevenSixAxisSensor combines the SixAxisSensor for the Console and Joy-Cons together.
|
// SevenSixAxisSensor combines the SixAxisSensor for the Console and Joy-Cons together.
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
// Main program entrypoint
|
||||||
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
Result rc=0;
|
// This example uses a text console, as a simple way to output text to the screen.
|
||||||
|
// If you want to write a software-rendered graphics application,
|
||||||
|
// take a look at the graphics/simplegfx example, which uses the libnx Framebuffer API instead.
|
||||||
|
// If on the other hand you want to write an OpenGL based application,
|
||||||
|
// take a look at the graphics/opengl set of examples, which uses EGL instead.
|
||||||
consoleInit(NULL);
|
consoleInit(NULL);
|
||||||
|
|
||||||
|
// Configure our supported input layout: a single player with standard controller styles
|
||||||
|
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
||||||
|
|
||||||
|
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
|
||||||
|
PadState pad;
|
||||||
|
padInitializeDefault(&pad);
|
||||||
|
|
||||||
|
Result rc=0;
|
||||||
|
|
||||||
printf("Press A to get state.\n");
|
printf("Press A to get state.\n");
|
||||||
printf("Press + to exit.\n");
|
printf("Press + to exit.\n");
|
||||||
|
|
||||||
@ -31,15 +47,17 @@ int main(int argc, char **argv)
|
|||||||
// Main loop
|
// Main loop
|
||||||
while(appletMainLoop())
|
while(appletMainLoop())
|
||||||
{
|
{
|
||||||
//Scan all the inputs. This should be done once for each frame
|
// Scan the gamepad. This should be done once for each frame
|
||||||
hidScanInput();
|
padUpdate(&pad);
|
||||||
|
|
||||||
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
|
// padGetButtonsDown returns the set of buttons that have been
|
||||||
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
// newly pressed in this frame compared to the previous one
|
||||||
|
u64 kDown = padGetButtonsDown(&pad);
|
||||||
|
|
||||||
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
|
if (kDown & HidNpadButton_Plus)
|
||||||
|
break; // break in order to return to hbmenu
|
||||||
|
|
||||||
if (kDown & KEY_A) {
|
if (kDown & HidNpadButton_A) {
|
||||||
HidSevenSixAxisSensorState states[1]={0};
|
HidSevenSixAxisSensorState states[1]={0};
|
||||||
size_t total_out=0;
|
size_t total_out=0;
|
||||||
rc = hidGetSevenSixAxisSensorStates(states, 1, &total_out);
|
rc = hidGetSevenSixAxisSensorStates(states, 1, &total_out);
|
||||||
@ -52,6 +70,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the console, sending a new frame to the display
|
||||||
consoleUpdate(NULL);
|
consoleUpdate(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +83,7 @@ int main(int argc, char **argv)
|
|||||||
rc = hidFinalizeSevenSixAxisSensor();
|
rc = hidFinalizeSevenSixAxisSensor();
|
||||||
printf("hidFinalizeSevenSixAxisSensor(): 0x%x\n", rc);
|
printf("hidFinalizeSevenSixAxisSensor(): 0x%x\n", rc);
|
||||||
|
|
||||||
|
// Deinitialize and clean up resources used by the console (important!)
|
||||||
consoleExit(NULL);
|
consoleExit(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user