libwiidrc/demo/source/main.c
2017-09-14 00:11:40 +02:00

72 lines
2.5 KiB
C

/*
* Copyright (C) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#include <gccore.h>
#include <stdio.h>
#include <wiiuse/wpad.h>
#include <wiidrc/wiidrc.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char *argv[])
{
void *xfb = NULL;
GXRModeObj *rmode = NULL;
VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
int x = 24, y = 32, w, h;
w = rmode->fbWidth - (32);
h = rmode->xfbHeight - (48);
CON_InitEx(rmode, x, y, w, h);
VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
PAD_Init();
WPAD_Init();
WiiDRC_Init();
while(1)
{
printf("\x1b[2J");
printf("\x1b[37m");
printf("WiiDRC v1.0 Demo by FIX94\n");
printf("Press any button on a real Wiimote to exit\n");
WiiDRC_ScanPads();
const struct WiiDRCData *drcdat = WiiDRC_Data();
printf("Left Stick X: %i, Y: %i; Right Stick X: %i, Y: %i\n",
drcdat->xAxisL, drcdat->yAxisL, drcdat->xAxisR, drcdat->yAxisR);
if(drcdat->button & WIIDRC_BUTTON_A) printf("A pressed\n");
if(drcdat->button & WIIDRC_BUTTON_B) printf("B pressed\n");
if(drcdat->button & WIIDRC_BUTTON_X) printf("X pressed\n");
if(drcdat->button & WIIDRC_BUTTON_Y) printf("Y pressed\n");
if(drcdat->button & WIIDRC_BUTTON_LEFT) printf("D-Pad Left pressed\n");
if(drcdat->button & WIIDRC_BUTTON_RIGHT) printf("D-Pad Right pressed\n");
if(drcdat->button & WIIDRC_BUTTON_UP) printf("D-Pad Up pressed\n");
if(drcdat->button & WIIDRC_BUTTON_DOWN) printf("D-Pad Down pressed\n");
if(drcdat->button & WIIDRC_BUTTON_ZL) printf("ZL pressed\n");
if(drcdat->button & WIIDRC_BUTTON_ZR) printf("ZR pressed\n");
if(drcdat->button & WIIDRC_BUTTON_L) printf("L pressed\n");
if(drcdat->button & WIIDRC_BUTTON_R) printf("R pressed\n");
if(drcdat->button & WIIDRC_BUTTON_PLUS) printf("Plus pressed\n");
if(drcdat->button & WIIDRC_BUTTON_MINUS) printf("Minus pressed\n");
if(drcdat->button & WIIDRC_BUTTON_HOME) printf("HOME pressed\n");
if(drcdat->extra & WIIDRC_EXTRA_BUTTON_L3) printf("L3 pressed\n");
if(drcdat->extra & WIIDRC_EXTRA_BUTTON_R3) printf("R3 pressed\n");
if(drcdat->extra & WIIDRC_EXTRA_BUTTON_TV) printf("TV pressed\n");
VIDEO_WaitVSync();
VIDEO_WaitVSync();
PAD_ScanPads();
WPAD_ScanPads();
if(PAD_ButtonsHeld(0) || WPAD_ButtonsHeld(0))
break;
}
return 0;
}