1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BATTERY_SRV_BATERY_INFO_H 17 #define BATTERY_SRV_BATERY_INFO_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace PowerMgr { 23 static constexpr int32_t INVALID_BATT_INT_VALUE = -1; 24 static constexpr int32_t INVALID_BATT_TEMP_VALUE = 100; 25 static constexpr int32_t INVALID_BATT_LEVEL_VALUE = -1; 26 static constexpr int64_t INVALID_REMAINING_CHARGE_TIME_VALUE = -1; 27 static const std::string INVALID_STRING_VALUE = "Invalid"; 28 static constexpr bool INVALID_BATT_BOOL_VALUE = true; 29 30 /** 31 * Type for acquire BatteryChargeState. 32 */ 33 enum class BatteryChargeState : uint32_t { 34 /** 35 * Battery is discharge. 36 */ 37 CHARGE_STATE_NONE, 38 39 /** 40 * Battery is charging. 41 */ 42 CHARGE_STATE_ENABLE, 43 44 /** 45 * Battery is not charging. 46 */ 47 CHARGE_STATE_DISABLE, 48 49 /** 50 * Battery charge full. 51 */ 52 CHARGE_STATE_FULL, 53 54 /** 55 * The bottom of the enum. 56 */ 57 CHARGE_STATE_BUTT 58 }; 59 60 /** 61 * Type for acquire BatteryHealthState. 62 */ 63 enum class BatteryHealthState : uint32_t { 64 /** 65 * Health Status: unknown. 66 */ 67 HEALTH_STATE_UNKNOWN, 68 69 /** 70 * Health Status: good. 71 */ 72 HEALTH_STATE_GOOD, 73 74 /** 75 * Health Status: over heat. 76 */ 77 HEALTH_STATE_OVERHEAT, 78 79 /** 80 * Health Status: over voltage. 81 */ 82 HEALTH_STATE_OVERVOLTAGE, 83 84 /** 85 * Health Status: COLD. 86 */ 87 HEALTH_STATE_COLD, 88 89 /** 90 * Health Status: Dead. 91 */ 92 HEALTH_STATE_DEAD, 93 94 /** 95 * The bottom of the enum. 96 */ 97 HEALTH_STATE_BUTT 98 }; 99 100 /** 101 * Type for acquire BatteryPluggedType. 102 */ 103 enum class BatteryPluggedType : uint32_t { 104 /** 105 * Power source is unplugged. 106 */ 107 PLUGGED_TYPE_NONE, 108 109 /** 110 * Power source is an AC charger. 111 */ 112 PLUGGED_TYPE_AC, 113 114 /** 115 * Power source is a USB DC charger. 116 */ 117 PLUGGED_TYPE_USB, 118 119 /** 120 * Power source is wireless charger. 121 */ 122 PLUGGED_TYPE_WIRELESS, 123 124 /** 125 * The bottom of the enum. 126 */ 127 PLUGGED_TYPE_BUTT 128 }; 129 130 /** 131 * Battery charge level of a device 132 */ 133 enum class BatteryLevel : uint32_t { 134 /** 135 * Unknown level 136 */ 137 LEVEL_NONE, 138 139 /** 140 * High level 141 */ 142 LEVEL_HIGH, 143 144 /** 145 * Normal level 146 */ 147 LEVEL_NORMAL, 148 149 /** 150 * Low level 151 */ 152 LEVEL_LOW, 153 154 /** 155 * Emergency level 156 */ 157 LEVEL_EMERGENCY, 158 159 /** 160 * Reserved 161 */ 162 LEVEL_RESERVED 163 }; 164 165 class BatteryInfo { 166 public: 167 enum { 168 COMMON_EVENT_CODE_CAPACITY = 0, 169 COMMON_EVENT_CODE_VOLTAGE = 1, 170 COMMON_EVENT_CODE_TEMPERATURE = 2, 171 COMMON_EVENT_CODE_HEALTH_STATE = 3, 172 COMMON_EVENT_CODE_PLUGGED_TYPE = 4, 173 COMMON_EVENT_CODE_PLUGGED_MAX_CURRENT = 5, 174 COMMON_EVENT_CODE_PLUGGED_MAX_VOLTAGE = 6, 175 COMMON_EVENT_CODE_CHARGE_STATE = 7, 176 COMMON_EVENT_CODE_CHARGE_COUNTER = 8, 177 COMMON_EVENT_CODE_PRESENT = 9, 178 COMMON_EVENT_CODE_TECHNOLOGY = 10, 179 }; 180 181 BatteryInfo() = default; 182 ~BatteryInfo() = default; SetCapacity(const int32_t capacity)183 void SetCapacity(const int32_t capacity) 184 { 185 capacity_ = capacity; 186 } 187 SetVoltage(const int32_t voltage)188 void SetVoltage(const int32_t voltage) 189 { 190 voltage_ = voltage; 191 } 192 SetTemperature(const int32_t temperature)193 void SetTemperature(const int32_t temperature) 194 { 195 temperature_ = temperature; 196 } 197 SetHealthState(const BatteryHealthState healthState)198 void SetHealthState(const BatteryHealthState healthState) 199 { 200 healthState_ = healthState; 201 } 202 SetPluggedType(const BatteryPluggedType pluggedType)203 void SetPluggedType(const BatteryPluggedType pluggedType) 204 { 205 pluggedType_ = pluggedType; 206 } 207 SetPluggedMaxCurrent(const int32_t maxCurrent)208 void SetPluggedMaxCurrent(const int32_t maxCurrent) 209 { 210 pluggedMaxCurrent_ = maxCurrent; 211 } 212 SetPluggedMaxVoltage(const int32_t maxVoltage)213 void SetPluggedMaxVoltage(const int32_t maxVoltage) 214 { 215 pluggedMaxVoltage_ = maxVoltage; 216 } 217 SetChargeState(const BatteryChargeState chargeState)218 void SetChargeState(const BatteryChargeState chargeState) 219 { 220 chargeState_ = chargeState; 221 } 222 SetChargeCounter(const int32_t chargeCounter)223 void SetChargeCounter(const int32_t chargeCounter) 224 { 225 chargeCounter_ = chargeCounter; 226 } 227 SetPresent(const bool present)228 void SetPresent(const bool present) 229 { 230 present_ = present; 231 } 232 SetTechnology(const std::string & technology)233 void SetTechnology(const std::string& technology) 234 { 235 technology_ = technology; 236 } 237 GetCapacity()238 const int32_t& GetCapacity() const 239 { 240 return capacity_; 241 } 242 GetVoltage()243 const int32_t& GetVoltage() const 244 { 245 return voltage_; 246 } 247 GetTemperature()248 const int32_t& GetTemperature() const 249 { 250 return temperature_; 251 } 252 GetHealthState()253 BatteryHealthState GetHealthState() const 254 { 255 return healthState_; 256 } 257 GetPluggedType()258 BatteryPluggedType GetPluggedType() const 259 { 260 return pluggedType_; 261 } 262 GetPluggedMaxCurrent()263 const int32_t& GetPluggedMaxCurrent() const 264 { 265 return pluggedMaxCurrent_; 266 } 267 GetPluggedMaxVoltage()268 const int32_t& GetPluggedMaxVoltage() const 269 { 270 return pluggedMaxVoltage_; 271 } 272 GetChargeState()273 BatteryChargeState GetChargeState() const 274 { 275 return chargeState_; 276 } 277 GetChargeCounter()278 const int32_t& GetChargeCounter() const 279 { 280 return chargeCounter_; 281 } 282 IsPresent()283 bool IsPresent() const 284 { 285 return present_; 286 } 287 GetTechnology()288 const std::string& GetTechnology() const 289 { 290 return technology_; 291 } 292 293 private: 294 int32_t capacity_ = INVALID_BATT_INT_VALUE; 295 int32_t voltage_ = INVALID_BATT_INT_VALUE; 296 int32_t temperature_ = INVALID_BATT_TEMP_VALUE; 297 BatteryHealthState healthState_ = BatteryHealthState::HEALTH_STATE_BUTT; 298 BatteryPluggedType pluggedType_ = BatteryPluggedType::PLUGGED_TYPE_BUTT; 299 int32_t pluggedMaxCurrent_ = INVALID_BATT_INT_VALUE; 300 int32_t pluggedMaxVoltage_ = INVALID_BATT_INT_VALUE; 301 BatteryChargeState chargeState_ = BatteryChargeState::CHARGE_STATE_BUTT; 302 int32_t chargeCounter_ = INVALID_BATT_INT_VALUE; 303 bool present_ = INVALID_BATT_BOOL_VALUE; 304 std::string technology_ = INVALID_STRING_VALUE; 305 }; 306 } // namespace PowerMgr 307 } // namespace OHOS 308 309 #endif // BATTERY_SRV_BATERY_INFO_H 310