Flexible Logic is the fanciest-schmanciest feature of rusEfi.
Flexible Logic allows advanced users to get unprecedented level of configurability for custom outputs and engine control. rusEfi supports up to 16 flexible outputs, each of these could be either an on/off or PWM signal. In case of a PWM signal the frequency is defined in the configuration and the duty cycle is dynamically controlled by the evaluated expression.
Fuel pump is already using this mechanism - see https://svn.code.sf.net/p/rusefi/code/trunk/firmware/controllers/core/le_functions.h
Here are some commands to try:
eval "2 3 +" Prints the result of "2 + 3"
eval "rpm 100 max" Prints the result of "max(100, rpm)"
eval "100 200 1 if" Prints the result of "if(1, 200, 100)"
set_fsio 1 "rpm" Turn output #1 hi if rpm != 0
set_fsio_pin 1 pd11 Tells output #1 to use pin PD11
See https://svn.code.sf.net/p/rusefi/code/trunk/firmware/controllers/core/le_functions.cpp for list of available methods
set_fsio_frequency 1 100 Tells FSIO channel #1 to output 100Hz PWM
Now, let's assume we want duty cycle to be 10% if rpm is below 1000, 90% if rpm is above 5000, and have it grow linearly from 10% to 90% between 1000 rpm and 5000 rpm. The human-readable expression for that would be
min(0.9, max(0.1, (rpm - 1000) / 4000 * 0.8))
in RPN that's
rpm 1000 - 5000 / 0.1 max 0.9 min
We can use
eval "rpm 1000 - 5000 / 0.1 max 0.9 min"
to validate and then
set_fsio 1 "rpm 1000 - 5000 / 0.1 max 0.9 min"
Another version of the same logic would be
if (rpm < 1000, 0.1, if (rpm > 5000, 0.9, 0.1 + (rpm - 1000) / 4000 * 0.8))
FSIO expressions could be customized using 16 user-defined 'settings' which are stored within the configuration. To change a setting from dev console your command is set_fsio_setting INDEX VAlUE
To access for example setting #3 your FSIO expression is
Please note that these indexes are starting with zero
FSIO digital inputs
These feature allows you to pull toggle switches state from your fsio expressions.
Case study #2: A/C compressor control
Say we want to use PE0 as A/C toggle button, and we want A/C compressor logic to be 'if (rpm > 1200 AND button on PE0 depressed) then output 200Hz @ 80% duty cycle on PB1 else output nothing on PB1'.
First we need to configure digital input pin, we will use index 0: