nRF5 SDK for Mesh v5.0.0
app_level.h
1 /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef APP_LEVEL_H__
39 #define APP_LEVEL_H__
40 
41 #include <stdint.h>
42 
43 #include "generic_level_server.h"
44 #include "app_timer.h"
45 #include "app_transition.h"
46 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
47 #include "app_scene.h"
48 #endif
49 
113 #define APP_LEVEL_SERVER_DEF(_name, _force_segmented, _mic_size, _p_dtt, _set_cb, _get_cb, _transition_cb) \
114  APP_TIMER_DEF(_name ## _timer); \
115  static app_level_server_t _name = \
116  { \
117  .server.settings.force_segmented = _force_segmented, \
118  .server.settings.transmic_size = _mic_size, \
119  .state.transition.timer.p_timer_id = &_name ## _timer, \
120  .p_dtt_ms = _p_dtt, \
121  .level_set_cb = _set_cb, \
122  .level_get_cb = _get_cb, \
123  .level_transition_cb = _transition_cb \
124  };
125 
127 typedef struct
128 {
130  int32_t required_delta;
134 
136 typedef struct
137 {
139  int16_t required_move;
143 
145 typedef struct
146 {
148  int16_t present_level;
150  int16_t target_level;
151 
153  int32_t delta;
156 
161 
163  app_transition_t transition;
165 
166 /* Forward declaration */
167 typedef struct __app_level_server_t app_level_server_t;
168 
183 typedef void (*app_level_set_cb_t)(const app_level_server_t * p_app, int16_t present_level);
184 
193 typedef void (*app_level_get_cb_t)(const app_level_server_t * p_app, int16_t * p_present_level);
194 
206 typedef void (*app_level_transition_cb_t)(const app_level_server_t * p_app,
207  uint32_t transition_time_ms,
208  uint16_t target_level,
209  app_transition_type_t transition_type);
210 
213 {
215  generic_level_server_t server;
222 
224  const uint32_t * p_dtt_ms;
228 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
229 
231  app_scene_model_interface_t scene_if;
234  app_scene_setup_server_t * p_app_scene;
235 #endif
236 };
237 
262 uint32_t app_level_current_value_publish(app_level_server_t * p_app);
263 
283 uint32_t app_level_init(app_level_server_t * p_app, uint8_t element_index);
284 
297 uint32_t app_level_value_restore(app_level_server_t * p_app);
298 
299 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
300 
312 uint32_t app_level_scene_context_set(app_level_server_t * p_app,
313  app_scene_setup_server_t * p_app_scene);
314 #endif
315 
317 #endif /* APP_LEVEL_H__ */
int32_t required_delta
For storing actual required amount of level change.
Definition: app_level.h:130
int16_t required_move
Scaled representation of the Level value.
Definition: app_level.h:139
app_scene_model_interface_t scene_if
Internal variable.
Definition: app_level.h:231
Application level structure holding the Level server model context and Level state representation...
Definition: app_level.h:212
void(* app_level_get_cb_t)(const app_level_server_t *p_app, int16_t *p_present_level)
Application state read callback prototype.
Definition: app_level.h:193
const uint32_t * p_dtt_ms
Pointer to the default transition time value (in milliseconds) if present.
Definition: app_level.h:224
app_scene_setup_server_t * p_app_scene
Internal variable.
Definition: app_level.h:234
app_transition_t transition
Structure for using transition module functionality.
Definition: app_level.h:163
Internal structure for holding Move transition related variables.
Definition: app_level.h:136
int16_t present_level
Present value of the Level state.
Definition: app_level.h:148
uint32_t app_level_value_restore(app_level_server_t *p_app)
Restores the level value from persistent storage.
uint32_t app_level_scene_context_set(app_level_server_t *p_app, app_scene_setup_server_t *p_app_scene)
Sets the scene context.
generic_level_server_t server
Level server model interface context structure.
Definition: app_level.h:215
uint32_t app_level_init(app_level_server_t *p_app, uint8_t element_index)
Initializes the behavioral module for the Generic Level model.
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:132
int32_t delta
For storing actual required amount of level change.
Definition: app_level.h:153
int16_t target_snapshot
Requested target.
Definition: app_level.h:160
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:141
app_level_transition_cb_t level_transition_cb
Callaback to be called for informing the user application to update the value.
Definition: app_level.h:221
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:155
app_level_set_cb_t level_set_cb
Callaback to be called for informing the user application to update the value.
Definition: app_level.h:217
Internal structure to hold state and timing information.
Definition: app_level.h:145
uint32_t app_level_current_value_publish(app_level_server_t *p_app)
Initiates value fetch from the user application by calling a get callback, updates internal state...
app_transition_type_t
Transition types.
app_level_get_cb_t level_get_cb
Callback to be called for requesting current value from the user application.
Definition: app_level.h:219
int16_t init_present_snapshot
Present value when message was received.
Definition: app_level.h:158
Internal structure for holding Set/Delta Set transition related variables.
Definition: app_level.h:127
void(* app_level_transition_cb_t)(const app_level_server_t *p_app, uint32_t transition_time_ms, uint16_t target_level, app_transition_type_t transition_type)
Application transition time callback prototype.
Definition: app_level.h:206
void(* app_level_set_cb_t)(const app_level_server_t *p_app, int16_t present_level)
Application state set callback prototype.
Definition: app_level.h:183
app_level_state_t state
Internal variable.
Definition: app_level.h:227
int16_t target_level
Target value of the Level state, as received from the model interface.
Definition: app_level.h:150

Documentation feedback | Developer Zone | Subscribe | Updated