| 158 | } |
| 159 | |
| 160 | bool testRxChannelSanity(fl::shared_ptr<fl::RxChannel> rx, int pin_tx) { |
| 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; |
nothing calls this directly
no test coverage detected