⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a2dp_sd_led.c

📁 蓝牙远程控制协议的运用
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.5.2-release

FILE NAME
    a2dp_sd_led.c

DESCRIPTION
    Led flashing code

NOTES
    
*/


/****************************************************************************
    Header files
*/
#include "a2dp_sd_private.h"
#include "a2dp_sd_led.h"

#include <pio.h>


/* PIO line attached to the LED */
#define LED             (1<<1)


/* Define the LED flashing duty cycles */
#define LED_IDLE_ON         (100)
#define LED_IDLE_OFF        (1000)

#define LED_CONNECTING_ON   (100)
#define LED_CONNECTING_OFF  (100)

#define LED_DISCOVER_ON     (100)
#define LED_DISCOVER_OFF    (100)

#define LED_CONNECTED_ON    (500)
#define LED_CONNECTED_OFF   (100)

#define LED_BUTTON_ON       (100)
#define LED_BUTTON_OFF      (100)


/****************************************************************************
NAME    
    a2dpSdInitLed
    
DESCRIPTION
    Initialise the flashing LED

RETURNS
    void
*/
void a2dpSdInitLed(void)
{
    /* Set the PIO line as an output */
    PioSetDir(LED, LED);

    /* Turn off the PIO */
    PioSet(LED, 0);

    /* Start flashing the LED */
    a2dpSdUpdateLed(0, a2dp_state_initialising);
}


/****************************************************************************
NAME    
    a2dpSdUpdateLed
    
DESCRIPTION
    Update the LED flash duty cycle.

RETURNS
    void
*/
void a2dpSdUpdateLed(bool button_pressed, a2dp_state state)
{
    bool on = (PioGet() & LED ? 1 : 0);
    uint32 duty_cycle = 0;

    /* Cancel all messages because we sometimes call this fun directly */
    (void) MessageCancelAll(getTheAppTask(), APP_LED_TIMEOUT_IND);

    /* Is the LED on or off */
    if (on)
    {
        /* Turn off the LED */
        PioSet(LED, 0);

        /* Flashing to indicate button pressed takes precidence */
        if (button_pressed)
            duty_cycle = LED_BUTTON_OFF;

        /* Schedule next callback */
        switch (state)
        {
            case a2dp_state_initiating:
                duty_cycle = LED_CONNECTING_OFF;
                break;

            case a2dp_state_discovering:
                duty_cycle = LED_DISCOVER_OFF;
                break;

            case a2dp_state_connected:
            case a2dp_state_streaming:
            case a2dp_state_disconnecting:
                duty_cycle = LED_CONNECTED_OFF;
                break;

            case a2dp_state_accepting:
            case a2dp_state_initialising:
            default:
                duty_cycle = LED_IDLE_OFF;
                break;
        }
    }
    else
    {
        /* Turn on LED */
        PioSet(LED, LED);

        /* Flashing to indicate button pressed takes precidence */
        if (button_pressed)
            duty_cycle = LED_BUTTON_ON;

        /* Schedule next callback */
        switch (state)
        {
            case a2dp_state_initiating:
                duty_cycle = LED_CONNECTING_ON;
                break;

            case a2dp_state_discovering:
                duty_cycle = LED_DISCOVER_ON;
                break;

            case a2dp_state_connected:
            case a2dp_state_streaming:
            case a2dp_state_disconnecting:
                duty_cycle = LED_CONNECTED_ON;
                break;

            case a2dp_state_accepting:
            case a2dp_state_initialising:
            default:
                duty_cycle = LED_IDLE_ON;
                break;
        }
    }

    /* Schedule the next LED state change. */
    MessageSendLater(getTheAppTask(), APP_LED_TIMEOUT_IND, 0x00, duty_cycle);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -