| 83 | /// Returns an owned vector to avoid lifetime issues |
| 84 | template<int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER> |
| 85 | fl::vector<u8> captureBytes(const CRGB* leds, int num_leds, u8 brightness) { |
| 86 | // CRITICAL: Ensure complete isolation between tests |
| 87 | // Clear all previous strip data and reset tracking state |
| 88 | ActiveStripData& stripData = ActiveStripData::Instance(); |
| 89 | stripData.onBeginFrame(); // Clears mStripMap |
| 90 | ActiveStripTracker::resetForTesting(); |
| 91 | |
| 92 | // Create ColorAdjustment with simplified setup |
| 93 | // Since HD108Controller uses loadAndScaleRGB(), we just need to set up brightness |
| 94 | ColorAdjustment adjustment; |
| 95 | adjustment.premixed = CRGB(255, 255, 255); // No color correction - use raw pixel values |
| 96 | #if FASTLED_HD_COLOR_MIXING |
| 97 | adjustment.color = CRGB(255, 255, 255); // No color correction |
| 98 | adjustment.brightness = brightness; // Set brightness for HD108 |
| 99 | #endif |
| 100 | |
| 101 | // Create PixelController with the LED data |
| 102 | PixelController<RGB_ORDER> pixels(leds, num_leds, adjustment, DISABLE_DITHER); |
| 103 | |
| 104 | // Create test controller and show pixels directly |
| 105 | // Each unique DATA_PIN creates a distinct controller type for isolation |
| 106 | HD108TestController<DATA_PIN, CLOCK_PIN, RGB_ORDER> controller; |
| 107 | controller.init(); |
| 108 | controller.showPixels(pixels); |
| 109 | |
| 110 | // Trigger the driver event that pushes data to ActiveStripData |
| 111 | fl::EngineEvents::onEndShowLeds(); |
| 112 | |
| 113 | // Get the captured data - should be exactly one strip after onBeginFrame() + showPixels() |
| 114 | const auto& dataMap = stripData.getData(); |
| 115 | |
| 116 | // Ensure exactly one strip is present (test isolation check) |
| 117 | FL_REQUIRE_MESSAGE(dataMap.size() == 1, |
| 118 | "Expected exactly 1 strip after capture, got " << dataMap.size()); |
| 119 | |
| 120 | // CRITICAL: Return a COPY of the data (owned vector) to avoid lifetime issues |
| 121 | // The span in dataMap points to the controller's internal buffer (mBytes in StubSPIOutput) |
| 122 | // which will be destroyed when the controller goes out of scope |
| 123 | const auto& capturedSpan = dataMap.begin()->second; |
| 124 | fl::vector<u8> result; |
| 125 | result.assign(capturedSpan.begin(), capturedSpan.end()); |
| 126 | return result; |
| 127 | } |
| 128 | |
| 129 | FL_TEST_CASE("HD108 - Protocol format verification") { |
| 130 | // Test single LED with full protocol verification: |
nothing calls this directly
no test coverage detected