| 115 | template <int DATA_PIN, typename TIMING, EOrder RGB_ORDER = GRB, |
| 116 | int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 0> |
| 117 | class NeoPixelBusLikeClocklessT : public CPixelLEDController<RGB_ORDER> { |
| 118 | public: |
| 119 | using ColorFeature = typename NeoPixelBusColorFeature<RGB_ORDER>::Type; |
| 120 | using Method = typename NeoPixelBusMethodSelector<DATA_PIN>::DefaultMethod; |
| 121 | using BusType = NeoPixelBus<ColorFeature, Method>; |
| 122 | |
| 123 | private: |
| 124 | fl::unique_ptr<BusType> mPixelBus; |
| 125 | bool mInitialized; |
| 126 | |
| 127 | public: |
| 128 | /// Constructor - creates uninitialized controller |
| 129 | NeoPixelBusLikeClocklessT() : mPixelBus(nullptr), mInitialized(false) {} |
| 130 | |
| 131 | /// Destructor - automatic cleanup via unique_ptr |
| 132 | virtual ~NeoPixelBusLikeClocklessT() = default; |
| 133 | |
| 134 | /// Initialize the controller |
| 135 | /// Creates the NeoPixelBus instance with appropriate color feature and method |
| 136 | virtual void init() FL_NOEXCEPT override { |
| 137 | if (!mInitialized) { |
| 138 | try { |
| 139 | // Create NeoPixelBus instance |
| 140 | // Note: numPixels will be set when FastLED calls setLeds() |
| 141 | mPixelBus = createPixelBus(); |
| 142 | if (!mPixelBus) { |
| 143 | FL_WARN("Failed to create NeoPixelBus instance"); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | mPixelBus->Begin(); |
| 148 | mInitialized = true; |
| 149 | |
| 150 | // Allow derived classes to perform additional initialization |
| 151 | onInitialized(); |
| 152 | } catch (...) { |
| 153 | FL_WARN("NeoPixelBus initialization failed"); |
| 154 | mInitialized = false; |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /// Output pixels to the LED strip |
| 160 | /// Converts FastLED pixel data to NeoPixelBus format and displays |
| 161 | /// @param pixels the pixel controller containing LED data |
| 162 | virtual void showPixels(PixelController<RGB_ORDER> &pixels) FL_NOEXCEPT override { |
| 163 | if (!mPixelBus || !mInitialized) { |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | // Update strip length if needed |
| 168 | if (mPixelBus->PixelCount() != pixels.size()) { |
| 169 | // Recreate bus with new pixel count |
| 170 | mPixelBus.reset(); |
| 171 | mPixelBus = createPixelBus(pixels.size()); |
| 172 | if (!mPixelBus) { |
| 173 | FL_WARN("Failed to recreate NeoPixelBus with new size"); |
| 174 | return; |