Skip to content

Commit 5af5407

Browse files
vikrant8052jhedberg
authored andcommitted
samples: mesh: nrf52: added some preprocessor directive
Added some preprocessor directive so that code get compile for some more nRF52 boards which has only one LED & one button. Signed-off-by: Vikrant More <[email protected]>
1 parent b80b359 commit 5af5407

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/src/app_gpio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <drivers/gpio.h>
99

10+
#include "app_gpio.h"
1011
#include "publisher.h"
1112

1213
struct device *led_device[4];
@@ -31,6 +32,7 @@ void app_gpio_init(void)
3132
GPIO_DIR_OUT | GPIO_PUD_PULL_UP);
3233
gpio_pin_write(led_device[0], DT_ALIAS_LED0_GPIOS_PIN, 1);
3334

35+
#ifndef ONE_LED_ONE_BUTTON_BOARD
3436
led_device[1] = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
3537
gpio_pin_configure(led_device[1], DT_ALIAS_LED1_GPIOS_PIN,
3638
GPIO_DIR_OUT | GPIO_PUD_PULL_UP);
@@ -45,7 +47,7 @@ void app_gpio_init(void)
4547
gpio_pin_configure(led_device[3], DT_ALIAS_LED3_GPIOS_PIN,
4648
GPIO_DIR_OUT | GPIO_PUD_PULL_UP);
4749
gpio_pin_write(led_device[3], DT_ALIAS_LED3_GPIOS_PIN, 1);
48-
50+
#endif
4951
/* Buttons configuration & setting */
5052

5153
k_work_init(&button_work, publish);
@@ -61,6 +63,7 @@ void app_gpio_init(void)
6163
gpio_add_callback(button_device[0], &button_cb[0]);
6264
gpio_pin_enable_callback(button_device[0], DT_ALIAS_SW0_GPIOS_PIN);
6365

66+
#ifndef ONE_LED_ONE_BUTTON_BOARD
6467
button_device[1] = device_get_binding(DT_ALIAS_SW1_GPIOS_CONTROLLER);
6568
gpio_pin_configure(button_device[1], DT_ALIAS_SW1_GPIOS_PIN,
6669
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
@@ -93,4 +96,5 @@ void app_gpio_init(void)
9396
BIT(DT_ALIAS_SW3_GPIOS_PIN));
9497
gpio_add_callback(button_device[3], &button_cb[3]);
9598
gpio_pin_enable_callback(button_device[3], DT_ALIAS_SW3_GPIOS_PIN);
99+
#endif
96100
}

samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ static void light_default_status_init(void)
9393

9494
void update_vnd_led_gpio(void)
9595
{
96+
#ifndef ONE_LED_ONE_BUTTON_BOARD
9697
if (vnd_user_data.current == STATE_ON) {
9798
/* LED2 On */
9899
gpio_pin_write(led_device[1], DT_ALIAS_LED1_GPIOS_PIN, 0);
99100
} else {
100101
/* LED2 Off */
101102
gpio_pin_write(led_device[1], DT_ALIAS_LED1_GPIOS_PIN, 1);
102103
}
104+
#endif
103105
}
104106

105107
void update_led_gpio(void)
@@ -120,6 +122,7 @@ void update_led_gpio(void)
120122
gpio_pin_write(led_device[0], DT_ALIAS_LED0_GPIOS_PIN, 1);
121123
}
122124

125+
#ifndef ONE_LED_ONE_BUTTON_BOARD
123126
if (power < 50) {
124127
/* LED3 On */
125128
gpio_pin_write(led_device[2], DT_ALIAS_LED2_GPIOS_PIN, 0);
@@ -135,6 +138,7 @@ void update_led_gpio(void)
135138
/* LED4 Off */
136139
gpio_pin_write(led_device[3], DT_ALIAS_LED3_GPIOS_PIN, 1);
137140
}
141+
#endif
138142
}
139143

140144
void update_light_state(void)

samples/boards/nrf/mesh/onoff_level_lighting_vnd_app/src/mesh/publisher.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void publish(struct k_work *work)
2929
{
3030
int err = 0;
3131

32+
#ifndef ONE_LED_ONE_BUTTON_BOARD
3233
if (button_read(button_device[0], DT_ALIAS_SW0_GPIOS_PIN) == 0U) {
3334
#if defined(ONOFF)
3435
bt_mesh_model_msg_init(root_models[3].pub->msg,
@@ -213,6 +214,20 @@ void publish(struct k_work *work)
213214
err = bt_mesh_model_publish(&root_models[16]);
214215
#endif
215216
}
217+
#else
218+
if (button_read(button_device[0], DT_ALIAS_SW0_GPIOS_PIN) == 0U) {
219+
#if defined(ONOFF)
220+
static u8_t state = STATE_ON;
221+
222+
bt_mesh_model_msg_init(root_models[3].pub->msg,
223+
BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK);
224+
net_buf_simple_add_u8(root_models[3].pub->msg,
225+
state = state ^ 0x01);
226+
net_buf_simple_add_u8(root_models[3].pub->msg, tid++);
227+
err = bt_mesh_model_publish(&root_models[3]);
228+
#endif
229+
}
230+
#endif
216231

217232
if (err) {
218233
printk("bt_mesh_model_publish: err: %d\n", err);

0 commit comments

Comments
 (0)