6#include "freertos/FreeRTOS.h"
7#include "freertos/task.h"
9#include "driver/gpio.h"
18#ifndef CONFIG_ALARM_ACTIVE_SECONDS
19#define CONFIG_ALARM_ACTIVE_SECONDS 2
22#ifndef CONFIG_ALARM_TASK_PERIOD_MS
23#define CONFIG_ALARM_TASK_PERIOD_MS 500
26#define ALARM_ACTIVE_SECONDS CONFIG_ALARM_ACTIVE_SECONDS
27#define ALARM_TASK_PERIOD_MS CONFIG_ALARM_TASK_PERIOD_MS
28#define BUZZER_GPIO_PIN 1
30static const char *
TAG =
"alarm_service";
34 int64_t alarm_until_epoch = 0;
41 last_trigger_minute[i] = -1;
47 int64_t now_epoch = 0;
54 int64_t current_minute = now_epoch / 60;
64 if (due && current_minute != last_trigger_minute[i]) {
65 last_trigger_minute[i] = current_minute;
67 ESP_LOGI(
TAG,
"Alarm %u triggered at %02d:%02d",
68 (
unsigned int)i, local_time.tm_hour, local_time.tm_min);
73 if (alarm_until_epoch > 0 && time_valid && now_epoch < alarm_until_epoch) {
79 alarm_until_epoch = 0;
90 gpio_config_t gpio_cfg = {
92 .mode = GPIO_MODE_OUTPUT,
93 .pull_up_en = GPIO_PULLUP_DISABLE,
94 .pull_down_en = GPIO_PULLDOWN_DISABLE,
95 .intr_type = GPIO_INTR_DISABLE,
98 ESP_RETURN_ON_ERROR(gpio_config(&gpio_cfg),
TAG,
"GPIO config failed");
101 BaseType_t task_ok = xTaskCreate(
alarm_service_task,
"alarm_task", 4096, NULL, 5, NULL);
103 return (task_ok == pdPASS) ? ESP_OK : ESP_FAIL;
#define ALARM_TASK_PERIOD_MS
#define ALARM_ACTIVE_SECONDS
static void alarm_service_task(void *arg)
esp_err_t alarm_service_start(void)
Start the alarm service task.
Alarm scheduling service API.
void app_state_set_alarm_active(bool active)
Update runtime alarm active flag.
void app_state_get_snapshot(app_state_snapshot_t *snapshot)
Get a thread-safe snapshot of the full state.
Thread-safe application state and persisted configuration APIs.
#define APP_ALARM_MAX_COUNT
Maximum number of configurable alarms.
alarm_entry_t alarms[APP_ALARM_MAX_COUNT]
Snapshot of full app state.
bool time_service_get_local_time(struct tm *out_tm, int64_t *out_epoch)
Get local time adjusted by the configured timezone offset.
Time service APIs for local time access and synchronization triggers.