From deb5b36c1bd63c8da8f32a3c1a07eb72aef3baaa Mon Sep 17 00:00:00 2001 From: FIX94 Date: Fri, 29 Sep 2017 19:50:25 +0200 Subject: [PATCH] handle a couple more bits --- README.md | 3 ++- demo/source/main.c | 7 ++++++- include/wiidrc/wiidrc.h | 10 +++++++--- source/wiidrc.c | 9 +++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b9e1c07..62c1a35 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/demo/source/main.c b/demo/source/main.c index b60db3c..44ca62a 100644 --- a/demo/source/main.c +++ b/demo/source/main.c @@ -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"); diff --git a/include/wiidrc/wiidrc.h b/include/wiidrc/wiidrc.h index 5cefedc..32657f0 100644 --- a/include/wiidrc/wiidrc.h +++ b/include/wiidrc/wiidrc.h @@ -17,6 +17,7 @@ struct WiiDRCData { s16 yAxisL; s16 yAxisR; u16 button; + u8 battery; u8 extra; }; @@ -37,15 +38,18 @@ struct WiiDRCData { #define WIIDRC_BUTTON_HOME 0x0002 #define WIIDRC_BUTTON_SYNC 0x0001 -#define WIIDRC_EXTRA_BUTTON_L3 0x80 -#define WIIDRC_EXTRA_BUTTON_R3 0x40 -#define WIIDRC_EXTRA_BUTTON_TV 0x30 +#define WIIDRC_EXTRA_BUTTON_L3 0x80 +#define WIIDRC_EXTRA_BUTTON_R3 0x40 +#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(); diff --git a/source/wiidrc.c b/source/wiidrc.c index 0fe2eb1..39d65ad 100644 --- a/source/wiidrc.c +++ b/source/wiidrc.c @@ -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;