BSB Developer Docs
Loading...
Searching...
No Matches
busy_timer_i.h
1#pragma once
2
3#include "busy_timer.h"
4#include "settings/busy_timer_settings.h"
5#include "settings/busy_timer_saved_state.h"
6
7#include <furi.h>
8
9#include <mqtt/mqtt.h>
10#include <matter/matter.h>
12
13#include <toolbox/api_lock.h>
14
15#define TAG "BusyTimer"
16
17#define BUSY_TIMER_TIME_MIN_S M_TO_S(BUSY_TIMER_TIME_MIN_MN)
18#define BUSY_TIMER_TIME_MAX_S M_TO_S(BUSY_TIMER_TIME_MAX_MN)
19
20typedef enum {
21 BusyTimerApiMessageTypeStart,
22 BusyTimerApiMessageTypeStop,
23 BusyTimerApiMessageTypeAddTime,
24 BusyTimerApiMessageTypeToggle,
25 BusyTimerApiMessageTypeSkip,
26 BusyTimerApiMessageTypeFinalize,
27 BusyTimerApiMessageTypeGetRunInfo,
28 BusyTimerApiMessageTypeGetSnapshot,
29 BusyTimerApiMessageTypeSetSnapshot,
30 BusyTimerApiMessageTypeGetProfile,
31 BusyTimerApiMessageTypeSetProfile,
32 BusyTimerApiMessageTypeGetPreset,
33 BusyTimerApiMessageTypeSetPreset,
34 BusyTimerApiMessageTypeHandleMatter,
35
36 BusyTimerApiMessageTypeMax,
37} BusyTimerApiMessageType;
38
39typedef struct {
40 BusyTimerProfileId profile_id;
42
43typedef struct {
44 int32_t time_minutes;
46
47typedef struct {
48 BusyTimerSnapshot* snapshot;
50
51typedef struct {
52 BusyTimerSnapshot snapshot;
54
55typedef struct {
56 BusyTimerRunInfo* run_info;
58
59typedef struct {
60 BusyTimerProfileId profile_id;
61 BusyTimerProfile* profile;
63
64typedef struct {
65 BusyTimerProfileId profile_id;
66 BusyTimerProfile profile;
68
69typedef struct {
70 BusyTimerProfileId profile_id;
71 BusyTimerPreset* preset;
73
74typedef struct {
75 BusyTimerProfileId profile_id;
76 BusyTimerPreset preset;
78
79typedef struct {
80 MatterSwitchState switch_state;
82
95
96typedef struct {
97 BusyTimerApiMessageType type;
99 FuriApiLock lock;
101
102typedef enum {
103 BusyTimerSetProfileResultRejectedInvalid,
104 BusyTimerSetProfileResultRejectedOutdated,
105 BusyTimerSetProfileResultRejectedOwn,
106 BusyTimerSetProfileResultAccepted,
107 BusyTimerSetProfileResultMax,
108} BusyTimerSetProfileResult;
109
110struct BusyTimer {
111 FuriThread* thread;
112 FuriEventLoop* event_loop;
113 FuriEventLoopTimer* poll_timer;
114 FuriEventLoopTimer* snapshot_timer;
115 FuriEventLoopTimer* profile_timer;
116 FuriMessageQueue* api_queue;
117 FuriPubSub* event_pubsub;
118 Mqtt* mqtt;
119 Matter* matter;
120 MatterSwitchState matter_switch_state;
121 StatusLights* status_lights;
122 BusyTimerSnapshot last_known_snapshot;
123 BusyTimerSettings settings[BusyTimerProfileIdMax];
124 BusyTimerSavedState saved_state;
125 // TODO FW-635: Refactor & simplify internals ---->
126 BusyTimerState state;
127 BusyAppConfig app_config;
128 BusyTimerConfig timer_config;
129 time_t prev_tick_timestamp_ms;
130 uint32_t current_interval_index;
131 uint32_t time_elapsed_s;
132 uint32_t time_remaining_s;
133 char card_id[BUSY_TIMER_CARD_ID_LEN + 1];
134 // <----- Refactor section ends
135 uint32_t snapshot_update_count;
136 uint32_t profile_update_count[BusyTimerProfileIdMax];
137 bool is_timer_running;
138 bool is_demo_mode_enabled;
139};
140
141// busy_timer.c
142
143void busy_timer_apply_profile_settings(BusyTimer* instance, BusyTimerProfileId profile_id);
144
145bool busy_timer_is_running(const BusyTimer* instance);
146
147void busy_timer_start_internal(BusyTimer* instance);
148
149void busy_timer_stop_internal(BusyTimer* instance);
150
151void busy_timer_toggle_internal(BusyTimer* instance);
152
153void busy_timer_skip_internal(BusyTimer* instance);
154
155// busy_timer_api.c
156
157void busy_timer_handle_matter(BusyTimer* instance, MatterSwitchState switch_state);
158
159// busy_timer_smart_home.c
160
161void busy_timer_smart_home_init(BusyTimer* instance);
162
163void busy_timer_smart_home_handle_switch_state(BusyTimer* instance, MatterSwitchState switch_state);
164
165// busy_timer_status_lights.c
166
167void busy_timer_status_lights_init(BusyTimer* instance);
168
169// busy_timer_util.c
170
171void busy_timer_start_app(const BusyAppConfig* app_config);
172
173void busy_timer_exit_app(void);
API for Matter service on u5.
MQTT & BUSY account service API.
API for controlling Status Lights.
BusyApp configuration structure.
Definition busy_common.h:22
Definition busy_timer_i.h:43
Definition busy_timer_i.h:69
Definition busy_timer_i.h:59
Definition busy_timer_i.h:55
Definition busy_timer_i.h:47
Definition busy_timer_i.h:79
Definition busy_timer_i.h:96
Definition busy_timer_i.h:74
Definition busy_timer_i.h:64
Definition busy_timer_i.h:51
Definition busy_timer_i.h:39
Definition busy_timer_common.h:72
Definition busy_timer_i.h:110
Definition busy_timer.h:86
Definition busy_timer_profile.h:20
Definition busy_timer.h:80
Definition busy_timer_saved_state_interface_v1.h:12
Definition busy_timer_settings_interface_v1.h:7
Definition busy_timer_snapshot.h:42
Definition matter_i.h:59
Definition mqtt_i.h:84
Definition status_lights_backend.c:19
Definition busy_timer_i.h:83