nRF5 SDK for Mesh v2.2.0
app_onoff.h
1 /* Copyright (c) 2010 - 2018, 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_timer.h"
45 
46 
88 #define APP_ONOFF_SERVER_DEF(_name, _force_segmented, _mic_size, _set_cb, _get_cb) \
89  APP_TIMER_DEF(_name ## _timer); \
90  static app_onoff_server_t _name = \
91  { \
92  .server.settings.force_segmented = _force_segmented, \
93  .server.settings.transmic_size = _mic_size, \
94  .p_timer_id = &_name ## _timer, \
95  .onoff_set_cb = _set_cb, \
96  .onoff_get_cb = _get_cb \
97  };
98 
99 
101 typedef struct
102 {
110  uint32_t delay_ms;
112 
113 /* Forward declaration */
114 typedef struct __app_onoff_server_t app_onoff_server_t;
115 
131 typedef void (*app_onoff_set_cb_t)(const app_onoff_server_t * p_server, bool onoff);
132 
141 typedef void (*app_onoff_get_cb_t)(const app_onoff_server_t * p_server, bool * p_present_onoff);
142 
145 {
147  generic_onoff_server_t server;
149  app_timer_id_t const * p_timer_id;
154 
163 };
164 
175 void app_onoff_status_publish(app_onoff_server_t * p_server);
176 
189 uint32_t app_onoff_init(app_onoff_server_t * p_server, uint8_t element_index);
190 
192 #endif /* APP_ONOFF_H__ */
bool present_onoff
Present value of the OnOff state.
Definition: app_onoff.h:104
bool value_updated
Internal variable.
Definition: app_onoff.h:162
void(* app_onoff_get_cb_t)(const app_onoff_server_t *p_server, bool *p_present_onoff)
Application state read callback prototype.
Definition: app_onoff.h:141
void app_onoff_status_publish(app_onoff_server_t *p_server)
Initiates value fetch from the user application by calling a get callback, updates internal state...
app_onoff_state_t state
Internal variable.
Definition: app_onoff.h:157
void(* app_onoff_set_cb_t)(const app_onoff_server_t *p_server, bool onoff)
Application state set callback prototype.
Definition: app_onoff.h:131
uint32_t app_onoff_init(app_onoff_server_t *p_server, uint8_t element_index)
Initializes the behavioral module for the generic OnOff model.
app_timer_id_t const * p_timer_id
APP timer instance pointer.
Definition: app_onoff.h:149
generic_onoff_server_t server
OnOff server model interface context structure.
Definition: app_onoff.h:147
Internal structure to hold state and timing information.
Definition: app_onoff.h:101
Application level structure holding the OnOff server model context and OnOff state representation...
Definition: app_onoff.h:144
uint32_t last_rtc_counter
Internal variable.
Definition: app_onoff.h:159
app_onoff_get_cb_t onoff_get_cb
Callback to be called for requesting current value from the user application.
Definition: app_onoff.h:153
uint32_t delay_ms
Time to delay the processing of received SET message.
Definition: app_onoff.h:110
uint32_t remaining_time_ms
Remaining time to reach target_onoff.
Definition: app_onoff.h:108
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:151
bool target_onoff
Target value of the OnOff state, as received from the model interface.
Definition: app_onoff.h:106

Documentation feedback | Developer Zone | Subscribe | Updated