/* * Used to update the background menu. DSi only. */ void updateBackgroundMenu() { /* * Checks if the system is a DSi. */ if (REG_DSIMODE == 0) { /* * If it is not a DSi, then we exit the method. */ return; } /* * Sets the battery's current charge. This is done * because when charging, things tend to get messed up if * the batter level is gotten. */ batteryLevel = getBatteryLevel(); /* * Sets whether the game should be paused or not. */ isPaused = pausedValue; /* * Creates a while loop while the system is paused. */ while (isPaused) { /* * Sets the battery's current charge. This is done * because when charging, things tend to get messed up if * the batter level is gotten. */ batteryLevel = getBatteryLevel(); /* * Sets whether the game should be paused or not. */ isPaused = pausedValue; /* * Updates the keys. */ scanKeys(); /* * Each time through, swiWaitForVBlank is called. */ swiWaitForVBlank(); } }
/*! \internal */ bool Ficgta01Battery::batteryIsFull() { qLog(PowerManagement) << __PRETTY_FUNCTION__; if(getBatteryLevel() + 3400 > 4200) return true; return false; }
float Grove_Joint::BatteryManager(void) { static bool ledFlip = false; static long clock = millis(); BatteryLevel = BatteryLevel * 0.6 + getBatteryLevel() * 0.4; if(BatteryLevel <= LowPowerValue) { if(millis()-clock >= 100) { clock = millis(); ledFlip ^= 1; } batteryLedOn(ledFlip); } else { batteryLedOn(OFF); } if(BatteryLevel <= DangerPowerValue) { batteryLedOn(ON); powerOff(); } return BatteryLevel; }
/* Function: void initHardware() * Description: * Parameter: * Return: */ void Grove_Joint::initHardware() { //pin initial pinMode(CHRG_LED, OUTPUT); pinMode(PWR, OUTPUT); pinMode(LED , OUTPUT); pinMode(KEY, INPUT); pinMode(PWR_HOLD, OUTPUT); pinMode(LIGHT_SENSOR, INPUT); pinMode(BATTERY_ADC, INPUT); digitalWrite(PWR, LOW); //power led digitalWrite(CHRG_LED, HIGH); digitalWrite(PWR_HOLD, LOW); //hold the power so the button can be used AmbientLight = initLightSensor(); //starting shining analogWrite(LED, 5); delay(500); analogWrite(LED, 0); delay(500); analogWrite(LED, 5); delay(500); analogWrite(LED, 0); //get battery level BatteryLevel = getBatteryLevel(); }
//------------------------------------------------------------------------------------------------------------------------------------------------------ //set abstract state void Update_Battery_Level(int rawAN7data, int rawAN6data) //setting abtract control of Servo Steer device -50% to 0 to 50% { while(pthread_mutex_lock(&POS_Battery_Write_Lock) != 0) //prevent thread lock up { usleep(1027+(rawAN7data%10)); //odd number for timer } #if defined(LINEAR_BATTERY_POWER_ESTIMATE) //calculate estimates... POS_Battery_Logic_Board_Value = (BATTERY_LOGIC_BOARD_BITSTEP_VALUE*(rawAN7data - BATTERY_LOGIC_BOARD_DEPLETED_VOLTAGE_BITVALUE)); POS_Battery_Motor_Value = (BATTERY_MOTOR_BITSTEP_VALUE*(rawAN6data - BATTERY_MOTOR_DEPLETED_VOLTAGE_BITVALUE)); if(POS_Battery_Logic_Board_Value > BATTERY_SCALE_RESOLUTION_INT){ POS_Battery_Logic_Board_Value = (BATTERY_SCALE_RESOLUTION_INT); } if(POS_Battery_Motor_Value > BATTERY_SCALE_RESOLUTION_INT){ POS_Battery_Motor_Value = (BATTERY_SCALE_RESOLUTION_INT); } #else //Limit battery characterization data (0% if <= min, 100% if >= max) if(rawAN7data > BATTERY_LOGIC_BOARD_FULL_VOLTAGE_BITVALUE ){ rawAN7data = BATTERY_LOGIC_BOARD_FULL_VOLTAGE_BITVALUE; } if(rawAN6data > BATTERY_MOTOR_FULL_VOLTAGE_BITVALUE){ rawAN6data = BATTERY_MOTOR_FULL_VOLTAGE_BITVALUE; } //get characterized sample from tested data... POS_Battery_Logic_Board_Value = getBatteryLevel(rawAN7data); //assumes both battery packs are the same type POS_Battery_Motor_Value = getBatteryLevel(rawAN6data); #endif if((POS_Battery_Logic_Board_Value <= 0) || (POS_Battery_Motor_Value <= 0)) { printf("\33[10;1HBattery Error: Board=%i(%i%%), Motor=%i(%i%%)",rawAN7data,POS_Battery_Logic_Board_Value,rawAN6data,POS_Battery_Motor_Value); //Todo: consider 3 strikes safe shutdown }else{ printf("\33[10;1HBattery Levels: Board=%i%%, Motor=%i%%",POS_Battery_Logic_Board_Value,POS_Battery_Motor_Value); } pthread_mutex_unlock(&POS_Battery_Write_Lock); //enable other threads to write state }
/** * @brief This function handles TIM3 global interrupt request. * @param None * @retval None */ void TIM3_IRQHandler(void) { if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) { /* Get ADC values */ uint32_t bat_level_value=ADC_ConvertedValueTabPointer[1]*/*41*/ADC_TO_MV_CONSTANT; uint32_t regulatedOutputCurrentValue=ADC_ConvertedValueTabPointer[2]*ADC_TO_MA_CONSTANT; uint32_t bat_current_value=ADC_ConvertedValueTabPointer[3]*/*32*/ADC_TO_MA_CONSTANT; /* printf("Bat Level: %d\n\r", bat_level_value); printf("Bat charge current: %d\n\r", bat_current_value); printf("Reg output Level: %d\n\r", ADC_ConvertedValueTabPointer[0]*ADC_TO_MV_CONSTANT); printf("Reg output current: %d\n\r", regulatedOutputCurrentValue); printf("Charger Level: %d\n\r", ADC_ConvertedValueTabPointer[4]*ADC_TO_MV_CONSTANT); */ /* Check for the events related to the ADC values */ /* PC is turned off (it was previously on) */ if (state.regulatedOutputState==ON && regulatedOutputCurrentValue<CURRENT_ON_OFF_THRESHOLD && TurnOnDelyTime==0 && !noCurrentFlag /* && state.externalPowerSourceState==DISCONNECTED */ && pcOn) { NoCurrentTimeout=2; noCurrentFlag=true; } else if(noCurrentFlag && regulatedOutputCurrentValue>CURRENT_ON_OFF_THRESHOLD) { noCurrentFlag=false; if(!pcOn) pcOn=true; } if(noCurrentFlag && NoCurrentTimeout<=0 && pcOn) { /* Event EV.3 detected */ noCurrentFlag=false; EXTI_GenerateSWInterrupt(EXTI_Line9); } /* Battery below KO level */ if (state.batteryState==DISCHARGING && bat_level_value<BATTERY_KO_THRESHOLD && !batteryKoFlag) { BatteryKoTimeout=5; batteryKoFlag=true; } else if(batteryKoFlag) { if(bat_level_value>BATTERY_KO_THRESHOLD || state.externalPowerSourceState==CONNECTED) batteryKoFlag=false; } if(batteryKoFlag && BatteryKoTimeout<=0) { /* Event EV.6 detected */ batteryKoFlag=false; EXTI_GenerateSWInterrupt(EXTI_Line6); } /* Battery charge to constant voltage mode */ else if (state.batteryState==CHARGING_CC && bat_level_value>BAT_CC_CV_THRESHOLD) { /* Event EV.4 detected */ EXTI_GenerateSWInterrupt(EXTI_Line8); } /* Battery fully charged */ else if (state.batteryState==CHARGING_CV && bat_current_value<BAT_CURRENT_CHARGED_THRESHOLD) { /* Event EV.5 detected */ EXTI_GenerateSWInterrupt(EXTI_Line7); } getBatteryLevel(4, 3300, 3600, state.batteryState, bat_level_value); TIM_ClearITPendingBit(TIM3, TIM_IT_Update); } }
int _powerController::getBatteryLevel(){ return getBatteryLevel(); }
int get_BatteryLevelAsPercentage(void) { return 900 / getBatteryLevel(); }