Пример #1
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool is_notification_mode    = false;
    bool is_non_connectable_mode = false;

    timers_init();

    APP_GPIOTE_INIT(1);
    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    APP_ERROR_CHECK(err_code);
#if BUTTONS_NUMBER > 2

    // Check button states.
    // Notification Start button.
    err_code = bsp_button_is_pressed(NOTIF_BUTTON_ID, &(is_notification_mode));
    APP_ERROR_CHECK(err_code);
    // Non-connectable advertisement start button.
    if (!is_notification_mode)
    {
        err_code = bsp_button_is_pressed(NON_CONN_ADV_BUTTON_ID, &(is_non_connectable_mode));
        APP_ERROR_CHECK(err_code);
    }
    // Un-configured button.
    else
    {
    }

#else
    is_notification_mode = true;
#endif

    // Initialize SoftDevice.
    ble_stack_init();

    if (!is_notification_mode && !is_non_connectable_mode)
    {
        // The startup was not because of button presses. This is the first start. 
        // Go into System-Off mode. Button presses will wake the chip up.
        err_code = sd_power_system_off();  
        APP_ERROR_CHECK(err_code);
    }
    
    // If we reach this point, the application was woken up by pressing one of the two configured
    // buttons.
    gap_params_init();

    if (is_notification_mode)
    {
        // Notification button is pressed. Start connectable advertisement.
        connectable_adv_init();
        service_add();
    }
    else
    {
        non_connectable_adv_init();
    }
    
    advertising_data_init();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
Пример #2
0
/**@brief Function for application main entry.
 */
int main(void)
{
    bool is_notification_mode    = false;
    bool is_non_connectable_mode = false;

    buttons_init();

    // Check button states.
    // Notification Start button.
    if (nrf_gpio_pin_read(NOTIF_BUTTON_PIN_NO) == 0)
    {
        is_notification_mode = true;
    }
    // Non-connectable advertisement start button.
    else if (nrf_gpio_pin_read(NON_CONN_ADV_BUTTON_PIN_NO) == 0)
    {
        is_non_connectable_mode = true;
    }
    // Un-configured button.
    else
    {
    }

    // Initialize SoftDevice.
    ble_stack_init();

    if (!is_notification_mode && !is_non_connectable_mode)
    {
        uint32_t err_code;

        // The startup was not because of button presses. This is the first start.
        // Go into System-Off mode. Button presses will wake the chip up.
        err_code = sd_power_system_off();
        APP_ERROR_CHECK(err_code);
    }

    // If we reach this point, the application was woken up by pressing one of the two configured
    // buttons.

    timers_init();
    gap_params_init();

    if (is_notification_mode)
    {
        // Notification button is pressed. Start connectable advertisement.
        connectable_adv_init();
        service_add();
    }
    else
    {
        non_connectable_adv_init();
    }

    advertising_data_init();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}