Skip to content

Commit

Permalink
Added 3 functions CpuTemp GpuTemp CpuFrequency
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Feb 12, 2014
1 parent 2ab2929 commit cf51866
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/PhpGpio/Pi.php
Expand Up @@ -15,4 +15,36 @@ public function getVersion()

return 0;
}

public function getCpuLoad()
{
return sys_getloadavg();
}

public function getCpuTemp($fahrenheit = false)
{
$cputemp = floatval(file_get_contents('/sys/class/thermal/thermal_zone0/temp'))/1000;

if($fahrenheit)
$cputemp = 1.8* $cputemp+32;

return $cputemp;
}

public function getGpuTemp($fahrenheit = false)
{
$gputemp = floatval(str_replace(array('temp=', '\'C'), '', exec('/opt/vc/bin/vcgencmd measure_temp')));

if($fahrenheit)
$gputemp = 1.8* $gputemp+32;

return $gputemp;
}

public function getCpuFrequency()
{
$frequency = floatval(file_get_contents('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq'))/1000;

return $frequency;
}
}
37 changes: 37 additions & 0 deletions tests/PhpGpio/Tests/PiTest.php
Expand Up @@ -38,4 +38,41 @@ public function testGetVersion()

}

public function testGetCpuLoad()
{
$this->assertPreconditionOrMarkTestSkipped();
$this->assertTrue($this->pi instanceof Pi);
$result = $this->pi->getCpuLoad();
$this->assertTrue(is_array($result));
$this->assertCount(3, $result);

}

public function testGetCpuTemp()
{
$this->assertPreconditionOrMarkTestSkipped();
$this->assertTrue($this->pi instanceof Pi);
$result = $this->pi->getCpuTemp();
$this->assertInternalType('float' , $result);

}

public function testGetGpuTemp()
{
$this->assertPreconditionOrMarkTestSkipped();
$this->assertTrue($this->pi instanceof Pi);
$result = $this->pi->getGpuTemp();
$this->assertInternalType('float' , $result);

}

public function testGetCpuFrequence()
{
$this->assertPreconditionOrMarkTestSkipped();
$this->assertTrue($this->pi instanceof Pi);
$result = $this->pi->getCpuFrequency();
$this->assertInternalType('float' , $result);

}

}

0 comments on commit cf51866

Please sign in to comment.