libctru  v2.3.1
input/touch-screen/source/main.c
/*
Touch Screen example made by Aurelio Mannara for libctru
Please refer to https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/services/hid.h for more information
This code was modified for the last time on: 12/13/2014 2:30 UTC+1
This wouldn't be possible without the amazing work done by:
-Smealum
-fincs
-WinterMute
-yellows8
-plutoo
-mtheall
-Many others who worked on 3DS and I'm surely forgetting about
*/
#include <3ds.h>
#include <stdio.h>
int main(int argc, char **argv)
{
//Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one
printf("\x1b[0;0HPress Start to exit.");
printf("\x1b[1;0HTouch Screen position:");
// Main loop
while (aptMainLoop())
{
//Scan all the inputs. This should be done once for each frame
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown();
if (kDown & KEY_START) break; // break in order to return to hbmenu
//Read the touch screen coordinates
hidTouchRead(&touch);
//Print the touch screen coordinates
printf("\x1b[2;0H%03d; %03d", touch.px, touch.py);
// Flush and swap framebuffers
//Wait for VBlank
}
// Exit services
return 0;
}
Central 3DS header.
bool aptMainLoop(void)
Main function which handles sleep mode and HOME/power buttons - call this at the beginning of every f...
PrintConsole * consoleInit(gfxScreen_t screen, PrintConsole *console)
Initialise the console.
void gfxSwapBuffers(void)
Updates the configuration of both screens.
void gfxInitDefault(void)
Initializes the LCD framebuffers with default parameters This is equivalent to calling:
@ GFX_TOP
Top screen.
Definition: gfx.h:26
void gfxExit(void)
Deinitializes and frees the LCD framebuffers.
void gfxFlushBuffers(void)
Flushes the data cache for the current framebuffers.
#define gspWaitForVBlank()
Waits for VBlank.
Definition: gspgpu.h:151
@ KEY_START
Start.
Definition: hid.h:15
u32 hidKeysDown(void)
Returns a bitmask of newly pressed buttons, this frame.
void hidScanInput(void)
Scans HID for input data.
void hidTouchRead(touchPosition *pos)
Reads the current touch position.
Touch position.
Definition: hid.h:45
u16 px
Touch X.
Definition: hid.h:46
u16 py
Touch Y.
Definition: hid.h:47
uint32_t u32
32-bit unsigned integer
Definition: types.h:23