diff --git a/src/main.cpp b/src/main.cpp index 98e32a1..24db710 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,16 @@ void setup() { // Task Creation + xTaskCreatePinnedToCore( + taskCharger, + "TaskCharger", // Name of the process + 4096, // This stack size can be checked & adjusted by reading the Stack Highwater + NULL, + 4, // Priority + NULL, + CPU_1 + ); + xTaskCreatePinnedToCore( taskScreen, "TaskScreen", // Name of the process @@ -109,6 +119,43 @@ void taskScreen(void *pvParameters) { } +void taskCharger(void *pvParameters) { + (void) pvParameters; + + bool charging = false; + bool high_current_charging = false; + uint32_t last_charging_time = 0; + + for(;;) { + if(M5.Axp.isCharging()) { + // Just flipped... + if(!charging) { + charging = true; + last_charging_time = millis(); + } else { + // Only after 5 seconds then put to 1A... + if(!high_current_charging) { + if((uint32_t)(millis() - last_charging_time) > 5000) { + high_current_charging = true; + M5.Axp.SetCHGCurrent(M5.Axp.kCHG_1000mA); + } + } + } + } else { + if(charging) { + // Setting back to 100mA + charging = false; + high_current_charging = false; + last_charging_time = millis(); + M5.Axp.SetCHGCurrent(M5.Axp.kCHG_100mA); + } + } + + vTaskDelay(200); + } +} + + void taskSpeak(void *pvParameters) { (void) pvParameters; diff --git a/src/main.h b/src/main.h index 2fcabff..a1bd4f0 100644 --- a/src/main.h +++ b/src/main.h @@ -23,5 +23,6 @@ void taskWeb(void *pvParameters); void taskInput(void *pvParameters); void taskBLE(void *pvParameters); void taskNRF(void *pvParameters); +void taskCharger(void *pvParameters); #endif