|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* pitemp sensor class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI_Sensor |
|
9
|
|
|
* @author Marc Hillesheim <[email protected]> |
|
10
|
|
|
* @copyright 2012 Marc Hillesheim |
|
11
|
|
|
* @link http://pi.no-ip.biz |
|
12
|
|
|
*/ |
|
13
|
|
|
class PiTemp extends Sensors |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
private function _temperature() |
|
16
|
|
|
{ |
|
17
|
|
|
$temp = null; |
|
18
|
|
|
$temp_max = null; |
|
19
|
|
|
if (!CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input', $temp, 0, 4096, false)) { // Not Banana Pi |
|
20
|
|
|
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/temp', $temp); |
|
21
|
|
|
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/trip_point_0_temp', $temp_max, 0, 4096, PSI_DEBUG); |
|
22
|
|
|
} |
|
23
|
|
|
if (!is_null($temp) && (trim($temp) != "")) { |
|
24
|
|
|
$dev = new SensorDevice(); |
|
25
|
|
|
$dev->setName("CPU 1"); |
|
26
|
|
|
$dev->setValue($temp / 1000); |
|
27
|
|
|
if (!is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) { |
|
28
|
|
|
$dev->setMax($temp_max / 1000); |
|
29
|
|
|
} |
|
30
|
|
|
$this->mbinfo->setMbTemp($dev); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
private function _voltage() |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
$volt = null; |
|
37
|
|
|
if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/voltage_now', $volt, 0, 4096, false) && !is_null($volt) && (trim($volt) != "")) { // Banana Pi |
|
38
|
|
|
$dev = new SensorDevice(); |
|
39
|
|
|
$dev->setName("Voltage 1"); |
|
40
|
|
|
$dev->setValue($volt / 1000000); |
|
41
|
|
|
$this->mbinfo->setMbVolt($dev); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
private function _current() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
$current = null; |
|
48
|
|
|
if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/current_now', $current, 0, 4096, false) && !is_null($current) && (trim($current) != "")) { // Banana Pi |
|
49
|
|
|
$dev = new SensorDevice(); |
|
50
|
|
|
$dev->setName("Current 1"); |
|
51
|
|
|
$dev->setValue($current / 1000000); |
|
52
|
|
|
$this->mbinfo->setMbCurrent($dev); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function build() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->_temperature(); |
|
59
|
|
|
$this->_voltage(); |
|
60
|
|
|
$this->_current(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.