58 lines
1.9 KiB
C++
58 lines
1.9 KiB
C++
#pragma once
|
||
|
||
#include "cpdecoder.hh"
|
||
#include <cstdint>
|
||
#include <optional>
|
||
#include <vector>
|
||
|
||
namespace ffmsep::tactile {
|
||
inline constexpr std::uint8_t kStartByteFirst = 0xAA;
|
||
inline constexpr std::uint8_t kStartByteSecond = 0x55;
|
||
inline constexpr std::uint8_t kPiezoresistiveBStartByteFirst = 0xF0;
|
||
inline constexpr std::uint8_t kPiezoresistiveBStartByteSecond = 0xF1;
|
||
inline constexpr std::uint8_t kPiezoresistiveBEndByteFirst = 0xF1;
|
||
inline constexpr std::uint8_t kPiezoresistiveBEndByteSecond = 0xF0;
|
||
inline constexpr std::size_t kPiezoresistiveBValueCount = 200;
|
||
|
||
enum class FunctionCode : std::uint8_t {
|
||
Unknown = 0x00,
|
||
ReadMatrix = 0x01,
|
||
ReadSingle = 0x02,
|
||
ReadTemperature = 0x03,
|
||
SetDeviceId = 0x51,
|
||
SetMatrixSize = 0x52,
|
||
CalibrationMode = 0x53,
|
||
};
|
||
|
||
struct MatrixSize {
|
||
std::uint8_t long_edge = 0;
|
||
std::uint8_t short_edge = 0;
|
||
};
|
||
|
||
struct TactileFrame {
|
||
std::uint8_t device_address = 0;
|
||
std::uint8_t reserved = 0;
|
||
std::uint8_t response_function = 0;
|
||
FunctionCode function = FunctionCode::Unknown;
|
||
std::uint32_t start_address = 0;
|
||
std::uint16_t return_byte_count = 0;
|
||
std::uint8_t status = 0;
|
||
std::vector<std::uint8_t> payload;
|
||
};
|
||
|
||
std::optional<TactileFrame> parse_frame(const CPFrame &frame);
|
||
std::vector<std::uint16_t> parse_pressure_values(const TactileFrame &frame);
|
||
std::optional<MatrixSize> parse_matrix_size_payload(const TactileFrame &frame);
|
||
std::optional<MatrixSize>
|
||
parse_patrix_coordinate_payload(const TactileFrame &frame);
|
||
std::vector<std::uint16_t> parse_piezoresistive_b_pressures(const CPFrame &frame);
|
||
std::vector<std::uint8_t> extract_piezoresistive_b_payload(const CPFrame &frame);
|
||
// 配置触觉 A 类型预期的 payload 字节数(点数 * 2),用于限制解码 FIFO。
|
||
void set_tactile_expected_payload_bytes(std::size_t bytes);
|
||
|
||
const CPCodec *tactile_codec();
|
||
void register_tactile_codec();
|
||
const CPCodec *tactile_b_codec();
|
||
void register_tactile_b_codec();
|
||
} // namespace ffmsep::tactile
|