nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
lightness_srv.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
14#ifndef BT_MESH_LIGHTNESS_SRV_H__
15#define BT_MESH_LIGHTNESS_SRV_H__
16
17#include <zephyr/bluetooth/mesh.h>
18
23#if IS_ENABLED(CONFIG_EMDS) && IS_ENABLED(CONFIG_BT_SETTINGS)
24#include "emds/emds.h"
25#endif
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
32
39#define BT_MESH_LIGHTNESS_SRV_INIT(_handlers) \
40 { \
41 .lvl = BT_MESH_LVL_SRV_INIT( \
42 &_bt_mesh_lightness_srv_lvl_handlers), \
43 .ponoff = BT_MESH_PONOFF_SRV_INIT( \
44 &_bt_mesh_lightness_srv_onoff_handlers, NULL, NULL), \
45 .handlers = _handlers, \
46 }
47
57#define BT_MESH_MODEL_LIGHTNESS_SRV(_srv, ...) \
58 BT_MESH_MODEL_LVL_SRV(&(_srv)->lvl), \
59 BT_MESH_MODEL_PONOFF_SRV(&(_srv)->ponoff), \
60 BT_MESH_MODEL_METADATA_CB(BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, \
61 _bt_mesh_lightness_srv_op, &(_srv)->pub, \
62 BT_MESH_MODEL_USER_DATA(struct bt_mesh_lightness_srv, \
63 _srv), \
64 &_bt_mesh_lightness_srv_cb, __VA_ARGS__), \
65 BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV, \
66 _bt_mesh_lightness_setup_srv_op, NULL, \
67 BT_MESH_MODEL_USER_DATA(struct bt_mesh_lightness_srv, \
68 _srv), \
69 &_bt_mesh_lightness_setup_srv_cb)
70
72#define BT_MESH_LIGHT_PURPOSE_METADATA_ID 0x0002
73
75#define BT_MESH_LIGHT_LIGHTNESS_RANGE_METADATA_ID 0x0003
76
82#define BT_MESH_LIGHT_PURPOSE_METADATA(light_purpose) \
83 BT_MESH_MODELS_METADATA_ENTRY(2, BT_MESH_LIGHT_PURPOSE_METADATA_ID, \
84 ((uint16_t[]){(light_purpose)}))
85
92#define BT_MESH_LIGHT_LIGHTNESS_RANGE_METADATA(range_min, range_max) \
93 BT_MESH_MODELS_METADATA_ENTRY(4, BT_MESH_LIGHT_LIGHTNESS_RANGE_METADATA_ID, \
94 ((uint16_t[]){(range_min), (range_max)}))
95
118 void (*const light_set)(struct bt_mesh_lightness_srv *srv,
119 struct bt_mesh_msg_ctx *ctx,
120 const struct bt_mesh_lightness_set *set,
121 struct bt_mesh_lightness_status *rsp);
122
136 void (*const light_get)(struct bt_mesh_lightness_srv *srv,
137 struct bt_mesh_msg_ctx *ctx,
138 struct bt_mesh_lightness_status *rsp);
139
151 void (*const default_update)(struct bt_mesh_lightness_srv *srv,
152 struct bt_mesh_msg_ctx *ctx,
153 uint16_t old_default, uint16_t new_default);
154
170 void (*const range_update)(
171 struct bt_mesh_lightness_srv *srv, struct bt_mesh_msg_ctx *ctx,
172 const struct bt_mesh_lightness_range *old_range,
173 const struct bt_mesh_lightness_range *new_range);
174};
175
187 atomic_t flags;
189 const struct bt_mesh_model *lightness_model;
191 const struct bt_mesh_model *lightness_setup_model;
193 struct bt_mesh_model_pub pub;
194 /* Publication buffer */
195 struct net_buf_simple pub_buf;
196 /* Publication data */
197 uint8_t pub_data[BT_MESH_MODEL_BUF_LEN(
198 BT_MESH_LIGHTNESS_OP_STATUS,
199 BT_MESH_LIGHTNESS_MSG_MAXLEN_STATUS)];
204
210 uint16_t delta_start;
211 struct __packed {
213 uint16_t last;
215 bool is_on;
217
218#if IS_ENABLED(CONFIG_EMDS) && IS_ENABLED(CONFIG_BT_SETTINGS)
221#endif
222
223#if defined(CONFIG_BT_MESH_LIGHT_CTRL_SRV)
226#endif
227};
228
235static inline uint16_t bt_mesh_lightness_clamp(const struct bt_mesh_lightness_srv *srv,
236 uint16_t lightness)
237{
238 return lightness == 0 ? 0 : CLAMP(lightness, srv->range.min, srv->range.max);
239}
240
260 struct bt_mesh_msg_ctx *ctx,
261 const struct bt_mesh_lightness_status *status);
262
264extern const struct bt_mesh_model_cb _bt_mesh_lightness_srv_cb;
265extern const struct bt_mesh_model_cb _bt_mesh_lightness_setup_srv_cb;
266extern const struct bt_mesh_model_op _bt_mesh_lightness_srv_op[];
267extern const struct bt_mesh_model_op _bt_mesh_lightness_setup_srv_op[];
268extern const struct bt_mesh_lvl_srv_handlers
269 _bt_mesh_lightness_srv_lvl_handlers;
270extern const struct bt_mesh_onoff_srv_handlers
271 _bt_mesh_lightness_srv_onoff_handlers;
274#ifdef __cplusplus
275}
276#endif
277
278#endif /* BT_MESH_LIGHTNESS_SRV_H__ */
279
int bt_mesh_lightness_srv_pub(struct bt_mesh_lightness_srv *srv, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_lightness_status *status)
Publish the current Light state.
static uint16_t bt_mesh_lightness_clamp(const struct bt_mesh_lightness_srv *srv, uint16_t lightness)
Clamp lightness to lightness range.
Definition: lightness_srv.h:235
struct bt_mesh_lightness_srv * lightness
Definition: light_ctrl_srv.h:208
Light Lightness Control Server instance.
Definition: light_ctrl_srv.h:153
uint16_t max
Definition: lightness.h:60
uint16_t min
Definition: lightness.h:59
Definition: lightness.h:58
Definition: lightness.h:30
void(*const range_update)(struct bt_mesh_lightness_srv *srv, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_lightness_range *old_range, const struct bt_mesh_lightness_range *new_range)
The Light Range state has changed.
Definition: lightness_srv.h:170
void(*const light_set)(struct bt_mesh_lightness_srv *srv, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_lightness_set *set, struct bt_mesh_lightness_status *rsp)
Set the Light state.
Definition: lightness_srv.h:118
void(*const default_update)(struct bt_mesh_lightness_srv *srv, struct bt_mesh_msg_ctx *ctx, uint16_t old_default, uint16_t new_default)
The Default Light state has changed.
Definition: lightness_srv.h:151
void(*const light_get)(struct bt_mesh_lightness_srv *srv, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_lightness_status *rsp)
Get the current Light state.
Definition: lightness_srv.h:136
Definition: lightness_srv.h:97
uint16_t delta_start
Definition: lightness_srv.h:210
uint8_t pub_data[BT_MESH_MODEL_BUF_LEN(BT_MESH_LIGHTNESS_OP_STATUS, BT_MESH_LIGHTNESS_MSG_MAXLEN_STATUS)]
Definition: lightness_srv.h:199
struct net_buf_simple pub_buf
Definition: lightness_srv.h:195
const struct bt_mesh_model * lightness_setup_model
Definition: lightness_srv.h:191
struct bt_mesh_light_ctrl_srv * ctrl
Definition: lightness_srv.h:225
uint16_t default_light
Definition: lightness_srv.h:208
const struct bt_mesh_model * lightness_model
Definition: lightness_srv.h:189
const struct bt_mesh_lightness_srv_handlers *const handlers
Definition: lightness_srv.h:203
struct bt_mesh_lightness_srv::@156 transient
uint16_t last
Definition: lightness_srv.h:213
atomic_t flags
Definition: lightness_srv.h:187
struct bt_mesh_lightness_range range
Definition: lightness_srv.h:206
struct bt_mesh_ponoff_srv ponoff
Definition: lightness_srv.h:185
struct bt_mesh_model_pub pub
Definition: lightness_srv.h:193
bool is_on
Definition: lightness_srv.h:215
struct bt_mesh_lvl_srv lvl
Definition: lightness_srv.h:183
struct bt_mesh_tid_ctx tid
Definition: lightness_srv.h:201
Definition: lightness_srv.h:181
Definition: lightness.h:44
Definition: gen_lvl_srv.h:52
Definition: gen_lvl_srv.h:143
Definition: gen_onoff_srv.h:52
Definition: gen_ponoff_srv.h:74
Definition: model_types.h:46
Definition: emds.h:46
Definition: emds.h:31