Skip to content

Commit 4d83dbb

Browse files
committed
Added a fahrenheit mode for the temperature
1 parent ba24aff commit 4d83dbb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

RpiInternalSensors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
class RpiInternalSensors:
44

5-
def get_cpu_temp(self):
5+
def get_cpu_temp(self, fahrenheit=False):
66
lines = subprocess.check_output(["vcgencmd", "measure_temp"])
7-
temp = self.parse_lines(lines)['temp'][:-2]
7+
temp = float(self.parse_lines(lines)['temp'][:-2])
8+
9+
if fahrenheit:
10+
temp = ((temp * 9.0)/5.0) + 32
11+
812
return temp
913

1014
def get_ram_split(self):

print_all_sensors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
sen = RpiInternalSensors()
44

5-
print sen.get_cpu_temp()
5+
print sen.get_cpu_temp(), "'C"
6+
print sen.get_cpu_temp(fahrenheit=True), "'F"
67
print sen.get_ram_split()

0 commit comments

Comments
 (0)