@@ -494,45 +494,69 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
494494 static_cast <int >(INA260 ::power_mW));
495495 ESP_LOGI (TAG , " Initial load adjustment, setpoint: %d" ,
496496 LOAD ::RES_INDEX_TABLE [powerIndex]);
497-
498497 } else if ((adjustmentHistory[0 ] != LoadAdjustment::DECREASE ) &&
499- (adjustmentHistory[1 ] != LoadAdjustment::INCREASE ) &&
500498 (INA260 ::power_mW > powerHistory.back ()) &&
501- (powerIndex > 5 )) {
502- // searchDone = false;
503- // powerIndex--;
504- powerIndex -= 5 ;
499+ (powerIndex > 0 )) {
500+ // Decreasing + got better -> decrease again
501+ powerIndex--;
505502 load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
506- // lastAdjustment = LoadAdjustment::DECREASE;
507503 adjustmentHistory.push (LoadAdjustment::DECREASE );
508504 ESP_LOGD (TAG , " Last power: %d mW, current power: %d mW" ,
509505 static_cast <int >(powerHistory.back ()),
510506 static_cast <int >(INA260 ::power_mW));
511- ESP_LOGI (TAG , " Decreasing load to %d" ,
507+ ESP_LOGI (TAG , " 1Decreasing load to %d" ,
512508 LOAD ::RES_INDEX_TABLE [powerIndex]); // TODO: Try by twos
509+ } else if ((adjustmentHistory[0 ] != LoadAdjustment::INCREASE ) &&
510+ (powerIndex <
511+ LOAD ::RES_INDEX_TABLE .size () - 1 )) { // MARK: BOLD LOAD
512+ // increasing + got better -> increase again
513+ // TODO: Not the best?
514+ powerIndex++;
515+ load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
516+ adjustmentHistory.push (LoadAdjustment::INCREASE );
517+ ESP_LOGI (TAG , " Last power: %d mW, current power: %d mW" ,
518+ static_cast <int >(powerHistory.back ()),
519+ static_cast <int >(INA260 ::power_mW));
520+ ESP_LOGI (TAG , " 2Increasing load to %d" ,
521+ LOAD ::RES_INDEX_TABLE [powerIndex]);
522+ // Delay an extra 1/2 second
523+ delay (RUN ::TASK_INTERVALS ::TI_ADJUST_LOAD_mS);
513524 } else if ((INA260 ::power_mW < powerHistory[powerHistory.size () - 3 ]) &&
514525 (INA260 ::power_mW < powerHistory[powerHistory.size () - 2 ]) &&
515526 (INA260 ::power_mW < powerHistory[powerHistory.size () - 1 ]) &&
527+ (adjustmentHistory[0 ] != LoadAdjustment::DECREASE ) &&
516528 (powerIndex <
517529 LOAD ::RES_INDEX_TABLE .size () - 1 )) { // MARK: BOLD LOAD
518- // INA260::power_mW < powerHistory[powerHistory.size() - 2])
519- // didn't work
530+ // Decreasing + got worse a bunch -> increase again
520531 // TODO: Not the best?
521532 powerIndex++;
522533 load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
523- // lastAdjustment = LoadAdjustment::INCREASE;
524534 adjustmentHistory.push (LoadAdjustment::INCREASE );
525535 ESP_LOGI (TAG , " Last power: %d mW, current power: %d mW" ,
526536 static_cast <int >(powerHistory.back ()),
527537 static_cast <int >(INA260 ::power_mW));
528- ESP_LOGI (TAG , " Increasing load to %d" ,
538+ ESP_LOGI (TAG , " 3Increasing load to %d" ,
539+ LOAD ::RES_INDEX_TABLE [powerIndex]);
540+ // Delay an extra 1/2 second
541+ delay (RUN ::TASK_INTERVALS ::TI_ADJUST_LOAD_mS);
542+ } else if ((INA260 ::power_mW < powerHistory.back ()) &&
543+ (adjustmentHistory[0 ] != LoadAdjustment::INCREASE ) &&
544+ (powerIndex > 0 )) { // MARK: BOLD LOAD
545+ // increasing + got worse a bunch -> decrease
546+ powerIndex--;
547+ load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
548+ adjustmentHistory.push (LoadAdjustment::DECREASE );
549+ ESP_LOGI (TAG , " Last power: %d mW, current power: %d mW" ,
550+ static_cast <int >(powerHistory.back ()),
551+ static_cast <int >(INA260 ::power_mW));
552+ ESP_LOGI (TAG , " 4Decreasing load to %d" ,
529553 LOAD ::RES_INDEX_TABLE [powerIndex]);
530- // todo RUN::TASK_INTERVALS::TI_ADJUST_LOAD_mS * 100
531554 // Delay an extra 1/2 second
532555 delay (RUN ::TASK_INTERVALS ::TI_ADJUST_LOAD_mS);
533- } else { // todo : change trigger to when rpm changes or when power
556+ } else { // DONE : change trigger to when rpm changes or when power
534557 // changes
535558 // No change
559+ // DONE: What if it increases and gets worse?
536560 }
537561 powerHistory.push (INA260 ::power_mW);
538562
0 commit comments