Skip to content

FOperatingSystemBattery

#include <OperatingSystemSimulator/Public/OperatingSystemBattery.h>
---
config:
  class:
    hideEmptyMembersBox: true
---
classDiagram
  class FOperatingSystemBattery["FOperatingSystemBattery"]
  class EOperatingSystemBatteryEfficiencyLoss["EOperatingSystemBatteryEfficiencyLoss"]
  FOperatingSystemBattery ..> EOperatingSystemBatteryEfficiencyLoss
---
config:
  class:
    hideEmptyMembersBox: true
---
classDiagram
  class FOperatingSystemBattery {
    +BatteryName : FText
    +BatteryBrand : FText
    +BatteryCapacity : float
    +ChargeRate : float
    +EfficiencyLoss : EOperatingSystemBatteryEfficiencyLoss()
    +Validate(FGenericError &OutError) const
    +GetEfficiencyLossValue() const float
    +GetBatteryHealth(const bool bNormalize) const float
    +GetTimeToFullyRechargeInSeconds() const float
    +GetHealthState() const EOperatingSystemBatteryHealthState()
    +GetHealthStateString() const FString
    +operator==(const FOperatingSystemBattery &Other) const bool
    +FOperatingSystemBattery()
    +FOperatingSystemBattery(const FText &BatteryName, const FText &Batt
  }

Documented call sites inside the plugin (3):

flowchart LR
  FOperatingSystemBattery__Validate["FOperatingSystemBattery::Validate"]
  AOperatingSystemPortableDeviceActor__BeginChargingBattery["AOperatingSystemPortableDeviceActor::BeginChargingBattery"]
  AOperatingSystemPortableDeviceActor__BeginChargingBattery --> FOperatingSystemBattery__Validate
  AOperatingSystemPortableDeviceActor__OnValidate["AOperatingSystemPortableDeviceActor::OnValidate"]
  AOperatingSystemPortableDeviceActor__OnValidate --> FOperatingSystemBattery__Validate
  AOperatingSystemPortableDeviceActor__SetBattery["AOperatingSystemPortableDeviceActor::SetBattery"]
  AOperatingSystemPortableDeviceActor__SetBattery --> FOperatingSystemBattery__Validate
struct FOperatingSystemBattery

Defined in OperatingSystemBattery.h:87 Represents the save/load data for a portable device battery.

FOperatingSystemBattery is a struct that represents the properties and behavior of an operating system battery.

This struct stores the save/load data for a portable device battery. It includes information such as whether the battery is present, the battery level, and whether the device is a portable device or not.

See also: FOperatingSystemDeviceSaveLoad

ReturnNameDescription
FTextBatteryNameBattery Name
FTextBatteryBrandBrand name of this battery.
floatBatteryCapacityTotal battery power. In milli-amp Hour units
floatChargeRateSpeed at which this battery should charge. Higher rate charges battery faster.
EOperatingSystemBatteryEfficiencyLossEfficiencyLossSimulates energy loss while charging. Higher loss means more time to charge. This can also be considered as battery health. Higher loss means less healthy. For example: A battery with 3200 mAh and charge rate of 1000 mA will take 3.2 hours to fully charge without energy loss. With 40% energy loss it would take 4.5 hours to fully charge.

FText BatteryName

Defined in OperatingSystemBattery.h:93 Battery Name


FText BatteryBrand

Defined in OperatingSystemBattery.h:97 Brand name of this battery.


float BatteryCapacity

Defined in OperatingSystemBattery.h:101 Total battery power. In milli-amp Hour units


float ChargeRate

Defined in OperatingSystemBattery.h:105 Speed at which this battery should charge. Higher rate charges battery faster.


EOperatingSystemBatteryEfficiencyLoss EfficiencyLoss

Defined in OperatingSystemBattery.h:111 Simulates energy loss while charging. Higher loss means more time to charge. This can also be considered as battery health. Higher loss means less healthy. For example: A battery with 3200 mAh and charge rate of 1000 mA will take 3.2 hours to fully charge without energy loss. With 40% energy loss it would take 4.5 hours to fully charge.

ReturnNameDescription
voidValidate const inlineValidates the battery properties.
floatGetEfficiencyLossValue const inlineGet the efficiency loss value based on the current efficiency loss setting.
floatGetBatteryHealth const inlineGet the battery health value.
floatGetTimeToFullyRechargeInSeconds const inlineCalculate the time required to fully recharge the battery in seconds.
EOperatingSystemBatteryHealthStateGetHealthState const inlineGets the health state of the battery.
FStringGetHealthStateString const inlineGet the health state of the battery as a string representation.
booloperator== const inline
FOperatingSystemBattery inline
FOperatingSystemBattery inline

const inline

inline void Validate(FGenericError & OutError) const

Defined in OperatingSystemBattery.h:127 Validates the battery properties.

  • OutError The error object to store the validation error.

This method validates the battery properties and sets the OutError object with the validation error if any. The battery properties that are validated include:

  • BatteryName: The battery name should not be empty or consist of only whitespace.

  • BatteryBrand: The battery must have a valid brand set which is not empty or consist of only whitespace.

  • BatteryCapacity: The battery capacity must be 1000 or higher.

  • ChargeRate: The charge rate must be 1000 or higher.

If any of the above validations fail, the OutError object is set with the corresponding error message and the method returns early.


const inline

inline float GetEfficiencyLossValue() const

Defined in OperatingSystemBattery.h:183 Get the efficiency loss value based on the current efficiency loss setting.

The efficiency loss value.

This will return a float value that represents the percentage of energy loss while charging the battery.

The possible efficiency loss settings and their corresponding efficiency loss values are as follows:

  • TenPercent: 11.0

  • TwentyPercent: 12.0

  • ThirtyPercent: 13.0

  • FortyPercent: 14.0

  • FiftyPercent: 15.0

  • SixtyPercent: 16.0

  • SeventyPercent: 17.0

  • EightyPercent: 18.0

  • NinetyPercent: 19.0

  • NoLoss (Default): 10.0

If the efficiency loss setting is not recognized, the method returns the default efficiency loss value of 10.0.

Example usage:

FOperatingSystemBattery Battery;
Battery.EfficiencyLoss = EOperatingSystemBatteryEfficiencyLoss::FiftyPercent;
float LossValue = Battery.GetEfficiencyLossValue(); // Returns 15.0
  • EfficiencyLoss
  • EightyPercent
  • FiftyPercent
  • FortyPercent
  • NinetyPercent
  • NoLoss
  • SeventyPercent
  • SixtyPercent
  • TenPercent
  • ThirtyPercent
  • TwentyPercent

const inline

inline float GetBatteryHealth(const bool bNormalize) const

Defined in OperatingSystemBattery.h:235 Get the battery health value.

  • bNormalize Flag indicating whether to normalize the battery health value.

The battery health value.

This method returns the battery health value as a float. The battery health value represents the percentage of energy loss while charging the battery. By default, the efficiency loss value is calculated using the formula ((static_cast<uint8>(EfficiencyLoss) + 1) * 100.f) / 10.f. If bNormalize is true, the efficiency loss value is normalized to a range of [0, 1] using the formula (static_cast<uint8>(EfficiencyLoss) + 1) / 10.f.

Example usage:

FOperatingSystemBattery Battery;
Battery.EfficiencyLoss = EOperatingSystemBatteryEfficiencyLoss::FiftyPercent;
// Returns the default battery health value
float HealthValue = Battery.GetBatteryHealth(false);
// Returns the battery health value normalized to [0, 1]
float NormalizedHealthValue = Battery.GetBatteryHealth(true);

const inline

inline float GetTimeToFullyRechargeInSeconds() const

Defined in OperatingSystemBattery.h:261 Calculate the time required to fully recharge the battery in seconds.

The time required to fully recharge the battery in seconds.

This method calculates the time required to fully recharge the battery in seconds based on the battery capacity, charge rate, and efficiency loss value. The formula used to calculate the time is: ((BatteryCapacity / ChargeRate) * GetEfficiencyLossValue()) / 10.f) * 3600.f

Please note that the efficiency loss value is obtained by calling the GetEfficiencyLossValue() method. The efficiency loss value represents the percentage of energy loss while charging the battery.

Example usage:

FOperatingSystemBattery Battery;
Battery.BatteryCapacity = 3200.f;
Battery.ChargeRate = 1000.f;
Battery.EfficiencyLoss = EOperatingSystemBatteryEfficiencyLoss::FortyPercent;
float TimeToFullyRecharge = Battery.GetTimeToFullyRechargeInSeconds(); // Returns the time required to fully recharge the battery in seconds

const inline

inline EOperatingSystemBatteryHealthState GetHealthState() const

Defined in OperatingSystemBattery.h:279 Gets the health state of the battery.

This method returns the current health state of the battery based on the efficiency loss value. The efficiency loss value is compared to predefined thresholds to determine the health state.

The health state of the battery:

  • Unhealthy if the efficiency loss is 10%, 20%, or 30%

  • Poor if the efficiency loss is 40%, 50%, or 60%

  • Critical if the efficiency loss is 70%, 80%, or 90%

  • Healthy if the efficiency loss does not match any predefined thresholds

  • Critical
  • EfficiencyLoss
  • EightyPercent
  • FiftyPercent
  • FortyPercent
  • Healthy
  • NinetyPercent
  • Poor
  • SeventyPercent
  • SixtyPercent
  • TenPercent
  • ThirtyPercent
  • TwentyPercent
  • Unhealthy

const inline

inline FString GetHealthStateString() const

Defined in OperatingSystemBattery.h:317 Get the health state of the battery as a string representation.

This method returns a string that represents the health state of the battery. The health state is determined by the value returned by the GetHealthState() method. The possible health states and their corresponding string representations are as follows:

  • EOperatingSystemBatteryHealthState::Healthy: “Healthy”

  • EOperatingSystemBatteryHealthState::Unhealthy: “Unhealthy”

  • EOperatingSystemBatteryHealthState::Poor: “Poor”

  • EOperatingSystemBatteryHealthState::Critical: “Critical”

If the health state does not match any of the above values, the method will return “Unknown”.

A string that represents the health state of the battery.


const inline

inline bool operator==(const FOperatingSystemBattery & Other) const

Defined in OperatingSystemBattery.h:336


inline

inline FOperatingSystemBattery()

inline

inline FOperatingSystemBattery(const FText & BatteryName, const FText & BatteryBrand)

Defined in OperatingSystemBattery.h:354