Merged with Pad example
Also updated to make it work with latest ctrulib and devkitARM
This commit is contained in:
parent
adeffd27ea
commit
24bceda509
@ -35,7 +35,7 @@ INCLUDES := include
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# options for code generation
|
# options for code generation
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=softfp
|
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
|
||||||
|
|
||||||
CFLAGS := -g -Wall -O2 -mword-relocations \
|
CFLAGS := -g -Wall -O2 -mword-relocations \
|
||||||
-fomit-frame-pointer -ffast-math \
|
-fomit-frame-pointer -ffast-math \
|
||||||
|
@ -18,15 +18,26 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
//Matrix containing the name of each key. Useful for printing when a key is pressed
|
||||||
|
char keysNames[32][32] = {
|
||||||
|
"KEY_A", "KEY_B", "KEY_SELECT", "KEY_START",
|
||||||
|
"KEY_DRIGHT", "KEY_DLEFT", "KEY_DUP", "KEY_DDOWN",
|
||||||
|
"KEY_R", "KEY_L", "KEY_X", "KEY_Y",
|
||||||
|
"", "", "KEY_ZL", "KEY_ZR",
|
||||||
|
"", "", "", "",
|
||||||
|
"KEY_TOUCH", "", "", "",
|
||||||
|
"KEY_CSTICK_RIGHT", "KEY_CSTICK_LEFT", "KEY_CSTICK_UP", "KEY_CSTICK_DOWN",
|
||||||
|
"KEY_CPAD_RIGHT", "KEY_CPAD_LEFT", "KEY_CPAD_UP", "KEY_CPAD_DOWN"
|
||||||
|
};
|
||||||
|
|
||||||
// Initialize services
|
// Initialize services
|
||||||
srvInit();
|
gfxInitDefault();
|
||||||
aptInit();
|
|
||||||
gfxInit();
|
|
||||||
hidInit(NULL);
|
|
||||||
|
|
||||||
//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
|
//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
|
||||||
consoleInit(GFX_TOP, NULL);
|
consoleInit(GFX_TOP, NULL);
|
||||||
|
|
||||||
|
u32 kDownOld = 0, kHeldOld = 0, kUpOld = 0; //In these variables there will be information about keys detected in the previous frame
|
||||||
|
|
||||||
printf("\x1b[0;0HPress Start to exit.");
|
printf("\x1b[0;0HPress Start to exit.");
|
||||||
printf("\x1b[1;0HCirclePad position:");
|
printf("\x1b[1;0HCirclePad position:");
|
||||||
|
|
||||||
@ -38,9 +49,40 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
|
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
|
||||||
u32 kDown = hidKeysDown();
|
u32 kDown = hidKeysDown();
|
||||||
|
//hidKeysHeld returns information about which buttons have are held down in this frame
|
||||||
|
u32 kHeld = hidKeysHeld();
|
||||||
|
//hidKeysUp returns information about which buttons have been just released
|
||||||
|
u32 kUp = hidKeysUp();
|
||||||
|
|
||||||
if (kDown & KEY_START) break; // break in order to return to hbmenu
|
if (kDown & KEY_START) break; // break in order to return to hbmenu
|
||||||
|
|
||||||
|
//Do the keys printing only if keys have changed
|
||||||
|
if (kDown != kDownOld || kHeld != kHeldOld || kUp != kUpOld)
|
||||||
|
{
|
||||||
|
//Clear console
|
||||||
|
consoleClear();
|
||||||
|
|
||||||
|
//These two lines must be rewritten because we cleared the whole console
|
||||||
|
printf("\x1b[0;0HPress Start to exit.");
|
||||||
|
printf("\x1b[1;0HCirclePad position:");
|
||||||
|
|
||||||
|
printf("\x1b[3;0H"); //Move the cursor to the fourth row because on the third one we'll write the circle pad position
|
||||||
|
|
||||||
|
//Check if some of the keys are down, held or up
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
if (kDown & BIT(i)) printf("%s down\n", keysNames[i]);
|
||||||
|
if (kHeld & BIT(i)) printf("%s held\n", keysNames[i]);
|
||||||
|
if (kUp & BIT(i)) printf("%s up\n", keysNames[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set keys old values for the next frame
|
||||||
|
kDownOld = kDown;
|
||||||
|
kHeldOld = kHeld;
|
||||||
|
kUpOld = kUp;
|
||||||
|
|
||||||
circlePosition pos;
|
circlePosition pos;
|
||||||
|
|
||||||
//Read the CirclePad position
|
//Read the CirclePad position
|
||||||
@ -49,7 +91,6 @@ int main(int argc, char **argv)
|
|||||||
//Print the CirclePad position
|
//Print the CirclePad position
|
||||||
printf("\x1b[2;0H%04d; %04d", pos.dx, pos.dy);
|
printf("\x1b[2;0H%04d; %04d", pos.dx, pos.dy);
|
||||||
|
|
||||||
|
|
||||||
// Flush and swap framebuffers
|
// Flush and swap framebuffers
|
||||||
gfxFlushBuffers();
|
gfxFlushBuffers();
|
||||||
gfxSwapBuffers();
|
gfxSwapBuffers();
|
||||||
@ -60,8 +101,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Exit services
|
// Exit services
|
||||||
gfxExit();
|
gfxExit();
|
||||||
hidExit();
|
|
||||||
aptExit();
|
|
||||||
srvExit();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user