diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 9cc1b67..029619b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,5 @@ #include <FreeRTOS.h> #include <task.h> -#include <BlinkApp/BlinkApp.h> #include <libraries/bsp/bsp.h> #include <legacy/nrf_drv_clock.h> #include <libraries/timer/app_timer.h> @@ -9,6 +8,8 @@ #include <softdevice/common/nrf_sdh.h> #include <softdevice/common/nrf_sdh_freertos.h> +#include <hal/nrf_rtc.h> +#include <timers.h> #include "BLE/BleManager.h" @@ -20,9 +21,10 @@ Pinetime::Logging::NrfLogger logger; Pinetime::Logging::DummyLogger logger; #endif -Pinetime::Applications::BlinkApp blinkApp; Pinetime::Applications::DisplayApp displayApp; TaskHandle_t systemThread; +bool isSleeping = false; +TimerHandle_t debounceTimer; extern "C" { void vApplicationIdleHook() { @@ -34,17 +36,48 @@ extern "C" { } } + + +void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken); + // TODO should I do something if xHigherPriorityTaskWoken == pdTRUE? +} + +void DebounceTimerCallback(TimerHandle_t xTimer) { + xTimerStop(xTimer, 0); + if(isSleeping) { + displayApp.PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToRunning); + isSleeping = false; + } + else { + displayApp.PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep); + isSleeping = true; + } +} + void SystemTask(void *) { APP_GPIOTE_INIT(2); - app_timer_init(); bool erase_bonds=false; nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds); -// blinkApp.Start(); displayApp.Start(); - while (1) { - vTaskSuspend(nullptr); - } + debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); + + nrf_gpio_cfg_sense_input(13, (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t)GPIO_PIN_CNF_SENSE_High); + nrf_gpio_cfg_output(15); + nrf_gpio_pin_set(15); + + nrfx_gpiote_in_config_t pinConfig; + pinConfig.skip_gpio_setup = true; + pinConfig.hi_accuracy = false; + pinConfig.is_watcher = false; + pinConfig.sense = (nrf_gpiote_polarity_t)NRF_GPIOTE_POLARITY_HITOLO; + pinConfig.pull = (nrf_gpio_pin_pull_t)GPIO_PIN_CNF_PULL_Pulldown; + + nrfx_gpiote_in_init(13, &pinConfig, nrfx_gpiote_evt_handler); + + vTaskSuspend(nullptr); } void OnNewTime(uint8_t minutes, uint8_t hours) { @@ -55,7 +88,6 @@ int main(void) { logger.Init(); nrf_drv_clock_init(); - if (pdPASS != xTaskCreate(SystemTask, "MAIN", 256, nullptr, 0, &systemThread)) APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); |
