rusefi/firmware/controllers/sensors/tps.cpp

84 lines
2.7 KiB
C++
Raw Normal View History

2015-12-31 13:02:30 -08:00
/**
2020-01-07 21:02:40 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-12-31 13:02:30 -08:00
*/
#include "pch.h"
#include "sent.h"
#include "tunerstudio.h"
2015-07-10 06:01:56 -07:00
2024-08-13 17:39:29 -07:00
/*
2019-04-29 22:21:09 -07:00
void grabTPSIsClosed() {
#if EFI_PROD_CODE
engineConfiguration->tpsMin = convertVoltageTo10bitADC(Sensor::getRaw(SensorType::Tps1));
2024-08-13 17:39:29 -07:00
#endif // EFI_PROD_CODE
2019-04-29 22:21:09 -07:00
}
void grabTPSIsWideOpen() {
#if EFI_PROD_CODE
engineConfiguration->tpsMax = convertVoltageTo10bitADC(Sensor::getRaw(SensorType::Tps1));
2024-08-13 17:39:29 -07:00
#endif // EFI_PROD_CODE
2019-04-29 22:21:09 -07:00
}
2024-08-13 17:39:29 -07:00
*/
2019-04-29 22:21:09 -07:00
static void onGrabPedal() {
static uint8_t grabPedalCounter = 0;
grabPedalCounter++;
if (grabPedalCounter % 2 == 0) {
// todo fix root cause! work-around: make sure not to write bad tune since that would brick requestBurn();
}
}
2019-04-30 15:46:39 -07:00
void grabPedalIsUp() {
2022-01-27 17:10:55 -08:00
/**
* search for 'maintainConstantValue' to find how this TS magic works
*/
engine->outputChannels.calibrationMode = (uint8_t)TsCalMode::PedalMin;
engine->outputChannels.calibrationValue = Sensor::getRaw(SensorType::AcceleratorPedalPrimary);
engine->outputChannels.calibrationValue2 = Sensor::getRaw(SensorType::AcceleratorPedalSecondary);
onGrabPedal();
2019-04-30 15:46:39 -07:00
}
void grabPedalIsWideOpen() {
2022-01-27 17:10:55 -08:00
engine->outputChannels.calibrationMode = (uint8_t)TsCalMode::PedalMax;
engine->outputChannels.calibrationValue = Sensor::getRaw(SensorType::AcceleratorPedalPrimary);
engine->outputChannels.calibrationValue2 = Sensor::getRaw(SensorType::AcceleratorPedalSecondary);
onGrabPedal();
}
2022-11-29 17:11:29 -08:00
bool isTps1Error() {
return !Sensor::get(SensorType::Tps1).Valid;
}
bool isTps2Error() {
return !Sensor::get(SensorType::Tps2).Valid && Sensor::hasSensor(SensorType::Tps2Primary);
}
bool isPedalError() {
return !Sensor::get(SensorType::AcceleratorPedal).Valid && Sensor::hasSensor(SensorType::AcceleratorPedalPrimary);
2019-04-30 15:46:39 -07:00
}
extern SentTps sentTps;
2023-03-01 14:20:34 -08:00
float decodeTpsSentValue(float sentValue) {
switch (engineConfiguration->sentEtbType) {
case SentEtbType::GM_TYPE_1:
2023-03-01 15:56:06 -08:00
return interpolateMsg("tps", /*x1*/0xE48, /*y1*/0, /*x2*/0x1A0, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue);
case SentEtbType::FORD_TYPE_1:
return interpolateMsg("tps", /*x1*/ 250, /*y1*/0, /*x2*/ 3560, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue);
2023-03-01 14:20:34 -08:00
default:
return interpolateMsg("tps", /*x1*/engineConfiguration->customSentTpsMin, /*y1*/0, /*x2*/engineConfiguration->customSentTpsMax, /*y2*/POSITION_FULLY_OPEN, /*x*/sentValue);
}
}
void sentTpsDecode() {
#if EFI_SENT_SUPPORT
if (!isDigitalTps1()) {
return;
}
2023-03-01 13:09:23 -08:00
// todo: move away from weird float API
float sentValue = getSentValue(0);
2023-03-01 14:20:34 -08:00
float tpsValue = decodeTpsSentValue(sentValue);
2023-03-01 13:09:23 -08:00
sentTps.setValidValue(tpsValue, getTimeNowNt());
#endif // EFI_SENT_SUPPORT
2023-03-01 14:20:34 -08:00
}