|
CodexPadFrameDecoder Arduino 库 1.0.3
|
CodexPad 手柄数据帧解码主类。 更多...
#include <codex_pad_frame_decoder.h>
Public 类型 | |
| 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 成员函数 | |
| CodexPadFrameDecoder (Stream &stream) | |
| 构造函数。 | |
| void | Update () |
| 更新解码器状态。需要在主循环中不断调用此函数,以喂入并解析字节流。 | |
| 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 |
| 获取指定摇杆轴的原始值(0~255)。 | |
| const uint8_t * | axis_values () const |
| 获取所有模拟轴的当前值(返回只读数组指针)。 | |
| bool | HasAxisValueChanged (const Axis axis, const uint8_t threshold) const |
| 查询轴值是否发生变化。 | |
静态 Public 属性 | |
| static constexpr size_t | kAxisValueNum = 4 |
| 摇杆轴值的数量。 | |
| static constexpr uint8_t | kAxisCenter = 0x80 |
| 摇杆轴的中心值(静止时的典型值)。 | |
| static constexpr uint8_t | kPayloadType = 0x01 |
| 手柄输入报告的类型标识(有效载荷的第一个字节)。 | |
CodexPad 手柄数据帧解码主类。
通过外部传入的 Stream 对象获取原始字节流,内部使用 robust_frame 协议解析器完成帧同步、转义还原和 CRC 校验,成功接收完整的有效载荷后,输出按键状态和摇杆轴值。
在文件 codex_pad_frame_decoder.h 第 29 行定义.
|
strong |
摇杆轴索引枚举。
| 枚举值 | |
|---|---|
| kLeftStickX | 左摇杆X轴。 |
| kLeftStickY | 左摇杆Y轴。 |
| kRightStickX | 右摇杆X轴。 |
| kRightStickY | 右摇杆Y轴。 |
在文件 codex_pad_frame_decoder.h 第 253 行定义.
|
strong |
手柄按键掩码枚举。
在文件 codex_pad_frame_decoder.h 第 71 行定义.
| CodexPadFrameDecoder::CodexPadFrameDecoder | ( | Stream & | stream | ) |
| uint8_t CodexPadFrameDecoder::axis_value | ( | const Axis | axis | ) | const |
| const uint8_t * CodexPadFrameDecoder::axis_values | ( | ) | const |
获取所有模拟轴的当前值(返回只读数组指针)。
返回指向内部 4 字节数组的 const 指针,索引与 Axis 枚举对应关系:
在文件 codex_pad_frame_decoder.cpp 第 56 行定义.
| bool CodexPadFrameDecoder::button_state | ( | const Button | button | ) | const |
| uint32_t CodexPadFrameDecoder::button_states | ( | ) | const |
以位掩码形式获取所有按键的当前状态。
在文件 codex_pad_frame_decoder.cpp 第 48 行定义.
| bool CodexPadFrameDecoder::HasAxisValueChanged | ( | const Axis | axis, |
| const uint8_t | threshold ) const |
查询轴值是否发生变化。
| [in] | axis | 轴。 |
| [in] | threshold | 阈值。 |
| true | 轴值发生变化。 |
| false | 轴值未发生变化。 |
在文件 codex_pad_frame_decoder.cpp 第 60 行定义.
| bool CodexPadFrameDecoder::holding | ( | const Button | button | ) | const |
| bool CodexPadFrameDecoder::pressed | ( | const Button | button | ) | const |
| bool CodexPadFrameDecoder::released | ( | const Button | button | ) | const |
| void CodexPadFrameDecoder::Update | ( | ) |
更新解码器状态。需要在主循环中不断调用此函数,以喂入并解析字节流。
在文件 codex_pad_frame_decoder.cpp 第 24 行定义.
|
staticconstexpr |
摇杆轴的中心值(静止时的典型值)。
在文件 codex_pad_frame_decoder.h 第 49 行定义.
|
staticconstexpr |
摇杆轴值的数量。
在文件 codex_pad_frame_decoder.h 第 39 行定义.
|
staticconstexpr |
手柄输入报告的类型标识(有效载荷的第一个字节)。
在文件 codex_pad_frame_decoder.h 第 59 行定义.