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
|
|
|
*/
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2023-03-01 06:19:22 -08:00
|
|
|
#include "sent.h"
|
2024-10-03 17:00:01 -07:00
|
|
|
#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
|
2020-04-05 16:33:33 -07:00
|
|
|
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
|
2020-04-05 16:33:33 -07:00
|
|
|
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
|
|
|
|
2024-10-03 17:00:01 -07:00
|
|
|
static void onGrabPedal() {
|
|
|
|
static uint8_t grabPedalCounter = 0;
|
|
|
|
grabPedalCounter++;
|
|
|
|
if (grabPedalCounter % 2 == 0) {
|
2024-10-26 10:23:39 -07:00
|
|
|
// todo fix root cause! work-around: make sure not to write bad tune since that would brick requestBurn();
|
2024-10-03 17:00:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2024-10-03 17:00:01 -07:00
|
|
|
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);
|
2024-10-03 17:00:01 -07:00
|
|
|
onGrabPedal();
|
2022-11-27 15:44:44 -08:00
|
|
|
}
|
|
|
|
|
2022-11-29 17:11:29 -08:00
|
|
|
bool isTps1Error() {
|
|
|
|
return !Sensor::get(SensorType::Tps1).Valid;
|
|
|
|
}
|
|
|
|
|
2022-11-27 15:44:44 -08:00
|
|
|
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
|
|
|
}
|
2023-02-28 19:10:19 -08:00
|
|
|
|
2023-03-01 06:19:22 -08: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 19:10:19 -08:00
|
|
|
void sentTpsDecode() {
|
2023-03-01 06:19:22 -08:00
|
|
|
#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());
|
2023-03-01 06:19:22 -08:00
|
|
|
#endif // EFI_SENT_SUPPORT
|
2023-03-01 14:20:34 -08:00
|
|
|
}
|