-
Notifications
You must be signed in to change notification settings - Fork 1
Signals
Jazda is an event-driven project. To trigger an action, you need to send a signal. The signals and their handlers are defined in signals.c, triggered by sensors and handled by any piece of code that requires it.
A typical signal definition together with registered handlers:
inline void on_crank_pulse(void) {
uint16_t now = get_time();
on_crank_pulse_collect_data(now);
#ifdef CADENCE
cadence_on_crank_pulse();
#endif
}
All signals are public to dispatch, so the function prototype must be present in the header.
The on_signal_collect_data() handler is a special handler exposed by the sensor itself to collect data for use with every module.
To add a new handler, just call your function from this file. The only exception is registering timer handlers.
The job going behind the scenes. It's as simple as #including "signals.h" and then calling the signal handler.
It is fired each time the wheel sensor triggers. A callback can determine if this was the first pulse after a stop by checking wheel_pulse_table_count in wheel sensor.
This function is called every time the wheel sensor detects that the bike has just stopped. You need only one pulse to get out of the stopped state.
This signal is defined only when CRANK sensor is enabled. The event fires every time the crank sensor is triggered.
As above, ths signal is only valid with CRANK sensor. Works just as on_wheel_stop.
Timer signals are not defined in signals.h, because the callback time and order is unpredictable at compile-time. Instead, they are registered at runtime using functions from lib/timer.h. See API.