### Main Setup Function in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp.html The setup function in C++ is executed once at the beginning of the ReactESP application's lifecycle. It performs all necessary initializations, including configuring hardware, setting up communication channels, and preparing the event loop. This function is critical for the application's startup. ```cpp void setup() { // ... initialization code ... } ``` -------------------------------- ### Setup Functions Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html Functions for initializing various components of the ReactESP system. ```APIDOC ## Setup Functions ### Description Functions for initializing various components of the ReactESP system. ### Functions * **setup_serial(EventLoop &event_loop)** * Description: Initializes serial communication. * Parameters: * event_loop (EventLoop &) - Reference to the EventLoop instance. * Definition: [main.cpp:82](#l00082) * **setup_timers(EventLoop &event_loop)** * Description: Initializes the timer system. * Parameters: * event_loop (EventLoop &) - Reference to the EventLoop instance. * Definition: [main.cpp:35](#l00035) * **setup()** * Description: The main setup function for the application. * Definition: [main.cpp:124](#l00124) * **setup_tick(EventLoop &event_loop)** * Description: Configures the tick event for the event loop. * Parameters: * event_loop (EventLoop &) - Reference to the EventLoop instance. * Definition: [main.cpp:102](#l00102) * **setup_io_pins(EventLoop *event_loop)** * Description: Configures the input and output pins. * Parameters: * event_loop (EventLoop *) - Pointer to the EventLoop instance. * Definition: [main.cpp:51](#l00051) ``` -------------------------------- ### Main Setup Function with Event Loop Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html The main setup function initializes serial communication, configures the LED pin, and calls helper functions to set up timers, I/O pins, serial communication, and tick events using a shared EventLoop instance. It also configures ESP32 power management settings. ```C++ void [setup](main_8cpp.html#a4fc01d736fe50cf5b977f755b675f11d)() { Serial.begin(115200); Serial.println("Starting"); pinMode([LED_PIN](main_8cpp.html#ab4553be4db9860d940f81d7447173b2f), OUTPUT); [setup_timers](main_8cpp.html#a4ce2b9b2cc8c29c788ce0a1870b7bbe9)([event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67)); [setup_io_pins](main_8cpp.html#ad991f139e8442b81f0e042d82d00bd7e)(&[event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67)); [setup_serial](main_8cpp.html#a1921d9a3d419e00436d8938e6521b9f2)([event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67)); [setup_tick](main_8cpp.html#ac138bb00421f2c926d7029d0b293cc0f)([event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67)); // //xTaskCreatePinnedToCore(execute_task, "SecondTask", 4096, NULL, // 1, NULL, 0); // esp_pm_config_esp32_t pm_config; pm_config.max_freq_mhz = 240; pm_config.min_freq_mhz = 80; pm_config.light_sleep_enable = true; esp_pm_configure(&pm_config); } ``` -------------------------------- ### Setup Timers Function in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp.html This C++ function, setup_timers, initializes and configures the timers for the ReactESP project. It takes an EventLoop object to integrate timer events into the asynchronous system. Proper timer setup is essential for time-based operations and scheduling. ```cpp void setup_timers(EventLoop &event_loop) { // ... implementation details for timer setup ... } ``` -------------------------------- ### Setup IO Pins Function in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp.html This C++ function, setup_io_pins, configures the input and output pins for the ReactESP project. It takes an EventLoop object as a parameter to manage event-driven operations. This setup is crucial for interacting with hardware peripherals connected to the ESP microcontroller. ```cpp void setup_io_pins(EventLoop *event_loop) { // ... implementation details for pin configuration ... } ``` -------------------------------- ### Menu and Search Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_i_s_r_event-members.html Initializes the navigation menu and search functionality. It sets up the menu structure and triggers an initial search setup. ```javascript $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); ``` -------------------------------- ### C Example: Including Private Libraries in main.c Source: https://github.com/mairas/reactesp/blob/master/examples/torture_test/lib/readme.txt Demonstrates how to include custom private libraries (Foo and Bar) in the main C source file. This assumes the libraries are correctly placed within the 'lib' directory and recognized by PlatformIO. ```c #include #include // rest H/C/CPP code ``` -------------------------------- ### ReactESP Initialization - Version 2 vs Version 1 (C++) Source: https://github.com/mairas/reactesp/blob/master/README.md Compares the initialization approach for ReactESP between version 1 and version 2. Version 2 requires explicit setup() and loop() functions with app.tick() called in the loop. ```cpp // Version 1 (deprecated) // ReactESP app([]() { // app.onDelay(...); // }); // Version 2 (current) ReactESP app; void setup() { app.onDelay(...); } void loop() { app.tick(); } ``` -------------------------------- ### Doxygen Initialization and SearchBox Setup (JavaScript) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/graph_legend.html Initializes the Doxygen search box functionality and code folding. It includes standard MIT license boilerplate. ```javascript /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ var searchBox = new SearchBox("searchBox", "search/",".html"); /* @license-end */ ``` ```javascript /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ $(function() { codefold.init(0); }); /* @license-end */ ``` ```javascript /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); /* @license-end */ ``` ```javascript /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ $(function(){initNavTree('graph_legend.html',''); initResizable(true); }); /* @license-end */ ``` -------------------------------- ### Setup Serial Communication Event Listener Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html Initializes serial communication and sets up a listener for incoming data on the serial port. When data is available, it reads the byte, writes it back to the serial port, turns on the LED, and schedules an event to turn off the LED after 1 second. This demonstrates handling asynchronous serial input. ```C++ // if something is received on the serial port, turn the led off for one second [event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67).[onAvailable](classreactesp_1_1_event_loop.html#a3a85d2eebfb959d5d0caa15acbda6a72)(Serial, [&[event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67)]() { static int event_counter = 0; Serial.write(Serial.read()); digitalWrite([LED_PIN](main_8cpp.html#ab4553be4db9860d940f81d7447173b2f), HIGH); event_counter++; int current = event_counter; [event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67).[onDelay](classreactesp_1_1_event_loop.html#a4bae6985931b6acda6afcbab5e1086a1)(1000, [current]() { if (event_counter==current) { digitalWrite([LED_PIN](main_8cpp.html#ab4553be4db9860d940f81d7447173b2f), LOW); } }); }); ``` -------------------------------- ### Doxygen Code Folding Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/structreactesp_1_1_event_interface-members.html Initializes the code folding feature in Doxygen documentation, starting with an initial level of 0. ```javascript codefold.init(0); ``` -------------------------------- ### ReactESP Timer Setup and Reporting in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html This C++ code demonstrates how to set up multiple repeating timers using the ReactESP EventLoop. It initializes an array to track timer ticks and a separate timer to periodically report the ticks and system status. Dependencies include Arduino.h and ReactESP.h. ```C++ #include #include #include "esp_system.h" #include "esp_pm.h" using namespace reactesp; #define LED_PIN 2 #define OUT_PIN 18 // D5 #define INPUT_PIN1 12 // D6 #define INPUT_PIN2 13 // D7 #define NUM_TIMERS 20 int tick_counter = 0; int timer_ticks[NUM_TIMERS]; EventLoop event_loop; void reporter() { Serial.printf("Timer ticks: "); for (int i=0; i using namespace reactesp; EventLoop event_loop; void setup() { pinMode(LED_BUILTIN, OUTPUT); event_loop.onRepeat(1000, [] () { static bool state = false; digitalWrite(LED_BUILTIN, state = !state); }); } void loop() { event_loop.tick(); } ``` -------------------------------- ### ReactESP Event Registration Functions (C++) Source: https://github.com/mairas/reactesp/blob/master/README.md Provides examples of ReactESP's event registration functions, including onDelay, onRepeat, onAvailable, onInterrupt, and onTick. These functions return an Event object pointer. ```cpp DelayEvent event_loop.onDelay(uint32_t t, react_callback cb); RepeatEvent event_loop.onRepeat(uint32_t t, react_callback cb); StreamEvent event_loop.onAvailable(Stream *stream, react_callback cb); ISREvent event_loop.onInterrupt(uint8_t pin_number, int mode, react_callback cb); TickEvent event_loop.onTick(react_callback cb); ``` -------------------------------- ### Arduino Blink Sketch Source: https://github.com/mairas/reactesp/blob/master/README.md A standard Arduino sketch to blink the built-in LED every second. This example demonstrates basic Arduino programming concepts like `pinMode`, `digitalWrite`, `delay`, and the `loop` function. ```cpp #include void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); } ``` -------------------------------- ### Setup Tick Event for Counter Increment Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html Configures an event that fires on every system tick. This event simply increments a global 'tick_counter'. This is a basic mechanism for time-based operations or measuring elapsed time. ```C++ // increase the tick counter on every tick [event_loop](main_8cpp.html#a7718a5a56be1daaf27b1ef8966f6bd67).[onTick](classreactesp_1_1_event_loop.html#a4a4bfd4eea96041fb7518e6b3dbacb3e)([]() { [tick_counter](main_8cpp.html#a6a8cac11201c2aa688c56aa3d8ae4e60)++; }); ``` -------------------------------- ### Setup Tick Function in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp.html The setup_tick function in C++ is responsible for initializing a tick or heartbeat mechanism for the ReactESP application. It utilizes an EventLoop object to schedule and manage the tick events. This is often used for periodic updates or health monitoring. ```cpp void setup_tick(EventLoop &event_loop) { // ... implementation details for tick setup ... } ``` -------------------------------- ### Advanced Callbacks with Lambda Captures (C++) Source: https://github.com/mairas/reactesp/blob/master/README.md Demonstrates using std::function with lambda captures for advanced callback support in ReactESP. This example creates 20 repeating events that update different elements of an array. ```cpp static int timer_ticks[20]; for (int i=0; i<20; i++) { timer_ticks[i] = 0; int delay = (i+1)*(i+1); event_loop.onRepeat(delay, [i]() { timer_ticks[i]++; }); } ``` -------------------------------- ### Initialize ReactESP Event Loop Constructor Source: https://context7.com/mairas/reactesp/llms.txt Demonstrates the basic setup for initializing the ReactESP EventLoop. This involves including the library, creating an EventLoop instance, and calling event_loop.tick() in the main loop function to process events. It also shows how to register a simple repeating event for a heartbeat. ```cpp #include using namespace reactesp; EventLoop event_loop; void setup() { Serial.begin(115200); Serial.println("Event loop initialized"); // Register events here event_loop.onRepeat(1000, []() { Serial.println("Heartbeat"); }); } void loop() { event_loop.tick(); // Process all registered events } ``` -------------------------------- ### Schedule One-Time Callback with Delay using ReactESP Source: https://context7.com/mairas/reactesp/llms.txt Shows how to use the `onDelay` function to schedule a callback that executes once after a specified delay in milliseconds. This example demonstrates turning an LED on and off with delays, and chaining multiple delay callbacks. ```cpp #include using namespace reactesp; EventLoop event_loop; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); // Turn LED on immediately digitalWrite(LED_BUILTIN, HIGH); // Turn LED off after 2 seconds event_loop.onDelay(2000, []() { digitalWrite(LED_BUILTIN, LOW); Serial.println("LED turned off after 2 second delay"); }); // Chain multiple delays event_loop.onDelay(3000, []() { Serial.println("First message after 3 seconds"); event_loop.onDelay(1000, []() { Serial.println("Second message 1 second later"); }); }); } void loop() { event_loop.tick(); } ``` -------------------------------- ### ReactESP C++ Type Definitions and Utility Function Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/events_8h_source.html Defines type aliases for ReactESP callbacks and a utility function for getting 64-bit microseconds on ESP platforms. These are fundamental for asynchronous operations. ```cpp #include #include #include namespace reactesp { using react_callback = std::function; using isr_react_callback = void (*)(void*); inline uint64_t ICACHE_RAM_ATTR micros64() { return esp_timer_get_time(); } // forward declarations class EventLoop; struct EventInterface { virtual ~EventInterface() = default; virtual void add(EventLoop* event_loop) = 0; virtual void remove(EventLoop* event_loop) = 0; virtual void tick(EventLoop* event_loop) = 0; virtual void add(std::shared_ptr event_loop) { add(event_loop.get()); } virtual void remove(std::shared_ptr event_loop) { remove(event_loop.get()); } virtual void tick(std::shared_ptr event_loop) { tick(event_loop.get()); } }; class Event : public EventInterface { protected: const react_callback callback; public: ``` -------------------------------- ### Schedule Repeating Callbacks at Intervals using ReactESP Source: https://context7.com/mairas/reactesp/llms.txt Demonstrates the `onRepeat` function for scheduling callbacks that execute at regular intervals in milliseconds. This example shows blinking an LED, printing uptime, and managing multiple independent timers with lambda captures for parametric behavior. ```cpp #include using namespace reactesp; EventLoop event_loop; void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); // Blink LED every 500ms static bool led_state = false; event_loop.onRepeat(500, []() { led_state = !led_state; digitalWrite(LED_BUILTIN, led_state); }); // Multiple independent timers event_loop.onRepeat(1000, []() { Serial.print("Uptime: "); Serial.print(millis() / 1000); Serial.println(" seconds"); }); // Using lambda captures for parametric callbacks static int counters[3] = {0, 0, 0}; for (int i = 0; i < 3; i++) { event_loop.onRepeat((i + 1) * 1000, [i]() { counters[i]++; Serial.printf("Timer %d tick: %d\n", i, counters[i]); }); } } void loop() { event_loop.tick(); } ``` -------------------------------- ### Multi-Sensor Data Logger with Averaging and Reporting (C++) Source: https://context7.com/mairas/reactesp/llms.txt This example showcases a multi-sensor data logger using ReactESP. It continuously samples temperature and light sensors, calculates their averages over a defined number of samples, and reports these averages periodically. It also includes a simple serial command interface for resetting samples and immediate reporting. Dependencies include the ReactESP library. ```cpp #include using namespace reactesp; EventLoop event_loop; #define TEMP_SENSOR_PIN A0 #define LIGHT_SENSOR_PIN A1 #define NUM_SAMPLES 10 static int temp_samples[NUM_SAMPLES]; static int light_samples[NUM_SAMPLES]; static int sample_index = 0; int calculate_average(int* samples, int count) { long sum = 0; for (int i = 0; i < count; i++) { sum += samples[i]; } return sum / count; } void setup() { Serial.begin(115200); Serial.println("Multi-sensor data logger starting..."); // Initialize sample arrays for (int i = 0; i < NUM_SAMPLES; i++) { temp_samples[i] = 0; light_samples[i] = 0; } // Sample sensors every 100ms event_loop.onRepeat(100, []() { temp_samples[sample_index] = analogRead(TEMP_SENSOR_PIN); light_samples[sample_index] = analogRead(LIGHT_SENSOR_PIN); sample_index = (sample_index + 1) % NUM_SAMPLES; }); // Report averages every 5 seconds event_loop.onRepeat(5000, []() { int avg_temp = calculate_average(temp_samples, NUM_SAMPLES); int avg_light = calculate_average(light_samples, NUM_SAMPLES); Serial.printf("Temperature: %d, Light: %d\n", avg_temp, avg_light); // Check for alerts if (avg_temp > 800) { Serial.println("ALERT: High temperature detected!"); } if (avg_light < 100) { Serial.println("ALERT: Low light condition!"); } }); // Periodic status report event_loop.onRepeat(30000, []() { Serial.printf("System uptime: %lu seconds\n", millis() / 1000); Serial.printf("Samples collected: %d\n", sample_index); Serial.printf("Loop performance: %llu ticks\n", event_loop.getTickCount()); }); // Serial command interface for configuration static String cmd_buffer = ""; event_loop.onAvailable(Serial, []() { while (Serial.available()) { char c = Serial.read(); if (c == '\n') { if (cmd_buffer == "reset") { sample_index = 0; Serial.println("Sample buffer reset"); } else if (cmd_buffer == "report") { Serial.printf("Current readings - Temp: %d, Light: %d\n", temp_samples[sample_index], light_samples[sample_index]); } cmd_buffer = ""; } else { cmd_buffer += c; } } }); } void loop() { event_loop.tick(); } ``` -------------------------------- ### ReactESP ISREvent Constructor (ESP32) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/events_8h_source.html Initializes an ISREvent for ESP32 microcontrollers, which is triggered by hardware interrupts. It configures the GPIO pin, interrupt type, and installs the ISR service if not already present. It takes the pin number, mode (RISING, FALLING, CHANGE), and a callback function. ```cpp #ifdef ESP32 // ... other members ISREvent(uint8_t pin_number, int mode, react_callback callback) : Event(callback), pin_number(pin_number), mode(mode) { gpio_int_type_t intr_type; switch (mode) { case RISING: intr_type = GPIO_INTR_POSEDGE; break; case FALLING: intr_type = GPIO_INTR_NEGEDGE; break; case CHANGE: intr_type = GPIO_INTR_ANYEDGE; break; default: intr_type = GPIO_INTR_DISABLE; break; } // configure the IO pin gpio_set_intr_type((gpio_num_t)pin_number, intr_type); if (!isr_service_installed) { isr_service_installed = true; gpio_install_isr_service(ESP_INTR_FLAG_LOWMED); } } #endif // ESP32 ``` -------------------------------- ### Main Loop Function in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp.html The loop function in C++ represents the main execution cycle for the ReactESP application. It is responsible for continuously running the application's logic and handling events. This function is typically called repeatedly after the initial setup is complete. ```cpp void loop() { // ... main application logic and event handling ... } ``` -------------------------------- ### Execute Callbacks Every Event Loop Cycle with onTick in C++ Source: https://context7.com/mairas/reactesp/llms.txt The onTick function executes a provided callback on every iteration of the event loop. This is ideal for continuous monitoring, background tasks, or implementing logic that needs to run frequently. Examples include counting loop iterations, monitoring sensor values, and implementing watchdog timers. ```cpp #include using namespace reactesp; EventLoop event_loop; void setup() { Serial.begin(115200); // Count loop iterations static uint64_t tick_count = 0; event_loop.onTick([]() { tick_count++; }); // Report performance every second event_loop.onRepeat(1000, []() { Serial.printf("Event loop ticks per second: %llu\n", tick_count); tick_count = 0; }); // Continuous sensor monitoring static int last_sensor_value = 0; event_loop.onTick([]() { int current_value = analogRead(A0); if (abs(current_value - last_sensor_value) > 50) { Serial.printf("Sensor change detected: %d -> %d\n", last_sensor_value, current_value); last_sensor_value = current_value; } }); // Watchdog implementation static uint32_t last_activity = millis(); event_loop.onTick([]() { if (millis() - last_activity > 10000) { Serial.println("WARNING: No activity for 10 seconds"); last_activity = millis(); } }); } void loop() { event_loop.tick(); } ``` -------------------------------- ### C++ Class Definitions for Doxygen Graph Example Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/graph_legend.html Defines several C++ classes with varying inheritance types (public, protected, private) and template usage, intended for demonstration within Doxygen-generated graphs. Includes an invisible class and a truncated class. ```cpp /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### Initialize Navigation Tree and Search Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/globals_defs.html Sets up the navigation tree for the documentation and initializes the search functionality. This ensures users can navigate the project documentation and find relevant information. ```javascript $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); $(function(){ initNavTree('globals_defs.html',''); initResizable(true); }); ``` -------------------------------- ### Doxygen Menu and Search Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/structreactesp_1_1_event_interface-members.html Initializes the navigation menu and search functionality for Doxygen documentation. It sets up the menu and initiates the search index. ```javascript initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); ``` -------------------------------- ### Get trigger time of reactesp::TimedEvent Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_delay_event.html Returns the trigger time of the TimedEvent in milliseconds. This can be used to determine when the event is scheduled to occur. ```cpp uint32_t getTriggerTime() const ``` -------------------------------- ### Initialize Navigation Tree and Resizable Layout Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/index.html Initializes the navigation tree and configures the page layout to be resizable. This script is essential for creating interactive and user-friendly documentation interfaces, allowing for dynamic adjustments to layout elements. ```javascript $(function(){ initNavTree('index.html',''); initResizable(true); }); ``` -------------------------------- ### Get Trigger Time Methods (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_repeat_event-members.html Methods to retrieve the trigger time of a TimedEvent, including both standard time and microseconds. These are useful for timing-critical operations. ```cpp getTriggerTime() const ``` ```cpp getTriggerTimeMicros() const ``` -------------------------------- ### Initialize SearchBox Functionality Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/index.html Initializes the search box functionality for the documentation. This script sets up a new SearchBox object, specifying the search directory and file extension for search results. It's a common pattern in generated documentation for site navigation. ```javascript var searchBox = new SearchBox("searchBox", "search/", ".html"); ``` -------------------------------- ### Get trigger time in microseconds for reactesp::TimedEvent Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_delay_event.html Returns the trigger time of the TimedEvent in microseconds. This provides a more precise timestamp for event scheduling. ```cpp uint64_t getTriggerTimeMicros() const ``` -------------------------------- ### Get Event Counts - C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/event__loop_8h_source.html Returns the total count of timed and untimed events that have occurred. These counters are useful for analyzing event frequency and system activity over time. ```cpp uint64_t getTimedEventCount() const { return timed_event_counter; } uint64_t getUntimedEventCount() const { return untimed_event_counter; } ``` -------------------------------- ### Get Tick Count - C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/event__loop_8h_source.html Retrieves the current tick count, which represents the number of times the event loop's main `tick()` function has been called. This is useful for timing and scheduling. ```cpp uint64_t getTickCount() const { return tick_counter; } ``` -------------------------------- ### Get Event Queue Sizes - C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/event__loop_8h_source.html Retrieves the current number of timed, untimed, and ISR events in the event queue. These functions are essential for monitoring the event loop's load and performance. ```cpp uint64_t getTimedEventQueueSize() const; uint64_t getUntimedEventQueueSize() const; uint64_t getISREventQueueSize() const; uint64_t getEventCount() { return getTimedEventCount() + getUntimedEventCount(); } ``` -------------------------------- ### Doxygen Navigation Tree and Resizable Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/structreactesp_1_1_event_interface-members.html Initializes the navigation tree for Doxygen documentation and enables resizable panels. It targets the 'structreactesp_1_1_event_interface.html' page. ```javascript initNavTree('structreactesp_1_1_event_interface.html',''); initResizable(true); ``` -------------------------------- ### Doxygen Navigation Tree and Resizable Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_event-members.html Initializes the navigation tree and resizable panel features in Doxygen-generated documentation. ```javascript $(function(){ initNavTree('classreactesp_1_1_event.html',''); initResizable(true); }); ``` -------------------------------- ### Doxygen Navigation Tree and Resizable Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/structreactesp_1_1_trigger_time_compare-members.html Initializes the navigation tree and resizable elements within Doxygen documentation. This helps in structuring the navigation and allowing users to resize panels. ```javascript $(function(){ initNavTree('structreactesp_1_1_trigger_time_compare.html',''); initResizable(true); }); ``` -------------------------------- ### Get Trigger Time in Microseconds (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/events_8h_source.html Retrieves the next trigger time for a TimedEvent in microseconds. It sums the last trigger time and the interval. This function is useful for high-precision timing within the reactesp::TimedEvent class. ```C++ uint64_t getTriggerTimeMicros() const { return (last_trigger_time + interval); } ``` -------------------------------- ### Initialize Doxygen Navigation Tree Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_untimed_event-members.html Initializes the navigation tree for Doxygen documentation, typically used for navigating class hierarchies and file structures. It also enables resizable panels. ```javascript $(function(){ initNavTree('classreactesp_1_1_untimed_event.html',''); initResizable(true); }); ``` -------------------------------- ### Doxygen Navigation Tree Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_tick_event-members.html Initializes the navigation tree within Doxygen documentation, providing a hierarchical view of the project's structure. It also enables resizable panels for a better user experience. ```javascript $(function(){ initNavTree('classreactesp_1_1_tick_event.html',''); initResizable(true); }); ``` -------------------------------- ### Navigation Tree and Resizable Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_i_s_r_event-members.html Initializes the navigation tree for a given page and enables resizable elements. It sets the current tree and enables dynamic resizing. ```javascript $(function(){ initNavTree('classreactesp_1_1_i_s_r_event.html',''); initResizable(true); }); ``` -------------------------------- ### Search Box Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_i_s_r_event-members.html Initializes a search box for a documentation system. It takes the search box ID and the base path for search results. ```javascript var searchBox = new SearchBox("searchBox", "search/",".html"); ``` -------------------------------- ### Get Untimed Event Count (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_event_loop.html Retrieves the current count of untimed events managed by the EventLoop. This inline function is defined in event_loop.h and returns a uint64_t value indicating the total number of scheduled untimed events. ```cpp uint64_t reactesp::EventLoop::getUntimedEventCount() { // Implementation details... } ``` -------------------------------- ### ReactESP I/O Pin Configuration and Toggling in C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html This C++ code configures an output pin and sets up a repeating event to toggle its state every 900 milliseconds using ReactESP's EventLoop. It also defines a lambda function for reporting pin changes. Dependencies include ReactESP.h. ```C++ #include using namespace reactesp; #define OUT_PIN 18 // D5 void setup_io_pins(EventLoop *event_loop) { static ISREvent* ire2 = nullptr; static int out_pin_state = 0; // change OUT_PIN state every 900 ms pinMode(OUT_PIN, OUTPUT); event_loop->onRepeat(900, [] () { out_pin_state = !out_pin_state; digitalWrite(OUT_PIN, out_pin_state); }); auto reporter = [] (int pin) { Serial.printf("Pin %d changed state.\n", pin); }; } ``` -------------------------------- ### Get Timed Event Count (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_event_loop.html Retrieves the current count of timed events managed by the EventLoop. This function is inline and defined in event_loop.h. It returns a uint64_t value representing the total number of scheduled timed events. ```cpp uint64_t reactesp::EventLoop::getTimedEventCount() { // Implementation details... } ``` -------------------------------- ### Initialize Search Box and Code Folding (JavaScript) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/files.html Initializes the search box and code folding functionality. It uses jQuery and is likely part of the Doxygen documentation generation process. ```javascript var searchBox = new SearchBox("searchBox", "search/",".html"); $(function() { codefold.init(0); }); $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); $(function(){initNavTree('files.html',''); initResizable(true); }); ``` -------------------------------- ### JavaScript Initialization Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_stream_event-members.html Initializes search functionality and code folding for the documentation. It uses jQuery and a custom searchBox object. It is protected by MIT license. ```javascript var searchBox = new SearchBox("searchBox", "search/", ".html"); $(function() { codefold.init(0); }); $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); $(function(){ initNavTree('classreactesp_1_1_stream_event.html',''); initResizable(true); }); ``` -------------------------------- ### Get Trigger Time in Seconds (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/events_8h_source.html Calculates the next trigger time for a TimedEvent in seconds. It sums the last trigger time and the interval, then divides by 1000. This function assumes time is measured in milliseconds. It is part of the reactesp::TimedEvent class. ```C++ uint32_t getTriggerTime() const { return (last_trigger_time + interval) / 1000; } ``` -------------------------------- ### Utility Functions Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html Utility functions used in the application. ```APIDOC ## Utility Functions ### Description Utility functions used in the application. ### Functions * **reporter()** * Description: A function likely used for reporting status or data. * Definition: [main.cpp:21](#l00021) * **execute_task(void *arg)** * Description: A function to execute a task, possibly in a separate thread or context. * Parameters: * arg (void *) - Argument passed to the task. * Definition: [main.cpp:109](#l00109) * **loop()** * Description: The main application loop function. * Definition: [main.cpp:146](#l00146) ``` -------------------------------- ### Get Untimed Event Queue Size (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_event_loop.html Retrieves the current size of the untimed event queue within the EventLoop. This inline function, defined in event_loop.h, returns an int representing the number of elements in the untimed event queue. ```cpp int reactesp::EventLoop::getUntimedEventQueueSize() { // Implementation details... } ``` -------------------------------- ### Get Timed Event Queue Size (C++) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_event_loop.html Retrieves the current size of the timed event queue within the EventLoop. This inline function, defined in event_loop.h, returns an int representing the number of elements in the timed event queue. ```cpp int reactesp::EventLoop::getTimedEventQueueSize() { // Implementation details... } ``` -------------------------------- ### Namespace Usage in ReactESP (C++) Source: https://github.com/mairas/reactesp/blob/master/README.md Illustrates how to use the 'reactesp' namespace in ReactESP 2.0.0 and later. It shows both global 'using namespace' and specific 'reactesp::' prefix usage. ```cpp using namespace reactesp; // ... reactesp::EventLoop event_loop; ``` -------------------------------- ### Global Variables and Definitions Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/main_8cpp_source.html Global variables and preprocessor definitions used within the project. ```APIDOC ## Global Variables and Definitions ### Description Global variables and preprocessor definitions used within the project. ### Definitions * **NUM_TIMERS** * Description: Defines the number of timers available. * Definition: [main.cpp:14](#l00014) * **INPUT_PIN2** * Description: Pin definition for input 2. * Definition: [main.cpp:11](#l00011) * **OUT_PIN** * Description: Pin definition for the output pin. * Definition: [main.cpp:9](#l00009) * **LED_PIN** * Description: Pin definition for the LED. * Definition: [main.cpp:8](#l00008) * **INPUT_PIN1** * Description: Pin definition for input 1. * Definition: [main.cpp:10](#l00010) ### Global Variables * **tick_counter** (int) * Description: Counter for the number of ticks. * Definition: [main.cpp:16](#l00016) * **event_loop** (EventLoop) * Description: The main event loop instance. * Definition: [main.cpp:19](#l00019) * **timer_ticks** (int[NUM_TIMERS]) * Description: Array to store timer tick counts. * Definition: [main.cpp:17](#l00017) ``` -------------------------------- ### Initialize Search Box and Code Folding Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/dir_68267d1309a1af8e8297ef4c3efbcdba.html This JavaScript code initializes the search functionality and code folding for a web page, likely generated by a documentation tool like Doxygen. It sets up a search box and activates code folding for better code readability. ```javascript var searchBox = new SearchBox("searchBox", "search/",".html"); $(function() { codefold.init(0); }); $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); $(function(){initNavTree('dir_68267d1309a1af8e8297ef4c3efbcdba.html',''); initResizable(true); }); ``` -------------------------------- ### Initialize Search Box and Code Folding Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/globals_defs.html Initializes the search box functionality and enables code folding for documentation elements. This is typically part of a documentation generation tool like Doxygen. ```javascript var searchBox = new SearchBox("searchBox", "search/",".html"); $(function() { codefold.init(0); }); ``` -------------------------------- ### Include Directives for events.cpp Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/events_8cpp.html This snippet shows the necessary include directives for the events.cpp file. It requires the local events.h header, the FreeRTOS semaphore header, and the ReactESP event_loop.h header to enable asynchronous event handling. ```c++ #include "events.h" #include #include "event_loop.h" ``` -------------------------------- ### Initialize Search Box and Code Folding - JavaScript Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/globals_vars.html Initializes the search box and code folding functionality using JavaScript. This code is typically found in documentation generated by tools like Doxygen and relies on jQuery. ```javascript var searchBox = new SearchBox("searchBox", "search/",".html"); $(function() { codefold.init(0); }); $(function() { initMenu(\'',true,false,'search.php','Search',true); $(function() { init_search(); }); }); $(function(){initNavTree('globals_vars.html',''); initResizable(true); }); ``` -------------------------------- ### Initialize Menu and Search (JavaScript) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_repeat_event-members.html Initializes the main menu and search functionality for the web interface. This code ensures that navigation and search features are ready for user interaction. ```javascript $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); ``` -------------------------------- ### MathJax Configuration for TeX Input Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/globals_defs.html Configures MathJax to use TeX input and HTML-CSS output, along with the tex2jax.js extension for automatic equation rendering. ```javascript MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"], }); ``` -------------------------------- ### MathJax Configuration for TeX Input Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_i_s_r_event-members.html Configures MathJax to use TeX input and HTML-CSS output extensions. This is useful for rendering mathematical formulas within web pages. ```javascript MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX","output/HTML-CSS"] }); ``` -------------------------------- ### ReactESP.h Header File - C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/_react_e_s_p_8h_source.html This C++ header file, ReactESP.h, defines the main interface for the ReactESP library. It includes necessary Arduino headers and other ReactESP components like event_loop.h and events.h. It also utilizes standard C++ functional for callbacks and defines a namespace for the library's functionality, noting that core features are now in event_loop.h and events.h. ```cpp #ifndef REACTESP_H_ #define REACTESP_H_ #include #include "event_loop.h" #include "events.h" #include namespace reactesp { // Functionality is now in event_loop.h and events.h } // namespace reactesp #endif ``` -------------------------------- ### Include ReactESP.h Header - Arduino C++ Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/_react_e_s_p_8h.html This code snippet shows the necessary include directives for the ReactESP.h file. It depends on the Arduino core library and other ReactESP-specific header files for event handling and functional programming. ```cpp #include #include "event_loop.h" #include "events.h" #include ``` -------------------------------- ### Initialize Navigation Tree (JavaScript) Source: https://github.com/mairas/reactesp/blob/master/docs/generated/docs/classreactesp_1_1_repeat_event-members.html Initializes the navigation tree structure, essential for browsing through the project's documentation or code. It also sets up a resizable feature for the tree. ```javascript $(function(){initNavTree('classreactesp_1_1_repeat_event.html',''); initResizable(true); }); ``` -------------------------------- ### Microsecond Precision Delay with ReactESP Source: https://context7.com/mairas/reactesp/llms.txt Illustrates the use of `onDelayMicros` for scheduling callbacks with microsecond precision. This is useful for high-accuracy timing requirements, such as generating precise pulses or triggering sensors at exact intervals. ```cpp #include using namespace reactesp; EventLoop event_loop; void setup() { Serial.begin(115200); pinMode(14, OUTPUT); // Generate a 500 microsecond pulse digitalWrite(14, HIGH); event_loop.onDelayMicros(500, []() { digitalWrite(14, LOW); Serial.println("500μs pulse completed"); }); // Precise timing for sensor triggering event_loop.onDelayMicros(10000, []() { // 10ms Serial.println("Precise 10000μs delay"); }); } void loop() { event_loop.tick(); } ```