/**************************************************************************** NAME handleBatteryLow DESCRIPTION Called when the battery voltage is detected to be in Battery Low state */ static void handleBatteryLow( void ) { bool last_state = theHeadset.battery_low_state; PM_DEBUG(("PM: Battery Low\n")); /*we only want low battery reminders if the headset is ON and not charging */ if(stateManagerGetState() != headsetLimbo) { MessageSend(&theHeadset.task, EventLowBattery, 0); #if 0 theHeadset.battery_low_state = TRUE; #endif PM_DEBUG(("battery_low_state = true\n")); } if(ChargerIsChargerConnected() || stateManagerGetState() == headsetLimbo) { /* printf("the battery is charging or the headset is in limbo state\n");*/ theHeadset.battery_low_state = FALSE; PM_DEBUG(("battery_low_state = false\n")); } if(!last_state || !theHeadset.battery_low_state) { #ifdef ROM_LEDS /* update state indication to indicate low batt state change */ PM_DEBUG(("Low battery state\n")); LEDManagerIndicateState( stateManagerGetState() ); #endif } }
/**************************************************************************** NAME batteryNormal DESCRIPTION Called when the battery voltage is detected to be in a Normal state */ static void handleBatteryNormal(power_battery_level pLevel) { uint16 level = (uint16)(pLevel - POWER_BATT_LEVEL0); PM_DEBUG(("PM: Battery Normal,level %d\n",level)); #ifndef BHC612 MessageSend(&theHeadset.task, EventOkBattery, 0); /* If charger connected send a charger gas gauge message (these don't have any functional use but can be associated with LEDs/tones) */ if (ChargerIsChargerConnected()) MessageSend(&theHeadset.task, (EventChargerGasGauge0+level), 0); #endif /* Send notification to AG if batt level has changed */ MessageSend(&theHeadset.task, EventGasGauge0+level, 0); #ifdef ROM_LEDS /* when changing from low battery state to a normal state, refresh the led state pattern to replace the low battery pattern should it have been shown */ if(theHeadset.battery_low_state == TRUE) { /* kick off a check to see if there is a low battery led state configured */ PM_DEBUG(("Battery Normal\n")); LEDManagerIndicateState( stateManagerGetState() ); } #endif /* reset any low battery warning that may be in place */ theHeadset.battery_low_state = FALSE; theHeadset.low_battery_flag_ag = FALSE; }
/**************************************************************************** NAME powerManagerHandleVbatLow DESCRIPTION Called when the battery voltage is detected to be in Battery Low state */ static void powerManagerHandleVbatLow( void ) { sinkState lSinkState = stateManagerGetState (); bool batt_was_low = powerManagerIsVbatLow(); PM_DEBUG(("PM: Battery Low\n")); if(powerManagerIsChargerConnected() || lSinkState == deviceLimbo) { theSink.battery_state = POWER_BATT_LEVEL0; } else { theSink.battery_state = POWER_BATT_LOW; } if(!batt_was_low || !powerManagerIsVbatLow()) { /* update state indication to indicate low batt state change */ #ifndef NO_LED LEDManagerIndicateState( lSinkState ); #endif } AudioSetPower(powerManagerGetLBIPM()); }
/**************************************************************************** NAME LedsEnableFilterOverrides DESCRIPTION Enable or disable filters overriding LEDs. This will not change which filters are active, it will just turn off any LEDs the filters are forcing on. RETURNS void */ void LedsEnableFilterOverrides(bool enable) { uint16 lFilterIndex; /* Run through all filters */ for (lFilterIndex = 0 ; lFilterIndex < theSink.theLEDTask->gLMNumFiltersUsed ; lFilterIndex ++ ) { LEDFilter_t *lEventFilter = &(theSink.theLEDTask->gEventFilters [ lFilterIndex ]); /* If filter is overriding an LED turn it off */ if (LedsIsFilterEnabled(lFilterIndex) && (lEventFilter->FilterType == OVERRIDE)) PioSetLedPin(lEventFilter->OverideLED, (enable ? LED_ON : LED_OFF)); } /* Restore state (ensures we haven't disabled any LEDs we shouldn't) */ #ifndef NO_LED LEDManagerIndicateState ( stateManagerGetState () ) ; #endif }
/**************************************************************************** NAME batteryNormal DESCRIPTION Called when the battery voltage is detected to be in a Normal state */ static void powerManagerHandleVbatNormal(uint8 level) { #ifndef NO_LED bool low_batt = powerManagerIsVbatLow(); #endif PM_DEBUG(("PM: Battery Normal %d\n", level)); MessageSend(&theSink.task, EventSysBatteryOk, 0); /* If charger connected send a charger gas gauge message (these don't have any functional use but can be associated with LEDs/tones) */ if (powerManagerIsChargerConnected()) MessageSend(&theSink.task, (EventSysChargerGasGauge0+level), 0); /* reset any low battery warning that may be in place */ theSink.battery_state = POWER_BATT_LEVEL0 + level; csr2csrHandleAgBatteryRequestRes(level); #ifndef NO_LED /* when changing from low battery state to a normal state, refresh the led state pattern to replace the low battery pattern should it have been shown */ if(low_batt) LEDManagerIndicateState(stateManagerGetState()); #endif AudioSetPower(powerManagerGetLBIPM()); }
/**************************************************************************** NAME LedsEnableFilter DESCRIPTION enable / disable a given filter ID RETURNS void */ static void LedsEnableFilter ( uint16 pFilter , bool pEnable) { uint32 lOldMask = LED_GETACTIVEFILTERS() ; if (pEnable) { /*to set*/ LED_SETACTIVEFILTERS((lOldMask | ( (uint32)0x1 << pFilter ))); LED_DEBUG(("LED: EnF [%lx] [%lx] [%x]\n", lOldMask , LED_GETACTIVEFILTERS() , pFilter)); } else { /*to unset*/ LED_SETACTIVEFILTERS(lOldMask & ~( (uint32)0x1 << pFilter )); LED_DEBUG(("LED: DisF [%lx] [%lx] [%x]\n", lOldMask , LED_GETACTIVEFILTERS() , pFilter)); } #ifndef NO_LED /* Check if we should indicate state */ if ((theSink.theLEDTask->gEventFilters[pFilter].OverideDisable) && (lOldMask != LED_GETACTIVEFILTERS())) LEDManagerIndicateState ( stateManagerGetState () ) ; #endif }
/**************************************************************************** NAME LedsCheckForFilter DESCRIPTION This function checksif a filter has been configured for the given event, if it has then activates / deactivates the filter Regardless of whether a filter has been activated or not, the event is signalled as completed as we have now deaklt with it (only checked for a filter if a pattern was not associated. RETURNS void */ void LedsCheckForFilter ( sinkEvents_t pEvent ) { uint16 lFilterIndex = 0 ; for (lFilterIndex = 0 ; lFilterIndex < theSink.theLEDTask->gLMNumFiltersUsed ; lFilterIndex ++ ) { LEDFilter_t *lEventFilter = &(theSink.theLEDTask->gEventFilters [ lFilterIndex ]); if((uint16)(lEventFilter->Event) == pEvent && lEventFilter->FilterType != DISABLED) { if (lEventFilter->FilterType != CANCEL) { /* Check filter isn't already enabled */ if (!LedsIsFilterEnabled(lFilterIndex)) { /* Enable filter */ LedsEnableFilter (lFilterIndex , TRUE) ; /* If it is an overide fLED filter and the currently playing pattern is OFF then turn on the overide led immediately*/ if ( lEventFilter->FilterType == OVERRIDE) { uint16 lOverideLEDIndex = lEventFilter->OverideLED ; /* this should only happen if the led in question is currently off*/ if ( theSink.theLEDTask->gActiveLEDS[lOverideLEDIndex].OnOrOff == LED_OFF) { LED_DEBUG(("LED: FilEnable Turn on[%d][%d] \n",lFilterIndex + 1 , lOverideLEDIndex )) ; PioSetLedPin ( lOverideLEDIndex , LED_ON) ; } } } } else { uint16 lFilterToCancel = lEventFilter->FilterToCancel ; /*disable the according filter*/ if ( lFilterToCancel != 0 ) { uint16 lFilterToCancelIndex = lFilterToCancel - 1 ; LEDFilter_t *lEventFilter1 = &(theSink.theLEDTask->gEventFilters [ lFilterToCancelIndex ]); uint16 lOverideLEDIndex = lEventFilter1->OverideLED ; LED_DEBUG(("LED: FilCancel[%d][%d] [%d]\n",lFilterIndex + 1 , lFilterToCancel , lFilterToCancelIndex )) ; /*lFilter To cancel = 1-n, LedsEbnable filter requires 0-n */ LedsEnableFilter (lFilterToCancelIndex , FALSE ) ; if ( theSink.theLEDTask->gActiveLEDS[lOverideLEDIndex].OnOrOff == LED_OFF) { /* LedsHandleOverideLED ( theSink.theLEDTask , LED_OFF) ;*/ if ( lEventFilter1->FilterType == OVERRIDE) { LED_DEBUG(("LED: FilCancel Turn off[%d][%d] [%d]\n",lFilterIndex + 1 , lFilterToCancel , lFilterToCancelIndex )) ; PioSetLedPin ( lOverideLEDIndex, LED_OFF) ; /* it is possible for the cancel filter to turn off leds used in a solid led state indication such as a solid blue pairing indication, should the charger be removed and then reinserted the solid blue state is turned off, this call will reset the state indication and turn it back on again */ #ifndef NO_LED LEDManagerIndicateState ( stateManagerGetState () ) ; #endif } } } else { LED_DEBUG(("LED: Fil !\n")) ; } } LED_DEBUG(("LM : Filter Found[%d]A[%x] [%d]\n", lFilterIndex + 1, pEvent , theSink.theLEDTask->gEventFilters[ lFilterIndex ].IsFilterActive )) ; } } }