|
IoT25S IoT Klocka 0.1
Grupparbete för IoT25S på Jensen YH
|
#include "app_state.h"#include <stdio.h>#include <string.h>#include "freertos/FreeRTOS.h"#include "freertos/semphr.h"#include "esp_check.h"#include "esp_log.h"#include "esp_mac.h"#include "esp_random.h"#include "nvs.h"
Include dependency graph for app_state.c:Go to the source code of this file.
Data Structures | |
| struct | alarm_store_blob_t |
Macros | |
| #define | APP_STATE_NAMESPACE "clock" |
| #define | APP_TIMEZONE_LOCATION_CUSTOM "custom" |
| #define | ALARM_BLOB_VERSION 1 |
Functions | |
| static void | app_state_set_defaults (app_config_t *config) |
| static void | app_state_make_ap_ssid (char *buffer, size_t buffer_len) |
| static void | app_state_generate_ap_password (char *buffer, size_t buffer_len) |
| static void | app_state_load_string (nvs_handle_t handle, const char *key, char *buffer, size_t buffer_len) |
| static esp_err_t | app_state_save_config_locked (void) |
| esp_err_t | app_state_init (void) |
| Initialize state, defaults, and NVS-backed values. | |
| void | app_state_get_snapshot (app_state_snapshot_t *snapshot) |
| Get a thread-safe snapshot of the full state. | |
| void | app_state_get_config (app_config_t *config) |
| Get current persisted configuration. | |
| esp_err_t | app_state_update_config (const app_config_t *config) |
| Replace persisted configuration with provided values. | |
| void | app_state_get_time_epoch (int64_t *epoch, bool *valid) |
| Get stored epoch value and validity flag. | |
| esp_err_t | app_state_set_time_epoch (int64_t epoch, bool valid) |
| Update stored epoch and validity flag. | |
| void | app_state_set_portal_mode (bool portal_mode) |
| Update runtime portal mode flag. | |
| void | app_state_set_wifi_connected (bool connected, const char *ip_address) |
| Update runtime Wi-Fi status and optional station IP. | |
| void | app_state_set_alarm_active (bool active) |
| Update runtime alarm active flag. | |
| esp_err_t | app_state_reset_wifi_credentials (void) |
| Clear persisted Wi-Fi credentials. | |
| void | app_state_get_alarms (alarm_entry_t *out, uint8_t *count) |
| Get current alarm list. | |
| esp_err_t | app_state_add_alarm (uint8_t hour, uint8_t minute, bool enabled) |
| Add a new alarm. | |
| 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. | |
| esp_err_t | app_state_delete_alarm (uint8_t index) |
| Delete an alarm by index (subsequent alarms shift down). | |
| esp_err_t | app_state_toggle_alarm (uint8_t index) |
| Toggle the enabled flag of an alarm by index. | |
Variables | |
| static const char * | TAG = "app_state" |
| static SemaphoreHandle_t | s_state_lock |
| static app_state_snapshot_t | s_state |
| #define ALARM_BLOB_VERSION 1 |
Definition at line 24 of file app_state.c.
| #define APP_STATE_NAMESPACE "clock" |
Definition at line 15 of file app_state.c.
| #define APP_TIMEZONE_LOCATION_CUSTOM "custom" |
Definition at line 16 of file app_state.c.
| esp_err_t app_state_add_alarm | ( | uint8_t | hour, |
| uint8_t | minute, | ||
| bool | enabled | ||
| ) |
Add a new alarm.
Fails if APP_ALARM_MAX_COUNT is already reached.
Definition at line 304 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:| esp_err_t app_state_delete_alarm | ( | uint8_t | index | ) |
Delete an alarm by index (subsequent alarms shift down).
Definition at line 338 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 51 of file app_state.c.
Here is the caller graph for this function:| void app_state_get_alarms | ( | alarm_entry_t * | out, |
| uint8_t * | count | ||
| ) |
Get current alarm list.
| [out] | out | Buffer of at least APP_ALARM_MAX_COUNT entries. |
| [out] | count | Number of configured alarms. |
Definition at line 296 of file app_state.c.
Here is the caller graph for this function:| void app_state_get_config | ( | app_config_t * | config | ) |
Get current persisted configuration.
| [out] | config | Destination configuration buffer. |
Definition at line 214 of file app_state.c.
Here is the caller graph for this function:| void app_state_get_snapshot | ( | app_state_snapshot_t * | snapshot | ) |
Get a thread-safe snapshot of the full state.
| [out] | snapshot | Destination snapshot buffer. |
Definition at line 207 of file app_state.c.
Here is the caller graph for this function:| void app_state_get_time_epoch | ( | int64_t * | epoch, |
| bool * | valid | ||
| ) |
Get stored epoch value and validity flag.
| [out] | epoch | Stored epoch seconds. |
| [out] | valid | Stored validity state. |
Definition at line 234 of file app_state.c.
Here is the caller graph for this function:| esp_err_t app_state_init | ( | void | ) |
Initialize state, defaults, and NVS-backed values.
Definition at line 123 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 70 of file app_state.c.
Here is the caller graph for this function:
|
static |
Definition at line 43 of file app_state.c.
Here is the caller graph for this function:| esp_err_t app_state_reset_wifi_credentials | ( | void | ) |
Clear persisted Wi-Fi credentials.
Definition at line 282 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 82 of file app_state.c.
Here is the caller graph for this function:| void app_state_set_alarm_active | ( | bool | active | ) |
Update runtime alarm active flag.
| active | true when alarm is active. |
Definition at line 275 of file app_state.c.
Here is the caller graph for this function:
|
static |
Definition at line 32 of file app_state.c.
Here is the caller graph for this function:| void app_state_set_portal_mode | ( | bool | portal_mode | ) |
Update runtime portal mode flag.
| portal_mode | true for provisioning AP mode, false otherwise. |
Definition at line 256 of file app_state.c.
Here is the caller graph for this function:| esp_err_t app_state_set_time_epoch | ( | int64_t | epoch, |
| bool | valid | ||
| ) |
Update stored epoch and validity flag.
| epoch | Epoch seconds to store. |
| valid | Validity flag to store. |
Definition at line 242 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void app_state_set_wifi_connected | ( | bool | connected, |
| const char * | ip_address | ||
| ) |
Update runtime Wi-Fi status and optional station IP.
| connected | true if connected. |
| ip_address | Optional station IP string when connected. |
Definition at line 263 of file app_state.c.
Here is the caller graph for this function:| esp_err_t app_state_toggle_alarm | ( | uint8_t | index | ) |
Toggle the enabled flag of an alarm by index.
Definition at line 356 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 at line 322 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:| esp_err_t app_state_update_config | ( | const app_config_t * | config | ) |
Replace persisted configuration with provided values.
| config | Source configuration. |
Definition at line 221 of file app_state.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 21 of file app_state.c.
|
static |
Definition at line 20 of file app_state.c.
|
static |
Definition at line 18 of file app_state.c.