www.pudn.com > headset.rar > on_off.c


#include "demohs.h" 
 
#include  
#include  
 
 
/* 
    enterDeepSleepAsap 
     
    Disconnect everything and disable all you can to enable to chip 
    to go into deep sleep as soon as possible 
*/ 
void enterDeepSleepAsap(void) 
{     
    hsState.turnOffHs = 1; 
 
    /* Disable battery monitoring completely */ 
    BattInit(VM_ADC_TEST_A, D_NEVER); 
 
    if (hsState.connectState == idle) 
    { 
        /* Cancel the flashing LEDs */ 
        changeFlash(); 
    } 
    else if (hsState.connectState == connectingAsMaster || 
            hsState.connectState == connectingAsSlave || 
            hsState.connectState == pairing) 
    {             
        /* 
            Check the current state and cancel it 
            NOTE this button only works if the headset is not already connected  
            Entering idle state will call changeFlash() and stop the LEDs 
        */ 
        cancelOperation();   
 
        if (hsState.connectState == pairing) 
            hsState.pairingPending = 1; 
    } 
    else 
    { 
        /*  
            Reset this flag otherwise the headset will turn off as soon  
            as the AG drops the connections and that can be confusing  
            to the user. This way the headset will go into idle mode  
            and the off button can then be pressed to switch off  
            everything else 
        */ 
        hsState.turnOffHs = 0; 
    } 
} 
 
 
/* 
    enterActiveStateAsap 
 
    Re-enable everything so headset can operate as before. The flashing LEDs  
    will be re-enabled when the headset changes state. 
*/ 
void enterActiveStateAsap(void) 
{ 
    hsState.turnOffHs = 0; 
 
    /* enable battery monitoring */ 
    BattInit(VM_ADC_TEST_A, BATT_MONITOR_PERIOD); 
 
    /* Power up into idle mode */ 
    updateHsConnectState(idle); 
 
    /*  
        If we were in pairing mode before the power down go back  
        into it as all pairing info has been reset anyway. Otherwise  
        become connectable. 
    */ 
    if (hsState.pairingPending) 
        pairButton(); 
    else 
        talkButton(); 
}