Skip to content

Commit

Permalink
Merge branch 'gc'
Browse files Browse the repository at this point in the history
  • Loading branch information
Crayon2000 committed Mar 17, 2024
2 parents dba7608 + 5f2cdee commit d0b37c0
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 16 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ jobs:
steps:

- name: Checkout the Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Update packages
run: bash ./.github/workflows/update.sh

- name: Build application
run: |
mkdir --parents build
/opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -B build
cmake --build build -j $(nproc)
/opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -B $GITHUB_WORKSPACE/build
cmake --build $GITHUB_WORKSPACE/build -j $(nproc)
- name: Prepare artifact
run: |
Expand All @@ -31,7 +30,7 @@ jobs:
mv --verbose build/MiisendU-Wii-U.wuhb artifact/MiisendU-Wii-U/MiisendU-Wii-U.wuhb
cp --verbose meta/* artifact/MiisendU-Wii-U
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: MiisendU-Wii-U
path: artifact/
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

All notable changes to this project will be documented in this file.

## [Unreleased]
## [1.3.0] - 2024-03-17

- Send USB Gamecube Controller Adapter button states to UsendMii.
- Remove code for emulated buttons.

## [1.2.0] - 2023-05-12
Expand Down Expand Up @@ -46,7 +47,7 @@ All notable changes to this project will be documented in this file.

- Initial release.

[unreleased]: https://github.com/Crayon2000/MiisendU-Wii-U/compare/v1.2.0...HEAD
[1.3.0]: https://github.com/Crayon2000/MiisendU-Wii-U/compare/v1.2.0...HEAD
[1.2.0]: https://github.com/Crayon2000/MiisendU-Wii-U/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/Crayon2000/MiisendU-Wii-U/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/Crayon2000/MiisendU-Wii-U/compare/v0.3.0...v1.0.0
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Prerequisites:
To compile:

```bash
mkdir --parents build
/opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -B build
cmake --build build
```
4 changes: 2 additions & 2 deletions meta/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<app version="1">
<name>MiisendU Wii U</name>
<coder>Crayon</coder>
<version>1.2.0</version>
<release_date>20230512000000</release_date>
<version>1.3.0</version>
<release_date>20240317000000</release_date>
<short_description>A UsendMii client</short_description>
<long_description>A UsendMii client for Wii U.

Expand Down
32 changes: 31 additions & 1 deletion source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void PrintHeader(OSScreenID bufferNum)
OSScreenPutFontEx(bufferNum, -4, 0, " __ __ _ _ _ _ _ __ ___ _ _ _ ");
OSScreenPutFontEx(bufferNum, -4, 1, "| \\/ (_|_)___ ___ _ _ __| | | | | \\ \\ / (_|_) | | | |");
OSScreenPutFontEx(bufferNum, -4, 2, "| |\\/| | | (_-</ -_) ' \\/ _` | |_| | \\ \\/\\/ /| | | | |_| |");
OSScreenPutFontEx(bufferNum, -4, 3, "|_| |_|_|_/__/\\___|_||_\\__,_|\\___/ \\_/\\_/ |_|_| \\___/ v1.2.0");
OSScreenPutFontEx(bufferNum, -4, 3, "|_| |_|_|_/__/\\___|_||_\\__,_|\\___/ \\_/\\_/ |_|_| \\___/ v1.3.0");
}

/**
Expand Down Expand Up @@ -94,6 +94,7 @@ int main(int argc, char **argv)
WHBProcInit();
VPADInit();
KPADInit();
HPADInit();
WPADEnableURCC(true);

WHBMountSdCard();
Expand Down Expand Up @@ -258,6 +259,10 @@ int main(int argc, char **argv)
KPADStatus kpad_data2;
KPADStatus kpad_data3;
KPADStatus kpad_data4;
HPADStatus hpad_data1[16];
HPADStatus hpad_data2[16];
HPADStatus hpad_data3[16];
HPADStatus hpad_data4[16];

// Read the VPAD
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &error);
Expand All @@ -268,6 +273,12 @@ int main(int argc, char **argv)
KPADReadEx(WPAD_CHAN_2, &kpad_data3, 1, &kpad_error3);
KPADReadEx(WPAD_CHAN_3, &kpad_data4, 1, &kpad_error4);

// Read the HPADs
int32_t hpad_error1 = HPADRead(HPAD_CHAN_0, &hpad_data1[0], 16);
int32_t hpad_error2 = HPADRead(HPAD_CHAN_1, &hpad_data2[0], 16);
int32_t hpad_error3 = HPADRead(HPAD_CHAN_2, &hpad_data3[0], 16);
int32_t hpad_error4 = HPADRead(HPAD_CHAN_3, &hpad_data4[0], 16);

// Flush the cache (may be needed due to continuous refresh of the data ?)
DCFlushRange(&vpad_data, sizeof(VPADStatus));

Expand All @@ -291,6 +302,22 @@ int main(int argc, char **argv)
{
pad_data.kpad[3] = &kpad_data4;
}
if(hpad_error1 >= 0)
{
pad_data.hpad[0] = &hpad_data1[0];
}
if(hpad_error2 >= 0)
{
pad_data.hpad[1] = &hpad_data2[0];
}
if(hpad_error3 >= 0)
{
pad_data.hpad[2] = &hpad_data3[0];
}
if(hpad_error4 >= 0)
{
pad_data.hpad[3] = &hpad_data4[0];
}
pad_to_json(pad_data, msg_data, sizeof(msg_data));

// Send the message
Expand All @@ -315,6 +342,9 @@ int main(int argc, char **argv)
}

free(IP_ADDRESS);
VPADShutdown();
KPADShutdown();
HPADShutdown();
WHBUnmountSdCard();
ConsoleFree();
WHBProcShutdown();
Expand Down
86 changes: 81 additions & 5 deletions source/vpad_to_json.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#include <string.h>
#include <jansson.h>
#include <map>
#include "vpad_to_json.h"

/**
* Mask for the Gamecube Controller.
*/
static const std::map gcmask = {
std::pair{HPAD_BUTTON_LEFT, 0x0001},
{HPAD_BUTTON_RIGHT, 0x0002},
{HPAD_BUTTON_DOWN, 0x0004},
{HPAD_BUTTON_UP, 0x0008},
{HPAD_TRIGGER_Z, 0x0010},
{HPAD_TRIGGER_R, 0x0020},
{HPAD_TRIGGER_L, 0x0040},
{HPAD_BUTTON_A, 0x0100},
{HPAD_BUTTON_B, 0x0200},
{HPAD_BUTTON_X, 0x0400},
{HPAD_BUTTON_Y, 0x0800},
{HPAD_BUTTON_START, 0x1000},
};

/**
* Change the range.
*/
[[nodiscard]] static constexpr int change_range(int value, int oldMin, int oldMax, int newMin, int newMax)
{
return static_cast<int>((static_cast<float>(value - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin);
}

/**
* Convert GamePad data to JSON string used by UsendMii.
* @param[in] pad_data Controllers data.
Expand Down Expand Up @@ -48,16 +75,16 @@ void pad_to_json(PADData pad_data, char* out, uint32_t out_size)
json_object_set_new_nocheck(wiiugamepad, "dirZz", json_real(pad_data.vpad->direction.z.z));

// Wii Remotes / Wii U Pro Controllers
if(pad_data.kpad[0] != NULL ||
pad_data.kpad[1] != NULL ||
pad_data.kpad[2] != NULL ||
pad_data.kpad[3] != NULL)
if(pad_data.kpad[0] != nullptr ||
pad_data.kpad[1] != nullptr ||
pad_data.kpad[2] != nullptr ||
pad_data.kpad[3] != nullptr)
{
json_t *wiiremotes = json_array();
json_t *wiiuprocontrollers = json_array();
for(int i = 0; i < 4; ++i)
{
if(pad_data.kpad[i] != NULL)
if(pad_data.kpad[i] != nullptr)
{
if(pad_data.kpad[i]->extensionType != WPAD_EXT_PRO_CONTROLLER)
{ // Wii Remote with or without an extension
Expand Down Expand Up @@ -132,6 +159,55 @@ void pad_to_json(PADData pad_data, char* out, uint32_t out_size)
}
}

// USB Gamecube Controller Adapter
if(pad_data.hpad[0] != nullptr ||
pad_data.hpad[1] != nullptr ||
pad_data.hpad[2] != nullptr ||
pad_data.hpad[3] != nullptr)
{
json_t *gccontrollers = json_array();
for(int i = 0; i < 4; ++i)
{
if(pad_data.hpad[i] == nullptr)
{
continue;
}
int32_t holdgc = 0;
const int32_t badgc = pad_data.hpad[i]->hold;
for (auto const& [oldid, newid] : gcmask)
{
if(badgc & oldid) {
holdgc |= newid;
}
}

json_t *gccontroller = json_object();
json_object_set_new_nocheck(gccontroller, "order", json_integer(i + 1));
json_object_set_new_nocheck(gccontroller, "hold", json_integer(holdgc));
json_object_set_new_nocheck(gccontroller, "ctrlStickX", json_integer(
change_range(pad_data.hpad[i]->stickX, HPAD_STICK_AXIS_MIN, HPAD_STICK_AXIS_MAX, -128, 127)));
json_object_set_new_nocheck(gccontroller, "ctrlStickY", json_integer(
change_range(pad_data.hpad[i]->stickY, HPAD_STICK_AXIS_MIN, HPAD_STICK_AXIS_MAX, -128, 127)));
json_object_set_new_nocheck(gccontroller, "cStickX", json_integer(
change_range(pad_data.hpad[i]->substickX, HPAD_SUBSTICK_AXIS_MIN, HPAD_SUBSTICK_AXIS_MAX, -128, 127)));
json_object_set_new_nocheck(gccontroller, "cStickY", json_integer(
change_range(pad_data.hpad[i]->substickY, HPAD_SUBSTICK_AXIS_MIN, HPAD_SUBSTICK_AXIS_MAX, -128, 127)));
json_object_set_new_nocheck(gccontroller, "lTrigger", json_integer(
change_range(pad_data.hpad[i]->triggerL, HPAD_TRIGGER_MIN, HPAD_TRIGGER_MAX, 0, 255)));
json_object_set_new_nocheck(gccontroller, "rTrigger", json_integer(
change_range(pad_data.hpad[i]->triggerR, HPAD_TRIGGER_MIN, HPAD_TRIGGER_MAX, 0, 255)));
json_array_append(gccontrollers, gccontroller);
}
if(json_array_size(gccontrollers) > 0)
{
json_object_set_new_nocheck(root, "gameCubeControllers", gccontrollers);
}
else
{
json_delete(gccontrollers);
}
}

// Convert to string
char* s = json_dumps(root, JSON_COMPACT | JSON_REAL_PRECISION(10));
strncpy(out, s, out_size);
Expand Down
2 changes: 2 additions & 0 deletions source/vpad_to_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <wut_types.h>
#include <padscore/kpad.h>
#include <vpad/input.h>
#include <nn/hpad/hpad.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -15,6 +16,7 @@ extern "C" {
typedef struct {
VPADStatus* vpad; /**< Wii U Gamepad. */
KPADStatus* kpad[4]; /**< Wii Remotes. */
HPADStatus* hpad[4]; /**< USB Gamecube Controller Adapter. */
} PADData;

void pad_to_json(PADData pad_data, char* out, uint32_t out_size);
Expand Down

0 comments on commit d0b37c0

Please sign in to comment.