libctru  v2.3.1
qtm/source/main.c
#include <string.h>
#include <stdio.h>
#include <3ds.h>
int main()
{
u32 pos;
u32 x, y;
Result ret;
bool qtm_usable;
u32 colors[4] = {0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF};
//gfxSet3D(true); // uncomment if using stereoscopic 3D
printf("qtm example\n");
qtm_usable = qtmCheckInitialized();
if(!qtm_usable)printf("QTM is not usable, therefore this example won't do anything with QTM.\n");
// Main loop
while (aptMainLoop())
{
u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break; // break in order to return to hbmenu
if(qtm_usable)
{
u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memset(fb, 0, 400*240*3);
ret = QTM_GetHeadTrackingInfo(0, &qtminfo);
if(ret==0)
{
for(pos=0; pos<5; pos++)
{
printf("flags[%x]=0x%x", (unsigned int)pos, qtminfo.flags[pos]);
if(pos<4)printf(", ");
}
printf("\nfloatdata_x08: %f\n", qtminfo.floatdata_x08);
printf("coords0: ");
for(pos=0; pos<4; pos++)
{
printf("[%x].x=%f, y=%f", (unsigned int)pos, qtminfo.coords0[pos].x, qtminfo.coords0[pos].y);
if(pos<3)printf(", ");
}
printf("\n");
{
for(pos=0; pos<4; pos++)
{
ret = qtmConvertCoordToScreen(&qtminfo.coords0[pos], NULL, NULL, &x, &y);
if(ret==0)memcpy(&fb[(x*240 + y) * 3], &colors[pos], 3);
}
}
}
}
// Flush and swap framebuffers
}
// 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 consoleClear(void)
Clears the screen by using iprintf("\x1b[2J");.
void gfxSwapBuffers(void)
Updates the configuration of both screens.
void gfxInitDefault(void)
Initializes the LCD framebuffers with default parameters This is equivalent to calling:
u8 * gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16 *width, u16 *height)
Retrieves the framebuffer of the specified screen to which graphics should be rendered.
@ GFX_BOTTOM
Bottom screen.
Definition: gfx.h:27
@ GFX_TOP
Top screen.
Definition: gfx.h:26
void gfxExit(void)
Deinitializes and frees the LCD framebuffers.
@ GFX_LEFT
Left eye framebuffer.
Definition: gfx.h:37
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 qtmExit(void)
Exits QTM.
bool qtmCheckInitialized(void)
Checks whether QTM is initialized.
Result qtmInit(void)
Initializes QTM.
Result qtmConvertCoordToScreen(QTM_HeadTrackingInfoCoord *coord, float *screen_width, float *screen_height, u32 *x, u32 *y)
Converts QTM coordinates to screen coordinates.
Result QTM_GetHeadTrackingInfo(u64 val, QTM_HeadTrackingInfo *out)
Gets the current head tracking info.
bool qtmCheckHeadFullyDetected(QTM_HeadTrackingInfo *info)
Checks whether a head is fully detected.
float x
X coordinate.
Definition: qtm.h:11
float y
Y coordinate.
Definition: qtm.h:12
Head tracking info.
Definition: qtm.h:16
float floatdata_x08
Unknown. Not used by System_Settings.
Definition: qtm.h:19
u8 flags[5]
Flags.
Definition: qtm.h:17
QTM_HeadTrackingInfoCoord coords0[4]
Head coordinates.
Definition: qtm.h:20
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
s32 Result
Function result.
Definition: types.h:42
uint32_t u32
32-bit unsigned integer
Definition: types.h:23