on_off.c

来自「蓝牙耳机软件源代码」· C语言 代码 · 共 78 行

C
78
字号
#include "demohs.h"

#include <batt.h>
#include <pio.h>


/*
    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();
}

⌨️ 快捷键说明

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