2018-06-13 13:11:00 +02:00
|
|
|
#pragma once
|
|
|
|
#include <wut.h>
|
2018-06-17 20:18:51 +02:00
|
|
|
#include <padscore/wpad.h>
|
2018-06-13 13:11:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup padscore_kpad KPAD
|
|
|
|
* \ingroup padscore
|
2020-01-20 07:38:29 +01:00
|
|
|
*
|
|
|
|
* KPAD is a high-level library over WPAD.
|
|
|
|
*
|
2018-06-13 13:11:00 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Wii Remote channel.
|
2018-06-18 11:04:47 +02:00
|
|
|
typedef enum WPADChan KPADChan;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Data format.
|
2018-06-18 11:04:47 +02:00
|
|
|
typedef enum WPADDataFormat KPADDataFormat;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Extension type.
|
2018-06-18 11:04:47 +02:00
|
|
|
typedef enum WPADExtensionType KPADExtensionType;
|
|
|
|
|
|
|
|
typedef struct KPADStatus KPADStatus;
|
|
|
|
typedef struct KPADVec2D KPADVec2D;
|
2020-01-20 07:38:29 +01:00
|
|
|
typedef struct KPADVec3D KPADVec3D;
|
2018-06-18 11:04:47 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Error.
|
2018-06-18 11:04:47 +02:00
|
|
|
typedef enum KPADError
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! No errors.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPAD_ERROR_OK = 0,
|
|
|
|
} KPADError;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! 2D vector.
|
2018-06-18 11:04:47 +02:00
|
|
|
struct KPADVec2D
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! x.
|
|
|
|
float x;
|
|
|
|
//! y.
|
|
|
|
float y;
|
2018-06-18 11:04:47 +02:00
|
|
|
};
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_CHECK_OFFSET(KPADVec2D, 0x00, x);
|
|
|
|
WUT_CHECK_OFFSET(KPADVec2D, 0x04, y);
|
|
|
|
WUT_CHECK_SIZE(KPADVec2D, 0x08);
|
2018-06-18 11:04:47 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! 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.
|
2018-06-18 11:04:47 +02:00
|
|
|
struct KPADStatus
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what KPADButtons are held down.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t hold;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what KPADButtons have been pressed since last sample.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t trigger;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what KPADButtons have been released since last sample.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t release;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates the value of the acceleration sensor.
|
|
|
|
KPADVec3D acc;
|
|
|
|
|
|
|
|
//! Indicates the magnitude of acceleration.
|
|
|
|
float accMagnitude;
|
2018-06-18 11:04:47 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates the variation in acceleration.
|
|
|
|
float accVariation;
|
|
|
|
|
|
|
|
//! Indicates the position where the Wii Remote is pointing.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D pos;
|
|
|
|
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_UNKNOWN_BYTES(3 * 4);
|
2018-06-18 11:04:47 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Angle.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D angle;
|
|
|
|
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_UNKNOWN_BYTES(8 * 4);
|
2018-06-18 11:04:47 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Value from KPADExtensionType.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint8_t extensionType;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Value from KPADError.
|
2018-06-18 11:04:47 +02:00
|
|
|
int8_t error;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Validity of the result.
|
|
|
|
int8_t posValid;
|
2018-06-18 11:04:47 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Value from KPADDataFormat.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint8_t format;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Extension data, check with extensionType to see what is valid to read.
|
2018-06-18 11:04:47 +02:00
|
|
|
union
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Structure to use when extension type is set to \link WPAD_EXT_NUNCHUK \endlink.
|
2018-06-18 11:04:47 +02:00
|
|
|
struct
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Position of the analog stick.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D stick;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! 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;
|
2018-06-18 11:04:47 +02:00
|
|
|
} nunchuck;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Structure to use when extension type is set to \link WPAD_EXT_CLASSIC \endlink.
|
2018-06-18 11:04:47 +02:00
|
|
|
struct
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what buttons are held down.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t hold;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what buttons have been pressed since last sample.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t trigger;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what buttons have been released since last sample.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t release;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Position of left analog stick.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D leftStick;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Position of right analog stick.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D rightStick;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Left trigger.
|
2018-06-18 11:04:47 +02:00
|
|
|
float leftTrigger;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Right trigger.
|
2018-06-18 11:04:47 +02:00
|
|
|
float rightTrigger;
|
|
|
|
} classic;
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Structure to use when extension type is set to \link WPAD_EXT_PRO_CONTROLLER \endlink.
|
2018-06-18 11:04:47 +02:00
|
|
|
struct
|
|
|
|
{
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what buttons are held down.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t hold;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what buttons have been pressed since last sample.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t trigger;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Indicates what buttons have been released since last sample.
|
2018-06-18 11:04:47 +02:00
|
|
|
uint32_t release;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Position of left analog stick.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D leftStick;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Position of right analog stick.
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADVec2D rightStick;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Is charging flag.
|
2018-06-18 11:04:47 +02:00
|
|
|
int32_t charging;
|
2020-01-20 07:38:29 +01:00
|
|
|
//! Is wired flag.
|
2018-06-18 11:04:47 +02:00
|
|
|
int32_t wired;
|
|
|
|
} pro;
|
|
|
|
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_UNKNOWN_BYTES(20 * 4);
|
2018-06-18 11:04:47 +02:00
|
|
|
};
|
|
|
|
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_UNKNOWN_BYTES(16 * 4);
|
2018-06-18 11:04:47 +02:00
|
|
|
};
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x00, hold);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x04, trigger);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x08, release);
|
2020-01-20 07:38:29 +01:00
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x0C, acc);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x18, accMagnitude);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x1C, accVariation);
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x20, pos);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x34, angle);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x5C, extensionType);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x5D, error);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x5E, posValid);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x5F, format);
|
2018-06-18 11:04:47 +02:00
|
|
|
// For WPAD_EXT_NUNCHUK
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x60, nunchuck.stick);
|
2020-01-20 07:38:29 +01:00
|
|
|
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);
|
2018-06-18 11:04:47 +02:00
|
|
|
// For WPAD_EXT_CLASSIC
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x60, classic.hold);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x64, classic.trigger);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x68, classic.release);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x6C, classic.leftStick);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x74, classic.rightStick);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x7C, classic.leftTrigger);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x80, classic.rightTrigger);
|
2018-06-18 11:04:47 +02:00
|
|
|
// For WPAD_EXT_PRO_CONTROLLER
|
2018-06-20 11:31:53 +02:00
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x60, pro.hold);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x64, pro.trigger);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x68, pro.release);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x6C, pro.leftStick);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x74, pro.rightStick);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x7C, pro.charging);
|
|
|
|
WUT_CHECK_OFFSET(KPADStatus, 0x80, pro.wired);
|
|
|
|
WUT_CHECK_SIZE(KPADStatus, 0xF0);
|
2018-06-17 19:13:21 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
/**
|
|
|
|
* Initialises the KPAD library for use.
|
|
|
|
*/
|
2018-06-17 19:13:21 +02:00
|
|
|
void
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADInit();
|
2018-06-17 19:13:21 +02:00
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-06-17 19:13:21 +02:00
|
|
|
int32_t
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADRead(KPADChan chan,
|
|
|
|
KPADStatus *data,
|
2018-06-17 19:13:21 +02:00
|
|
|
uint32_t size);
|
|
|
|
|
2020-01-20 07:38:29 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-06-17 19:13:21 +02:00
|
|
|
int32_t
|
2018-06-18 11:04:47 +02:00
|
|
|
KPADReadEx(KPADChan chan,
|
|
|
|
KPADStatus *data,
|
2018-06-17 19:13:21 +02:00
|
|
|
uint32_t size,
|
|
|
|
int32_t *error);
|
2018-06-13 13:11:00 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** @} */
|