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

◆ testRxChannelSanity()

bool testRxChannelSanity ( fl::shared_ptr< fl::RxChannel > rx,
int pin_tx )

Test RX channel functionality with low-frequency pattern.

Validates the given RX channel can capture edge transitions by generating a simple test pattern (HIGH/LOW toggles) and verifying the captured timing data matches expectations.

Parameters
rxShared pointer to the RX channel to test
pin_txTX pin number to toggle
Returns
true if RX channel captures expected edges, false otherwise
Examples
RX.ino.

Definition at line 160 of file test.cpp.

160 {
161 FL_WARN("Testing RX channel with low-frequency pattern...");
162
163 if (!rx) {
164 FL_ERROR("Failed to test RX channel - null channel provided");
165 return false;
166 }
167
168 int pin_rx = rx->getPin();
169
170 // Configure RX channel for low-frequency test
171 fl::RxChannelConfig config(pin_rx);
172 config.signal_range_min_ns = 100; // 100ns glitch filter
173 config.signal_range_max_ns = 30000000; // 30ms idle timeout (ESP-IDF RMT limit: 32767000ns)
174 config.start_low = true; // Pin starts LOW
175
176 // Initialize TX pin and set to LOW
177 pinMode(pin_tx, OUTPUT);
178 pinMode(pin_rx, INPUT);
179 digitalWrite(pin_tx, LOW);
180 delay(10); // Allow pin to settle
181
182 if (!rx->begin(config)) {
183 FL_ERROR("Failed to initialize RX channel");
184 return false;
185 }
186
187 // Generate simple test pattern: 4 edges (LOW->HIGH->LOW->HIGH)
188 // Pattern: HIGH 10ms, LOW 10ms, HIGH 10ms
189 FL_WARN("Generating test pattern on GPIO " << pin_tx << "...");
190 digitalWrite(pin_tx, HIGH);
191 delay(10);
192 digitalWrite(pin_tx, LOW);
193 delay(10);
194 digitalWrite(pin_tx, HIGH);
195 delay(10);
196 digitalWrite(pin_tx, LOW);
197
198 // Wait for capture with timeout
199 FL_WARN("Waiting for RX capture...");
200 auto wait_result = rx->wait(100);
201
202 if (wait_result == fl::RxWaitResult::TIMEOUT) {
203 FL_ERROR("RX channel test FAILED - timeout waiting for data");
204 FL_ERROR(" No edges captured within 100ms");
205 FL_ERROR(" This suggests the RX channel cannot read from GPIO " << pin_rx);
206 return false;
207 }
208
209 // Get captured edges
210 fl::array<fl::EdgeTime, 10> edge_buffer;
211 size_t edge_count = rx->getRawEdgeTimes(edge_buffer);
212
213 if (edge_count < 3) {
214 FL_ERROR("RX channel test FAILED - insufficient edges captured");
215 FL_ERROR(" Expected at least 3 edges, got " << edge_count);
216 FL_ERROR(" Pin loopback may not be working correctly");
217 return false;
218 }
219
220 // Validate timing is reasonable (each edge should be ~10ms apart)
221 bool timing_ok = true;
222 for (size_t i = 0; i < edge_count && i < 3; i++) {
223 uint32_t duration_ms = edge_buffer[i].ns / 1000000;
224 if (duration_ms < 5 || duration_ms > 20) {
225 FL_WARN("WARNING: Edge " << i << " timing unusual: " << duration_ms << "ms (expected ~10ms)");
226 timing_ok = false;
227 }
228 }
229
230 if (timing_ok) {
231 FL_WARN("✓ RX channel test PASSED");
232 FL_WARN(" Captured " << edge_count << " edges");
233 FL_WARN(" Timing appears correct (~10ms per edge)");
234 return true;
235 } else {
236 FL_WARN("✓ RX channel test PASSED (with timing warnings)");
237 FL_WARN(" Captured " << edge_count << " edges");
238 FL_WARN(" Timing may be affected by system load");
239 return true; // Still pass - we got edges
240 }
241}
bool begin(const RxChannelConfig &config) FL_NOEXCEPT
size_t getRawEdgeTimes(fl::span< EdgeTime > out, size_t offset=0) FL_NOEXCEPT
RxWaitResult wait(u32 timeout_ms) FL_NOEXCEPT
int getPin() const FL_NOEXCEPT
A fixed-size array implementation similar to std::array.
Definition array.h:27
#define FL_WARN(X)
Definition log.h:276
#define FL_ERROR(X)
Definition log.h:219
fl::u32 uint32_t
Definition s16x16x4.h:219
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
void pinMode(int pin, PinMode mode)
Set pin mode (input, output, pull-up, pull-down)
Definition pin.cpp.hpp:378
void digitalWrite(int pin, PinValue val)
Write digital value to pin.
Definition pin.cpp.hpp:51
@ TIMEOUT
Operation timed out.
Definition rx.h:153

References FL_ERROR, FL_WARN, fl::RxChannelConfig::signal_range_max_ns, fl::RxChannelConfig::signal_range_min_ns, fl::RxChannelConfig::start_low, and fl::TIMEOUT.

Referenced by setup().

+ Here is the caller graph for this function: