diff --git a/firmware/config/boards/hellen/hellen-gm-e67/connectors/generated_ts_name_by_pin.cpp b/firmware/config/boards/hellen/hellen-gm-e67/connectors/generated_ts_name_by_pin.cpp index f78ab69a6b..4be2ccf8fd 100644 --- a/firmware/config/boards/hellen/hellen-gm-e67/connectors/generated_ts_name_by_pin.cpp +++ b/firmware/config/boards/hellen/hellen-gm-e67/connectors/generated_ts_name_by_pin.cpp @@ -14,6 +14,7 @@ const char * getBoardSpecificPinName(brain_pin_e brainPin) { case Gpio::C13: return "C2-1 - IGN 1"; case Gpio::D10: return "C2-70 INJ 4"; case Gpio::D11: return "C2-16 INJ 3"; + case Gpio::D13: return "C3-7 - Alternator Enable"; case Gpio::D15: return "C1-25 Tach"; case Gpio::D2: return "C1-13 - Fuel Pump"; case Gpio::D9: return "C2-49 INJ 5"; @@ -22,12 +23,14 @@ const char * getBoardSpecificPinName(brain_pin_e brainPin) { case Gpio::E4: return "C2-55 - IGN 3"; case Gpio::E5: return "C2-53 - IGN 2"; case Gpio::E6: return "C2-17 - IGN 8"; + case Gpio::F11: return "C3-66 - VSS Input"; case Gpio::F12: return "C2-52 INJ 6"; case Gpio::F13: return "C2-71 INJ 7"; case Gpio::F14: return "C2-48 INJ 8"; case Gpio::F4: return "C2-63 - Crank"; case Gpio::F6: return "C2-59 - Cam"; case Gpio::G11: return "C1-26 - Starter Relay"; + case Gpio::G13: return "C3-16 - Coolant Pump"; case Gpio::G14: return "C1-40 - MAIN"; case Gpio::G2: return "C1-12 Check Engine"; case Gpio::G4: return "C1-56 - Starter Enable"; diff --git a/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-black.yaml b/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-black.yaml index 7dc85d44ee..1d85941419 100644 --- a/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-black.yaml +++ b/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-black.yaml @@ -114,6 +114,15 @@ pins: type: ls color: purple + - pin: 60 + # H144_IN_O2S2 + id: EFI_ADC_1 + class: analog_inputs + ts_name: C2-60 - Oil Pressure + function: Oil Pressure + type: av + color: purple + - pin: 63 # H144_IN_SENS2 id: F4 diff --git a/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-grey.yaml b/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-grey.yaml index 1cea6b1fb4..b0b9d13170 100644 --- a/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-grey.yaml +++ b/firmware/config/boards/hellen/hellen-gm-e67/connectors/gm-e67-grey.yaml @@ -1,4 +1,20 @@ pins: + - pin: 7 + # H144_OUT_PWM1 + id: D13 + class: outputs + function: Alternator Enable + type: hs + ts_name: C3-7 - Alternator Enable + + - pin: 16 + # H144_OUT_IO9 + id: G13 + class: outputs + function: Coolant Pump + type: hs + ts_name: C3-16 - Coolant Pump + - pin: 33 function: CAN bus low type: can @@ -59,3 +75,16 @@ pins: ts_name: C3-59 - MAP function: MAP color: purple + + - pin: 66 + # H144_IN_VSS + id: F11 + class: switch_inputs + function: Vehicle Speed Sensor Input Pos + type: hall + ts_name: C3-66 - VSS Input + color: gray + + - pin: 67 + function: Vehicle Speed Sensor Input Neg + color: gray \ No newline at end of file diff --git a/firmware/controllers/date_stamp.h b/firmware/controllers/date_stamp.h index a8477ed151..ec2b919828 100644 --- a/firmware/controllers/date_stamp.h +++ b/firmware/controllers/date_stamp.h @@ -1,2 +1,2 @@ #pragma once -#define VCS_DATE 20220603 +#define VCS_DATE 20220604 diff --git a/firmware/controllers/generated/signature_48way.h b/firmware/controllers/generated/signature_48way.h index 6f310fc551..1cfcfa6490 100644 --- a/firmware/controllers/generated/signature_48way.h +++ b/firmware/controllers/generated/signature_48way.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 705317436 -#define TS_SIGNATURE "rusEFI 2022.06.03.48way.705317436" +#define TS_SIGNATURE "rusEFI 2022.06.04.48way.705317436" diff --git a/firmware/controllers/generated/signature_all.h b/firmware/controllers/generated/signature_all.h index 0e1baaf97c..e69cf6ca64 100644 --- a/firmware/controllers/generated/signature_all.h +++ b/firmware/controllers/generated/signature_all.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1026376307 -#define TS_SIGNATURE "rusEFI 2022.06.03.all.1026376307" +#define TS_SIGNATURE "rusEFI 2022.06.04.all.1026376307" diff --git a/firmware/controllers/generated/signature_alphax-2chan.h b/firmware/controllers/generated/signature_alphax-2chan.h index 285c799d08..ef014dd74e 100644 --- a/firmware/controllers/generated/signature_alphax-2chan.h +++ b/firmware/controllers/generated/signature_alphax-2chan.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 255844127 -#define TS_SIGNATURE "rusEFI 2022.06.03.alphax-2chan.255844127" +#define TS_SIGNATURE "rusEFI 2022.06.04.alphax-2chan.255844127" diff --git a/firmware/controllers/generated/signature_alphax-4chan.h b/firmware/controllers/generated/signature_alphax-4chan.h index 758718af5a..15e5a8f690 100644 --- a/firmware/controllers/generated/signature_alphax-4chan.h +++ b/firmware/controllers/generated/signature_alphax-4chan.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 513912112 -#define TS_SIGNATURE "rusEFI 2022.06.03.alphax-4chan.513912112" +#define TS_SIGNATURE "rusEFI 2022.06.04.alphax-4chan.513912112" diff --git a/firmware/controllers/generated/signature_atlas.h b/firmware/controllers/generated/signature_atlas.h index 7a257ac7e3..3f65b85727 100644 --- a/firmware/controllers/generated/signature_atlas.h +++ b/firmware/controllers/generated/signature_atlas.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 568833876 -#define TS_SIGNATURE "rusEFI 2022.06.03.atlas.568833876" +#define TS_SIGNATURE "rusEFI 2022.06.04.atlas.568833876" diff --git a/firmware/controllers/generated/signature_core8.h b/firmware/controllers/generated/signature_core8.h index 1524a61db2..c6fc89387e 100644 --- a/firmware/controllers/generated/signature_core8.h +++ b/firmware/controllers/generated/signature_core8.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3418428298 -#define TS_SIGNATURE "rusEFI 2022.06.03.core8.3418428298" +#define TS_SIGNATURE "rusEFI 2022.06.04.core8.3418428298" diff --git a/firmware/controllers/generated/signature_f407-discovery.h b/firmware/controllers/generated/signature_f407-discovery.h index 70df44ea69..25cd5ac029 100644 --- a/firmware/controllers/generated/signature_f407-discovery.h +++ b/firmware/controllers/generated/signature_f407-discovery.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1026376307 -#define TS_SIGNATURE "rusEFI 2022.06.03.f407-discovery.1026376307" +#define TS_SIGNATURE "rusEFI 2022.06.04.f407-discovery.1026376307" diff --git a/firmware/controllers/generated/signature_f429-discovery.h b/firmware/controllers/generated/signature_f429-discovery.h index 7ecb61601b..b99425484e 100644 --- a/firmware/controllers/generated/signature_f429-discovery.h +++ b/firmware/controllers/generated/signature_f429-discovery.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1026376307 -#define TS_SIGNATURE "rusEFI 2022.06.03.f429-discovery.1026376307" +#define TS_SIGNATURE "rusEFI 2022.06.04.f429-discovery.1026376307" diff --git a/firmware/controllers/generated/signature_frankenso_na6.h b/firmware/controllers/generated/signature_frankenso_na6.h index ea458ef5e0..377245bada 100644 --- a/firmware/controllers/generated/signature_frankenso_na6.h +++ b/firmware/controllers/generated/signature_frankenso_na6.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 2135015095 -#define TS_SIGNATURE "rusEFI 2022.06.03.frankenso_na6.2135015095" +#define TS_SIGNATURE "rusEFI 2022.06.04.frankenso_na6.2135015095" diff --git a/firmware/controllers/generated/signature_harley81.h b/firmware/controllers/generated/signature_harley81.h index f0bea9213b..d2bb7d4479 100644 --- a/firmware/controllers/generated/signature_harley81.h +++ b/firmware/controllers/generated/signature_harley81.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1237392652 -#define TS_SIGNATURE "rusEFI 2022.06.03.harley81.1237392652" +#define TS_SIGNATURE "rusEFI 2022.06.04.harley81.1237392652" diff --git a/firmware/controllers/generated/signature_hellen-gm-e67.h b/firmware/controllers/generated/signature_hellen-gm-e67.h index 02945be968..b0f9236004 100644 --- a/firmware/controllers/generated/signature_hellen-gm-e67.h +++ b/firmware/controllers/generated/signature_hellen-gm-e67.h @@ -2,5 +2,5 @@ // was generated automatically by rusEFI tool ConfigDefinition.jar based on gen_config.sh null // -#define SIGNATURE_HASH 2003219992 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen-gm-e67.2003219992" +#define SIGNATURE_HASH 2168582308 +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen-gm-e67.2168582308" diff --git a/firmware/controllers/generated/signature_hellen-nb1.h b/firmware/controllers/generated/signature_hellen-nb1.h index 2203f39e1e..a88dcdb547 100644 --- a/firmware/controllers/generated/signature_hellen-nb1.h +++ b/firmware/controllers/generated/signature_hellen-nb1.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3836113855 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen-nb1.3836113855" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen-nb1.3836113855" diff --git a/firmware/controllers/generated/signature_hellen121nissan.h b/firmware/controllers/generated/signature_hellen121nissan.h index d1ba8a9d12..56e49b4006 100644 --- a/firmware/controllers/generated/signature_hellen121nissan.h +++ b/firmware/controllers/generated/signature_hellen121nissan.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3820612870 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen121nissan.3820612870" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen121nissan.3820612870" diff --git a/firmware/controllers/generated/signature_hellen121vag.h b/firmware/controllers/generated/signature_hellen121vag.h index 1dab68ee7c..8d78706d30 100644 --- a/firmware/controllers/generated/signature_hellen121vag.h +++ b/firmware/controllers/generated/signature_hellen121vag.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1897585401 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen121vag.1897585401" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen121vag.1897585401" diff --git a/firmware/controllers/generated/signature_hellen128.h b/firmware/controllers/generated/signature_hellen128.h index 10e804c743..d8235938e6 100644 --- a/firmware/controllers/generated/signature_hellen128.h +++ b/firmware/controllers/generated/signature_hellen128.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1392942754 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen128.1392942754" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen128.1392942754" diff --git a/firmware/controllers/generated/signature_hellen154hyundai.h b/firmware/controllers/generated/signature_hellen154hyundai.h index 96fdb1af11..4ad68a3f85 100644 --- a/firmware/controllers/generated/signature_hellen154hyundai.h +++ b/firmware/controllers/generated/signature_hellen154hyundai.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 2774675703 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen154hyundai.2774675703" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen154hyundai.2774675703" diff --git a/firmware/controllers/generated/signature_hellen72.h b/firmware/controllers/generated/signature_hellen72.h index adea9ce112..aa3bbd543a 100644 --- a/firmware/controllers/generated/signature_hellen72.h +++ b/firmware/controllers/generated/signature_hellen72.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 2325188489 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen72.2325188489" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen72.2325188489" diff --git a/firmware/controllers/generated/signature_hellen81.h b/firmware/controllers/generated/signature_hellen81.h index dff7cd46f9..9b254a2436 100644 --- a/firmware/controllers/generated/signature_hellen81.h +++ b/firmware/controllers/generated/signature_hellen81.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 530094713 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen81.530094713" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen81.530094713" diff --git a/firmware/controllers/generated/signature_hellen88bmw.h b/firmware/controllers/generated/signature_hellen88bmw.h index 66e5cb304d..71cac645ef 100644 --- a/firmware/controllers/generated/signature_hellen88bmw.h +++ b/firmware/controllers/generated/signature_hellen88bmw.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1639613655 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen88bmw.1639613655" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen88bmw.1639613655" diff --git a/firmware/controllers/generated/signature_hellenNA6.h b/firmware/controllers/generated/signature_hellenNA6.h index 09ef59ae0f..9fe898fcc9 100644 --- a/firmware/controllers/generated/signature_hellenNA6.h +++ b/firmware/controllers/generated/signature_hellenNA6.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3215373075 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellenNA6.3215373075" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellenNA6.3215373075" diff --git a/firmware/controllers/generated/signature_hellenNA8_96.h b/firmware/controllers/generated/signature_hellenNA8_96.h index bf194cf143..7815c002f0 100644 --- a/firmware/controllers/generated/signature_hellenNA8_96.h +++ b/firmware/controllers/generated/signature_hellenNA8_96.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 2298012637 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellenNA8_96.2298012637" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellenNA8_96.2298012637" diff --git a/firmware/controllers/generated/signature_hellen_cypress.h b/firmware/controllers/generated/signature_hellen_cypress.h index 928a610490..1c7785efa3 100644 --- a/firmware/controllers/generated/signature_hellen_cypress.h +++ b/firmware/controllers/generated/signature_hellen_cypress.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 2013334649 -#define TS_SIGNATURE "rusEFI 2022.06.03.hellen_cypress.2013334649" +#define TS_SIGNATURE "rusEFI 2022.06.04.hellen_cypress.2013334649" diff --git a/firmware/controllers/generated/signature_kin.h b/firmware/controllers/generated/signature_kin.h index 8538630e6d..183f2f7868 100644 --- a/firmware/controllers/generated/signature_kin.h +++ b/firmware/controllers/generated/signature_kin.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 641887220 -#define TS_SIGNATURE "rusEFI 2022.06.03.kin.641887220" +#define TS_SIGNATURE "rusEFI 2022.06.04.kin.641887220" diff --git a/firmware/controllers/generated/signature_mre_f4.h b/firmware/controllers/generated/signature_mre_f4.h index 8a331d49bc..c10e858132 100644 --- a/firmware/controllers/generated/signature_mre_f4.h +++ b/firmware/controllers/generated/signature_mre_f4.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1883235271 -#define TS_SIGNATURE "rusEFI 2022.06.03.mre_f4.1883235271" +#define TS_SIGNATURE "rusEFI 2022.06.04.mre_f4.1883235271" diff --git a/firmware/controllers/generated/signature_mre_f7.h b/firmware/controllers/generated/signature_mre_f7.h index 16e47852d9..1d0a6c86a0 100644 --- a/firmware/controllers/generated/signature_mre_f7.h +++ b/firmware/controllers/generated/signature_mre_f7.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1883235271 -#define TS_SIGNATURE "rusEFI 2022.06.03.mre_f7.1883235271" +#define TS_SIGNATURE "rusEFI 2022.06.04.mre_f7.1883235271" diff --git a/firmware/controllers/generated/signature_prometheus_405.h b/firmware/controllers/generated/signature_prometheus_405.h index b11c21cae6..448828fb7b 100644 --- a/firmware/controllers/generated/signature_prometheus_405.h +++ b/firmware/controllers/generated/signature_prometheus_405.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1841798037 -#define TS_SIGNATURE "rusEFI 2022.06.03.prometheus_405.1841798037" +#define TS_SIGNATURE "rusEFI 2022.06.04.prometheus_405.1841798037" diff --git a/firmware/controllers/generated/signature_prometheus_469.h b/firmware/controllers/generated/signature_prometheus_469.h index 84a645c7e7..52e2b3573c 100644 --- a/firmware/controllers/generated/signature_prometheus_469.h +++ b/firmware/controllers/generated/signature_prometheus_469.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 1841798037 -#define TS_SIGNATURE "rusEFI 2022.06.03.prometheus_469.1841798037" +#define TS_SIGNATURE "rusEFI 2022.06.04.prometheus_469.1841798037" diff --git a/firmware/controllers/generated/signature_proteus_f4.h b/firmware/controllers/generated/signature_proteus_f4.h index 3df14d52a6..983d38f1f7 100644 --- a/firmware/controllers/generated/signature_proteus_f4.h +++ b/firmware/controllers/generated/signature_proteus_f4.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3760342879 -#define TS_SIGNATURE "rusEFI 2022.06.03.proteus_f4.3760342879" +#define TS_SIGNATURE "rusEFI 2022.06.04.proteus_f4.3760342879" diff --git a/firmware/controllers/generated/signature_proteus_f7.h b/firmware/controllers/generated/signature_proteus_f7.h index 6dcf32ee1b..45ab62c5d6 100644 --- a/firmware/controllers/generated/signature_proteus_f7.h +++ b/firmware/controllers/generated/signature_proteus_f7.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3760342879 -#define TS_SIGNATURE "rusEFI 2022.06.03.proteus_f7.3760342879" +#define TS_SIGNATURE "rusEFI 2022.06.04.proteus_f7.3760342879" diff --git a/firmware/controllers/generated/signature_proteus_h7.h b/firmware/controllers/generated/signature_proteus_h7.h index e90cc85d25..bd44e959a8 100644 --- a/firmware/controllers/generated/signature_proteus_h7.h +++ b/firmware/controllers/generated/signature_proteus_h7.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 3760342879 -#define TS_SIGNATURE "rusEFI 2022.06.03.proteus_h7.3760342879" +#define TS_SIGNATURE "rusEFI 2022.06.04.proteus_h7.3760342879" diff --git a/firmware/controllers/generated/signature_subaru_eg33_f7.h b/firmware/controllers/generated/signature_subaru_eg33_f7.h index f13ad4df9f..73edc21721 100644 --- a/firmware/controllers/generated/signature_subaru_eg33_f7.h +++ b/firmware/controllers/generated/signature_subaru_eg33_f7.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 909949889 -#define TS_SIGNATURE "rusEFI 2022.06.03.subaru_eg33_f7.909949889" +#define TS_SIGNATURE "rusEFI 2022.06.04.subaru_eg33_f7.909949889" diff --git a/firmware/controllers/generated/signature_tdg-pdm8.h b/firmware/controllers/generated/signature_tdg-pdm8.h index 28024cadc3..209b36db7b 100644 --- a/firmware/controllers/generated/signature_tdg-pdm8.h +++ b/firmware/controllers/generated/signature_tdg-pdm8.h @@ -3,4 +3,4 @@ // #define SIGNATURE_HASH 2535820327 -#define TS_SIGNATURE "rusEFI 2022.06.03.tdg-pdm8.2535820327" +#define TS_SIGNATURE "rusEFI 2022.06.04.tdg-pdm8.2535820327" diff --git a/firmware/controllers/sensors/sensor.h b/firmware/controllers/sensors/sensor.h index 0dab8fac5e..744775b2a3 100644 --- a/firmware/controllers/sensors/sensor.h +++ b/firmware/controllers/sensors/sensor.h @@ -138,7 +138,7 @@ public: * Get a friendly name for the sensor. * For example, CLT, IAT, Throttle Position 2, etc. */ - const char* getSensorName() { return getSensorName(m_type); } + const char* getSensorName() const { return getSensorName(m_type); } static const char* getSensorName(SensorType type); // Retrieve the current reading from the sensor. @@ -170,6 +170,10 @@ public: void unregister(); + SensorType type() const { + return m_type; + } + protected: // Protected constructor - only subclasses call this explicit Sensor(SensorType type) diff --git a/firmware/init/sensor/init_tps.cpp b/firmware/init/sensor/init_tps.cpp index b444746d66..93fe3f6d5d 100644 --- a/firmware/init/sensor/init_tps.cpp +++ b/firmware/init/sensor/init_tps.cpp @@ -8,114 +8,180 @@ #include "linear_func.h" #include "tps.h" -LinearFunc tpsFunc1p(TPS_TS_CONVERSION); -LinearFunc tpsFunc1s(TPS_TS_CONVERSION); -LinearFunc tpsFunc2p(TPS_TS_CONVERSION); -LinearFunc tpsFunc2s(TPS_TS_CONVERSION); +struct TpsConfig { + adc_channel_e channel; + float closed; + float open; + float min; + float max; +}; -FunctionalSensor tpsSens1p(SensorType::Tps1Primary, MS2NT(10)); -FunctionalSensor tpsSens1s(SensorType::Tps1Secondary, MS2NT(10)); -FunctionalSensor tpsSens2p(SensorType::Tps2Primary, MS2NT(10)); -FunctionalSensor tpsSens2s(SensorType::Tps2Secondary, MS2NT(10)); +class FuncSensPair { +public: + FuncSensPair(float divideInput, SensorType type) + : m_func(divideInput) + , m_sens(type, MS2NT(10)) + { + m_sens.setFunction(m_func); + } + + bool init(const TpsConfig& cfg) { + // If the configuration was invalid, don't continue to configure the sensor + if (!configure(cfg)) { + return false; + } + + AdcSubscription::SubscribeSensor(m_sens, cfg.channel, 200); + + return m_sens.Register(); + } + + void unsubscribe() { + AdcSubscription::UnsubscribeSensor(m_sens); + } + + SensorType type() const { + return m_sens.type(); + } + + const char* name() const { + return m_sens.getSensorName(); + } + +private: + bool configure(const TpsConfig& cfg) { + // Only configure if we have a channel + if (!isAdcChannelValid(cfg.channel)) { + return false; + } + + float scaledClosed = cfg.closed / m_func.getDivideInput(); + float scaledOpen = cfg.open / m_func.getDivideInput(); + + float split = absF(scaledOpen - scaledClosed); + + // If the voltage for closed vs. open is very near, something is wrong with your calibration + if (split < 0.5f) { + firmwareError(OBD_Throttle_Position_Sensor_Circuit_Malfunction, "\"%s\" problem: open %.2f/closed %.2f cal values are too close together. Check your calibration and wiring!", name(), + cfg.open, + cfg.closed); + return false; + } + + m_func.configure( + cfg.closed, 0, + cfg.open, 100, + cfg.min, cfg.max + ); + + return true; + } + + LinearFunc m_func; + FunctionalSensor m_sens; +}; + +struct RedundantPair { +public: + RedundantPair(FuncSensPair& pri, FuncSensPair& sec, SensorType outputType) + : m_pri(pri) + , m_sec(sec) + , m_redund(outputType, m_pri.type(), m_sec.type()) + { + } + + void init(bool isFordTps, RedundantFordTps* fordTps, const TpsConfig& primary, const TpsConfig& secondary) { + { + // Check that the primary and secondary aren't too close together - if so, the user may have done + // an unsafe thing where they wired a single sensor to both inputs. Don't do that! + bool hasBothSensors = isAdcChannelValid(primary.channel) && isAdcChannelValid(secondary.channel); + bool tooCloseClosed = absF(primary.closed - secondary.closed) < 0.2f; + bool tooCloseOpen = absF(primary.open - secondary.open) < 0.2f; + + if (hasBothSensors && tooCloseClosed && tooCloseOpen) { + firmwareError(OBD_Throttle_Position_Sensor_Circuit_Malfunction, "Configuration for redundant pair %s/%s are too similar - did you wire one sensor to both inputs...?", m_pri.name(), m_sec.name()); + return; + } + } + + m_pri.init(primary); + + bool hasSecond = m_sec.init(secondary); + + if (isFordTps && fordTps) { + // we have a secondary + fordTps->configure(5.0f, 52.6f); + fordTps->Register(); + } else { + // not ford TPS + m_redund.configure(5.0f, !hasSecond); + m_redund.Register(); + } + } + + void unsubscribe() { + m_pri.unsubscribe(); + m_sec.unsubscribe(); + } + +private: + FuncSensPair& m_pri; + FuncSensPair& m_sec; + + RedundantSensor m_redund; +}; + +static FuncSensPair tps1p(TPS_TS_CONVERSION, SensorType::Tps1Primary); +static FuncSensPair tps1s(TPS_TS_CONVERSION, SensorType::Tps1Secondary); +static FuncSensPair tps2p(TPS_TS_CONVERSION, SensorType::Tps2Primary); +static FuncSensPair tps2s(TPS_TS_CONVERSION, SensorType::Tps2Secondary); // Used in case of "normal", non-Ford ETB TPS -RedundantSensor tps1(SensorType::Tps1, SensorType::Tps1Primary, SensorType::Tps1Secondary); -RedundantSensor tps2(SensorType::Tps2, SensorType::Tps2Primary, SensorType::Tps2Secondary); +static RedundantPair tps1(tps1p, tps1s, SensorType::Tps1); +static RedundantPair tps2(tps2p, tps2s, SensorType::Tps2); // Used only in case of weird Ford-style ETB TPS -RedundantFordTps fordTps1(SensorType::Tps1, SensorType::Tps1Primary, SensorType::Tps1Secondary); -RedundantFordTps fordTps2(SensorType::Tps2, SensorType::Tps2Primary, SensorType::Tps2Secondary); +static RedundantFordTps fordTps1(SensorType::Tps1, SensorType::Tps1Primary, SensorType::Tps1Secondary); +static RedundantFordTps fordTps2(SensorType::Tps2, SensorType::Tps2Primary, SensorType::Tps2Secondary); -LinearFunc pedalFuncPrimary; -LinearFunc pedalFuncSecondary; -FunctionalSensor pedalSensorPrimary(SensorType::AcceleratorPedalPrimary, MS2NT(10)); -FunctionalSensor pedalSensorSecondary(SensorType::AcceleratorPedalSecondary, MS2NT(10)); - -RedundantSensor pedal(SensorType::AcceleratorPedal, SensorType::AcceleratorPedalPrimary, SensorType::AcceleratorPedalSecondary); +// Pedal sensors and redundancy +static FuncSensPair pedalPrimary(1, SensorType::AcceleratorPedalPrimary); +static FuncSensPair pedalSecondary(1, SensorType::AcceleratorPedalSecondary); +static RedundantPair pedal(pedalPrimary, pedalSecondary, SensorType::AcceleratorPedal); // This sensor indicates the driver's throttle intent - Pedal if we have one, TPS if not. -ProxySensor driverIntent(SensorType::DriverThrottleIntent); +static ProxySensor driverIntent(SensorType::DriverThrottleIntent); // These sensors are TPS-like, so handle them in here too -LinearFunc wastegateFunc(PACK_MULT_VOLTAGE); -LinearFunc idlePosFunc(PACK_MULT_VOLTAGE); -FunctionalSensor wastegateSens(SensorType::WastegatePosition, MS2NT(10)); -FunctionalSensor idlePosSens(SensorType::IdlePosition, MS2NT(10)); - -static bool configureTps(LinearFunc& func, adc_channel_e channel, float closed, float open, float min, float max, const char* msg) { - // Only configure if we have a channel - if (!isAdcChannelValid(channel)) { - return false; - } - - float scaledClosed = closed / func.getDivideInput(); - float scaledOpen = open / func.getDivideInput(); - - float split = absF(scaledOpen - scaledClosed); - - // If the voltage for closed vs. open is very near, something is wrong with your calibration - if (split < 0.5f) { - firmwareError(OBD_Throttle_Position_Sensor_Circuit_Malfunction, "\"%s\" problem: open %.2f/closed %.2f cal values are too close together. Check your calibration and wiring!", msg, - open, - closed); - return false; - } - - func.configure( - closed, 0, - open, 100, - min, max - ); - - return true; -} - -static bool initTpsFunc(LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open, float min, float max) { - // If the configuration was invalid, don't continue to configure the sensor - if (!configureTps(func, channel, closed, open, min, max, sensor.getSensorName())) { - return false; - } - - sensor.setFunction(func); - - AdcSubscription::SubscribeSensor(sensor, channel, 200); - - return sensor.Register(); -} - -static void initTpsFuncAndRedund(RedundantSensor& redund, RedundantFordTps* fordTps, bool isFordTps, LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open, float min, float max) { - bool hasSecond = initTpsFunc(func, sensor, channel, closed, open, min, max); - - if (isFordTps && fordTps) { - fordTps->configure(5.0f, 52.6f); - fordTps->Register(); - } else { - redund.configure(5.0f, !hasSecond); - redund.Register(); - } -} +static FuncSensPair wastegate(PACK_MULT_VOLTAGE, SensorType::WastegatePosition); +static FuncSensPair idlePos(PACK_MULT_VOLTAGE, SensorType::IdlePosition); void initTps() { percent_t min = engineConfiguration->tpsErrorDetectionTooLow; percent_t max = engineConfiguration->tpsErrorDetectionTooHigh; if (!engineConfiguration->consumeObdSensors) { - // primary TPS sensors - initTpsFunc(tpsFunc1p, tpsSens1p, engineConfiguration->tps1_1AdcChannel, engineConfiguration->tpsMin, engineConfiguration->tpsMax, min, max); - initTpsFunc(tpsFunc2p, tpsSens2p, engineConfiguration->tps2_1AdcChannel, engineConfiguration->tps2Min, engineConfiguration->tps2Max, min, max); - - // Secondary TPS sensors (and redundant combining) bool isFordTps = engineConfiguration->useFordRedundantTps; - initTpsFuncAndRedund(tps1, &fordTps1, isFordTps, tpsFunc1s, tpsSens1s, engineConfiguration->tps1_2AdcChannel, engineConfiguration->tps1SecondaryMin, engineConfiguration->tps1SecondaryMax, min, max); - initTpsFuncAndRedund(tps2, &fordTps2, isFordTps, tpsFunc2s, tpsSens2s, engineConfiguration->tps2_2AdcChannel, engineConfiguration->tps2SecondaryMin, engineConfiguration->tps2SecondaryMax, min, max); + + tps1.init(isFordTps, &fordTps1, + { engineConfiguration->tps1_1AdcChannel, (float)engineConfiguration->tpsMin, (float)engineConfiguration->tpsMax, min, max }, + { engineConfiguration->tps1_2AdcChannel, (float)engineConfiguration->tps1SecondaryMin, (float)engineConfiguration->tps1SecondaryMax, min, max } + ); + + tps2.init(isFordTps, &fordTps2, + { engineConfiguration->tps2_1AdcChannel, (float)engineConfiguration->tps2Min, (float)engineConfiguration->tps2Max, min, max }, + { engineConfiguration->tps2_2AdcChannel, (float)engineConfiguration->tps2SecondaryMin, (float)engineConfiguration->tps2SecondaryMax, min, max } + ); // Pedal sensors - initTpsFunc(pedalFuncPrimary, pedalSensorPrimary, engineConfiguration->throttlePedalPositionAdcChannel, engineConfiguration->throttlePedalUpVoltage, engineConfiguration->throttlePedalWOTVoltage, min, max); - initTpsFuncAndRedund(pedal, nullptr, false, pedalFuncSecondary, pedalSensorSecondary, engineConfiguration->throttlePedalPositionSecondAdcChannel, engineConfiguration->throttlePedalSecondaryUpVoltage, engineConfiguration->throttlePedalSecondaryWOTVoltage, min, max); + pedal.init(false, nullptr, + { engineConfiguration->throttlePedalPositionAdcChannel, engineConfiguration->throttlePedalUpVoltage, engineConfiguration->throttlePedalWOTVoltage, min, max }, + { engineConfiguration->throttlePedalPositionSecondAdcChannel, engineConfiguration->throttlePedalSecondaryUpVoltage, engineConfiguration->throttlePedalSecondaryWOTVoltage, min, max } + ); // TPS-like stuff that isn't actually a TPS - initTpsFunc(wastegateFunc, wastegateSens, engineConfiguration->wastegatePositionSensor, engineConfiguration->wastegatePositionMin, engineConfiguration->wastegatePositionMax, min, max); - initTpsFunc(idlePosFunc, idlePosSens, engineConfiguration->idlePositionSensor, engineConfiguration->idlePositionMin, engineConfiguration->idlePositionMax, min, max); + wastegate.init({ engineConfiguration->wastegatePositionSensor, (float)engineConfiguration->wastegatePositionMin, (float)engineConfiguration->wastegatePositionMax, min, max }); + idlePos.init({ engineConfiguration->idlePositionSensor, (float)engineConfiguration->idlePositionMin, (float)engineConfiguration->idlePositionMax, min, max }); } // Route the pedal or TPS to driverIntent as appropriate @@ -129,15 +195,10 @@ void initTps() { } void deinitTps() { - AdcSubscription::UnsubscribeSensor(tpsSens1p); - AdcSubscription::UnsubscribeSensor(tpsSens1s); + tps1.unsubscribe(); + tps2.unsubscribe(); + pedal.unsubscribe(); - AdcSubscription::UnsubscribeSensor(tpsSens2p); - AdcSubscription::UnsubscribeSensor(tpsSens2s); - - AdcSubscription::UnsubscribeSensor(pedalSensorPrimary); - AdcSubscription::UnsubscribeSensor(pedalSensorSecondary); - - AdcSubscription::UnsubscribeSensor(wastegateSens); - AdcSubscription::UnsubscribeSensor(idlePosSens); + wastegate.unsubscribe(); + idlePos.unsubscribe(); } diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 470cf0938f..6fd5274082 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Fri Jun 03 00:17:45 UTC 2022 +// Sat Jun 04 00:20:22 UTC 2022 #ifndef GIT_HASH -#define GIT_HASH "e3dfc02faabd84bf9cca7793e110aebdfb6256ae" +#define GIT_HASH "0116be2f176acca81a40d144fca008b2086391d7" #endif #ifndef VCS_VERSION -#define VCS_VERSION "40664" +#define VCS_VERSION "41194" #endif