?? piohshf_flash.c
字號:
#include "piohshf_private.h"
#include "handsfree.h"
#include <pio.h>
static void setLEDstate(uint8 led_id, uint8 state)
{
/* make sure the led_id doesn't try to drive any non-output PIOs */
led_id &= (LED_PAIR | LED_CONNECT);
/* store the current LED state */
if ((LED_CONNECT & led_id) == LED_CONNECT)
hshfState.hshfConnectLedState = state;
if ((LED_PAIR & led_id) == LED_PAIR)
hshfState.hshfPairLedState = state;
/* Implementation dependent. In this case driving the PIO to zero lights it */
if (state == led_off)
PioSet(led_id, 0);
else
PioSet(led_id, ~0);
}
static void toggleLED(uint8 led, uint16 led_state)
{
if (led_state == led_on)
setLEDstate(led, led_off);
else
setLEDstate(led, led_on);
}
static Delay flasherCallback(TimerHandle h)
{
/* keep the compiler happy */
h = h;
if (HFstate.connectState == pairing)
{
/* In pairing mode so ensure the connect LED is off */
toggleLED(LED_PAIR, hshfState.hshfPairLedState);
setLEDstate(LED_CONNECT, led_off);
if (hshfState.hshfPairLedState)
return LED_PAIR_ON;
else
return LED_PAIR_OFF;
}
else
{
/* In connect mode so turn off pair led */
setLEDstate(LED_PAIR, led_off);
if (HFstate.connectState == connectingAsSlave)
{
/* toggle the state of the flashing LED */
toggleLED(LED_CONNECT, hshfState.hshfConnectLedState);
/* Return the next timeout interval */
if (hshfState.hshfConnectLedState)
return LED_CONNECT_SLAVE_ON;
else
return LED_CONNECT_SLAVE_OFF;
}
else if (HFstate.connectState == connectingAsMaster)
{
/* toggle the state of the flashing LED */
toggleLED(LED_CONNECT, hshfState.hshfConnectLedState);
/* Return the next timeout interval */
if (hshfState.hshfConnectLedState)
return LED_CONNECT_MASTER_ON;
else
return LED_CONNECT_MASTER_OFF;
}
else if (HFstate.connectState == connected)
{
/* toggle the state of the flashing LED */
toggleLED(LED_CONNECT, hshfState.hshfConnectLedState);
/* Return the next timeout interval */
if (hshfState.hshfConnectLedState)
return LED_CONNECTED_ON;
else
return LED_CONNECTED_OFF;
}
else
{
/* in idle or some other unknown state so try again later */
setLEDstate(LED_CONNECT, led_off);
/* Return the next timeout interval */
return D_SEC(100);
}
}
}
/*
pioHsHfFlashInit
Initialise the flashing LEDs and start flashing depending on the current
state.
*/
void pioHsHfFlashInit(void)
{
/* Set the two PIOs to be outputs */
PioSetDir((LED_PAIR | LED_CONNECT), ~0);
/* to start with turn off the LEDs */
setLEDstate((LED_PAIR | LED_CONNECT), led_off);
/* kick off the flashing LEDs routine */
(void) TimerAdd(D_mSEC(500), flasherCallback);
}
/*
handleLocalStateChange
Local connect state has changed so change the flashing LEDs to show this
*/
void handleLocalStateChange(void)
{
/* Cancel the current flashing */
TimerCancelCallback(flasherCallback);
if (HFstate.connectState != idle)
{
/* State changed so go into that flash mode */
(void) TimerAdd(D_IMMEDIATE, flasherCallback);
}
else
{
/* State idle so disable all flashing */
setLEDstate(LED_CONNECT, led_off);
setLEDstate(LED_PAIR, led_off);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -