@@ -439,10 +439,10 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
439439 // i)); // todo - just a quick performances test
440440 // i += 20;
441441 // static int_fast32_t lastPower = INT_FAST32_MIN;
442- constexpr uint32_t powerHistoryLength_s = 5 ;
442+ constexpr uint32_t powerHistoryLength_s = 3 * 3 ;
443443 constexpr uint32_t powerHistoryLength =
444- powerHistoryLength_s *
445- ( UNITS :: MILLIS_PER_SEC / RUN ::TASK_INTERVALS ::TI_ADJUST_LOAD_mS) ;
444+ powerHistoryLength_s * UNITS :: MILLIS_PER_SEC /
445+ RUN ::TASK_INTERVALS ::TI_ADJUST_LOAD_mS;
446446 static etl::circular_buffer<int_fast32_t , powerHistoryLength>
447447 powerHistory;
448448 // static int_fast8_t powerIndex = powerHistory.size() - 1;
@@ -484,9 +484,10 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
484484 static_cast <int >(powerHistory.back ()),
485485 static_cast <int >(INA260 ::power_mW));
486486 // Don't do anything until one reading has been made
487- } else if ((powerHistory.size () == 1 ) && (powerIndex > 0 )) {
487+ } else if ((powerHistory.size () == 1 ) && (powerIndex > 1 )) {
488488 // Make initial adjustment when one value filled
489- powerIndex--;
489+ // powerIndex--;
490+ powerIndex -= 2 ;
490491 load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
491492 adjustmentHistory.push (LoadAdjustment::DECREASE );
492493 ESP_LOGD (TAG , " Last power: %d mW, current power: %d mW" ,
@@ -496,9 +497,10 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
496497 LOAD ::RES_INDEX_TABLE [powerIndex]);
497498 } else if ((adjustmentHistory[0 ] != LoadAdjustment::DECREASE ) &&
498499 (INA260 ::power_mW > powerHistory.back ()) &&
499- (powerIndex > 0 )) {
500+ (powerIndex > 1 )) {
500501 // Decreasing + got better -> decrease again
501- powerIndex--;
502+ // powerIndex--;
503+ powerIndex -= 2 ;
502504 load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
503505 adjustmentHistory.push (LoadAdjustment::DECREASE );
504506 ESP_LOGD (TAG , " Last power: %d mW, current power: %d mW" ,
@@ -507,10 +509,13 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
507509 ESP_LOGI (TAG , " 1Decreasing load to %d" ,
508510 LOAD ::RES_INDEX_TABLE [powerIndex]); // TODO: Try by twos
509511 } else if ((adjustmentHistory[0 ] != LoadAdjustment::INCREASE ) &&
512+ (INA260 ::power_mW > powerHistory.back ()) &&
510513 (powerIndex <
511514 LOAD ::RES_INDEX_TABLE .size () - 1 )) { // MARK: BOLD LOAD
512515 // increasing + got better -> increase again
513516 // TODO: Not the best?
517+ // TODO: Fix cycleing
518+ // TODO: DOn't decrease when equal power
514519 powerIndex++;
515520 load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
516521 adjustmentHistory.push (LoadAdjustment::INCREASE );
@@ -543,7 +548,8 @@ vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
543548 (adjustmentHistory[0 ] != LoadAdjustment::INCREASE ) &&
544549 (powerIndex > 0 )) { // MARK: BOLD LOAD
545550 // increasing + got worse a bunch -> decrease
546- powerIndex--;
551+ // powerIndex--;
552+ powerIndex -= 2 ;
547553 load.setLoadGPIO (LOAD ::RES_INDEX_TABLE [powerIndex]);
548554 adjustmentHistory.push (LoadAdjustment::DECREASE );
549555 ESP_LOGI (TAG , " Last power: %d mW, current power: %d mW" ,
0 commit comments