FastLED 3.9.15
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 53 of file AutoResearchAsync.h.

55 {
56#ifdef FL_IS_STUB
57 // Register a task that runs on the next async_run() cycle (during loop())
58 // Note: every_ms(0) fires immediately; after_frame() requires frame-task
59 // dispatch which isn't wired up in the stub example runner.
61 if (!state || state->drivers_available.empty()) {
62 FL_ERROR("[STUB CLIENT] No drivers discovered — autoresearch cannot run");
63 exit(1);
64 }
65
66 FL_PRINT("\n[STUB CLIENT] ============================================");
67 FL_PRINT("[STUB CLIENT] Simulated host client — running autoresearch");
68 FL_PRINT("[STUB CLIENT] Drivers: " << state->drivers_available.size());
69 FL_PRINT("[STUB CLIENT] ============================================");
70
71 // WS2812B-V5 timing (same as the Python client default)
72 fl::NamedTimingConfig timing_cfg(
74
75 // Static LED storage — span must remain valid for the entire call
76 static CRGB stub_leds[10];
77 const int num_leds = 10;
78
79 // ChannelConfig stores timing by value internally, so passing a local ref is fine
80 fl::ChannelConfig stub_tx_cfg(
81 state->pin_tx,
82 timing_cfg.timing,
83 fl::span<CRGB>(stub_leds, num_leds),
84 RGB);
85
86 int grand_total = 0, grand_passed = 0;
87
88 for (fl::size di = 0; di < state->drivers_available.size(); di++) {
89 const auto& drv = state->drivers_available[di];
90
91 // BIT_BANG is the cycle-counted GPIO fallback. On the stub/host
92 // platform there is no actual GPIO toggling, so its TX output
93 // can't be captured by the loopback RX path the stub uses for
94 // self-verification. Skip it in the stub autorun (#2469) — it's
95 // still available for explicit selection by name on real hardware.
96 if (drv.name == "BIT_BANG") {
97 FL_PRINT("\n[STUB CLIENT] Driver: " << drv.name.c_str() << " (skipped — no loopback in host stub)");
98 continue;
99 }
100
101 FL_PRINT("\n[STUB CLIENT] Driver: " << drv.name.c_str());
102
103 if (!autoResearchSetExclusiveDriverByName(drv.name.c_str())) {
104 FL_ERROR("[STUB CLIENT] Failed to activate driver: " << drv.name.c_str());
105 grand_total++; // count as a failure
106 continue;
107 }
108
109 // AutoResearchConfig holds timing by reference — timing_cfg is in scope
110 fl::AutoResearchConfig vcfg(
111 timing_cfg.timing,
112 timing_cfg.name,
113 fl::span<fl::ChannelConfig>(&stub_tx_cfg, 1),
114 drv.name.c_str(),
115 state->rx_channel,
116 state->rx_buffer,
117 num_leds,
119
120 int driver_total = 0, driver_passed = 0;
121 uint32_t driver_duration_ms = 0;
122 autoResearchChipsetTiming(vcfg, driver_total, driver_passed, driver_duration_ms);
123
124 FL_PRINT("[STUB CLIENT] " << drv.name.c_str()
125 << ": " << driver_passed << "/" << driver_total << " passed");
126
127 grand_total += driver_total;
128 grand_passed += driver_passed;
129 }
130
131 FL_PRINT("\n[STUB CLIENT] ============================================");
132 FL_PRINT("[STUB CLIENT] TOTAL: " << grand_passed << "/" << grand_total);
133
134 if (grand_total == 0) {
135 FL_ERROR("[STUB CLIENT] No tests ran — exiting 1");
136 exit(1);
137 } else if (grand_passed == grand_total) {
138 FL_PRINT("[STUB CLIENT] ALL TESTS PASSED ✓ — exiting 0");
139 exit(0);
140 } else {
141 FL_ERROR("[STUB CLIENT] " << (grand_total - grand_passed)
142 << " TESTS FAILED — exiting 1");
143 exit(1);
144 }
145 });
146#endif
147}
bool autoResearchSetExclusiveDriverByName(const char *name)
AutoResearch-style helper: set an exclusive driver by name.
void autoResearchChipsetTiming(fl::AutoResearchConfig &config, int &driver_total, int &driver_passed, uint32_t &out_show_duration_ms, fl::vector< fl::RunResult > *out_results, int num_runs_per_pattern)
TestState state
Handle & then(function< void()> on_then) FL_NOEXCEPT
Definition task.cpp.hpp:276
constexpr EOrder RGB
Definition eorder.h:17
fl::CRGB CRGB
Definition crgb.h:25
#define FL_ERROR(X)
Definition log.h:219
#define FL_PRINT(X)
Print without prefix (like FL_WARN but without "WARN: " prefix) Uses sstream for dynamic formatting (...
Definition log.h:457
Handle every_ms(int interval_ms)
Definition task.cpp.hpp:320
fl::u32 uint32_t
Definition s16x16x4.h:219
constexpr ChipsetTimingConfig makeTimingConfig() FL_NOEXCEPT
Convert compile-time CHIPSET type to runtime timing config.
void exit(int code)
No-op exit function for embedded systems In embedded environments, calling exit is typically not mean...
Definition exit.h:8
@ RMT
RMT-based receiver (ESP32)
Definition rx.h:166
Configuration for a single LED channel.
Definition config.h:163
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, fl::makeTimingConfig(), fl::NamedTimingConfig::name, RGB, fl::RMT, state, fl::task::Handle::then(), and fl::NamedTimingConfig::timing.

Referenced by setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: