CodexPad Arduino Lib 4.0.0
Loading...
Searching...
No Matches
codex_pad::Client Class Reference

Client main class. More...

#include <client.h>

Inheritance diagram for codex_pad::Client:

Public Member Functions

 Client () noexcept
 Constructor.
 
 ~Client () 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.
 
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.
 
int32_t rssi () const noexcept
 Get the RSSI of the CodexPad.
 
NimBLEClient * ble_client () const noexcept
 Get the BLE client object.
 

Detailed Description

Client main class.

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

Definition at line 25 of file client.h.

Constructor & Destructor Documentation

◆ Client()

codex_pad::Client::Client ( )
noexcept

Constructor.

Definition at line 37 of file client.cpp.

◆ ~Client()

codex_pad::Client::~Client ( )
noexcept

Destructor.

Definition at line 39 of file client.cpp.

Member Function Documentation

◆ ble_client()

NimBLEClient * codex_pad::Client::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 239 of file client.h.

◆ Connect()

bool codex_pad::Client::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 47 of file client.cpp.

◆ Disconnect()

void codex_pad::Client::Disconnect ( )
inlinenoexcept

Disconnect.

Definition at line 138 of file client.h.

◆ Init()

void codex_pad::Client::Init ( )
noexcept

Initialize.

Definition at line 41 of file client.cpp.

◆ input_tracker()

const gamepad::input::Tracker & codex_pad::Client::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 212 of file client.h.

◆ is_connected()

bool codex_pad::Client::is_connected ( ) const
noexcept

Is connected.

Return values
trueif connected
falseif not

Definition at line 142 of file client.cpp.

◆ remote_device_name()

const std::string & codex_pad::Client::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 174 of file client.h.

◆ remote_firmware_version()

const std::array< uint8_t, 3 > & codex_pad::Client::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 198 of file client.h.

◆ remote_model_number()

const std::string & codex_pad::Client::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 186 of file client.h.

◆ rssi()

int32_t codex_pad::Client::rssi ( ) const
noexcept

Get the RSSI of the CodexPad.

Returns
RSSI of the CodexPad
Examples
inputs_detection.ino, and scan_and_connect.ino.

Definition at line 229 of file client.cpp.

◆ ScanAndConnect()

bool codex_pad::Client::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:
codex_pad::Client g_codex_pad_client;
g_codex_pad_client.Init();
// Continuously try to connect to a device where the Start and Cross/A buttons are pressed.
while (!g_codex_pad_client.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!");
Client main class.
Definition client.h:25
void Init() noexcept
Initialize.
Definition client.cpp:41
bool ScanAndConnect(gamepad::input::Button buttons) noexcept
Scans for nearby CodexPad devices and automatically connects to a device whose button state matches t...
Definition client.cpp:58
Examples
scan_and_connect.ino.

Definition at line 58 of file client.cpp.

◆ Update()

const gamepad::input::Tracker & codex_pad::Client::Update ( )
noexcept

Update, need to be called in Loop.

Definition at line 117 of file client.cpp.


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