LTFT: glue to engine
This commit is contained in:
parent
b7049b7fbc
commit
5314eed4ea
|
@ -508,6 +508,10 @@ void commonInitEngineController() {
|
|||
|
||||
initTachometer();
|
||||
initSpeedometer();
|
||||
|
||||
#if EFI_LTFT_CONTROL
|
||||
initLtft();
|
||||
#endif
|
||||
}
|
||||
|
||||
PUBLIC_API_WEAK bool validateBoardConfig() {
|
||||
|
|
|
@ -1,9 +1,67 @@
|
|||
#include "pch.h"
|
||||
|
||||
#if EFI_LTFT_CONTROL
|
||||
|
||||
#include "storage.h"
|
||||
|
||||
#include "long_term_fuel_trim.h"
|
||||
|
||||
#if EFI_BACKUP_SRAM
|
||||
// current trims are stored in backup ram
|
||||
// TODO: current trims should be stored in backup ram
|
||||
static LtftState ltftState;
|
||||
#else
|
||||
//
|
||||
static LtftState ltftState;
|
||||
#endif
|
||||
|
||||
void LtftState::save() {
|
||||
ecuRestartCounter++;
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
storageWrite(EFI_LTFT_RECORD_ID, (const uint8_t *)this, sizeof(*this));
|
||||
#endif //EFI_PROD_CODE
|
||||
}
|
||||
|
||||
void LtftState::load() {
|
||||
#if EFI_PROD_CODE
|
||||
if (storageRead(EFI_LTFT_RECORD_ID, (uint8_t *)this, sizeof(*this)) != StorageStatus::Ok) {
|
||||
#else
|
||||
if (1) {
|
||||
#endif
|
||||
//Reset to some defaules
|
||||
memset(trims, 0, sizeof(trims));
|
||||
}
|
||||
}
|
||||
|
||||
void LongTermFuelTrim::init(LtftState *state) {
|
||||
m_state = state;
|
||||
|
||||
m_state->load();
|
||||
}
|
||||
|
||||
void LongTermFuelTrim::store() {
|
||||
// TODO: lock to avoid modification while writing
|
||||
|
||||
if (m_state) {
|
||||
m_state->save();
|
||||
}
|
||||
|
||||
// TODO: unlock
|
||||
}
|
||||
|
||||
void LongTermFuelTrim::onSlowCallback() {
|
||||
// Do some magic math here?
|
||||
|
||||
/* ... */
|
||||
}
|
||||
|
||||
bool LongTermFuelTrim::needsDelayedShutoff() {
|
||||
// TODO: We should delay power off until we store LTFT
|
||||
return false;
|
||||
}
|
||||
|
||||
void initLtft(void)
|
||||
{
|
||||
engine->module<LongTermFuelTrim>()->init(<ftState);
|
||||
}
|
||||
|
||||
#endif // EFI_LTFT_CONTROL
|
||||
|
|
|
@ -2,12 +2,23 @@
|
|||
|
||||
struct LtftState {
|
||||
int ecuRestartCounter = 0;
|
||||
void save() {
|
||||
ecuRestartCounter++;
|
||||
}
|
||||
int8_t trims[FUEL_TRIM_RPM_COUNT][FUEL_TRIM_LOAD_COUNT];
|
||||
|
||||
void save();
|
||||
void load();
|
||||
};
|
||||
|
||||
class LongTermFuelTrim : public EngineModule {
|
||||
public:
|
||||
// EngineModule implementation
|
||||
void onSlowCallback() override;
|
||||
bool needsDelayedShutoff() override;
|
||||
|
||||
void init(LtftState *state);
|
||||
void store();
|
||||
|
||||
private:
|
||||
LtftState *m_state;
|
||||
};
|
||||
|
||||
void initLtft(void);
|
||||
|
|
Loading…
Reference in New Issue