• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "syscfg/syscfg.h"
17 
18 #include "mesh/mesh.h"
19 #include "light_model.h"
20 
21 static u8_t gen_onoff_state;
22 static s16_t gen_level_state;
23 
update_light_state(void)24 static void update_light_state(void)
25 {
26     printf("Light state: onoff=%d lvl=0x%04x\n", gen_onoff_state, (u16_t)gen_level_state);
27 }
28 
light_model_gen_onoff_get(struct bt_mesh_model * model,u8_t * state)29 int light_model_gen_onoff_get(struct bt_mesh_model *model, u8_t *state)
30 {
31     *state = gen_onoff_state;
32     return 0;
33 }
34 
light_model_gen_onoff_set(struct bt_mesh_model * model,u8_t state)35 int light_model_gen_onoff_set(struct bt_mesh_model *model, u8_t state)
36 {
37     gen_onoff_state = state;
38     update_light_state();
39     return 0;
40 }
41 
light_model_gen_level_get(struct bt_mesh_model * model,s16_t * level)42 int light_model_gen_level_get(struct bt_mesh_model *model, s16_t *level)
43 {
44     *level = gen_level_state;
45     return 0;
46 }
47 
light_model_gen_level_set(struct bt_mesh_model * model,s16_t level)48 int light_model_gen_level_set(struct bt_mesh_model *model, s16_t level)
49 {
50     gen_level_state = level;
51 
52     if ((u16_t)gen_level_state > 0x0000) {
53         gen_onoff_state = 1;
54     }
55 
56     if ((u16_t)gen_level_state == 0x0000) {
57         gen_onoff_state = 0;
58     }
59 
60     update_light_state();
61     return 0;
62 }
63 
light_model_light_lightness_get(struct bt_mesh_model * model,s16_t * lightness)64 int light_model_light_lightness_get(struct bt_mesh_model *model, s16_t *lightness)
65 {
66     return light_model_gen_level_get(model, lightness);
67 }
68 
light_model_light_lightness_set(struct bt_mesh_model * model,s16_t lightness)69 int light_model_light_lightness_set(struct bt_mesh_model *model, s16_t lightness)
70 {
71     return light_model_gen_level_set(model, lightness);
72 }
73 
74