Skip to content
rhn edited this page Aug 31, 2011 · 2 revisions

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.

Definitions and registering callbacks

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.

Dispatching

The job going behind the scenes. It's as simple as #including "signals.h" and then calling the signal handler.

The signal list

on_wheel_pulse

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.

on_wheel_stop

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.

on_crank_pulse

This signal is defined only when CRANK sensor is enabled. The event fires every time the crank sensor is triggered.

on_crank_stop

As above, ths signal is only valid with CRANK sensor. Works just as on_wheel_stop.

Timer signals

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.

Clone this wiki locally