IoT25S IoT Klocka 0.1
Grupparbete för IoT25S på Jensen YH
Loading...
Searching...
No Matches
app_state.h
Go to the documentation of this file.
1#pragma once
2
8#include <stdbool.h>
9#include <stdint.h>
10
11#include "esp_err.h"
12
14#define APP_WIFI_SSID_MAX_LEN 32
16#define APP_WIFI_PASSWORD_MAX_LEN 64
18#define APP_AP_SSID_MAX_LEN 32
20#define APP_AP_PASSWORD_MAX_LEN 16
22#define APP_TIMEZONE_LOCATION_MAX_LEN 32
24#define APP_IP_ADDRESS_MAX_LEN 16
26#define APP_ALARM_MAX_COUNT 8
27
31typedef struct {
32 uint8_t hour;
33 uint8_t minute;
34 bool enabled;
36
40typedef struct {
41 char wifi_ssid[APP_WIFI_SSID_MAX_LEN + 1];
42 char wifi_password[APP_WIFI_PASSWORD_MAX_LEN + 1];
44 char ap_ssid[APP_AP_SSID_MAX_LEN + 1];
45 char ap_password[APP_AP_PASSWORD_MAX_LEN + 1];
47 uint8_t alarm_count;
48 char timezone_location[APP_TIMEZONE_LOCATION_MAX_LEN + 1];
50 uint8_t brightness;
51 int64_t saved_epoch;
54
65
73
79esp_err_t app_state_init(void);
80
87
94
101esp_err_t app_state_update_config(const app_config_t *config);
102
109void app_state_get_time_epoch(int64_t *epoch, bool *valid);
110
118esp_err_t app_state_set_time_epoch(int64_t epoch, bool valid);
119
125void app_state_set_portal_mode(bool portal_mode);
126
133void app_state_set_wifi_connected(bool connected, const char *ip_address);
134
140void app_state_set_alarm_active(bool active);
141
148
155void app_state_get_alarms(alarm_entry_t *out, uint8_t *count);
156
162esp_err_t app_state_add_alarm(uint8_t hour, uint8_t minute, bool enabled);
163
169esp_err_t app_state_update_alarm(uint8_t index, uint8_t hour, uint8_t minute, bool enabled);
170
176esp_err_t app_state_delete_alarm(uint8_t index);
177
183esp_err_t app_state_toggle_alarm(uint8_t index);
esp_err_t app_state_update_alarm(uint8_t index, uint8_t hour, uint8_t minute, bool enabled)
Replace an existing alarm entry by index.
Definition app_state.c:322
#define APP_TIMEZONE_LOCATION_MAX_LEN
Maximum timezone location identifier length (without null terminator).
Definition app_state.h:22
esp_err_t app_state_init(void)
Initialize state, defaults, and NVS-backed values.
Definition app_state.c:123
esp_err_t app_state_toggle_alarm(uint8_t index)
Toggle the enabled flag of an alarm by index.
Definition app_state.c:356
#define APP_WIFI_SSID_MAX_LEN
Maximum Wi-Fi SSID length (without null terminator).
Definition app_state.h:14
#define APP_AP_SSID_MAX_LEN
Maximum provisioning AP SSID length (without null terminator).
Definition app_state.h:18
void app_state_get_time_epoch(int64_t *epoch, bool *valid)
Get stored epoch value and validity flag.
Definition app_state.c:234
void app_state_get_alarms(alarm_entry_t *out, uint8_t *count)
Get current alarm list.
Definition app_state.c:296
#define APP_AP_PASSWORD_MAX_LEN
Maximum provisioning AP password length (without null terminator).
Definition app_state.h:20
esp_err_t app_state_delete_alarm(uint8_t index)
Delete an alarm by index (subsequent alarms shift down).
Definition app_state.c:338
esp_err_t app_state_add_alarm(uint8_t hour, uint8_t minute, bool enabled)
Add a new alarm.
Definition app_state.c:304
void app_state_set_wifi_connected(bool connected, const char *ip_address)
Update runtime Wi-Fi status and optional station IP.
Definition app_state.c:263
esp_err_t app_state_reset_wifi_credentials(void)
Clear persisted Wi-Fi credentials.
Definition app_state.c:282
void app_state_set_alarm_active(bool active)
Update runtime alarm active flag.
Definition app_state.c:275
void app_state_get_config(app_config_t *config)
Get current persisted configuration.
Definition app_state.c:214
#define APP_ALARM_MAX_COUNT
Maximum number of configurable alarms.
Definition app_state.h:26
void app_state_get_snapshot(app_state_snapshot_t *snapshot)
Get a thread-safe snapshot of the full state.
Definition app_state.c:207
esp_err_t app_state_set_time_epoch(int64_t epoch, bool valid)
Update stored epoch and validity flag.
Definition app_state.c:242
void app_state_set_portal_mode(bool portal_mode)
Update runtime portal mode flag.
Definition app_state.c:256
#define APP_WIFI_PASSWORD_MAX_LEN
Maximum Wi-Fi password length (without null terminator).
Definition app_state.h:16
#define APP_IP_ADDRESS_MAX_LEN
Maximum IPv4 address string length including null terminator.
Definition app_state.h:24
esp_err_t app_state_update_config(const app_config_t *config)
Replace persisted configuration with provided values.
Definition app_state.c:221
Single alarm entry.
Definition app_state.h:31
bool enabled
Definition app_state.h:34
uint8_t hour
Definition app_state.h:32
uint8_t minute
Definition app_state.h:33
Persisted configuration model.
Definition app_state.h:40
int16_t tz_offset_min
Definition app_state.h:49
uint8_t brightness
Definition app_state.h:50
bool wifi_configured
Definition app_state.h:43
bool saved_time_valid
Definition app_state.h:52
uint8_t alarm_count
Definition app_state.h:47
int64_t saved_epoch
Definition app_state.h:51
Runtime state model.
Definition app_state.h:58
bool portal_mode
Definition app_state.h:59
bool alarm_active
Definition app_state.h:61
bool time_valid
Definition app_state.h:62
bool wifi_connected
Definition app_state.h:60
Snapshot of full app state.
Definition app_state.h:69
app_config_t config
Definition app_state.h:70
app_runtime_t runtime
Definition app_state.h:71