diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 920c0c916a..35c3f0b4c7 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -741,7 +741,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE); } // offset 32 - tsOutputChannels->tpsADC = getTPS12bitAdc(PASS_ENGINE_PARAMETER_SIGNATURE) / TPS_TS_CONVERSION; + tsOutputChannels->tpsADC = getTPS12bitAdc(0 PASS_ENGINE_PARAMETER_SUFFIX) / TPS_TS_CONVERSION; // offset 36 #if EFI_ANALOG_SENSORS tsOutputChannels->baroPressure = hasBaroSensor() ? getBaroPressure() : 0; diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 38ba42141c..9afe1c5fb9 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -180,11 +180,11 @@ static percent_t currentEtbDuty; // this macro clamps both positive and negative percentages from about -100% to 100% #define ETB_PERCENT_TO_DUTY(X) (maxF(minF((X * 0.01), ETB_DUTY_LIMIT - 0.01), 0.01 - ETB_DUTY_LIMIT)) -void EtbController::init(DcMotor *motor) { +void EtbController::init(DcMotor *motor, int ownIndex) { this->m_motor = motor; + this->ownIndex = ownIndex; } - int EtbController::getPeriodMs() { return GET_PERIOD_LIMITED(&engineConfiguration->etb); } @@ -227,7 +227,7 @@ void EtbController::PeriodicTask() { return; } - percent_t actualThrottlePosition = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); + percent_t actualThrottlePosition = getTPSWithIndex(ownIndex PASS_ENGINE_PARAMETER_SIGNATURE); if (engine->etbAutoTune) { autoTune.input = actualThrottlePosition; @@ -639,7 +639,7 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #endif /* EFI_PROD_CODE */ for (int i = 0 ; i < ETB_COUNT; i++) { - etbController[i].init(&etbHardware[i].dcMotor); + etbController[i].init(&etbHardware[i].dcMotor, i); etbController[i].etbPid.initPidClass(&engineConfiguration->etb); INJECT_ENGINE_REFERENCE(etbController[i]); } diff --git a/firmware/controllers/actuators/electronic_throttle.h b/firmware/controllers/actuators/electronic_throttle.h index 2f72e70b85..3a8b0537a0 100644 --- a/firmware/controllers/actuators/electronic_throttle.h +++ b/firmware/controllers/actuators/electronic_throttle.h @@ -23,7 +23,7 @@ class DcMotor; class EtbController final : public PeriodicTimerController { public: DECLARE_ENGINE_PTR; - void init(DcMotor *motor); + void init(DcMotor *motor, int ownIndex); int getPeriodMs() override; void PeriodicTask() override; @@ -31,6 +31,7 @@ public: bool shouldResetPid = false; private: + int ownIndex; DcMotor *m_motor; }; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index ad542281ef..7935e0ffea 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -819,6 +819,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20191128; + return 20191129; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 96878731e4..22e5ee6f47 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -141,7 +141,7 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) { * We need ADC value because TunerStudio has a nice TPS configuration wizard, and this wizard * wants a TPS value. */ -int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +int getTPS12bitAdc(int index PASS_ENGINE_PARAMETER_SUFFIX) { #if !EFI_PROD_CODE if (engine->mockTpsAdcValue != MOCK_UNDEFINED) { return engine->mockTpsAdcValue; @@ -151,7 +151,11 @@ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return -1; #if EFI_PROD_CODE - return getAdcValue("tps10", engineConfiguration->tps1_1AdcChannel); + if (index == 0) { + return getAdcValue("tps10", engineConfiguration->tps1_1AdcChannel); + } else { + return getAdcValue("tps20", engineConfiguration->tps2_1AdcChannel); + } // return tpsFastAdc / 4; #else return 0; @@ -193,8 +197,8 @@ void grabPedalIsWideOpen() { /** * @brief Position on physical primary TPS */ -static percent_t getPrimatyRawTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - percent_t tpsValue = getTpsValue(getTPS12bitAdc(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); +static percent_t getPrimatyRawTPS(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { + percent_t tpsValue = getTpsValue(getTPS12bitAdc(index PASS_ENGINE_PARAMETER_SUFFIX) PASS_ENGINE_PARAMETER_SUFFIX); return tpsValue; } @@ -222,7 +226,7 @@ bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { return engineConfiguration->tps1_1AdcChannel != EFI_ADC_NONE; } -percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +percent_t getTPSWithIndex(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { #if !EFI_PROD_CODE if (!cisnan(engine->mockTpsValue)) { return engine->mockTpsValue; @@ -234,7 +238,11 @@ percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { // todo: blah blah // todo: if two TPS do not match - show OBD code via malfunction_central.c - return getPrimatyRawTPS(PASS_ENGINE_PARAMETER_SIGNATURE); + return getPrimatyRawTPS(index PASS_ENGINE_PARAMETER_SUFFIX); +} + +percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + return getTPSWithIndex(0 PASS_ENGINE_PARAMETER_SUFFIX); } void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index 3e4503aa9f..ed5af40ce2 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -24,9 +24,10 @@ percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE); * @return Current TPS position, percent of WOT. 0 means idle and 100 means Wide Open Throttle */ percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE); +percent_t getTPSWithIndex(int index DECLARE_ENGINE_PARAMETER_SUFFIX); bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE); int convertVoltageTo10bitADC(float voltage); -int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE); +int getTPS12bitAdc(int index PASS_ENGINE_PARAMETER_SUFFIX); #define getTPS10bitAdc() (getTPS12bitAdc() / TPS_TS_CONVERSION) float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE); percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX);