blob: 5384307dde2e8f7a21582844cde1b39e43fd160f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include "LibThermal.h"
namespace android {
namespace hardware {
namespace thermal {
namespace V2_0 {
namespace implementation {
struct thermal_zone *LibThermal::getThermalZone(int id)
{
return thermal_zone_find_by_id(this->m_tz, id);
}
struct thermal_zone *LibThermal::getThermalZone(std::string name)
{
return thermal_zone_find_by_name(this->m_tz, name.c_str());
}
int LibThermal::getThermalZonetemp(struct thermal_zone *tz)
{
if (thermal_cmd_get_temp(this->m_th, tz)) {
LOG(ERROR) << "Failed to read '" << tz->name << "' temperature";
return INT_MAX;
}
return tz->temp;
}
int LibThermal::getThermalZonetemp(int id)
{
struct thermal_zone *tz;
tz = getThermalZone(id);
if (!tz) {
LOG(ERROR) << "Thermal zone <id=" << id << "> not found";
return INT_MAX;
}
return getThermalZonetemp(tz);
}
int LibThermal::getThermalZonetemp(const std::string name)
{
struct thermal_zone *tz;
tz = getThermalZone(name);
if (!tz) {
LOG(ERROR) << "Thermal zone <" << name << "> not found";
return INT_MAX;
}
return getThermalZonetemp(tz);
}
bool LibThermal::init(LibThermalCallbacks &cb)
{
m_ops.events.tz_create = cb.thermalZoneCreate;
m_ops.events.tz_delete = cb.thermalZoneDelete;
m_ops.events.tz_disable = cb.thermalZoneDisable;
m_ops.events.tz_enable = cb.thermalZoneEnable;
m_ops.events.trip_high = cb.tripHigh;
m_ops.events.trip_low = cb.tripLow;
m_ops.events.trip_add = cb.tripAdd;
m_ops.events.trip_delete = cb.tripDelete;
m_ops.events.trip_change = cb.tripChange;
m_ops.events.cdev_add = cb.cdevAdd;
m_ops.events.cdev_delete = cb.cdevDelete;
m_ops.events.cdev_update = cb.cdevUpdate;
m_ops.events.gov_change = cb.govChange;
m_ops.sampling.tz_temp = cb.thermalZoneTemp;
m_th = thermal_init(&m_ops);
if (!m_th) {
LOG(ERROR) << "Failed to initialize the thermal library";
return false;
}
m_tz = thermal_zone_discover(m_th);
if (!m_tz) {
LOG(ERROR) << "Failed to discover the thermal zones";
return false;
}
return true;
}
} // namespace implementation
} // namespace V2_0
} // namespace thermal
} // namespace hardware
} // namespace android
|