nRF5 SDK for Mesh v4.2.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 
110 #define APP_LEVEL_SERVER_DEF(_name, _force_segmented, _mic_size, _p_dtt, _set_cb, _get_cb, _transition_cb) \
111  APP_TIMER_DEF(_name ## _timer); \
112  static app_level_server_t _name = \
113  { \
114  .server.settings.force_segmented = _force_segmented, \
115  .server.settings.transmic_size = _mic_size, \
116  .state.transition.timer.p_timer_id = &_name ## _timer, \
117  .p_dtt_ms = _p_dtt, \
118  .level_set_cb = _set_cb, \
119  .level_get_cb = _get_cb, \
120  .level_transition_cb = _transition_cb \
121  };
122 
124 typedef struct
125 {
127  int32_t required_delta;
131 
133 typedef struct
134 {
136  int16_t required_move;
140 
142 typedef struct
143 {
145  int16_t present_level;
147  int16_t target_level;
148 
150  int32_t delta;
153 
158 
160  app_transition_t transition;
162 
163 /* Forward declaration */
164 typedef struct __app_level_server_t app_level_server_t;
165 
180 typedef void (*app_level_set_cb_t)(const app_level_server_t * p_app, int16_t present_level);
181 
190 typedef void (*app_level_get_cb_t)(const app_level_server_t * p_app, int16_t * p_present_level);
191 
203 typedef void (*app_level_transition_cb_t)(const app_level_server_t * p_app,
204  uint32_t transition_time_ms,
205  uint16_t target_level,
206  app_transition_type_t transition_type);
207 
210 {
212  generic_level_server_t server;
219 
221  const uint32_t * p_dtt_ms;
225 };
226 
251 uint32_t app_level_current_value_publish(app_level_server_t * p_app);
252 
272 uint32_t app_level_init(app_level_server_t * p_app, uint8_t element_index);
273 
275 #endif /* APP_LEVEL_H__ */
int32_t required_delta
For storing actual required amount of level change.
Definition: app_level.h:127
int16_t required_move
Scaled representation of the Level value.
Definition: app_level.h:136
Application level structure holding the Level server model context and Level state representation...
Definition: app_level.h:209
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:190
const uint32_t * p_dtt_ms
Pointer to the default transition time value (in milliseconds) if present.
Definition: app_level.h:221
app_transition_t transition
Structure for using transition module functionality.
Definition: app_level.h:160
Internal structure for holding Move transition related variables.
Definition: app_level.h:133
int16_t present_level
Present value of the Level state.
Definition: app_level.h:145
generic_level_server_t server
Level server model interface context structure.
Definition: app_level.h:212
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:129
int32_t delta
For storing actual required amount of level change.
Definition: app_level.h:150
int16_t target_snapshot
Requested target.
Definition: app_level.h:157
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:138
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:218
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:152
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:214
Internal structure to hold state and timing information.
Definition: app_level.h:142
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:216
int16_t init_present_snapshot
Present value when message was received.
Definition: app_level.h:155
Internal structure for holding Set/Delta Set transition related variables.
Definition: app_level.h:124
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:203
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:180
app_level_state_t state
Internal variable.
Definition: app_level.h:224
int16_t target_level
Target value of the Level state, as received from the model interface.
Definition: app_level.h:147

Documentation feedback | Developer Zone | Subscribe | Updated