heater: do index to channels mapping in all cases (#189)

Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
rusefillc 2023-02-05 15:39:21 -05:00 committed by GitHub
parent 6d908fb110
commit 4148ba1567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -230,7 +230,7 @@ static float GetVoltageForState(struct heater_state &s, float heaterEsr)
static THD_WORKING_AREA(waHeaterThread, 256); static THD_WORKING_AREA(waHeaterThread, 256);
static void HeaterThread(void*) static void HeaterThread(void*)
{ {
int ch; int i;
chRegSetThreadName("Heater"); chRegSetThreadName("Heater");
@ -245,16 +245,16 @@ static void HeaterThread(void*)
{ {
auto heaterAllowState = GetHeaterAllowed(); auto heaterAllowState = GetHeaterAllowed();
for (ch = 0; ch < AFR_CHANNELS; ch++) { for (i = 0; i < AFR_CHANNELS; i++) {
heater_state &s = state[ch]; heater_state &s = state[i];
// Read sensor state // Read sensor state
float heaterEsr = GetSensorInternalResistance(ch); float heaterEsr = GetSensorInternalResistance(s.ch);
// If we haven't heard from rusEFI, use the internally sensed // If we haven't heard from rusEFI, use the internally sensed
// battery voltage instead of voltage over CAN. // battery voltage instead of voltage over CAN.
float batteryVoltage = heaterAllowState == HeaterAllow::Unknown float batteryVoltage = heaterAllowState == HeaterAllow::Unknown
? GetInternalBatteryVoltage(ch) ? GetInternalBatteryVoltage(s.ch)
: GetRemoteBatteryVoltage(); : GetRemoteBatteryVoltage();
// Run the state machine // Run the state machine