Skip to content

Commit c3bdc34

Browse files
committed
Refactor CPU throttle reason retrieval and consolidate throttle state logic
1 parent 1ab02fc commit c3bdc34

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

photon-core/src/main/java/org/photonvision/common/hardware/metrics/SystemMonitorRaspberryPi.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ public class SystemMonitorRaspberryPi extends SystemMonitor {
2525

2626
@Override
2727
public String getCpuThrottleReason() {
28-
int state = 0;
29-
String output = vcgencmd("get_throttled");
30-
try {
31-
state = Integer.decode(output);
32-
} catch (NumberFormatException e) {
33-
logger.warn("Could not parse return value: " + output);
34-
}
28+
int state = getThrottleState();
3529
if ((state & 0x01) != 0) {
3630
return "LOW VOLTAGE";
3731
} else if ((state & 0x08) != 0) {
@@ -44,6 +38,22 @@ public String getCpuThrottleReason() {
4438
return "None";
4539
}
4640

41+
@Override
42+
public boolean isThermallyThrottling() {
43+
return (getThrottleState() & 0x08) != 0;
44+
}
45+
46+
private int getThrottleState() {
47+
int state = 0;
48+
String output = vcgencmd("get_throttled");
49+
try {
50+
state = Integer.decode(output);
51+
} catch (NumberFormatException e) {
52+
logger.warn("Could not parse return value: " + output);
53+
}
54+
return state;
55+
}
56+
4757
@Override
4858
public double getGpuMem() {
4959
String output = vcgencmd("get_mem gpu");

0 commit comments

Comments
 (0)