CodexPad Arduino Lib 3.0.0
Loading...
Searching...
No Matches
CodexPad Class Reference

CodexPad main class. More...

#include <codex_pad.h>

Public Types

enum class  TxPower : int8_t {
  kMinus16dBm = -16 , kMinus12dBm = -12 , kMinus8dBm = -8 , kMinus5dBm = -5 ,
  kMinus3dBm = -3 , kMinus1dBm = -1 , k0dBm = 0 , k1dBm = 1 ,
  k2dBm = 2 , k3dBm = 3 , k4dBm = 4 , k5dBm = 5 ,
  k6dBm = 6
}
 

Public Member Functions

 CodexPad () noexcept
 Constructor.
 
 ~CodexPad () noexcept
 Destructor.
 
void Init () noexcept
 Initialize.
 
bool Connect (const std::string &bluetooth_device_address, uint32_t timeout_ms=5000) noexcept
 Connect.
 
bool ScanAndConnect (gamepad::input::Button buttons) noexcept
 Scans for nearby CodexPad devices and automatically connects to a device whose button state matches the specified mask.
 
void Disconnect () noexcept
 Disconnect.
 
const gamepad::input::Tracker & Update () noexcept
 Update, need to be called in Loop.
 
bool is_connected () const noexcept
 Is connected.
 
bool set_remote_tx_power (TxPower power) noexcept
 Set transmission power, only effective when connected, immediately effective for current connection, effective for next connection.
 
const std::string & remote_device_name () const noexcept
 Get model number of the CodexPad.
 
const std::string & remote_model_number () const noexcept
 Get model number of the CodexPad.
 
const std::array< uint8_t, 3 > & remote_firmware_version () const noexcept
 Get firmware version of the CodexPad.
 
const gamepad::input::Tracker & input_tracker () const noexcept
 Get the input tracker object.
 
NimBLEClient * ble_client () const noexcept
 Get the BLE client object.
 

Detailed Description

CodexPad main class.

Examples
basic_polling.ino, inputs_detection.ino, and scan_and_connect.ino.

Definition at line 23 of file codex_pad.h.

Member Enumeration Documentation

◆ TxPower

enum class CodexPad::TxPower : int8_t
strong
Enumerator
kMinus16dBm -16 

-16 dBm

kMinus12dBm -12 

-12 dBm

kMinus8dBm -8 

-8 dBm

kMinus5dBm -5 

-5 dBm

kMinus3dBm -3 

-3 dBm

kMinus1dBm -1 

-1 dBm

k0dBm 

0 dBm

k1dBm 

1 dBm

k2dBm 

2 dBm

k3dBm 

3 dBm

k4dBm 

4 dBm

k5dBm 

5 dBm

k6dBm 

6 dBm

Definition at line 35 of file codex_pad.h.

Constructor & Destructor Documentation

◆ CodexPad()

CodexPad::CodexPad ( )
noexcept

Constructor.

Definition at line 26 of file codex_pad.cpp.

◆ ~CodexPad()

CodexPad::~CodexPad ( )
noexcept

Destructor.

Definition at line 28 of file codex_pad.cpp.

Member Function Documentation

◆ ble_client()

NimBLEClient * CodexPad::ble_client ( ) const
inlinenoexcept

Get the BLE client object.

This function returns a pointer to the internal BLE client object. The caller should not try and release/delete it.

Returns
BLE client object
Examples
basic_polling.ino, inputs_detection.ino, and scan_and_connect.ino.

Definition at line 383 of file codex_pad.h.

◆ Connect()

bool CodexPad::Connect ( const std::string & bluetooth_device_address,
uint32_t timeout_ms = 5000 )
noexcept

Connect.

Parameters
[in]bluetooth_device_addressThe Bluetooth device address(BD_ADDR) of the CodexPad, formatted as "XX:XX:XX:XX:XX:XX", X is a number or uppercase letter, colon separated
[in]timeout_msTimeout in milliseconds
Return values
trueif connected successfully
falseif connection failed
Examples
basic_polling.ino, and inputs_detection.ino.

Definition at line 36 of file codex_pad.cpp.

◆ Disconnect()

void CodexPad::Disconnect ( )
inlinenoexcept

Disconnect.

Definition at line 277 of file codex_pad.h.

◆ Init()

void CodexPad::Init ( )
noexcept

Initialize.

Definition at line 30 of file codex_pad.cpp.

◆ input_tracker()

const gamepad::input::Tracker & CodexPad::input_tracker ( ) const
inlinenoexcept

Get the input tracker object.

This function returns a reference to the internal input tracker object.

Returns
Input tracker object

Definition at line 368 of file codex_pad.h.

◆ is_connected()

bool CodexPad::is_connected ( ) const
noexcept

Is connected.

Return values
trueif connected
falseif not

Definition at line 131 of file codex_pad.cpp.

◆ remote_device_name()

const std::string & CodexPad::remote_device_name ( ) const
inlinenoexcept

Get model number of the CodexPad.

Returns
Model number of the CodexPad
Examples
basic_polling.ino, inputs_detection.ino, and scan_and_connect.ino.

Definition at line 330 of file codex_pad.h.

◆ remote_firmware_version()

const std::array< uint8_t, 3 > & CodexPad::remote_firmware_version ( ) const
inlinenoexcept

Get firmware version of the CodexPad.

Returns
Firmware version of the CodexPad
Examples
basic_polling.ino, inputs_detection.ino, and scan_and_connect.ino.

Definition at line 354 of file codex_pad.h.

◆ remote_model_number()

const std::string & CodexPad::remote_model_number ( ) const
inlinenoexcept

Get model number of the CodexPad.

Returns
Model number of the CodexPad
Examples
basic_polling.ino, inputs_detection.ino, and scan_and_connect.ino.

Definition at line 342 of file codex_pad.h.

◆ ScanAndConnect()

bool CodexPad::ScanAndConnect ( gamepad::input::Button buttons)
noexcept

Scans for nearby CodexPad devices and automatically connects to a device whose button state matches the specified mask.

This method actively scans for Bluetooth devices. When it discovers one or more CodexPad devices whose current button states exactly match the provided button_mask, it will attempt to establish a connection. If multiple nearby devices match the button mask, the device with the strongest signal (highest RSSI) will be selected for connection.

Parameters
[in]button_maskA 32-bit button mask used to match the target device's button states. Use the ButtonMask() function to combine multiple Button values.
Return values
trueConnection successful (a device matching the button mask was found and connected).
falseConnection failed (no matching device found or connection attempt failed).
Note
This is a blocking call. It will continuously scan until a matching device is found, a connection is established, or the internal timeout is reached.
Warning
DO NOT include Button::kHome in the button mask. Holding the Home button triggers a device reboot, which will interrupt the connection process. Example:
pad.Init();
// Continuously try to connect to a device where the Start and Cross/A buttons are pressed.
while (!pad.ScanAndConnect(gamepad::input::Button::kStart | gamepad::input::Button::kStart)) {
// Optional: Add a small delay or other operations between attempts.
delay(100);
}
// Once the loop exits, connection is successful.
Serial.println("CodexPad connected!");
CodexPad() noexcept
Constructor.
Definition codex_pad.cpp:26
void Init() noexcept
Initialize.
Definition codex_pad.cpp:30
bool ScanAndConnect(gamepad::input::Button buttons) noexcept
Scans for nearby CodexPad devices and automatically connects to a device whose button state matches t...
Definition codex_pad.cpp:47
Examples
scan_and_connect.ino.

Definition at line 47 of file codex_pad.cpp.

◆ set_remote_tx_power()

bool CodexPad::set_remote_tx_power ( const CodexPad::TxPower tx_power)
noexcept

Set transmission power, only effective when connected, immediately effective for current connection, effective for next connection.

Parameters
[in]powerTransmission power
Return values
trueSuccess
falseFail
Examples
basic_polling.ino, inputs_detection.ino, and scan_and_connect.ino.

Definition at line 133 of file codex_pad.cpp.

◆ Update()

const gamepad::input::Tracker & CodexPad::Update ( )
noexcept

Update, need to be called in Loop.

Definition at line 106 of file codex_pad.cpp.


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