move FSIO aux analog inputs to sensor model (#2669)
* sensor entries * init * non-explicit for list init to work * switch fsio * no longer need this lua hook * init
This commit is contained in:
parent
591b2b3c6c
commit
3dd6b2efc9
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "fsio_core.h"
|
||||
#include "fsio_impl.h"
|
||||
#include "adc_inputs.h"
|
||||
|
||||
extern fsio8_Map3D_f32t fsioTable1;
|
||||
extern fsio8_Map3D_u8t fsioTable2;
|
||||
|
@ -247,7 +246,8 @@ FsioResult LECalculator::processElement(const LEElement *element DECLARE_ENGINE_
|
|||
case LE_METHOD_FSIO_ANALOG_INPUT:
|
||||
{
|
||||
int index = clampF(0, pop(LE_METHOD_FSIO_ANALOG_INPUT), FSIO_ANALOG_INPUT_COUNT - 1);
|
||||
return getVoltage("fsio", engineConfiguration->fsioAdc[index] PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
int sensorIdx = static_cast<int>(SensorType::Aux1) + index;
|
||||
return Sensor::get(static_cast<SensorType>(sensorIdx));
|
||||
}
|
||||
case LE_METHOD_KNOCK:
|
||||
return ENGINE(knockCount);
|
||||
|
|
|
@ -69,19 +69,6 @@ static int lua_fan(lua_State* l) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int lua_getAnalog(lua_State* l) {
|
||||
auto idx = luaL_checkinteger(l, 1);
|
||||
|
||||
// Sanitize parameter
|
||||
idx = clampI(0, idx, FSIO_ANALOG_INPUT_COUNT - 1);
|
||||
|
||||
// Do the analog read
|
||||
float voltage = getVoltage("lua", engineConfiguration->fsioAdc[idx]);
|
||||
|
||||
lua_pushnumber(l, voltage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lua_getDigital(lua_State* l) {
|
||||
auto idx = luaL_checkinteger(l, 1);
|
||||
|
||||
|
@ -132,7 +119,6 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
|
||||
#if !EFI_UNIT_TEST
|
||||
lua_register(l, "getFan", lua_fan);
|
||||
lua_register(l, "getAnalog", lua_getAnalog);
|
||||
lua_register(l, "getDigital", lua_getDigital);
|
||||
lua_register(l, "setDebug", lua_setDebug);
|
||||
#endif
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
class FunctionalSensor final : public StoredValueSensor {
|
||||
public:
|
||||
explicit FunctionalSensor(SensorType type, efitick_t timeoutPeriod)
|
||||
FunctionalSensor(SensorType type, efitick_t timeoutPeriod)
|
||||
: StoredValueSensor(type, timeoutPeriod) { }
|
||||
|
||||
void postRawValue(float inputValue, efitick_t timestamp);
|
||||
|
|
|
@ -47,6 +47,11 @@ static const char* s_sensorNames[] = {
|
|||
"Barometric Pressure",
|
||||
|
||||
"Fuel Level %",
|
||||
|
||||
"Aux 1",
|
||||
"Aux 2",
|
||||
"Aux 3",
|
||||
"Aux 4",
|
||||
};
|
||||
|
||||
// This struct represents one sensor in the registry.
|
||||
|
|
|
@ -68,6 +68,11 @@ enum class SensorType : unsigned char {
|
|||
|
||||
FuelLevel = 29,
|
||||
|
||||
Aux1 = 30,
|
||||
Aux2 = 31,
|
||||
Aux3 = 32,
|
||||
Aux4 = 33,
|
||||
|
||||
// Leave me at the end!
|
||||
PlaceholderLast = 30,
|
||||
PlaceholderLast = 34,
|
||||
};
|
||||
|
|
|
@ -474,10 +474,6 @@ static void configureInputs(void) {
|
|||
addChannel("CJ125 UA", engineConfiguration->cj125ua, ADC_SLOW);
|
||||
}
|
||||
|
||||
for (int i = 0; i < FSIO_ANALOG_INPUT_COUNT ; i++) {
|
||||
addChannel("FSIOadc", engineConfiguration->fsioAdc[i], ADC_SLOW);
|
||||
}
|
||||
|
||||
setAdcChannelOverrides();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|||
void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void initFuelLevel(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void initBaro(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void initAuxSensors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
||||
// Sensor reconfiguration
|
||||
void reconfigureVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
|
|
@ -10,3 +10,4 @@ INIT_SRC_CPP = $(PROJECT_DIR)/init/sensor/init_sensors.cpp \
|
|||
$(PROJECT_DIR)/init/sensor/init_vbatt.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_baro.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_fuel_level.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_aux.cpp \
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#include "init.h"
|
||||
#include "adc_inputs.h"
|
||||
#include "adc_subscription.h"
|
||||
#include "engine.h"
|
||||
#include "global.h"
|
||||
#include "functional_sensor.h"
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
// These aux sensors just read voltage - so the converter function has nothing to do
|
||||
struct IdentityFunction : public SensorConverter {
|
||||
SensorResult convert(float raw) const {
|
||||
return raw;
|
||||
}
|
||||
};
|
||||
|
||||
static IdentityFunction func;
|
||||
|
||||
static FunctionalSensor auxSensors[] = {
|
||||
{ SensorType::Aux1, MS2NT(50) },
|
||||
{ SensorType::Aux2, MS2NT(50) },
|
||||
{ SensorType::Aux3, MS2NT(50) },
|
||||
{ SensorType::Aux4, MS2NT(50) },
|
||||
};
|
||||
|
||||
static_assert(efi::size(auxSensors) == FSIO_ANALOG_INPUT_COUNT);
|
||||
|
||||
void initAuxSensors(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
for (size_t i = 0; i < efi::size(CONFIG(fsioAdc)); i++) {
|
||||
auto channel = CONFIG(fsioAdc)[i];
|
||||
|
||||
// Skip unconfigured channels
|
||||
if (!isAdcChannelValid(channel)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& sensor = auxSensors[i];
|
||||
sensor.setFunction(func);
|
||||
sensor.Register();
|
||||
|
||||
AdcSubscription::SubscribeSensor(sensor, channel, 10);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ void initNewSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
initLambda(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
initFlexSensor(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initBaro(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initAuxSensors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
||||
#if !EFI_UNIT_TEST
|
||||
initFuelLevel(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
|
Loading…
Reference in New Issue