Home | History | Annotate | Download | only in thermal
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef __SENSORS_H__
     18 #define __SENSORS_H__
     19 
     20 #include <string>
     21 #include <tuple>
     22 #include <unordered_map>
     23 
     24 #include <android/hardware/thermal/1.1/IThermal.h>
     25 
     26 namespace android {
     27 namespace hardware {
     28 namespace thermal {
     29 namespace V1_1 {
     30 namespace implementation {
     31 
     32 using ::android::hardware::thermal::V1_0::Temperature;
     33 using ::android::hardware::thermal::V1_0::TemperatureType;
     34 
     35 class Sensors {
     36     public:
     37      Sensors() = default;
     38      ~Sensors() = default;
     39      Sensors(const Sensors&) = delete;
     40      void operator=(const Sensors&) = delete;
     41 
     42      std::string getSensorPath(const std::string& sensor_name);
     43      // Returns true if add was successful, false otherwise.
     44      bool addSensor(
     45          const std::string& sensor_name, const std::string& path,
     46          const float throttling_threshold, const float shutdown_threshold,
     47          const float vr_threshold, const TemperatureType& type);
     48      // If sensor is not found in the sensor names to path map, this will set
     49      // data and file path to empty and return false.  If the sensor is found,
     50      // this function will fill in data and file_path accordingly then return
     51      // true.
     52      bool readSensorFile(
     53          const std::string& sensor_name, std::string* data,
     54          std::string* file_path) const;
     55      bool readTemperature(
     56          const std::string& sensor_name, const float mult,
     57          Temperature* out) const;
     58      size_t getNumSensors() const { return sensor_name_to_data_map_.size(); }
     59 
     60     private:
     61      // A map containing sensor names along with its thermal zone number, its
     62      // thresholds, and its type. The tuple is formatted as such:
     63      // <path, throttling threshold, shutdown threshold, vr threshold, type>
     64      std::unordered_map<std::string, std::tuple<
     65          std::string, float, float, float, TemperatureType>>
     66          sensor_name_to_data_map_;
     67 };
     68 
     69 }  // namespace implementation
     70 }  // namespace V1_1
     71 }  // namespace thermal
     72 }  // namespace hardware
     73 }  // namespace android
     74 
     75 #endif  // __SENSORS_H__
     76 
     77