|
CodexPadFrameDecoder Arduino Lib 1.0.0
|
CodexPad controller data frame decoding main class. More...
#include <codex_pad_frame_decoder.h>
Public Types | |
| enum class | Button : uint32_t { kUp = uint32_t{1} << 0 , kDown = uint32_t{1} << 1 , kLeft = uint32_t{1} << 2 , kRight = uint32_t{1} << 3 , kSquareX = uint32_t{1} << 4 , kTriangleY = uint32_t{1} << 5 , kCrossA = uint32_t{1} << 6 , kCircleB = uint32_t{1} << 7 , kL1 = uint32_t{1} << 8 , kL2 = uint32_t{1} << 9 , kL3 = uint32_t{1} << 10 , kR1 = uint32_t{1} << 11 , kR2 = uint32_t{1} << 12 , kR3 = uint32_t{1} << 13 , kSelect = uint32_t{1} << 14 , kStart = uint32_t{1} << 15 , kHome = uint32_t{1} << 16 } |
| Gamepad button mask enumeration. More... | |
| enum class | Axis : size_t { kLeftStickX , kLeftStickY , kRightStickX , kRightStickY } |
| Joystick axis index enumeration. More... | |
Public Member Functions | |
| CodexPadFrameDecoder (Stream &stream) | |
| Constructor. | |
| void | Update () |
| Update the decoder state. This function must be called continuously in the main loop to feed and parse the byte stream. | |
| bool | pressed (const Button button) const |
| check if a button is pressed. | |
| bool | released (const Button button) const |
| check if a button is released. | |
| bool | holding (const Button button) const |
| check if a button is held. | |
| bool | button_state (const Button button) const |
| check if a button is pressed or held. | |
| uint32_t | button_states () const |
| Get all button states, return a 32-bit unsigned integer where each bit represents the state of a specific button. | |
| uint8_t | axis_value (const Axis axis) const |
| Get the raw value (0~255) of a specified joystick axis. | |
| const uint8_t * | axis_values () const |
| Get current values of all analog axes (returns a read-only array pointer). | |
| bool | HasAxisValueChanged (const Axis axis, const uint8_t threshold) const |
| check if an axis value has changed. | |
Static Public Attributes | |
| static constexpr size_t | kAxisValueNum = 4 |
| Number of axis values. | |
| static constexpr uint8_t | kAxisCenter = 0x80 |
| Center value of joystick axes (typical value at rest). | |
| static constexpr uint8_t | kPayloadType = 0x01 |
| Input report type identifier for the gamepad (the first byte of the payload). | |
CodexPad controller data frame decoding main class.
It takes a Stream object as input to read the raw byte stream, and internally uses the robust_frame protocol parser for frame synchronization, escape sequence restoration, and CRC validation. Upon successfully receiving a complete and valid payload, it outputs button states and joystick axis values.
Definition at line 29 of file codex_pad_frame_decoder.h.
|
strong |
Joystick axis index enumeration.
| Enumerator | |
|---|---|
| kLeftStickX | Left stick X axis. |
| kLeftStickY | Left stick Y axis. |
| kRightStickX | Right stick X axis. |
| kRightStickY | Right stick Y axis. |
Definition at line 253 of file codex_pad_frame_decoder.h.
|
strong |
Gamepad button mask enumeration.
Definition at line 71 of file codex_pad_frame_decoder.h.
| CodexPadFrameDecoder::CodexPadFrameDecoder | ( | Stream & | stream | ) |
Constructor.
| [in] | stream | Reference to a Stream object for reading data byte stream. |
Definition at line 9 of file codex_pad_frame_decoder.cpp.
| uint8_t CodexPadFrameDecoder::axis_value | ( | const Axis | axis | ) | const |
Get the raw value (0~255) of a specified joystick axis.
| [in] | axis | The axis to read. |
Definition at line 52 of file codex_pad_frame_decoder.cpp.
| const uint8_t * CodexPadFrameDecoder::axis_values | ( | ) | const |
Get current values of all analog axes (returns a read-only array pointer).
Returns a const pointer to the internal 4-byte array. Indices correspond to the Axis enumeration:
Definition at line 56 of file codex_pad_frame_decoder.cpp.
| bool CodexPadFrameDecoder::button_state | ( | const Button | button | ) | const |
check if a button is pressed or held.
| true | if the button is pressed or held. |
| false | if the button is not pressed or held. |
Definition at line 44 of file codex_pad_frame_decoder.cpp.
| uint32_t CodexPadFrameDecoder::button_states | ( | ) | const |
Get all button states, return a 32-bit unsigned integer where each bit represents the state of a specific button.
Definition at line 48 of file codex_pad_frame_decoder.cpp.
| bool CodexPadFrameDecoder::HasAxisValueChanged | ( | const Axis | axis, |
| const uint8_t | threshold ) const |
check if an axis value has changed.
| [in] | axis | Axis. |
| [in] | threshold | Threshold. |
| true | if the axis value has changed. |
| false | if the axis value has not changed. |
Definition at line 60 of file codex_pad_frame_decoder.cpp.
| bool CodexPadFrameDecoder::holding | ( | const Button | button | ) | const |
check if a button is held.
| true | if the button is held. |
| false | if the button is not held. |
Definition at line 40 of file codex_pad_frame_decoder.cpp.
| bool CodexPadFrameDecoder::pressed | ( | const Button | button | ) | const |
check if a button is pressed.
| true | if the button is pressed. |
| false | if the button is not pressed. |
Definition at line 32 of file codex_pad_frame_decoder.cpp.
| bool CodexPadFrameDecoder::released | ( | const Button | button | ) | const |
check if a button is released.
| true | if the button is released. |
| false | if the button is not released. |
Definition at line 36 of file codex_pad_frame_decoder.cpp.
| void CodexPadFrameDecoder::Update | ( | ) |
Update the decoder state. This function must be called continuously in the main loop to feed and parse the byte stream.
Definition at line 24 of file codex_pad_frame_decoder.cpp.
|
staticconstexpr |
Center value of joystick axes (typical value at rest).
Definition at line 49 of file codex_pad_frame_decoder.h.
|
staticconstexpr |
Number of axis values.
Definition at line 39 of file codex_pad_frame_decoder.h.
|
staticconstexpr |
Input report type identifier for the gamepad (the first byte of the payload).
Definition at line 59 of file codex_pad_frame_decoder.h.