CodexPadFrameDecoder Arduino Lib 1.0.0
Loading...
Searching...
No Matches
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]streamReference 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]axisThe 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:

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
trueif the button is pressed or held.
falseif 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();
// Up button is pressed
}
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 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]axisAxis.
[in]thresholdThreshold.
Return values
trueif the axis value has changed.
falseif 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
trueif the button is held.
falseif 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
trueif the button is pressed.
falseif 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
trueif the button is released.
falseif 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
staticconstexpr

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
staticconstexpr

Number of axis values.

Definition at line 39 of file codex_pad_frame_decoder.h.

◆ kPayloadType

uint8_t CodexPadFrameDecoder::kPayloadType = 0x01
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.


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