Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
states.h
Go to the documentation of this file.
1
9
10#ifndef INFUSE_SDK_INCLUDE_INFUSE_STATES_H_
11#define INFUSE_SDK_INCLUDE_INFUSE_STATES_H_
12
13#include <stdint.h>
14#include <stdbool.h>
15
16#include <zephyr/sys/atomic.h>
17#include <zephyr/sys/slist.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
28
59
61#define INFUSE_STATES_ARRAY_SIZE ATOMIC_BITMAP_SIZE(INFUSE_STATES_END + 1)
62
66#define INFUSE_STATES_ARRAY(name) atomic_t name[INFUSE_STATES_ARRAY_SIZE]
67
80 void (*state_set)(enum infuse_state state, bool already, uint16_t timeout, void *user_ctx);
81
90 void (*state_cleared)(enum infuse_state state, void *user_ctx);
91
93 void *user_ctx;
94
96 sys_snode_t node;
98};
99
106
116
128
141bool infuse_state_set_timeout(enum infuse_state state, uint16_t timeout);
142
153
162
171static inline bool infuse_state_set_to(enum infuse_state state, bool val)
172{
173 if (val) {
174 return infuse_state_set(state);
175 } else {
176 return infuse_state_clear(state);
177 }
178}
179
188
195
209
213
214#ifdef __cplusplus
215}
216#endif
217
218#endif /* INFUSE_SDK_INCLUDE_INFUSE_STATES_H_ */
void infuse_state_register_callback(struct infuse_state_cb *cb)
Register to be notified of state update events.
#define INFUSE_STATES_ARRAY_SIZE
Required size of atomic array for Infuse-IoT application states.
Definition states.h:61
bool infuse_state_clear(enum infuse_state state)
Clear an application state.
void infuse_states_tick(atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])
Run one tick of the state timeouts.
bool infuse_state_unregister_callback(struct infuse_state_cb *cb)
Unregister previously registered callback structure.
bool infuse_state_set(enum infuse_state state)
Set an application state.
void infuse_states_snapshot(atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])
Get a snapshot of the current application states.
static bool infuse_state_set_to(enum infuse_state state, bool val)
Set an application state to a specific value.
Definition states.h:171
bool infuse_state_get(enum infuse_state state)
Get an application state.
int infuse_state_get_timeout(enum infuse_state state)
Get the timeout associated with a state.
bool infuse_state_set_timeout(enum infuse_state state, uint16_t timeout)
Set an application state that times out after a duration.
infuse_state
Infuse-IoT application states.
Definition states.h:35
@ INFUSE_STATE_DEVICE_STATIONARY
Device is stationary (not moving)
Definition states.h:43
@ INFUSE_STATE_HIGH_PRIORITY_UPLINK
Device is currently sending high-priority data to the cloud.
Definition states.h:45
@ INFUSE_STATE_LED_SUPPRESS
Suppress LED activity.
Definition states.h:51
@ INFUSE_STATE_DEVICE_STARTED_MOVING
Device started moving.
Definition states.h:47
@ INFUSE_STATE_APPLICATION_ACTIVE
Application is active according to KV-store values.
Definition states.h:39
@ INFUSE_STATE_REBOOTING
Device is about to reboot.
Definition states.h:37
@ INFUSE_STATE_TIME_KNOWN
Application has a valid time source.
Definition states.h:41
@ INFUSE_STATES_APP_START
Start of application-specific state range.
Definition states.h:55
@ INFUSE_STATES_END
End of the state range.
Definition states.h:57
@ INFUSE_STATE_DEVICE_STOPPED_MOVING
Device stopped moving.
Definition states.h:49
@ INFUSE_STATE_DEVICE_MOVING
Device is moving (not stationary)
Definition states.h:53
Infuse-IoT application state callback structure.
Definition states.h:69
void(* state_cleared)(enum infuse_state state, void *user_ctx)
Application state has been cleared.
Definition states.h:90
void * user_ctx
User provided context pointer.
Definition states.h:93
void(* state_set)(enum infuse_state state, bool already, uint16_t timeout, void *user_ctx)
Application state has been set.
Definition states.h:80