Generate stub main.cpp content that includes .ino files from sketch directory. Args: ino_files: List of .ino filenames to include Returns: Content for main.cpp file Note: We do NOT include FastLED.h here because some sketches define macros (like USE_OCT
(ino_files: list[str])
| 127 | |
| 128 | |
| 129 | def generate_main_cpp(ino_files: list[str]) -> str: |
| 130 | """Generate stub main.cpp content that includes .ino files from sketch directory. |
| 131 | |
| 132 | Args: |
| 133 | ino_files: List of .ino filenames to include |
| 134 | |
| 135 | Returns: |
| 136 | Content for main.cpp file |
| 137 | |
| 138 | Note: |
| 139 | We do NOT include FastLED.h here because some sketches define macros |
| 140 | (like USE_OCTOWS2811) before including FastLED.h. The sketch must include |
| 141 | FastLED.h itself at the appropriate point. |
| 142 | """ |
| 143 | includes: list[str] = [] |
| 144 | for ino_file in sorted(ino_files): |
| 145 | includes.append("#include <Arduino.h>") |
| 146 | # Don't include FastLED.h here - let the sketch include it after any |
| 147 | # required #defines (like USE_OCTOWS2811, USE_WS2812SERIAL, etc.) |
| 148 | includes.append(f'#include "sketch/{ino_file}"') |
| 149 | |
| 150 | include_lines = "\n".join(includes) |
| 151 | |
| 152 | int_main = """ |
| 153 | void init(void) __attribute__((weak)); |
| 154 | |
| 155 | __attribute__((weak)) int main() {{ |
| 156 | init(); // Initialize Arduino timers and enable interrupts (calls sei()) |
| 157 | setup(); |
| 158 | while (true) {{ |
| 159 | loop(); |
| 160 | fl::delay(0); // Yield to scheduler/watchdog (critical for ESP32 QEMU) |
| 161 | }} |
| 162 | }} |
| 163 | """ |
| 164 | |
| 165 | main_cpp_content = f"""// Auto-generated main.cpp stub for PlatformIO |
| 166 | // This file includes all .ino files from the sketch directory |
| 167 | |
| 168 | {include_lines} |
| 169 | |
| 170 | // main.cpp is required by PlatformIO but Arduino-style sketches |
| 171 | // use setup() and loop() functions which are called automatically |
| 172 | // by the FastLED/Arduino framework |
| 173 | // |
| 174 | // |
| 175 | {int_main} |
| 176 | """ |
| 177 | return main_cpp_content |
| 178 | |
| 179 | |
| 180 | def copy_example_source(project_root: Path, build_dir: Path, example: str) -> bool: |
no test coverage detected