Skip to content

Commit 352d506

Browse files
committed
[Probable ] Fix for logic error
1 parent 7508e3e commit 352d506

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
495495
static_cast<int>(INA260::power_mW));
496496
ESP_LOGI(TAG, "Initial load adjustment, setpoint: %d",
497497
LOAD::RES_INDEX_TABLE[powerIndex]);
498-
} else if ((adjustmentHistory[0] != LoadAdjustment::DECREASE) &&
498+
} else if ((adjustmentHistory.back() == LoadAdjustment::DECREASE) &&
499499
(INA260::power_mW > powerHistory.back()) &&
500500
(powerIndex > 1)) {
501501
// Decreasing + got better -> decrease again
@@ -508,7 +508,7 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
508508
static_cast<int>(INA260::power_mW));
509509
ESP_LOGI(TAG, "1Decreasing load to %d",
510510
LOAD::RES_INDEX_TABLE[powerIndex]); // TODO: Try by twos
511-
} else if ((adjustmentHistory[0] != LoadAdjustment::INCREASE) &&
511+
} else if ((adjustmentHistory.back() == LoadAdjustment::INCREASE) &&
512512
(INA260::power_mW > powerHistory.back()) &&
513513
(powerIndex <
514514
LOAD::RES_INDEX_TABLE.size() - 1)) { // MARK: BOLD LOAD
@@ -529,7 +529,7 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
529529
} else if ((INA260::power_mW < powerHistory[powerHistory.size() - 3]) &&
530530
(INA260::power_mW < powerHistory[powerHistory.size() - 2]) &&
531531
(INA260::power_mW < powerHistory[powerHistory.size() - 1]) &&
532-
(adjustmentHistory[0] != LoadAdjustment::DECREASE) &&
532+
(adjustmentHistory.back() == LoadAdjustment::DECREASE) &&
533533
(powerIndex <
534534
LOAD::RES_INDEX_TABLE.size() - 1)) { // MARK: BOLD LOAD
535535
// Decreasing + got worse a bunch -> increase again
@@ -545,7 +545,7 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
545545
// Delay an extra 1/2 second
546546
delay(RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS);
547547
} else if ((INA260::power_mW < powerHistory.back()) &&
548-
(adjustmentHistory[0] != LoadAdjustment::INCREASE) &&
548+
(adjustmentHistory.back() == LoadAdjustment::INCREASE) &&
549549
(powerIndex > 0)) { // MARK: BOLD LOAD
550550
// increasing + got worse a bunch -> decrease
551551
// powerIndex--;

0 commit comments

Comments
 (0)