1 /* 2 * Copyright (c) 2022 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_CONFIG_H 17 #define BATTERY_CONFIG_H 18 19 #include <fstream> 20 #include <string> 21 #include <vector> 22 #include <json/json.h> 23 24 namespace OHOS { 25 namespace HDI { 26 namespace Battery { 27 namespace V1_0 { 28 class BatteryConfig { 29 public: 30 struct LedConf { 31 int capacityBegin; 32 int capacityEnd; 33 int color; 34 int brightness; 35 }; 36 37 struct TempConf { 38 int lower; 39 int upper; 40 }; 41 42 int32_t Init(); 43 std::vector<LedConf> GetLedConf(); 44 BatteryConfig::TempConf GetTempConf(); 45 int GetCapacityConf(); 46 47 private: 48 enum JsonConfIndex { 49 INDEX_ZERO = 0, 50 INDEX_ONE, 51 INDEX_TWO, 52 INDEX_THREE, 53 }; 54 55 int32_t ParseLedConf(Json::Value& root); 56 int32_t ParseTempConf(Json::Value& root); 57 int32_t ParseCapacityConf(Json::Value& root); 58 int32_t ParseConfig(const std::string filename); 59 std::vector<BatteryConfig::LedConf> ledConf_; 60 struct TempConf tempConf_; 61 int capacityConf_ = -1; 62 }; 63 } // namespace V1_0 64 } // namespace Battery 65 } // namespace HDI 66 } // namespace OHOS 67 #endif 68