FOME-Tech / fome-fw

Free Open Motorsports ECU
https://www.fome.tech
Other
35 stars 17 forks source link

Resolve "missing" Lua: getAuxDigital hook #351

Closed nmschulte closed 5 months ago

nmschulte commented 5 months ago

Multiple times in the past year there have inquiries about rusEFI's getAuxDigital Lua hook, which does not exist in FOME.

In rusEFI (https://github.com/rusefi/rusefi/issues/4861), this addition allows Lua scripts to identify digital pin states (configured in the "Lua Digital [Aux] Inputs" TunerStudio dialog) other than and without breaking backward compatibility of the pre-determined set of getDigital:

        case 0: state = engine->engineState.clutchDownState; break;
        case 1: state = engine->engineState.clutchUpState; break;
        case 2: state = engine->engineState.brakePedalState; break;
        case 3: state = engine->module<AcController>().unmock().acButtonState; break;

I think expanding the capability of getDigital makes the most sense, but could/would break any backward compatibility; my initial thoughts to this end, assuming Lua supports optional arguments, was:

getAuxDigital could just be combined w/ getDigital, either with an isAux flag or indices 4+

nmschulte commented 5 months ago

In the interim, users have reported success by using getAuxAnalog and comparison with a threshold value for the desired inputs. If the input doesn't map to an analog pin, then also available is the readPin hook, which works in terms of the low-level MCU pin names.