FastLED 3.10.8
Loading...
Searching...
No Matches

◆ maybeRegisterStubAutorun()

void autoresearch::maybeRegisterStubAutorun ( AutoResearchRemoteControl & ,
fl::shared_ptr< AutoResearchState > state )
inline

On FL_IS_STUB: register a one-shot async task that drives autoresearch.

On the stub (native/host) platform, this registers an async task that:

  1. Discovers available drivers
  2. Tests each driver with autoResearchChipsetTiming()
  3. Collects results and exits 0 (all passed) or 1 (failure/no tests)

On all other platforms (ESP32, etc.), this is a no-op.

Parameters
remoteReference to RemoteControl singleton (unused on non-stub)
stateShared autoresearch state (contains driver list, pins, RX channel)

Definition at line 62 of file AutoResearchAsync.h.

64 {
65#ifdef FL_IS_STUB
66 // Register a task that runs on the next async_run() cycle (during loop()).
68 if (!state || state->drivers_available.empty()) {
69 FL_ERROR("[STUB CLIENT] No drivers discovered — autoresearch cannot run");
70 exit(1);
71 }
72
73 FL_PRINT("\n[STUB CLIENT] ============================================");
74 FL_PRINT("[STUB CLIENT] Simulated host client — running autoresearch");
75 FL_PRINT("[STUB CLIENT] Drivers: " << state->drivers_available.size());
76 FL_PRINT("[STUB CLIENT] ============================================");
77
78 // WS2812B-V5 timing (same as the Python client default)
79 fl::NamedTimingConfig timing_cfg(
81
82 // Static LED storage — span must remain valid for the entire call
83 CRGB* stub_leds = stubAutorunLedState().leds;
84 const int num_leds = 10;
85
86 // ChannelConfig stores timing by value internally, so passing a local ref is fine
87 fl::ChannelConfig stub_tx_cfg(
88 state->pin_tx,
89 timing_cfg.timing,
90 fl::span<CRGB>(stub_leds, num_leds),
91 RGB);
92
93 int grand_total = 0, grand_passed = 0;
94
95 for (fl::size di = 0; di < state->drivers_available.size(); di++) {
96 const auto& drv = state->drivers_available[di];
97
98 // BIT_BANG is the cycle-counted GPIO fallback. On the stub/host
99 // platform there is no actual GPIO toggling, so its TX output
100 // can't be captured by the loopback RX path the stub uses for
101 // self-verification. Skip it in the stub autorun (#2469) — it's
102 // still available for explicit selection by name on real hardware.
103 if (drv.name == "BIT_BANG") {
104 FL_PRINT("\n[STUB CLIENT] Driver: " << drv.name.c_str() << " (skipped — no loopback in host stub)");
105 continue;
106 }
107
108 FL_PRINT("\n[STUB CLIENT] Driver: " << drv.name.c_str());
109
110 if (!autoResearchSetExclusiveDriverByName(drv.name.c_str())) {
111 FL_ERROR("[STUB CLIENT] Failed to activate driver: " << drv.name.c_str());
112 grand_total++; // count as a failure
113 continue;
114 }
115
116 // AutoResearchConfig holds timing by reference — timing_cfg is in scope
117 fl::AutoResearchConfig vcfg(
118 timing_cfg.timing,
119 timing_cfg.name,
120 fl::span<fl::ChannelConfig>(&stub_tx_cfg, 1),
121 drv.name.c_str(),
122 state->rx_channel,
123 state->rx_buffer,
124 num_leds,
126
127 int driver_total = 0, driver_passed = 0;
128 uint32_t driver_duration_ms = 0;
129 autoResearchChipsetTiming(vcfg, driver_total, driver_passed, driver_duration_ms);
130
131 FL_PRINT("[STUB CLIENT] " << drv.name.c_str()
132 << ": " << driver_passed << "/" << driver_total << " passed");
133
134 grand_total += driver_total;
135 grand_passed += driver_passed;
136 }
137
138 FL_PRINT("\n[STUB CLIENT] ============================================");
139 FL_PRINT("[STUB CLIENT] TOTAL: " << grand_passed << "/" << grand_total);
140
141 if (grand_total == 0) {
142 FL_ERROR("[STUB CLIENT] No tests ran — exiting 1");
143 exit(1);
144 } else if (grand_passed == grand_total) {
145 FL_PRINT("[STUB CLIENT] ALL TESTS PASSED ✓ — exiting 0");
146 exit(0);
147 } else {
148 FL_ERROR("[STUB CLIENT] " << (grand_total - grand_passed)
149 << " TESTS FAILED — exiting 1");
150 exit(1);
151 }
152 });
153#endif
154}
bool autoResearchSetExclusiveDriverByName(const char *name)
AutoResearch-style helper: set an exclusive driver by name.
void autoResearchChipsetTiming(fl::AutoResearchConfig &config, int &total, int &passed, uint32_t &out_show_duration_ms, fl::vector< fl::RunResult > *out_results=nullptr, int num_runs_per_pattern=1)
TestState state
Handle & then(function< void()> on_then) FL_NO_EXCEPT
Sets the callback invoked when the task runs successfully.
Definition task.cpp.hpp:276
constexpr EOrder RGB
Definition eorder.h:17
fl::CRGB CRGB
Definition crgb.h:25
#define FL_ERROR(...)
Definition log.h:373
#define FL_PRINT(...)
Definition log.h:629
StubAutorunLedState & stubAutorunLedState()
Handle every_ms(int interval_ms) FL_NO_EXCEPT
Creates a task that runs at a fixed millisecond interval.
Definition task.cpp.hpp:320
constexpr ChipsetTimingConfig makeTimingConfig() FL_NO_EXCEPT
Convert compile-time CHIPSET type to runtime timing config.
FASTLED_FORCE_INLINE void exit(int code)
No-op exit function for embedded systems In embedded environments, calling exit is typically not mean...
Definition exit.h:12
@ RMT
RMT-based receiver (ESP32)
Definition rx.h:168
fl::u32 uint32_t
Definition stdint.h:218
Configuration for a single LED channel.
Definition config.h:167
Chipset timing configuration with name for testing.
Definition Common.h:33
#define FL_TRACE
A macro to capture the current source file, line number, and time.
Definition trace.h:102

References autoResearchChipsetTiming(), autoResearchSetExclusiveDriverByName(), fl::task::every_ms(), FL_ERROR, FL_PRINT, FL_TRACE, autoresearch::StubAutorunLedState::leds, fl::makeTimingConfig(), fl::NamedTimingConfig::name, RGB, fl::RMT, state, stubAutorunLedState(), fl::task::Handle::then(), and fl::NamedTimingConfig::timing.

+ Here is the call graph for this function: