feat:data slove and update heatmap
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -70,6 +71,11 @@ int main(int argc, char** argv) {
|
||||
cfg.read_chunk_size = 256;
|
||||
cfg.packet_queue_capacity = 128;
|
||||
cfg.frame_queue_capacity = 32;
|
||||
cfg.slave_request_command = {
|
||||
0x55, 0xAA, 0x09, 0x00, 0x34, 0x00, 0xFB,
|
||||
0x00, 0x1C, 0x00, 0x00, 0x18, 0x00, 0x7A
|
||||
};
|
||||
cfg.slave_request_interval = 200ms;
|
||||
|
||||
ffmsep::CPStreamCore core(cfg);
|
||||
if (!core.open()) {
|
||||
@@ -77,39 +83,74 @@ int main(int argc, char** argv) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Optional: receive frames via callback
|
||||
core.set_frame_callback([](const ffmsep::DecodedFrame& df) {
|
||||
const auto maybe = ffmsep::tactile::parse_frame(df.frame);
|
||||
if (!maybe) {
|
||||
return;
|
||||
}
|
||||
const auto& tf = *maybe;
|
||||
const auto pv = ffmsep::tactile::parse_pressure_values(tf);
|
||||
std::cout << "Frame pts=" << df.pts
|
||||
<< " addr=" << int(tf.device_address)
|
||||
<< " func=" << int(static_cast<std::uint8_t>(tf.function))
|
||||
<< " len=" << int(tf.data_length)
|
||||
<< " pressures=" << pv.size() << "\n";
|
||||
});
|
||||
|
||||
if (!core.start()) {
|
||||
std::cerr << "Start failed: " << core.last_error() << "\n";
|
||||
return 3;
|
||||
}
|
||||
|
||||
auto print_hex = [](const std::vector<std::uint8_t>& data) {
|
||||
if (data.empty()) {
|
||||
std::cout << "(empty)";
|
||||
return;
|
||||
}
|
||||
const auto old_flags = std::cout.flags();
|
||||
const auto old_fill = std::cout.fill();
|
||||
std::cout << std::hex << std::uppercase;
|
||||
for (std::size_t idx = 0; idx < data.size(); ++idx) {
|
||||
if (idx != 0U) {
|
||||
std::cout << ' ';
|
||||
}
|
||||
std::cout << std::setw(2) << std::setfill('0')
|
||||
<< static_cast<int>(data[idx]);
|
||||
}
|
||||
std::cout.flags(old_flags);
|
||||
std::cout.fill(old_fill);
|
||||
};
|
||||
|
||||
std::cout << "Streaming from " << port << ". Press Ctrl+C to stop...\n";
|
||||
if (!cfg.slave_request_command.empty()) {
|
||||
std::cout << "Slave mode active; request interval "
|
||||
<< cfg.slave_request_interval.count() << " ms.\n";
|
||||
}
|
||||
|
||||
// Also demonstrate polling API (in case users don't want callbacks)
|
||||
while (g_running) {
|
||||
ffmsep::DecodedFrame df;
|
||||
if (core.wait_for_frame(df, 200ms)) {
|
||||
const auto maybe = ffmsep::tactile::parse_frame(df.frame);
|
||||
if (maybe) {
|
||||
const auto sz = ffmsep::tactile::parse_matrix_size_payload(*maybe);
|
||||
if (sz) {
|
||||
std::cout << " matrix=" << int(sz->long_edge) << "x" << int(sz->short_edge) << "\n";
|
||||
std::cout << "Frame pts=" << df.pts
|
||||
<< " bytes=" << df.frame.data.size();
|
||||
if (df.tactile) {
|
||||
const auto& tf = *df.tactile;
|
||||
std::cout << " addr=" << int(tf.device_address)
|
||||
<< " func=0x" << std::hex << std::uppercase << int(tf.response_function)
|
||||
<< std::dec;
|
||||
if (df.tactile_matrix_size) {
|
||||
const auto& ms = *df.tactile_matrix_size;
|
||||
std::cout << " matrix=" << int(ms.long_edge)
|
||||
<< "x" << int(ms.short_edge);
|
||||
}
|
||||
if (!df.tactile_pressures.empty()) {
|
||||
std::cout << " pressures=" << df.tactile_pressures.size()
|
||||
<< " values=[";
|
||||
const std::size_t preview = std::min<std::size_t>(df.tactile_pressures.size(), 8);
|
||||
for (std::size_t idx = 0; idx < preview; ++idx) {
|
||||
if (idx != 0U) {
|
||||
std::cout << ", ";
|
||||
}
|
||||
std::cout << df.tactile_pressures[idx];
|
||||
}
|
||||
if (preview < df.tactile_pressures.size()) {
|
||||
std::cout << ", ...";
|
||||
}
|
||||
std::cout << "]";
|
||||
}
|
||||
std::cout << "\n raw=";
|
||||
print_hex(df.frame.data);
|
||||
} else {
|
||||
std::cout << " raw=";
|
||||
print_hex(df.frame.data);
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user