handle a couple more bits

This commit is contained in:
FIX94 2017-09-29 19:50:25 +02:00
parent 7986600ffc
commit deb5b36c1b
No known key found for this signature in database
GPG Key ID: CE39016A19D8EADA
4 changed files with 24 additions and 5 deletions

View File

@ -3,7 +3,8 @@ This is only usable with a sepcial patched fw.img and homebrew injected into a W
Most WiiU VC injector tools already contain the patches required for this, the patches below are only needed if you do it manually.
The usage is quite simple, call WiiDRC_Init on boot and after that call WiiDRC_ScanPads every time you update your pad inputs.
To check if the gamepad is ready to use, call WiiDRC_Inited and WiiDRC_Connected, if both are true its good to go.
The analog stick range goes from about -80 to 80 so make sure to scale it to whatever you need.
The analog stick range goes from about -75 to 75 so make sure to scale it to whatever you need.
The battery status goes from 6 (full) down to 1 (critical), 0 meaning that it is currently charging.
See the "demo" folder for an example on how to use it in a bit more detail.
Both compiled Library and Demo can be grabbed from the Releases tab.

View File

@ -40,7 +40,7 @@ int main(int argc, char *argv[])
{
printf("\x1b[2J");
printf("\x1b[37m");
printf("WiiDRC v1.1 Demo by FIX94\n");
printf("WiiDRC v1.2 Demo by FIX94\n");
printf("Press any button on a real Wiimote to exit\n");
if(inited)
{
@ -50,6 +50,9 @@ int main(int argc, char *argv[])
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->battery) printf("Battery: %i\n", drcdat->battery);
else printf("Battery: Charging\n");
if(WiiDRC_ShutdownRequested()) printf("Gamepad is asking for a shutdown\n");
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");
@ -69,6 +72,8 @@ int main(int argc, char *argv[])
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");
if(drcdat->extra & WIIDRC_EXTRA_OVERLAY_TV) printf("TV overlay\n");
if(drcdat->extra & WIIDRC_EXTRA_OVERLAY_POWER) printf("Shutdown overlay\n");
}
else
printf("Gamepad was not enabled when starting Wii VC.\n");

View File

@ -17,6 +17,7 @@ struct WiiDRCData {
s16 yAxisL;
s16 yAxisR;
u16 button;
u8 battery;
u8 extra;
};
@ -39,13 +40,16 @@ struct WiiDRCData {
#define WIIDRC_EXTRA_BUTTON_L3 0x80
#define WIIDRC_EXTRA_BUTTON_R3 0x40
#define WIIDRC_EXTRA_BUTTON_TV 0x30
#define WIIDRC_EXTRA_BUTTON_TV 0x20
#define WIIDRC_EXTRA_OVERLAY_TV 0x10
#define WIIDRC_EXTRA_OVERLAY_POWER 0x01
bool WiiDRC_Init();
bool WiiDRC_Inited();
bool WiiDRC_Recalibrate();
bool WiiDRC_ScanPads();
bool WiiDRC_Connected();
bool WiiDRC_ShutdownRequested();
const u8 *WiiDRC_GetRawI2CAddr();
const struct WiiDRCData *WiiDRC_Data();
u32 WiiDRC_ButtonsUp();

View File

@ -13,6 +13,7 @@
static struct WiiDRCStat __WiiDRC_Status;
static struct WiiDRCData __WiiDRC_PadData;
static struct WiiDRCButtons __WiiDRC_PadButtons;
static bool __WiiDRC_ShutdownRequested;
static u32 __WiiDRC_Inited = 0;
static u8 *__WiiDRC_I2CBuf = NULL;
@ -72,6 +73,7 @@ bool WiiDRC_Init()
WiiDRC_Recalibrate(); //sets up __WiiDRC_Status
memset(&__WiiDRC_PadData,0,sizeof(struct WiiDRCData));
memset(&__WiiDRC_PadButtons,0,sizeof(struct WiiDRCButtons));
__WiiDRC_ShutdownRequested = false;
return true;
}
@ -101,12 +103,14 @@ bool WiiDRC_ScanPads()
return false;
DCInvalidateRange(__WiiDRC_I2CBuf,9);
__WiiDRC_ShutdownRequested = !!(__WiiDRC_I2CBuf[1]&0x80);
__WiiDRC_PadData.button = (__WiiDRC_I2CBuf[2]<<8) | (__WiiDRC_I2CBuf[3]);
__WiiDRC_PadData.xAxisL = ((s8)(__WiiDRC_I2CBuf[4]-0x80)) - __WiiDRC_Status.xAxisLmid;
__WiiDRC_PadData.yAxisL = ((s8)(__WiiDRC_I2CBuf[5]-0x80)) - __WiiDRC_Status.yAxisLmid;
__WiiDRC_PadData.xAxisR = ((s8)(__WiiDRC_I2CBuf[6]-0x80)) - __WiiDRC_Status.xAxisRmid;
__WiiDRC_PadData.yAxisR = ((s8)(__WiiDRC_I2CBuf[7]-0x80)) - __WiiDRC_Status.yAxisRmid;
__WiiDRC_PadData.extra = __WiiDRC_I2CBuf[8];
__WiiDRC_PadData.battery = (__WiiDRC_PadData.extra>>1)&7;
u16 newstate, oldstate;
@ -129,6 +133,11 @@ bool WiiDRC_Connected()
return true; //default connect
}
bool WiiDRC_ShutdownRequested()
{
return __WiiDRC_ShutdownRequested;
}
const u8 *WiiDRC_GetRawI2CAddr()
{
return __WiiDRC_I2CBuf;