FastLED 3.9.15
Loading...
Searching...
No Matches

◆ dumpRawEdgeTiming()

void dumpRawEdgeTiming ( fl::shared_ptr< fl::RxChannel > rx_channel,
const fl::ChipsetTimingConfig & timing,
fl::EdgeRange range )

Dump raw edge timing data to console for debugging.

Parameters
rx_channelRX device to read edge data from
timingChipset timing configuration for pattern analysis
rangeEdge range to print (offset, count)

Definition at line 28 of file AutoResearchTest.cpp.

30 {
31 if (!rx_channel) {
32 FL_WARN("[RAW EDGE TIMING] ERROR: RX channel is null");
33 return;
34 }
35
36 // Allocate edge buffer sized to requested count (max 256 to avoid stack overflow)
38 size_t buffer_size = range.count < 256 ? range.count : 256;
39 edges.resize(buffer_size); // Default initializes to EdgeTime()
40
41 // Get edges starting at offset
42 size_t edge_count = rx_channel->getRawEdgeTimes(edges, range.offset);
43
44 if (edge_count == 0) {
45 FL_WARN("[RAW EDGE TIMING] WARNING: No edge data captured at offset " << range.offset);
46 return;
47 }
48
49 // Calculate actual range printed (start from offset)
50 size_t start_idx = range.offset;
51 size_t end_idx = range.offset + edge_count;
52
53 FL_WARN("[RAW EDGES " << start_idx << ".." << (end_idx - 1) << "]");
54
55 // Display edges (edges buffer contains data starting from offset)
56 for (size_t i = 0; i < edge_count; i++) {
57 const char* level = edges[i].high ? "H" : "L";
58 size_t absolute_index = start_idx + i;
59 FL_WARN(" [" << absolute_index << "] " << level << " " << edges[i].ns);
60 }
61
62 // Pattern analysis (only if showing edges from start)
63 if (range.offset == 0 && edge_count >= 16) {
64 // Calculate expected timings from config (3-phase to 4-phase conversion)
65 uint32_t expected_bit0_high = timing.t1_ns;
66 uint32_t expected_bit0_low = timing.t2_ns + timing.t3_ns;
67 uint32_t expected_bit1_high = timing.t1_ns + timing.t2_ns;
68 uint32_t expected_bit1_low = timing.t3_ns;
69
70 const uint32_t tolerance = 150;
71
72 bool has_short_high = false, has_long_high = false;
73 bool has_short_low = false, has_long_low = false;
74
75 for (size_t i = 0; i < edge_count; i++) {
76 uint32_t ns = edges[i].ns;
77 if (edges[i].high) {
78 if (ns >= expected_bit0_high - tolerance && ns <= expected_bit0_high + tolerance)
79 has_short_high = true;
80 if (ns >= expected_bit1_high - tolerance && ns <= expected_bit1_high + tolerance)
81 has_long_high = true;
82 } else {
83 if (ns >= expected_bit1_low - tolerance && ns <= expected_bit1_low + tolerance)
84 has_short_low = true;
85 if (ns >= expected_bit0_low - tolerance && ns <= expected_bit0_low + tolerance)
86 has_long_low = true;
87 }
88 }
89
90 fl::sstream ss;
91 ss << "\n[RAW EDGE TIMING] Pattern Analysis:\n";
92 ss << " Short HIGH (~" << expected_bit0_high << "ns, Bit 0): " << (has_short_high ? "FOUND ✓" : "MISSING ✗") << "\n";
93 ss << " Long HIGH (~" << expected_bit1_high << "ns, Bit 1): " << (has_long_high ? "FOUND ✓" : "MISSING ✗") << "\n";
94 ss << " Short LOW (~" << expected_bit1_low << "ns, Bit 1): " << (has_short_low ? "FOUND ✓" : "MISSING ✗") << "\n";
95 ss << " Long LOW (~" << expected_bit0_low << "ns, Bit 0): " << (has_long_low ? "FOUND ✓" : "MISSING ✗");
96 FL_WARN(ss.str());
97
98 if (has_short_high && has_long_high && has_short_low && has_long_low) {
99 FL_WARN("\n[RAW EDGE TIMING] ✓ Encoder appears to be working correctly (varied timing patterns)");
100 } else if (!has_short_high && !has_long_high) {
101 ss.clear();
102 ss << "[RAW EDGE TIMING] ✗ ENCODER BROKEN: No valid HIGH pulses detected!\n";
103 ss << "[RAW EDGE TIMING] Possible causes:\n";
104 ss << "[RAW EDGE TIMING] 1. Encoder not reading pixel buffer data\n";
105 ss << "[RAW EDGE TIMING] 2. Bytes encoder state machine stuck\n";
106 ss << "[RAW EDGE TIMING] 3. Data pointer not passed correctly to encoder";
107 FL_ERROR(ss.str());
108 } else if (!has_short_low && !has_long_low) {
109 // Use FL_WARN to avoid triggering bash autoresearch early exit
110 FL_WARN("[RAW EDGE TIMING] ✗ ENCODER BROKEN: No valid LOW pulses detected!");
111 } else {
112 FL_WARN("[RAW EDGE TIMING] ⚠ Partial pattern match - encoder may have issues");
113 }
114 }
115 FL_WARN("");
116}
void resize(fl::size n) FL_NOEXCEPT
Definition vector.h:173
size_t getRawEdgeTimes(fl::span< EdgeTime > out, size_t offset=0) FL_NOEXCEPT
string str() const FL_NOEXCEPT
Definition strstream.h:43
void clear() FL_NOEXCEPT
Definition strstream.h:358
#define FL_WARN(X)
Definition log.h:276
#define FL_ERROR(X)
Definition log.h:219
fl::u32 uint32_t
Definition s16x16x4.h:219
u32 t1_ns
T0H: High time for bit 0 (nanoseconds)
u32 t2_ns
T1H-T0H: Additional high time for bit 1 (nanoseconds)
u32 t3_ns
T0L: Low tail duration (nanoseconds)
size_t offset
Starting edge index.
Definition rx.h:57
size_t count
Number of edges to extract.
Definition rx.h:58

References fl::sstream::clear(), fl::EdgeRange::count, FL_ERROR, FL_WARN, fl::EdgeRange::offset, fl::FixedVector< T, N >::resize(), fl::sstream::str(), fl::ChipsetTimingConfig::t1_ns, fl::ChipsetTimingConfig::t2_ns, and fl::ChipsetTimingConfig::t3_ns.

Referenced by capture(), and runMultiTest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: