This is a list of all the events that a Module can register for in Smoothieware V1.
These events allow modules to respond to various system activities and communicate with each other.
Smoothieware V2 does not use the event-based module system. Instead, V2 uses FreeRTOS with configuration-based modules that communicate via direct lookup and request methods.
Module::lookup() and request() interface rather than global events.
| Name | Called from | Description | How to cast the argument |
|---|---|---|---|
ON_MAIN_LOOP |
/main.cpp |
Called in a loop in main(), all G/M commands must be executed or issued in this event. | no argument |
ON_CONSOLE_LINE_RECEIVED |
/modules/communication/SerialConsole.cpp |
Called every time a new line is received on the default Serial Console, with the line as a parameter | SerialMessage new_message = *static_cast<SerialMessage*>(argument); string received = new_message.message; |
ON_GCODE_RECEIVED |
/modules/communication/GcodeDispatch.cpp |
Called every time a new G code is received, with the Gcode object as a parameter | Gcode* gcode = static_cast<Gcode*>(argument); |
ON_IDLE |
/main.cpp |
Called in the main loop immediately after ON_MAIN_LOOP. Used by modules for periodic tasks that need to run frequently. Many modules use this for polling or checking states that need quick response times. |
no argument |
ON_SECOND_TICK |
/libs/SlowTicker.cpp |
Called once per second by the SlowTicker timer. Used for periodic tasks that don’t need to run as frequently as ON_IDLE, such as temperature monitoring, status updates, watchdog checks, etc. |
no argument |
ON_GET_PUBLIC_DATA |
/libs/PublicData.cpp |
Allow communication of data between modules. Module A can get data from B by providing checksums identifying Module B and the desired data. | PublicDataRequest *pdr = static_cast<PublicDataRequest *>(argument) |
ON_SET_PUBLIC_DATA |
/libs/PublicData.cpp |
Allow communication of data between modules. Module A can set data from B by providing checksums identifying Module B and the data to set up. | PublicDataRequest *pdr = static_cast<PublicDataRequest *>(argument); |
ON_HALT |
Multiple sources: /modules/communication/GcodeDispatch.cpp (/modules/tools/endstops/Endstops.cpp, /modules/tools/temperaturecontrol/TemperatureControl.cpp, etc. |
Called when the system enters or exits HALT state (emergency stop). This disables heaters and motors, ignores further incoming Gcode and clears block queue. Used by modules to safely shut down or restart after emergency conditions. | if(argument == nullptr) - entering halt state; if(argument == (void*)1) - clearing halt state ( |
ON_ENABLE |
/modules/robot/Robot.cpp (/modules/robot/Conveyor.cpp |
Called to enable or disable stepper motors. Triggered by |
uint32_t bm = (uint32_t)argument;if(bm == 0x01) - enable all motorsif(bm == 0 or nullptr) - disable all motorsOtherwise: bit 0 = enable/disable, bits 1-6 = axis mask (bit1=X, bit2=Y, bit3=Z, bit4=A, bit5=B, bit6=C) |
NUMBER_OF_DEFINED_EVENTS |
n/a | Only used to enumerate the events. Not an actual event that gets called. | no argument |
The Smoothieware V1 event system provides a publish-subscribe pattern for module communication. Events are defined in /libs/Module.h as an enumeration, and the kernel dispatches these events to all registered modules.
This section describes Smoothieware V1 only. V2 uses FreeRTOS with a module registry and request-based communication instead of the event system.
_EVENT_ENUM enumeration in /libs/Module.hregister_for_event(EVENT_NAME) in their constructor or on_module_loaded() methodTHEKERNEL->call_event(EVENT_NAME, argument)on_idle(), on_gcode_received(), etc.)To register your module for an event, add the registration call in your module’s constructor or on_module_loaded() method (V1 only):
This section applies to Smoothieware V1 only. V2 modules use configuration-based registration instead.
void MyModule::on_module_loaded() {
this->register_for_event(ON_GCODE_RECEIVED);
this->register_for_event(ON_IDLE);
this->register_for_event(ON_HALT);
}
Then implement the corresponding callback methods:
void MyModule::on_gcode_received(void *argument) {
Gcode *gcode = static_cast<Gcode*>(argument);
if(gcode->has_m && gcode->m == 123) {
// Handle M123 command
}
}
void MyModule::on_idle(void *argument) {
// Periodic tasks that need frequent execution
}
void MyModule::on_halt(void *argument) {
if(argument == nullptr) {
// System is entering halt state - disable outputs
} else {
// System is clearing halt state - can re-enable
}
}
Temperature Control registers for:
ON_IDLE - PID calculations and sensor readingON_SECOND_TICK - Temperature reporting and monitoringON_HALT - Emergency heater shutdownON_GCODE_RECEIVED - Endstops registers for:
ON_IDLE - Checking endstop states during movesON_GCODE_RECEIVED - Laser registers for:
ON_HALT - Immediately disable laser for safetyON_GCODE_RECEIVED - Laser power control commandsMotor Driver Control registers for:
ON_ENABLE - Enable/disable motor driversON_HALT - Disable motors on emergency stopON_SECOND_TICK - Monitor driver alarm conditionsON_IDLE - Process enable/disable events safely (SPI communication)These best practices apply to Smoothieware V1 module development using the event system.
This section applies to Smoothieware V1 only. V2 modules use a different architecture.
if(THEKERNEL->is_halted()) return;| Event | Frequency | Context |
|---|---|---|
ON_MAIN_LOOP |
~1000+ Hz | Main loop |
ON_IDLE |
~1000+ Hz | Main loop (immediately after ON_MAIN_LOOP) |
ON_CONSOLE_LINE_RECEIVED |
On demand | When serial data received |
ON_GCODE_RECEIVED |
On demand | When G-code parsed |
ON_SECOND_TICK |
1 Hz | SlowTicker timer interrupt |
ON_HALT |
On demand | Emergency or error conditions |
ON_ENABLE |
On demand | Motor enable/disable commands |
ON_GET_PUBLIC_DATA |
On demand | Inter-module data requests |
ON_SET_PUBLIC_DATA |
On demand | Inter-module data updates |
This page is for Smoothieware V1 module development. For V2, see the V2 module documentation (coming soon).