CodexPad Arduino 库 4.0.0
载入中...
搜索中...
未找到
codex_pad::Client类 参考

Client主类 更多...

#include <client.h>

类 codex_pad::Client 继承关系图:

Public 成员函数

 Client () noexcept
 构造函数
 
 ~Client () noexcept
 析构函数
 
void Init () noexcept
 初始化
 
bool Connect (const std::string &bluetooth_device_address, uint32_t timeout_ms=5000) noexcept
 连接
 
bool ScanAndConnect (gamepad::input::Button buttons) noexcept
 扫描附近的 CodexPad 设备,并自动连接到一个按键状态与指定掩码匹配的设备。
 
void Disconnect () noexcept
 断开连接
 
const gamepad::input::Tracker & Update () noexcept
 更新,需要在Loop中不断调用
 
bool is_connected () const noexcept
 是否连接
 
const std::string & remote_device_name () const noexcept
 获取CodexPad的型号
 
const std::string & remote_model_number () const noexcept
 获取CodexPad的型号
 
const std::array< uint8_t, 3 > & remote_firmware_version () const noexcept
 获取CodexPad的固件版本
 
const gamepad::input::Tracker & input_tracker () const noexcept
 获取输入跟踪器对象
 
int32_t rssi () const noexcept
 获取CodexPad的RSSI
 
NimBLEClient * ble_client () const noexcept
 获取 BLE 客户端对象
 

详细描述

Client主类

示例
basic_polling.ino, inputs_detection.ino , 以及 scan_and_connect.ino.

在文件 client.h 第 25 行定义.

构造及析构函数说明

◆ Client()

codex_pad::Client::Client ( )
noexcept

构造函数

在文件 client.cpp 第 37 行定义.

◆ ~Client()

codex_pad::Client::~Client ( )
noexcept

析构函数

在文件 client.cpp 第 39 行定义.

成员函数说明

◆ ble_client()

NimBLEClient * codex_pad::Client::ble_client ( ) const
inlinenoexcept

获取 BLE 客户端对象

此函数返回内部 BLE 客户端对象的指针。调用者不应尝试释放/删除它。

返回
BLE 客户端对象
示例
basic_polling.ino, inputs_detection.ino , 以及 scan_and_connect.ino.

在文件 client.h 第 239 行定义.

◆ Connect()

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

连接

参数
[in]bluetooth_device_addressCodexPad的蓝牙设备地址(BD_ADDR),格式为"XX:XX:XX:XX:XX:XX",X为数字或者大写字母, 半角冒号分隔
[in]timeout_ms超时时间,单位毫秒
返回值
true连接成功
false连接失败
示例
basic_polling.ino , 以及 inputs_detection.ino.

在文件 client.cpp 第 47 行定义.

◆ Disconnect()

void codex_pad::Client::Disconnect ( )
inlinenoexcept

断开连接

在文件 client.h 第 138 行定义.

◆ Init()

void codex_pad::Client::Init ( )
noexcept

初始化

在文件 client.cpp 第 41 行定义.

◆ input_tracker()

const gamepad::input::Tracker & codex_pad::Client::input_tracker ( ) const
inlinenoexcept

获取输入跟踪器对象

此函数返回内部输入跟踪器对象的引用。

返回
输入跟踪器对象

在文件 client.h 第 212 行定义.

◆ is_connected()

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

是否连接

返回值
true已连接
false未连接

在文件 client.cpp 第 142 行定义.

◆ remote_device_name()

const std::string & codex_pad::Client::remote_device_name ( ) const
inlinenoexcept

获取CodexPad的型号

返回
CodexPad的型号
示例
basic_polling.ino, inputs_detection.ino , 以及 scan_and_connect.ino.

在文件 client.h 第 174 行定义.

◆ remote_firmware_version()

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

获取CodexPad的固件版本

返回
CodexPad的固件版本
示例
basic_polling.ino, inputs_detection.ino , 以及 scan_and_connect.ino.

在文件 client.h 第 198 行定义.

◆ remote_model_number()

const std::string & codex_pad::Client::remote_model_number ( ) const
inlinenoexcept

获取CodexPad的型号

返回
CodexPad的型号
示例
basic_polling.ino, inputs_detection.ino , 以及 scan_and_connect.ino.

在文件 client.h 第 186 行定义.

◆ rssi()

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

获取CodexPad的RSSI

返回
CodexPad的RSSI
示例
inputs_detection.ino , 以及 scan_and_connect.ino.

在文件 client.cpp 第 229 行定义.

◆ ScanAndConnect()

bool codex_pad::Client::ScanAndConnect ( gamepad::input::Button buttons)
noexcept

扫描附近的 CodexPad 设备,并自动连接到一个按键状态与指定掩码匹配的设备。

此方法会主动扫描蓝牙设备。当发现一个或多个 CodexPad 设备,其当前按键状态与提供的 button_mask 完全匹配时,它将尝试建立连接。 如果附近有多个设备都符合按键掩码,则会选择信号最强(RSSI 值最大)的设备进行连接。

参数
[in]button_mask用于匹配目标设备按键状态的32位按钮掩码。 使用 ButtonMask() 函数来组合多个 Button 枚举值。
返回值
true连接成功(找到了符合按键掩码的设备并成功连接)。
false连接失败(未找到匹配设备或连接尝试失败)。
注解
这是一个阻塞式调用。它会持续扫描,直到找到匹配的设备、连接建立或达到内部超时时间。
警告
**请勿**在按钮掩码中包含 Button::kHome。按住 Home 键会触发设备重启,这将中断连接过程。 示例:
codex_pad::Client g_codex_pad_client;
g_codex_pad_client.Init();
// 持续尝试连接到 Start 和 Cross/A 按键被同时按下的设备。
while (!g_codex_pad_client.ScanAndConnect(gamepad::input::Button::kStart | gamepad::input::Button::kStart)) {
// 可选:在尝试之间添加短暂延时或其他操作。
delay(100);
}
// 循环退出,意味着连接成功。
Serial.println("CodexPad 连接成功!");
Client主类
void Init() noexcept
初始化
bool ScanAndConnect(gamepad::input::Button buttons) noexcept
扫描附近的 CodexPad 设备,并自动连接到一个按键状态与指定掩码匹配的设备。
示例
scan_and_connect.ino.

在文件 client.cpp 第 58 行定义.

◆ Update()

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

更新,需要在Loop中不断调用

在文件 client.cpp 第 117 行定义.


该类的文档由以下文件生成: