nRF5 SDK for Mesh v5.0.0
app_onoff.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_ONOFF_H__
39 #define APP_ONOFF_H__
40 
41 #include <stdint.h>
42 
43 #include "generic_onoff_server.h"
44 #include "app_transition.h"
45 #include "app_timer.h"
46 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
47 #include "app_scene.h"
48 #endif
49 
50 
98 #define APP_ONOFF_SERVER_DEF(_name, _force_segmented, _mic_size, _set_cb, _get_cb, _transition_cb) \
99  APP_TIMER_DEF(_name ## _timer); \
100  static app_onoff_server_t _name = \
101  { \
102  .server.settings.force_segmented = _force_segmented, \
103  .server.settings.transmic_size = _mic_size, \
104  .state.transition.timer.p_timer_id = &_name ## _timer, \
105  .onoff_set_cb = _set_cb, \
106  .onoff_get_cb = _get_cb, \
107  .onoff_transition_cb = _transition_cb \
108  };
109 
110 
112 typedef struct
113 {
121  app_transition_t transition;
123 
124 /* Forward declaration */
125 typedef struct __app_onoff_server_t app_onoff_server_t;
126 
142 typedef void (*app_onoff_set_cb_t)(const app_onoff_server_t * p_app, bool onoff);
143 
152 typedef void (*app_onoff_get_cb_t)(const app_onoff_server_t * p_app, bool * p_present_onoff);
153 
165 typedef void (*app_onoff_transition_cb_t)(const app_onoff_server_t * p_app,
166  uint32_t transition_time_ms,
167  bool target_onoff);
168 
171 {
173  generic_onoff_server_t server;
175  app_timer_id_t const * p_timer_id;
182 
188 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
189 
191  app_scene_model_interface_t scene_if;
194  app_scene_setup_server_t * p_app_scene;
195 #endif
196 };
197 
209 void app_onoff_status_publish(app_onoff_server_t * p_app);
210 
231 uint32_t app_onoff_init(app_onoff_server_t * p_app, uint8_t element_index);
232 
245 uint32_t app_onoff_value_restore(app_onoff_server_t * p_app);
246 
247 #if (SCENE_SETUP_SERVER_INSTANCES_MAX > 0) || (DOXYGEN)
248 
261 uint32_t app_onoff_scene_context_set(app_onoff_server_t * p_app, app_scene_setup_server_t * p_app_scene);
262 
263 #endif
264 
266 #endif /* APP_ONOFF_H__ */
bool present_onoff
Present value of the OnOff state.
Definition: app_onoff.h:115
app_onoff_state_t state
Internal variable.
Definition: app_onoff.h:185
void app_onoff_status_publish(app_onoff_server_t *p_app)
Initiates value fetch from the user application by calling a get callback, updates internal state...
void(* app_onoff_get_cb_t)(const app_onoff_server_t *p_app, bool *p_present_onoff)
Application state read callback prototype.
Definition: app_onoff.h:152
void(* app_onoff_transition_cb_t)(const app_onoff_server_t *p_app, uint32_t transition_time_ms, bool target_onoff)
Application transition time callback prototype.
Definition: app_onoff.h:165
uint32_t app_onoff_scene_context_set(app_onoff_server_t *p_app, app_scene_setup_server_t *p_app_scene)
Sets the scene context.
app_timer_id_t const * p_timer_id
APP timer instance pointer.
Definition: app_onoff.h:175
generic_onoff_server_t server
OnOff server model interface context structure.
Definition: app_onoff.h:173
Internal structure to hold state and timing information.
Definition: app_onoff.h:112
Application level structure holding the OnOff server model context and OnOff state representation...
Definition: app_onoff.h:170
uint32_t app_onoff_value_restore(app_onoff_server_t *p_app)
Restores the onoff value from persistent storage.
uint32_t last_rtc_counter
Internal variable.
Definition: app_onoff.h:187
app_scene_model_interface_t scene_if
Internal variable.
Definition: app_onoff.h:191
uint32_t app_onoff_init(app_onoff_server_t *p_app, uint8_t element_index)
Initializes the behavioral module for the generic OnOff model.
app_onoff_get_cb_t onoff_get_cb
Callback to be called for requesting current value from the user application.
Definition: app_onoff.h:179
app_transition_t transition
Structure for using transition module functionality.
Definition: app_onoff.h:121
app_scene_setup_server_t * p_app_scene
Internal variable.
Definition: app_onoff.h:194
app_onoff_set_cb_t onoff_set_cb
Callaback to be called for informing the user application to update the value.
Definition: app_onoff.h:177
app_onoff_transition_cb_t onoff_transition_cb
Callaback to be called for informing the user application to update the value.
Definition: app_onoff.h:181
void(* app_onoff_set_cb_t)(const app_onoff_server_t *p_app, bool onoff)
Application state set callback prototype.
Definition: app_onoff.h:142
bool target_onoff
Target value of the OnOff state, as received from the model interface.
Definition: app_onoff.h:119
bool initial_present_onoff
Initial value for transition.
Definition: app_onoff.h:117

Documentation feedback | Developer Zone | Subscribe | Updated