diff --git a/epicardium/modules/pmic.c b/epicardium/modules/pmic.c index 9e5c9b62412ea6ebe685af5bd55d57f859f077ab..492545bb3b47c33b5494351a6f321d0af376df2c 100644 --- a/epicardium/modules/pmic.c +++ b/epicardium/modules/pmic.c @@ -27,19 +27,21 @@ void pmic_interrupt_callback(void *_) void vPmicTask(void *pvParameters) { - int count = 0; - portTickType delay = portMAX_DELAY; - pmic_task_id = xTaskGetCurrentTaskHandle(); + pmic_task_id = xTaskGetCurrentTaskHandle(); - while (1) { - ulTaskNotifyTake(pdTRUE, delay); + TickType_t button_start_tick = 0; - if (count == PMIC_PRESS_SLEEP) { - LOG_ERR("pmic", "Sleep [[ Unimplemented ]]"); + while (1) { + if (button_start_tick == 0) { + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); + } else { + ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100)); } - if (count == PMIC_PRESS_POWEROFF) { - LOG_INFO("pmic", "Poweroff"); + TickType_t duration = xTaskGetTickCount() - button_start_tick; + + if (button_start_tick != 0 && duration > pdMS_TO_TICKS(1000)) { + LOG_WARN("pmic", "Poweroff"); MAX77650_setSFT_RST(0x2); } @@ -47,17 +49,17 @@ void vPmicTask(void *pvParameters) if (int_flag & MAX77650_INT_nEN_F) { /* Button was pressed */ - count = 0; - delay = portTICK_PERIOD_MS * 100; + button_start_tick = xTaskGetTickCount(); } if (int_flag & MAX77650_INT_nEN_R) { - /* Button was pressed */ - if (count < PMIC_PRESS_SLEEP) { + /* Button was released */ + button_start_tick = 0; + if (duration < pdMS_TO_TICKS(400)) { + return_to_menu(); + } else { + LOG_WARN("pmic", "Resetting ..."); card10_reset(); } - - count = 0; - delay = portMAX_DELAY; } /* TODO: Remove when all interrupts are handled */ @@ -68,9 +70,5 @@ void vPmicTask(void *pvParameters) int_flag ); } - - if (delay != portMAX_DELAY) { - count += 1; - } } }