CodexPadFrameDecoder Arduino Lib 1.0.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
CodexPadFrameDecoder Class Reference

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).

## Detailed Description

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.

Examples
  basic_polling/ble_uno_or_nl_16_module/ble_uno_or_nl_16_module.ino, and inputs_detection/ble_uno_or_nl_16_module/ble_uno_or_nl_16_module.ino.

Definition at line 29 of file codex_pad_frame_decoder.h.

## Member Enumeration Documentation

## ◆ Axis

enum class CodexPadFrameDecoder::Axis : size_t
| 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.

## ◆ Button

enum class CodexPadFrameDecoder::Button : uint32_t
| strong

Gamepad button mask enumeration.

Enumerator
kUp | uint32_t{1} << 0 | Up.
kDown | uint32_t{1} << 1 | Down.
kLeft | uint32_t{1} << 2 | Left.
kRight | uint32_t{1} << 3 | Right.
kSquareX | uint32_t{1} << 4 | Square or X.
kTriangleY | uint32_t{1} << 5 | Triangle or Y.
kCrossA | uint32_t{1} << 6 | Cross or A.
kCircleB | uint32_t{1} << 7 | Circle or B.
kL1 | uint32_t{1} << 8 | L1.
kL2 | uint32_t{1} << 9 | L2.
kL3 | uint32_t{1} << 10 | L3.
kR1 | uint32_t{1} << 11 | R1.
kR2 | uint32_t{1} << 12 | R2.
kR3 | uint32_t{1} << 13 | R3.
kSelect | uint32_t{1} << 14 | Select.
kStart | uint32_t{1} << 15 | Start.
kHome | uint32_t{1} << 16 | Home.

Definition at line 71 of file codex_pad_frame_decoder.h.

## Constructor & Destructor Documentation

## ◆ CodexPadFrameDecoder()

CodexPadFrameDecoder::CodexPadFrameDecoder | ( | Stream & | stream | ) |

Constructor.

Parameters

  [in] | stream | Reference to a Stream object for reading data byte stream.

Definition at line 9 of file codex_pad_frame_decoder.cpp.

## Member Function Documentation

## ◆ axis_value()

uint8_t CodexPadFrameDecoder::axis_value | ( | const Axis | axis | ) | const

Get the raw value (0~255) of a specified joystick axis.

Parameters

  [in] | axis | The axis to read.

Returns
  The current value of the axis, with center at 0x80.

Definition at line 52 of file codex_pad_frame_decoder.cpp.

## ◆ axis_values()

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:

- Index 0: Left stick X axis (Axis::kLeftStickX)
- Index 1: Left stick Y axis (Axis::kLeftStickY)
- Index 2: Right stick X axis (Axis::kRightStickX)
- Index 3: Right stick Y axis (Axis::kRightStickY) Each value ranges from 0 to 255, with the neutral center at 128 (0x80).
  Returns
    const uint8_t* Read-only pointer to the 4-byte axis value array.
  Note
    The returned pointer is valid for the lifetime of the CodexPadFrameDecoder object. Content will be updated after the next call to Update().
  Example:
  const uint8_t *axes = g_codex_pad_frame_decoder.axis_values();
  uint8_t left_stick_x = axes[static_cast<size_t>(CodexPadFrameDecoder::Axis::kLeftStickX)];
  uint8_t left_stick_y = axes[static_cast<size_t>(CodexPadFrameDecoder::Axis::kLeftStickY)];
  CodexPadFrameDecoder::Axis::kLeftStickX
  @ kLeftStickX
  Left stick X axis.
  Definition codex_pad_frame_decoder.h:262
  CodexPadFrameDecoder::Axis::kLeftStickY
  @ kLeftStickY
  Left stick Y axis.
  Definition codex_pad_frame_decoder.h:272

Definition at line 56 of file codex_pad_frame_decoder.cpp.

## ◆ button_state()

bool CodexPadFrameDecoder::button_state | ( | const Button | button | ) | const

check if a button is pressed or held.

Return values

  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.

## ◆ button_states()

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.

Returns
  A 32-bit unsigned integer where each bit represents the state of a specific button. The bits are from the least significant bit (LSB, bit 0) to the most significant bit (MSB, bit 31). You can use bit-and (&) operator to check specific button states. Example:
  const uint32_t button_states = g_codex_pad_frame_decoder.button_states();
  if ((button_states & CodexPadFrameDecoder::Button::kUp) != 0) {
  // Up button is pressed
  }
  CodexPadFrameDecoder::button_states
  uint32_t button_states() const
  Get all button states, return a 32-bit unsigned integer where each bit represents the state of a spec...
  Definition codex_pad_frame_decoder.cpp:48
  CodexPadFrameDecoder::Button::kUp
  @ kUp
  Up.
  Definition codex_pad_frame_decoder.h:80

Definition at line 48 of file codex_pad_frame_decoder.cpp.

## ◆ HasAxisValueChanged()

bool CodexPadFrameDecoder::HasAxisValueChanged | ( | const Axis | axis,
|  | const uint8_t | threshold ) const

check if an axis value has changed.

Parameters

  [in] | axis | Axis.
  [in] | threshold | Threshold.

Return values

  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.

## ◆ holding()

bool CodexPadFrameDecoder::holding | ( | const Button | button | ) | const

check if a button is held.

Return values

  true | if the button is held.
  false | if the button is not held.

Definition at line 40 of file codex_pad_frame_decoder.cpp.

## ◆ pressed()

bool CodexPadFrameDecoder::pressed | ( | const Button | button | ) | const

check if a button is pressed.

Return values

  true | if the button is pressed.
  false | if the button is not pressed.

Definition at line 32 of file codex_pad_frame_decoder.cpp.

## ◆ released()

bool CodexPadFrameDecoder::released | ( | const Button | button | ) | const

check if a button is released.

Return values

  true | if the button is released.
  false | if the button is not released.

Definition at line 36 of file codex_pad_frame_decoder.cpp.

## ◆ Update()

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.

## Member Data Documentation

## ◆ kAxisCenter

uint8_t CodexPadFrameDecoder::kAxisCenter = 0x80
| static constexpr

Center value of joystick axes (typical value at rest).

Definition at line 49 of file codex_pad_frame_decoder.h.

## ◆ kAxisValueNum

size_t CodexPadFrameDecoder::kAxisValueNum = 4
| static constexpr

Number of axis values.

Definition at line 39 of file codex_pad_frame_decoder.h.

## ◆ kPayloadType

uint8_t CodexPadFrameDecoder::kPayloadType = 0x01
| static constexpr

Input report type identifier for the gamepad (the first byte of the payload).

Definition at line 59 of file codex_pad_frame_decoder.h.

The documentation for this class was generated from the following files:

- src/codex_pad_frame_decoder.h
- src/codex_pad_frame_decoder.cpp