listen to heater enable bit

This commit is contained in:
Matthew Kennedy 2021-07-15 21:50:22 -07:00
parent 24cdee9c28
commit 18cc209f72
3 changed files with 19 additions and 4 deletions

View File

@ -61,8 +61,8 @@ void CanRxThread(void*)
SetBatteryVoltage(vbatt); SetBatteryVoltage(vbatt);
// data1 contains heater enable bit // data1 contains heater enable bit
// TODO use this bool heaterAllowed = (frame.data8[1] & 0x1) == 0x1;
//bool heaterEnabled = (frame.data8[1] & 0x1) == 0x1; SetHeaterAllowed(heaterAllowed);
} }
// If it's a bootloader entry request, reboot to the bootloader! // If it's a bootloader entry request, reboot to the bootloader!
else if (frame.DLC == 0 && frame.EID == 0xEF0'0000) else if (frame.DLC == 0 && frame.EID == 0xEF0'0000)

View File

@ -20,11 +20,20 @@ enum class HeaterState
Stopped, Stopped,
}; };
int timeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD; constexpr int preheatTimeCounter = HEATER_PREHEAT_TIME / HEATER_CONTROL_PERIOD;
float rampVoltage = 0; static int timeCounter = preheatTimeCounter;
static float rampVoltage = 0;
static bool heaterAllowed = false;
static HeaterState GetNextState(HeaterState state, float sensorEsr) static HeaterState GetNextState(HeaterState state, float sensorEsr)
{ {
if (!heaterAllowed)
{
// ECU hasn't allowed preheat yet, reset timer, and force preheat state
timeCounter = preheatTimeCounter;
return HeaterState::Preheat;
}
switch (state) switch (state)
{ {
case HeaterState::Preheat: case HeaterState::Preheat:
@ -187,3 +196,8 @@ void SetBatteryVoltage(float vbatt)
batteryVoltage = vbatt; batteryVoltage = vbatt;
} }
} }
void SetHeaterAllowed(bool allowed)
{
heaterAllowed = allowed;
}

View File

@ -5,3 +5,4 @@
void StartHeaterControl(); void StartHeaterControl();
bool IsRunningClosedLoop(); bool IsRunningClosedLoop();
void SetBatteryVoltage(float vbatt); void SetBatteryVoltage(float vbatt);
void SetHeaterAllowed(bool allowed);