コード例 #1
0
ファイル: main.c プロジェクト: BlueSkyGjj/nRF52
/**@brief Function for handling button events.
 *
 * @param[in] pin_no The pin number of the button pressed.
 * @param[in] button_action Action of button that caused this event.
 */
void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
    if (button_action == APP_BUTTON_PUSH)
    {
        switch (pin_no)
        {
            case BSP_BUTTON_0:
                // Toggle the ste of the LED
                m_led_change_counter++;

                LEDS_INVERT(BSP_LED_0_MASK);
                break;
            case BSP_BUTTON_1:
            {
                // Open slave channel to 
                uint8_t channel_status;
                uint32_t err_code = sd_ant_channel_status_get (ANT_RELAY_SLAVE_CHANNEL, &channel_status);
                APP_ERROR_CHECK(err_code);

                if((channel_status & STATUS_CHANNEL_STATE_MASK) == STATUS_ASSIGNED_CHANNEL)
                {
                    err_code = sd_ant_channel_open(ANT_RELAY_SLAVE_CHANNEL);
                    APP_ERROR_CHECK(err_code);
                }
                break;
            }
            default:

                break;
        }
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: BlueSkyGjj/nRF52
/**@brief Function for creating and sending main
 * relay data page.
 *
 * @param[in] channel ANT channel on which to send this message.
 */
void ant_relay_main_message(uint8_t channel)
{
    uint8_t status;
    uint32_t err_code = sd_ant_channel_status_get(ANT_RELAY_SLAVE_CHANNEL, &status);
    APP_ERROR_CHECK(err_code);
    
    m_broadcast_data[0] = ANT_RELAY_MAIN_PAGE;
    m_broadcast_data[1] = ( LED_IS_ON(BSP_LED_0_MASK) )? 1 : 0;
    m_broadcast_data[2] = (uint8_t)(m_led_change_counter >> 0);
    m_broadcast_data[3] = (uint8_t)(m_led_change_counter >> 8);
    m_broadcast_data[4] = (uint8_t)(m_led_change_counter >> 16);
    m_broadcast_data[5] = (uint8_t)(m_led_change_counter >> 24);
    m_broadcast_data[6] = 0xFF;
    m_broadcast_data[7] = status & STATUS_CHANNEL_STATE_MASK;
    
    err_code = sd_ant_broadcast_message_tx(channel, ANT_STANDARD_DATA_PAYLOAD_SIZE, m_broadcast_data);
    APP_ERROR_CHECK(err_code);
}
コード例 #3
0
/**@brief Sets the state machine to the applicable state
 */
static void set_state(connection_states_t new_state)
{
    uint32_t err_code;

    if(m_state != new_state)
    {
        switch(new_state)
        {
            case PHONE_OFF:
            {
                uint8_t channel_status;
                err_code = sd_ant_channel_status_get(m_channel_number, &channel_status);
                APP_ERROR_CHECK(err_code);

                m_state = new_state;

                switch(channel_status)
                {
                    case STATUS_SEARCHING_CHANNEL:
                        //Intentional fallthrough
                    case STATUS_TRACKING_CHANNEL:
                    {
                        err_code = sd_ant_channel_close(m_channel_number);
                        APP_ERROR_CHECK(err_code);
                    } //Intentional fallthrough
                    case STATUS_ASSIGNED_CHANNEL:
                    {
                        err_code = sd_ant_channel_unassign(m_channel_number);
                        APP_ERROR_CHECK(err_code);
                        break;
                    }
                    default:
                    {
                        return;
                    }
                }
                break;
            }
            case PHONE_ON:
            {
                //uint32_t err_code;
                if(m_state == PHONE_OFF)
                {
                    //Open the channel
                    err_code = sd_ant_channel_open(m_channel_number);
                    APP_ERROR_CHECK(err_code);
                }

                m_state = new_state;

                //Prepare the buffer
                asc_encode_device_availability_page(m_neighbor_id, m_tx_buffer);
                err_code = sd_ant_broadcast_message_tx (m_channel_number, ANT_STANDARD_DATA_PAYLOAD_SIZE, m_tx_buffer);
                APP_ERROR_CHECK(err_code);
                break;
            }
            default:
            {
                return;
            }
        }
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: BlueSkyGjj/nRF52
/**@brief Process ANT message on ANT mobile interface channel
 * 
 * @details   This function handles all events on the mobile interface channel.
 *            On EVENT_TX an ANT_MOBILE_MAIN_PAGE message is queue. The format is:
 *            byte[0]   = page (1 = ANT_MOBILE_MAIN_PAGE)
 *            byte[1]   = led state (1 = 0N, 0 = OFF)
 *            byte[2-6] = reserved (0xFF)
 *            byte[7]   = relay slave channel status (0 = unnassigned, 1 = assigned, 2 = searching, 3 = tracking)
 *
 *            On EVENT_RX the function will decode an ANT_MOBILE_COMMAND_PAGE. The format is:
 *            byte[0]   = page (2 = ANT_MOBILE_COMMAND_PAGE)
 *            byte[1]   = reserved (Set to 0xFF)
 *            byte[2]   = command (1 = pairing, 2 = led on, 3 = led off)
 *            byte[3-7] = reserved (Set to 0xFF)
 *
 * @param[in] p_ant_event ANT message content.
 */
void ant_process_mobile(ant_evt_t* p_ant_event)
{
    ANT_MESSAGE* p_ant_message = (ANT_MESSAGE*)p_ant_event->evt_buffer;
    switch(p_ant_event->event)
    {
        case EVENT_RX:
        {
            switch(p_ant_message->ANT_MESSAGE_aucPayload[0])
            {
                case ANT_MOBILE_COMMAND_PAGE:
                {
                    switch(p_ant_message->ANT_MESSAGE_aucPayload[2])
                    {
                        case ANT_COMMAND_ON:
                        {
                            LEDS_ON(BSP_LED_0_MASK);
                            m_led_change_counter++;
                            break;
                        }
                        case ANT_COMMAND_OFF:
                        {
                            LEDS_OFF(BSP_LED_0_MASK);
                            m_led_change_counter++;
                            break;
                        }
                        case ANT_COMMAND_PAIRING:
                        {
                            uint8_t channel_status;
                            uint32_t err_code = sd_ant_channel_status_get (ANT_RELAY_SLAVE_CHANNEL, &channel_status);
                            APP_ERROR_CHECK(err_code);

                            if((channel_status & STATUS_CHANNEL_STATE_MASK) == STATUS_ASSIGNED_CHANNEL)
                            {
                                err_code = sd_ant_channel_open(ANT_RELAY_SLAVE_CHANNEL);
                                APP_ERROR_CHECK(err_code);
                            }
                            break;
                        }
                    }

                    break;
                }
                default:
                {
                    break;
                }
            }
            break;
        }
        case EVENT_TX:
        {
            uint8_t status;

            uint32_t err_code = sd_ant_channel_status_get(ANT_RELAY_SLAVE_CHANNEL, &status);
            APP_ERROR_CHECK(err_code);

            m_broadcast_data[0] = ANT_MOBILE_MAIN_PAGE;
            m_broadcast_data[1] = ( LED_IS_ON(BSP_LED_0_MASK) )? 1 : 0;
            m_broadcast_data[2] = 0xFF;
            m_broadcast_data[3] = 0xFF;
            m_broadcast_data[4] = 0xFF;
            m_broadcast_data[5] = 0xFF;
            m_broadcast_data[6] = 0xFF;
            m_broadcast_data[7] = status & STATUS_CHANNEL_STATE_MASK;
            err_code = sd_ant_broadcast_message_tx(ANT_MOBILE_CHANNEL, ANT_STANDARD_DATA_PAYLOAD_SIZE, m_broadcast_data);
            APP_ERROR_CHECK(err_code);

            break;
        }
        default:
        {
            break;
        }
    }
}