Skip to content

Commit

Permalink
mesh network working! single attribute test with LED readout
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Apr 5, 2017
1 parent bc28b69 commit fd858a0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
12 changes: 12 additions & 0 deletions leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ void init_leds() {
void toggle_led(unsigned char led) {
LEDS_INVERT(1 << led);
}

void led_config(uint8_t led, uint8_t conf)
{
if (conf)
{
NRF_GPIO->OUTSET = (1 << (led + LED_START));
}
else
{
NRF_GPIO->OUTCLR = (1 << (led + LED_START));
}
}
1 change: 1 addition & 0 deletions leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {

void init_leds();
void toggle_led(unsigned char led);
void led_config(uint8_t led, uint8_t conf);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletions logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ void logger_print(const char str[]) {
void logger_println(const char str[]) {
Serial.println(str);
}

void logger_print_uint_with_base(unsigned int b, int base) {
Serial.print(b, base);
}

void logger_print_uint(unsigned int b) {
Serial.print(b, DEC);
}
7 changes: 7 additions & 0 deletions logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
extern "C" {
#endif

#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2

void logger_init();
void logger_print(const char[]);
void logger_println(const char[]);
void logger_print_uint_with_base(unsigned int, int);
void logger_print_uint(unsigned int);

#ifdef __cplusplus
}
Expand Down
29 changes: 28 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@ void HardFault_Handler(void)
*/
static void rbc_mesh_event_handler(rbc_mesh_event_t* p_evt)
{
toggle_led(LED_GREEN);

switch (p_evt->type)
{
case RBC_MESH_EVENT_TYPE_CONFLICTING_VAL:
case RBC_MESH_EVENT_TYPE_NEW_VAL:
case RBC_MESH_EVENT_TYPE_UPDATE_VAL:
if (p_evt->params.rx.value_handle == 1) {
led_config(LED_BLUE, p_evt->params.rx.p_data[0]);
}
break;
case RBC_MESH_EVENT_TYPE_TX:
case RBC_MESH_EVENT_TYPE_INITIALIZED:
case RBC_MESH_EVENT_TYPE_DFU_NEW_FW_AVAILABLE:
Expand All @@ -121,6 +127,8 @@ int main(void)
logger_init();
logger_println("mesh test!");

nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLDOWN);
nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLDOWN);

/* Enable Softdevice (including sd_ble before framework */
SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SRC, NULL);
Expand Down Expand Up @@ -160,7 +168,26 @@ int main(void)
rbc_mesh_event_t evt;
while (true)
{
toggle_led(LED_GREEN);

for (uint32_t pin = BUTTON_START; pin <= BUTTON_STOP; ++pin)
{
if(nrf_gpio_pin_read(pin) == 1)
{
logger_print("button press ");
logger_print_uint(pin);
logger_println("");
while(nrf_gpio_pin_read(pin) == 1);
uint8_t mesh_data[1];
uint32_t led_status = !!((pin - BUTTON_START) & 0x01); /* even buttons are OFF, odd buttons are ON */

mesh_data[0] = led_status;
if (rbc_mesh_value_set(1, mesh_data, 1) == NRF_SUCCESS)
{
led_config(LED_BLUE, led_status);
}
}
}

if (rbc_mesh_event_get(&evt) == NRF_SUCCESS)
{
rbc_mesh_event_handler(&evt);
Expand Down

0 comments on commit fd858a0

Please sign in to comment.