• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 THERMAL_CONFIG_SENSOR_CLUSTER_H
17 #define THERMAL_CONFIG_SENSOR_CLUSTER_H
18 
19 #include <string>
20 #include <map>
21 #include <vector>
22 #include <memory>
23 
24 namespace OHOS {
25 namespace PowerMgr {
26 struct LevelItem {
27     int32_t threshold;
28     int32_t thresholdClr;
29     double tempRiseRate;
30     uint32_t level;
31 };
32 
33 struct AuxLevelItem {
34     int32_t lowerTemp;
35     int32_t upperTemp;
36     int32_t level;
37 };
38 
39 using TypeTempMap = std::map<std::string, int32_t>;
40 using SensorInfoMap = std::map<std::string, std::vector<LevelItem>>;
41 using AuxSensorInfoMap = std::map<std::string, std::vector<AuxLevelItem>>;
42 
43 class ThermalConfigSensorCluster {
44 public:
45     bool CheckStandard();
46     void UpdateThermalLevel(const TypeTempMap& typeTempInfo);
47 
48     uint32_t GetCurrentLevel();
49     void SetSensorLevelInfo(SensorInfoMap& sensorInfolist);
50     void SetAuxSensorLevelInfo(AuxSensorInfoMap& auxSensorInfolist);
51     void SetDescFlag(bool descflag);
52     void SetAuxFlag(bool auxflag);
53     void SetRateFlag(bool rateFlag);
54 
55 private:
56     void CalculateSensorLevel(const TypeTempMap& typeTempInfo, std::vector<uint32_t>& levelList);
57     void AscJudgment(std::vector<LevelItem>& levItems, int32_t curTemp, uint32_t& level);
58     void DescJudgment(std::vector<LevelItem>& levItems, int32_t curTemp, uint32_t& level);
59     void CheckExtraCondition(const TypeTempMap& typeTempInfo, uint32_t& level);
60     bool IsTempRateTrigger(uint32_t& level);
61     bool IsAuxSensorTrigger(const TypeTempMap& typeTempInfo, uint32_t& level);
62 
63     bool descFlag_ {false};
64     bool auxFlag_ {false};
65     bool rateFlag_ {false};
66     uint32_t latestLevel_ {0};
67     SensorInfoMap sensorInfolist_;
68     AuxSensorInfoMap auxSensorInfolist_;
69 };
70 
71 using SensorClusterPtr = std::shared_ptr<ThermalConfigSensorCluster>;
72 using SensorClusterMap = std::map<std::string, SensorClusterPtr>;
73 } // namespace PowerMgr
74 } // namesapce OHOS
75 #endif // THERMAL_CONFIG_SENSOR_CLUSTER_H
76