Skip to content

Commit

Permalink
Add Nunchuk/CC emulated sticks, KPAD accelerometer data, WPAD/KPAD do…
Browse files Browse the repository at this point in the history
…cumentation (#114)

* Add emulated stick values for Nunchuk and Classic Controller

* Add acceleration sensor data to KPADStatus

I have also changed the posValid type from uint8_t to int8_t because the value can be negative.
A negative value means that the result validity is not really good.

* Set version to beta in the doc

* Added mask for button C and button Z on the Nunchuk

The same mask applies to WPADButton and WPADNunchukButton.

* Add doxygen comments and fix typos

Most of the comments are pretty obvious but at least it's a start.

* Fix a copy-paste error in my last commit

I have also added comments for VPADGetTPCalibrationParam and VPADSetTPCalibrationParam.

* Add documentation for all buttons
  • Loading branch information
Crayon2000 authored and ashquarky committed Jan 20, 2020
1 parent d39e7ca commit 78ee1c5
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(DOXYGEN_FOUND)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

set(DOXYGEN_PROJECT_NAME "wut")
set(DOXYGEN_PROJECT_NUMBER "1.0.0-alpha")
set(DOXYGEN_PROJECT_NUMBER "1.0.0-beta")
set(DOXYGEN_PROJECT_BRIEF "Wii U Toolchain")

set(DOXYGEN_GENERATE_HTML YES)
Expand Down
2 changes: 1 addition & 1 deletion include/nsysnet/nssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ NSSLCreateContext(int32_t unk);
* The NSSL context to destroy.
*
* \returns
* 0 on success, or a negative value if an error occured.
* 0 on success, or a negative value if an error occurred.
*/
int32_t
NSSLDestroyContext(NSSLContextHandle context);
Expand Down
138 changes: 124 additions & 14 deletions include/padscore/kpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,160 @@
/**
* \defgroup padscore_kpad KPAD
* \ingroup padscore
*
* KPAD is a high-level library over WPAD.
*
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif

//! Wii Remote channel.
typedef enum WPADChan KPADChan;
//! Data format.
typedef enum WPADDataFormat KPADDataFormat;
//! Extension type.
typedef enum WPADExtensionType KPADExtensionType;

typedef struct KPADStatus KPADStatus;
typedef struct KPADVec2D KPADVec2D;
typedef struct KPADVec3D KPADVec3D;

//! Error.
typedef enum KPADError
{
//! No errors.
KPAD_ERROR_OK = 0,
} KPADError;

//! 2D vector.
struct KPADVec2D
{
float x;
float y;
//! x.
float x;
//! y.
float y;
};
WUT_CHECK_OFFSET(KPADVec2D, 0x00, x);
WUT_CHECK_OFFSET(KPADVec2D, 0x04, y);
WUT_CHECK_SIZE(KPADVec2D, 0x08);

//! 3D vector.
struct KPADVec3D
{
//! x.
float x;
//! y.
float y;
//! z.
float z;
};
WUT_CHECK_OFFSET(KPADVec3D, 0x00, x);
WUT_CHECK_OFFSET(KPADVec3D, 0x04, y);
WUT_CHECK_OFFSET(KPADVec3D, 0x08, z);
WUT_CHECK_SIZE(KPADVec3D, 0x0C);

//! A structure conataining the Wii Remote data.
struct KPADStatus
{
//! Indicates what KPADButtons are held down
//! Indicates what KPADButtons are held down.
uint32_t hold;

//! Indicates what KPADButtons have been pressed since last sample
//! Indicates what KPADButtons have been pressed since last sample.
uint32_t trigger;

//! Indicates what KPADButtons have been released since last sample
//! Indicates what KPADButtons have been released since last sample.
uint32_t release;

WUT_UNKNOWN_BYTES(5 * 4);
//! Indicates the value of the acceleration sensor.
KPADVec3D acc;

//! Indicates the magnitude of acceleration.
float accMagnitude;

//! Indicates the variation in acceleration.
float accVariation;

//! Indicates the position where the Wii Remote is pointing.
KPADVec2D pos;

WUT_UNKNOWN_BYTES(3 * 4);

//! Angle.
KPADVec2D angle;

WUT_UNKNOWN_BYTES(8 * 4);

//! Value from KPADExtensionType
//! Value from KPADExtensionType.
uint8_t extensionType;

//! Value from KPADError
//! Value from KPADError.
int8_t error;

uint8_t posValid;
//! Validity of the result.
int8_t posValid;

//! Value from KPADDataFormat
//! Value from KPADDataFormat.
uint8_t format;

// Extension data, check with extensionType to see what is valid to read
//! Extension data, check with extensionType to see what is valid to read.
union
{
// For WPAD_EXT_NUNCHUK
//! Structure to use when extension type is set to \link WPAD_EXT_NUNCHUK \endlink.
struct
{
//! Position of the analog stick.
KPADVec2D stick;
//! Indicates the value of the acceleration sensor.
KPADVec3D acc;
//! Indicates the magnitude of acceleration.
float accMagnitude;
//! Indicates the variation in acceleration.
float accVariation;
//! Indicates what buttons are held down.
uint32_t hold;
//! Indicates what buttons have been pressed since last sample.
uint32_t trigger;
//! Indicates what buttons have been released since last sample.
uint32_t release;
} nunchuck;

// For WPAD_EXT_CLASSIC
//! Structure to use when extension type is set to \link WPAD_EXT_CLASSIC \endlink.
struct
{
//! Indicates what buttons are held down.
uint32_t hold;
//! Indicates what buttons have been pressed since last sample.
uint32_t trigger;
//! Indicates what buttons have been released since last sample.
uint32_t release;
//! Position of left analog stick.
KPADVec2D leftStick;
//! Position of right analog stick.
KPADVec2D rightStick;
//! Left trigger.
float leftTrigger;
//! Right trigger.
float rightTrigger;
} classic;

// For WPAD_EXT_PRO_CONTROLLER
//! Structure to use when extension type is set to \link WPAD_EXT_PRO_CONTROLLER \endlink.
struct
{
//! Indicates what buttons are held down.
uint32_t hold;
//! Indicates what buttons have been pressed since last sample.
uint32_t trigger;
//! Indicates what buttons have been released since last sample.
uint32_t release;
//! Position of left analog stick.
KPADVec2D leftStick;
//! Position of right analog stick.
KPADVec2D rightStick;
//! Is charging flag.
int32_t charging;
//! Is wired flag.
int32_t wired;
} pro;

Expand All @@ -105,6 +170,9 @@ struct KPADStatus
WUT_CHECK_OFFSET(KPADStatus, 0x00, hold);
WUT_CHECK_OFFSET(KPADStatus, 0x04, trigger);
WUT_CHECK_OFFSET(KPADStatus, 0x08, release);
WUT_CHECK_OFFSET(KPADStatus, 0x0C, acc);
WUT_CHECK_OFFSET(KPADStatus, 0x18, accMagnitude);
WUT_CHECK_OFFSET(KPADStatus, 0x1C, accVariation);
WUT_CHECK_OFFSET(KPADStatus, 0x20, pos);
WUT_CHECK_OFFSET(KPADStatus, 0x34, angle);
WUT_CHECK_OFFSET(KPADStatus, 0x5C, extensionType);
Expand All @@ -113,6 +181,12 @@ WUT_CHECK_OFFSET(KPADStatus, 0x5E, posValid);
WUT_CHECK_OFFSET(KPADStatus, 0x5F, format);
// For WPAD_EXT_NUNCHUK
WUT_CHECK_OFFSET(KPADStatus, 0x60, nunchuck.stick);
WUT_CHECK_OFFSET(KPADStatus, 0x68, nunchuck.acc);
WUT_CHECK_OFFSET(KPADStatus, 0x74, nunchuck.accMagnitude);
WUT_CHECK_OFFSET(KPADStatus, 0x78, nunchuck.accVariation);
WUT_CHECK_OFFSET(KPADStatus, 0x7C, nunchuck.hold);
WUT_CHECK_OFFSET(KPADStatus, 0x80, nunchuck.trigger);
WUT_CHECK_OFFSET(KPADStatus, 0x84, nunchuck.release);
// For WPAD_EXT_CLASSIC
WUT_CHECK_OFFSET(KPADStatus, 0x60, classic.hold);
WUT_CHECK_OFFSET(KPADStatus, 0x64, classic.trigger);
Expand All @@ -131,14 +205,50 @@ WUT_CHECK_OFFSET(KPADStatus, 0x7C, pro.charging);
WUT_CHECK_OFFSET(KPADStatus, 0x80, pro.wired);
WUT_CHECK_SIZE(KPADStatus, 0xF0);

/**
* Initialises the KPAD library for use.
*/
void
KPADInit();

/**
* Read data from the desired Wii Remote.
*
* \param chan
* The channel of the controller to read from.
*
* \param data
* The KPADStatus to fill.
*
* \param size
* The maximum number of data to read.
*
* \return
* The number of data read.
*/
int32_t
KPADRead(KPADChan chan,
KPADStatus *data,
uint32_t size);

/**
* Read data from the desired Wii Remote.
*
* \param chan
* The channel of the controller to read from.
*
* \param data
* The KPADStatus to fill.
*
* \param size
* The maximum number of data to read.
*
* \param error
* A pointer to an error code.
*
* \return
* The number of data read.
*/
int32_t
KPADReadEx(KPADChan chan,
KPADStatus *data,
Expand Down

0 comments on commit 78ee1c5

Please sign in to comment.