• 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 <mutex>
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 class ThermalConfigSensorCluster {
43 public:
44     bool Init();
45     void UpdateThermalLevel(TypeTempMap &typeTempInfo);
46     void CalculateSensorLevel(TypeTempMap &typeTempInfo, std::vector<uint32_t> &levelList, uint32_t &level);
47     bool IsAuxSensorTrigger(TypeTempMap &typeTempInfo, uint32_t &level);
48     bool IsTempRateTrigger(TypeTempMap &typeTempInfo, uint32_t &level);
49     void AscJudgment(std::vector<LevelItem> &vlev, int32_t curTemp, uint32_t &level);
50     void DescJudgment(std::vector<LevelItem> &vlev, int32_t curTemp, uint32_t &level);
51     static bool CmpValue(const std::pair<std::string, uint32_t> left, const std::pair<std::string, uint32_t> right);
52 
53     void Dump();
54     uint32_t GetCurrentLevel();
55     bool GetDescFlag();
56     bool GetAuxFlag();
57     bool GetRateFlag();
58 
59     SensorInfoMap GetSensorInfoList();
60     AuxSensorInfoMap GetAuxSensorInfoList();
61     void SetSensorLevelInfo(SensorInfoMap &sensorInfolist);
62     void SetAuxSensorLevelInfo(AuxSensorInfoMap &auxSensorInfolist);
63     void SetDescFlag(bool descflag);
64     void SetAuxFlag(bool auxflag);
65     void SetRateFlag(bool rateFlag);
66 private:
67     bool descFlag_ {false};
68     bool auxFlag_ {false};
69     bool rateFlag_ {false};
70     uint32_t latestLevel_;
71     SensorInfoMap sensorInfolist_;
72     AuxSensorInfoMap auxSensorInfolist_;
73     std::map<std::string, bool> isRateMap_;
74     std::mutex levelMutex_;
75 };
76 } // namespace PowerMgr
77 } // namesapce OHOS
78 
79 #endif // THERMAL_CONFIG_SENSOR_CLUSTER_H