|
CodexPad Arduino 库 2.2.1
|
CodexPad主类 更多...
#include <codex_pad.h>
Public 类型 | |
| 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 } |
| 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 } |
| enum class | Axis : size_t { kLeftStickX , kLeftStickY , kRightStickX , kRightStickY } |
Public 成员函数 | |
| CodexPad () | |
| 构造函数 | |
| ~CodexPad () | |
| 析构函数 | |
| void | Init () |
| 初始化 | |
| bool | Connect (const std::string &bluetooth_device_address, const uint32_t timeout_ms=5000) |
| 连接 | |
| bool | ScanAndConnect (const uint32_t button_mask) |
| 扫描附近的 CodexPad 设备,并自动连接到一个按键状态与指定掩码匹配的设备。 | |
| void | Disconnect () |
| 断开连接 | |
| void | Update () |
| 更新,需要在Loop中不断调用 | |
| bool | is_connected () const |
| 是否连接 | |
| bool | set_remote_tx_power (const TxPower power) |
| 设置发射功率,连接状态下调用,立即生效于当前连接,下次连接生效 | |
| const std::string & | remote_device_name () const |
| 获取CodexPad的型号 | |
| const std::string & | remote_model_number () const |
| 获取CodexPad的型号 | |
| const std::array< uint8_t, 3 > | remote_firmware_version () const |
| 获取CodexPad的固件版本 | |
| bool | pressed (const Button button) const |
| 查询按键是否被按下 | |
| bool | released (const Button button) const |
| 查询按键是否被释放 | |
| bool | holding (const Button button) const |
| 查询按键是否被持续按下 | |
| bool | button_state (const Button button) const |
| 查询按键是否被按下或持续按下 | |
| uint32_t | button_states () const |
| 以位掩码形式获取所有按键的当前状态 | |
| uint8_t | axis_value (const Axis axis) const |
| 获取轴值 | |
| std::array< uint8_t, kAxisValueNum > | axis_values () const |
| 获取所有模拟轴的当前值 | |
| bool | HasAxisValueChanged (const Axis axis, const uint8_t threshold) const |
| 查询轴值是否发生变化 | |
| NimBLEClient * | ble_client () const |
| 获取 BLE 客户端对象 | |
静态 Public 成员函数 | |
| static constexpr uint32_t | ButtonMask () |
| template<typename FirstButton, typename... RestButtons> | |
| static constexpr uint32_t | ButtonMask (FirstButton first, RestButtons... rest) |
| 将多个按键标识符组合成一个32位的按钮掩码。 | |
静态 Public 属性 | |
| static constexpr size_t | kAxisValueNum = 4 |
| 轴值数量 | |
| static constexpr uint8_t | kAxisCenter = 0x80 |
| 轴中心值 | |
CodexPad主类
在文件 codex_pad.h 第 46 行定义.
|
strong |
| 枚举值 | |
|---|---|
| kLeftStickX | 左摇杆X轴 |
| kLeftStickY | 左摇杆Y轴 |
| kRightStickX | 右摇杆X轴 |
| kRightStickY | 右摇杆Y轴 |
在文件 codex_pad.h 第 402 行定义.
|
strong |
在文件 codex_pad.h 第 220 行定义.
|
strong |
在文件 codex_pad.h 第 78 行定义.
| CodexPad::CodexPad | ( | ) |
构造函数
在文件 codex_pad.cpp 第 30 行定义.
| CodexPad::~CodexPad | ( | ) |
析构函数
在文件 codex_pad.cpp 第 32 行定义.
| uint8_t CodexPad::axis_value | ( | const Axis | axis | ) | const |
| std::array< uint8_t, CodexPad::kAxisValueNum > CodexPad::axis_values | ( | ) | const |
获取所有模拟轴的当前值
典型中心位置值为 128 (0x80)。
示例:
在文件 codex_pad.cpp 第 173 行定义.
|
inline |
| bool CodexPad::button_state | ( | const Button | button | ) | const |
| uint32_t CodexPad::button_states | ( | ) | const |
以位掩码形式获取所有按键的当前状态
在文件 codex_pad.cpp 第 169 行定义.
|
inlinestaticconstexpr |
在文件 codex_pad.h 第 445 行定义.
|
inlinestaticconstexpr |
将多个按键标识符组合成一个32位的按钮掩码。
这是一个工具函数,用于创建一个表示特定按键组合(例如 Start + A)的位掩码。 生成的掩码可作为参数用于 ScanAndConnect 等方法,或用于与 button_states 返回的组合状态进行比较。
| [in] | button | 一个或多个来自 Button 枚举的按键标识符。 |
constexpr 函数,允许掩码在编译时计算。 示例 - 为 Start 和 Cross/A 按键创建掩码: 在文件 codex_pad.h 第 493 行定义.
| bool CodexPad::Connect | ( | const std::string & | bluetooth_device_address, |
| const uint32_t | timeout_ms = 5000 ) |
连接
| [in] | bluetooth_device_address | CodexPad的蓝牙设备地址(BD_ADDR),格式为"XX:XX:XX:XX:XX:XX",X为数字或者大写字母, 半角冒号分隔 |
| [in] | timeout_ms | 超时时间,单位毫秒 |
| true | 连接成功 |
| false | 连接失败 |
在文件 codex_pad.cpp 第 40 行定义.
|
inline |
断开连接
在文件 codex_pad.h 第 658 行定义.
| bool CodexPad::HasAxisValueChanged | ( | const Axis | axis, |
| const uint8_t | threshold ) const |
| bool CodexPad::holding | ( | const Button | button | ) | const |
| void CodexPad::Init | ( | ) |
初始化
在文件 codex_pad.cpp 第 34 行定义.
| bool CodexPad::is_connected | ( | ) | const |
| bool CodexPad::pressed | ( | const Button | button | ) | const |
| bool CodexPad::released | ( | const Button | button | ) | const |
|
inline |
|
inline |
|
inline |
| bool CodexPad::ScanAndConnect | ( | const uint32_t | button_mask | ) |
扫描附近的 CodexPad 设备,并自动连接到一个按键状态与指定掩码匹配的设备。
此方法会主动扫描蓝牙设备。当发现一个或多个 CodexPad 设备,其当前按键状态与提供的 button_mask 完全匹配时,它将尝试建立连接。 如果附近有多个设备都符合按键掩码,则会选择信号最强(RSSI 值最大)的设备进行连接。
| [in] | button_mask | 用于匹配目标设备按键状态的32位按钮掩码。 使用 ButtonMask() 函数来组合多个 Button 枚举值。 |
| true | 连接成功(找到了符合按键掩码的设备并成功连接)。 |
| false | 连接失败(未找到匹配设备或连接尝试失败)。 |
Button::kHome。按住 Home 键会触发设备重启,这将中断连接过程。 示例: 在文件 codex_pad.cpp 第 51 行定义.
| bool CodexPad::set_remote_tx_power | ( | const TxPower | power | ) |
| void CodexPad::Update | ( | ) |
更新,需要在Loop中不断调用
在文件 codex_pad.cpp 第 110 行定义.
|
staticconstexpr |
轴中心值
在文件 codex_pad.h 第 66 行定义.
|
staticconstexpr |
轴值数量
在文件 codex_pad.h 第 56 行定义.