nRF5 SDK for Mesh v5.0.0
app_light_lightness.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_LIGHT_LIGHTNESS_H__
39 #define APP_LIGHT_LIGHTNESS_H__
40 
41 #include <stdint.h>
42 
43 #include "light_lightness_setup_server.h"
44 #include "app_timer.h"
45 #include "app_transition.h"
46 #include "list.h"
47 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
48 #include "app_scene.h"
49 #endif
50 
97 #define APP_LIGHT_LIGHTNESS_SETUP_SERVER_DEF(_name, _force_segmented, _mic_size, _set_cb, _get_cb, _transition_cb) \
98  APP_TIMER_DEF(_name ## _timer); \
99  static app_light_lightness_setup_server_t _name = \
100  { \
101  .light_lightness_setup_server.settings.force_segmented = _force_segmented, \
102  .light_lightness_setup_server.settings.transmic_size = _mic_size, \
103  .app_add_notify.app_add_publish_cb = NULL, \
104  .app_add_notify.app_notify_set_cb = NULL, \
105  .state.transition.timer.p_timer_id = &_name ## _timer, \
106  .app_light_lightness_set_cb = _set_cb, \
107  .app_light_lightness_get_cb = _get_cb, \
108  .app_light_lightness_transition_cb = _transition_cb \
109  };
110 
115 typedef struct
116 {
123 
127  uint16_t target_snapshot;
128 
130  bool new_tid;
131 
132  /* Elapsed time at last publication. */
133  uint32_t published_ms;
134 
136  app_transition_t transition;
138 
139 /* Forward declaration */
140 typedef struct __app_light_lightness_setup_server_t app_light_lightness_setup_server_t;
141 
156 typedef void (*app_light_lightness_set_cb_t)(const app_light_lightness_setup_server_t * p_app,
157  uint16_t lightness);
158 
159 
168 typedef void (*app_light_lightness_get_cb_t)(const app_light_lightness_setup_server_t * p_app,
169  uint16_t * p_present_lightness);
170 
181 typedef void (*app_light_lightness_transition_cb_t)(const app_light_lightness_setup_server_t * p_app,
182  uint32_t transition_time_ms, uint16_t target_lightness);
183 
196 typedef void (*app_additional_publish_cb_t)(const void * p_app_v,
197  light_lightness_status_params_t * p_pub_data);
198 
211 typedef void (*app_notify_set_cb_t)(const void * p_app_v, uint16_t lightness);
212 
215 typedef struct
216 {
226 
230 {
232  light_lightness_setup_server_t light_lightness_setup_server;
233 
236 
239 
242 
245 
253  list_node_t node;
254 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
255 
257  app_scene_model_interface_t scene_if;
260  app_scene_setup_server_t * p_app_scene;
261 #endif
262 };
263 
284 uint32_t app_light_lightness_model_init(app_light_lightness_setup_server_t * p_app, uint8_t element_index);
285 
298 uint32_t app_light_lightness_binding_setup(app_light_lightness_setup_server_t * p_app);
299 
325 uint32_t app_light_lightness_current_value_publish(app_light_lightness_setup_server_t * p_app);
326 
343 uint32_t app_light_lightness_direct_actual_set(app_light_lightness_setup_server_t * p_app, uint16_t lightness_value);
344 
345 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
346 
358 uint32_t app_light_lightness_scene_context_set(app_light_lightness_setup_server_t * p_app,
359  app_scene_setup_server_t * p_app_scene);
360 #endif
361 
363 #endif /* APP_LIGHT_LIGHTNESS_H__*/
void(* app_notify_set_cb_t)(const void *p_app_v, uint16_t lightness)
Application notify callback prototype.
void(* app_light_lightness_set_cb_t)(const app_light_lightness_setup_server_t *p_app, uint16_t lightness)
Application Light Lightness state set callback prototype.
uint16_t target_lightness
Target value of the lightness state, as received from the model interface.
app_light_lightness_state_t state
Internal variable.
app_light_lightness_get_cb_t app_light_lightness_get_cb
Get the device lightness value.
app_transition_t transition
Structure for using transition module functionality.
app_additional_light_lightness_notify_t app_add_notify
Additional publishing/notifying requirements structure.
uint16_t init_present_snapshot
Present value when message was received.
app_scene_setup_server_t * p_app_scene
Internal variable.
void * p_app_publish_v
Context pointer for the publish callback.
uint32_t app_light_lightness_binding_setup(app_light_lightness_setup_server_t *p_app)
Informs the model that the system is ready to have the powerup onoff bindings.
uint16_t initial_present_lightness
Initial present lightness required for handling Set/Delta Set message.
void(* app_light_lightness_transition_cb_t)(const app_light_lightness_setup_server_t *p_app, uint32_t transition_time_ms, uint16_t target_lightness)
Application Light Lightness transition time callback prototype.
void(* app_light_lightness_get_cb_t)(const app_light_lightness_setup_server_t *p_app, uint16_t *p_present_lightness)
Application Light Lightness state read callback prototype.
app_light_lightness_set_cb_t app_light_lightness_set_cb
Set the device lightness value.
uint32_t app_light_lightness_model_init(app_light_lightness_setup_server_t *p_app, uint8_t element_index)
Initializes the behavioral module for the generic Light Lightness model.
void(* app_additional_publish_cb_t)(const void *p_app_v, light_lightness_status_params_t *p_pub_data)
Application publish callback prototype.
uint32_t app_light_lightness_direct_actual_set(app_light_lightness_setup_server_t *p_app, uint16_t lightness_value)
Function to set the lightness value (sending to the hardware) and writing the flash state values...
Internal structure to hold state and timing information.
light_lightness_setup_server_t light_lightness_setup_server
Light lightness setup server context/.
uint32_t app_light_lightness_current_value_publish(app_light_lightness_setup_server_t *p_app)
Initiates value fetch from the user application by calling a get callback, updates internal state...
bool new_tid
To detect if TID is new while processing delta transition.
uint16_t target_snapshot
Requested target.
app_scene_model_interface_t scene_if
Internal variable.
Application level structure holding the Light Lightness Setup server model context and Light Lightnes...
app_notify_set_cb_t app_notify_set_cb
A notify callback to call after receiving lightness Set messages.
list_node_t node
Internal variable.
uint32_t app_light_lightness_scene_context_set(app_light_lightness_setup_server_t *p_app, app_scene_setup_server_t *p_app_scene)
Sets the scene context.
Parameters for the light_lightness Status message.
app_light_lightness_transition_cb_t app_light_lightness_transition_cb
The device lightness transition time.
uint16_t present_lightness
Present value of the lightness state.
Structure for holding publish and notification callbacks for other states bound to Light Lightness st...
void * p_app_notify_v
A context pointer for the notify callback.
app_additional_publish_cb_t app_add_publish_cb
Publish callback to call to before publishing lightness status.

Documentation feedback | Developer Zone | Subscribe | Updated