Skip to content

Commit

Permalink
delay restart on nunchuk activity too
Browse files Browse the repository at this point in the history
  • Loading branch information
karaulj committed Jun 30, 2021
1 parent 0e81d91 commit 6b6a6d1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions main/tasks/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ TaskHandle_t joystickCmdTaskHandle = NULL;
void touchDeepSleepTask(void *pvParameter)
{
ESP_LOGI(TAG, "start %s", TOUCH_DEEP_SLEEP_TASK);
NunchukController* nunchuk = NunchukController::getInstance();

uint8_t joystickX = nunchuk->getJoystickX();
uint8_t joystickY = nunchuk->getJoystickY();

uint64_t delay = DEEP_SLEEP_DELAY_SEC * 1000000;
uint8_t warningGiven = 0;
Expand All @@ -63,20 +67,31 @@ void touchDeepSleepTask(void *pvParameter)
// reset timer if touchpad touched
if (touch_pad_get_status() & (1<<DEEP_SLEEP_TOUCH_PAD_NUM))
{
ESP_LOGI(TAG, "touch detected");
//ESP_LOGI(TAG, "touch detected");
last = esp_timer_get_time();
warningGiven = 0;
touch_pad_clear_status();
}

// reset timer if nunchuk buttons pressed or joystick moved
if (nunchuk->getZButton() || nunchuk->getCButton() ||
nunchuk->getJoystickX() != joystickX ||
nunchuk->getJoystickY() != joystickY)
{
last = esp_timer_get_time();
warningGiven = 0;
}
joystickX = nunchuk->getJoystickX();
joystickY = nunchuk->getJoystickY();

// log message 10 seconds out
if ((esp_timer_get_time()-last >= (delay-10000000)) && !warningGiven)
{
ESP_LOGI(TAG, "deep sleep in 10 seconds unless touch pad triggered");
warningGiven = 1;
}

// restart if delay has passed
// restart ESP32 if delay passed
if (esp_timer_get_time()-last >= delay)
{
xQueueSend(
Expand All @@ -89,7 +104,7 @@ void touchDeepSleepTask(void *pvParameter)
esp_deep_sleep_start();
}

vTaskDelay(10/portTICK_PERIOD_MS);
vTaskDelay(20/portTICK_PERIOD_MS);
}
}

Expand Down

0 comments on commit 6b6a6d1

Please sign in to comment.