migrating to SensorType::Rpm API

This commit is contained in:
Andrey 2022-01-20 22:22:52 -05:00
parent 9f08db256b
commit 8361b6d1f6
7 changed files with 27 additions and 27 deletions

View File

@ -50,7 +50,7 @@ void AlternatorController::onFastCallback() {
#endif /* EFI_TUNER_STUDIO */
// todo: migrate this to FSIO
bool alternatorShouldBeEnabledAtCurrentRpm = GET_RPM() > engineConfiguration->cranking.rpm;
bool alternatorShouldBeEnabledAtCurrentRpm = Sensor::getOrZero(SensorType::Rpm) > engineConfiguration->cranking.rpm;
if (!engineConfiguration->isAlternatorControlEnabled || !alternatorShouldBeEnabledAtCurrentRpm) {
// we need to avoid accumulating iTerm while engine is not running

View File

@ -49,7 +49,7 @@ expected<float> BoostController::getSetpoint() {
return closedLoopPart;
}
float rpm = GET_RPM();
float rpm = Sensor::getOrZero(SensorType::Rpm);
auto tps = Sensor::get(SensorType::DriverThrottleIntent);
isTpsInvalid = !tps.Valid;
@ -67,7 +67,7 @@ expected<percent_t> BoostController::getOpenLoop(float target) {
// Boost control open loop doesn't care about target - only TPS/RPM
UNUSED(target);
float rpm = GET_RPM();
float rpm = Sensor::getOrZero(SensorType::Rpm);
auto tps = Sensor::get(SensorType::DriverThrottleIntent);
isTpsInvalid = !tps.Valid;
@ -101,7 +101,7 @@ percent_t BoostController::getClosedLoopImpl(float target, float manifoldPressur
}
// If the engine isn't running, don't correct.
isZeroRpm = GET_RPM() == 0;
isZeroRpm = Sensor::getOrZero(SensorType::Rpm) == 0;
if (isZeroRpm) {
m_pid.reset();
return 0;

View File

@ -140,7 +140,7 @@ void canDashboardBMW(CanCycle cycle) {
{
CanTxMessage msg(CAN_BMW_E46_RPM);
msg.setShortValue((int) (GET_RPM() * 6.4), 2);
msg.setShortValue((int) (Sensor::getOrZero(SensorType::Rpm) * 6.4), 2);
}
{
@ -163,7 +163,7 @@ void canMazdaRX8(CanCycle cycle) {
float kph = Sensor::getOrZero(SensorType::VehicleSpeed);
msg.setShortValue(SWAP_UINT16(GET_RPM() * 4), 0);
msg.setShortValue(SWAP_UINT16(Sensor::getOrZero(SensorType::Rpm) * 4), 0);
msg.setShortValue(0xFFFF, 2);
msg.setShortValue(SWAP_UINT16((int )(100 * kph + 10000)), 4);
msg.setShortValue(0, 6);
@ -192,7 +192,7 @@ void canMazdaRX8(CanCycle cycle) {
msg[4] = 0x01; //Oil Pressure (not really a gauge)
msg[5] = 0x00; //check engine light
msg[6] = 0x00; //Coolant, oil and battery
if ((GET_RPM()>0) && (Sensor::get(SensorType::BatteryVoltage).value_or(VBAT_FALLBACK_VALUE)<13)) {
if ((Sensor::getOrZero(SensorType::Rpm)>0) && (Sensor::get(SensorType::BatteryVoltage).value_or(VBAT_FALLBACK_VALUE)<13)) {
msg.setBit(6, 6); // battery light
}
if (!clt.Valid || clt.Value > 105) {
@ -213,7 +213,7 @@ void canDashboardFiat(CanCycle cycle) {
//Fiat Dashboard
CanTxMessage msg(CAN_FIAT_MOTOR_INFO);
msg.setShortValue((int) (Sensor::getOrZero(SensorType::Clt) - 40), 3); //Coolant Temp
msg.setShortValue(GET_RPM() / 32, 6); //RPM
msg.setShortValue(Sensor::getOrZero(SensorType::Rpm) / 32, 6); //RPM
}
}
}
@ -223,7 +223,7 @@ void canDashboardVAG(CanCycle cycle) {
{
//VAG Dashboard
CanTxMessage msg(CAN_VAG_Motor_1);
msg.setShortValue(GET_RPM() * 4, 2); //RPM
msg.setShortValue(Sensor::getOrZero(SensorType::Rpm) * 4, 2); //RPM
}
float clt = Sensor::getOrZero(SensorType::Clt);
@ -249,7 +249,7 @@ void canDashboardW202(CanCycle cycle) {
if (cycle.isInterval(CI::_20ms)) {
{
CanTxMessage msg(W202_STAT_1);
uint16_t tmp = GET_RPM();
uint16_t tmp = Sensor::getOrZero(SensorType::Rpm);
msg[0] = 0x08; // Unknown
msg[1] = (tmp >> 8); //RPM
msg[2] = (tmp & 0xff); //RPM
@ -308,7 +308,7 @@ void canDashboardGenesisCoupe(CanCycle cycle) {
if (cycle.isInterval(CI::_50ms)) {
{
CanTxMessage msg(GENESIS_COUPLE_RPM_316, 8);
int rpm8 = GET_RPM() * 4;
int rpm8 = Sensor::getOrZero(SensorType::Rpm) * 4;
msg[3] = rpm8 >> 8;
msg[4] = rpm8 & 0xFF;
}
@ -325,7 +325,7 @@ void canDashboardNissanVQ(CanCycle cycle) {
{
CanTxMessage msg(NISSAN_RPM_1F9, 8);
msg[0] = 0x20;
int rpm8 = (int)(GET_RPM() * 8);
int rpm8 = (int)(Sensor::getOrZero(SensorType::Rpm) * 8);
msg[2] = rpm8 >> 8;
msg[3] = rpm8 & 0xFF;
}
@ -349,7 +349,7 @@ void canDashboardNissanVQ(CanCycle cycle) {
// thank you "102 CAN Communication decoded"
#define CAN_23D_RPM_MULT 3.15
int rpm315 = (int)(GET_RPM() / CAN_23D_RPM_MULT);
int rpm315 = (int)(Sensor::getOrZero(SensorType::Rpm) / CAN_23D_RPM_MULT);
msg[3] = rpm315 & 0xFF;
msg[4] = rpm315 >> 8;
@ -372,8 +372,8 @@ void canDashboardVagMqb(CanCycle cycle) {
{ //RPM
CanTxMessage msg(0x107, 8);
msg[3] = ((int)(GET_RPM() / 3.5)) & 0xFF;
msg[4] = ((int)(GET_RPM() / 3.5)) >> 8;
msg[3] = ((int)(Sensor::getOrZero(SensorType::Rpm) / 3.5)) & 0xFF;
msg[4] = ((int)(Sensor::getOrZero(SensorType::Rpm) / 3.5)) >> 8;
}
}
}
@ -404,8 +404,8 @@ void canDashboardBMWE90(CanCycle cycle)
rpmcounter = 0xF0;
CanTxMessage msg(E90_RPM, 3);
msg[0] = rpmcounter;
msg[1] = (GET_RPM() * 4) & 0xFF;
msg[2] = (GET_RPM() * 4) >> 8;
msg[1] = (Sensor::getOrZero(SensorType::Rpm) * 4) & 0xFF;
msg[2] = (Sensor::getOrZero(SensorType::Rpm) * 4) >> 8;
}
{ //oil & coolant temp (all in C, despite gauge being F)
@ -534,7 +534,7 @@ void canDashboardHaltech(CanCycle cycle) {
/* 0x360 - 50Hz rate */
{
CanTxMessage msg(0x360, 8);
tmp = GET_RPM();
tmp = Sensor::getOrZero(SensorType::Rpm);
/* RPM */
msg[0] = (tmp >> 8);
msg[1] = (tmp & 0x00ff);
@ -575,7 +575,7 @@ void canDashboardHaltech(CanCycle cycle) {
{
CanTxMessage msg(0x362, 6);
/* Injection Stage 1 Duty Cycle - y = x/10 */
uint16_t rpm = GET_RPM();
uint16_t rpm = Sensor::getOrZero(SensorType::Rpm);
tmp = (uint16_t)( getInjectorDutyCycle(rpm) * 10) ;
msg[0] = (tmp >> 8);
msg[1] = (tmp & 0x00ff);

View File

@ -36,7 +36,7 @@ static void populateFrame(Status& msg) {
msg.warningCounter = engine->engineState.warnings.warningCounter;
msg.lastErrorCode = engine->engineState.warnings.lastErrorCode;
msg.revLimit = GET_RPM() > engineConfiguration->rpmHardLimit;
msg.revLimit = Sensor::getOrZero(SensorType::Rpm) > engineConfiguration->rpmHardLimit;
msg.mainRelay = enginePins.mainRelay.getLogicValue();
msg.fuelPump = enginePins.fuelPumpRelay.getLogicValue();
msg.checkEngine = enginePins.checkEnginePin.getLogicValue();
@ -53,7 +53,7 @@ struct Speeds {
};
static void populateFrame(Speeds& msg) {
auto rpm = GET_RPM();
auto rpm = Sensor::getOrZero(SensorType::Rpm);
msg.rpm = rpm;
auto timing = engine->engineState.timingAdvance[0];

View File

@ -102,7 +102,7 @@
*
* <BR>See main_trigger_callback.cpp for main trigger event handler
* <BR>See fuel_math.cpp for details on fuel amount logic
* <BR>See rpm_calculator.cpp for details on how getRpm() is calculated
* <BR>See rpm_calculator.cpp for details on how RPM is calculated
*
*/

View File

@ -67,7 +67,7 @@ TEST(BoostControl, OpenLoop) {
EXPECT_FLOAT_EQ(bc.getOpenLoop(0).value_or(-1), 47.0f);
}
TEST(BoostControl, ClosedLoop) {
TEST(BoostControl, TestClosedLoop) {
EngineTestHelper eth(TEST_ENGINE);
BoostController bc;
@ -87,15 +87,15 @@ TEST(BoostControl, ClosedLoop) {
engineConfiguration->minimumBoostClosedLoopMap = 75;
// At 0 RPM, closed loop is disabled
engine->rpmCalculator.mockRpm = 0;
Sensor::setMockValue(SensorType::Rpm, 0);
EXPECT_EQ(0, bc.getClosedLoop(150, 100).value_or(-1000));
// too low MAP, disable closed loop
engine->rpmCalculator.mockRpm = 0;
Sensor::setMockValue(SensorType::Rpm, 0);
EXPECT_EQ(0, bc.getClosedLoop(150, 50).value_or(-1000));
// With RPM, we should get an output
engine->rpmCalculator.mockRpm = 1000;
Sensor::setMockValue(SensorType::Rpm, 1000);
// Actual is below target -> positive output
EXPECT_FLOAT_EQ(50, bc.getClosedLoop(150, 100).value_or(-1000));
// Actual is above target -> negative output

View File

@ -73,7 +73,7 @@ TEST(GpPwm, OutputOnOff) {
ch.setOutput(41.0f);
}
TEST(GpPwm, GetOutput) {
TEST(GpPwm, TestGetOutput) {
EngineTestHelper eth(TEST_ENGINE);
GppwmChannel ch;