Fix throttled status web access

This commit is contained in:
seo
2026-06-18 04:28:12 +09:00
parent 421c44127f
commit b6d12f9a0e
2 changed files with 34 additions and 3 deletions
+30 -1
View File
@@ -204,22 +204,51 @@ function throttled_event_status(?int $flags, string $raw, int $activeBit, int $s
];
}
function throttled_statuses(): array
function read_throttled_flags(): array
{
$result = sh(['/usr/bin/vcgencmd', 'get_throttled'], false, 3);
$raw = trim((string)$result['out']);
$flags = null;
$source = 'direct';
if ((int)$result['code'] === 0 && preg_match('/throttled=0x([0-9a-f]+)/i', $raw, $m)) {
$flags = hexdec($m[1]);
}
if ($flags === null) {
$sudoResult = sh(['/usr/bin/vcgencmd', 'get_throttled'], true, 3);
$sudoRaw = trim((string)$sudoResult['out']);
if ((int)$sudoResult['code'] === 0 && preg_match('/throttled=0x([0-9a-f]+)/i', $sudoRaw, $m)) {
$result = $sudoResult;
$raw = $sudoRaw;
$flags = hexdec($m[1]);
$source = 'sudo';
}
}
return [
'result' => $result,
'raw' => $raw,
'flags' => $flags,
'source' => $source,
];
}
function throttled_statuses(): array
{
$read = read_throttled_flags();
$raw = (string)$read['raw'];
$flags = $read['flags'];
$source = (string)$read['source'];
$lowVoltage = throttled_event_status($flags, $raw, 0x1, 0x10000, '/tmp/control-low-voltage-state.json');
$throttling = throttled_event_status($flags, $raw, 0x4, 0x40000, '/tmp/control-throttling-state.json');
$lowVoltage['source'] = $source;
$lowVoltage['freq_capped'] = $flags !== null && (bool)($flags & 0x2);
$lowVoltage['throttled'] = $flags !== null && (bool)($flags & 0x4);
$lowVoltage['soft_temp_limit'] = $flags !== null && (bool)($flags & 0x8);
$throttling['source'] = $source;
$throttling['low_voltage'] = $flags !== null && (bool)($flags & 0x1);
$throttling['freq_capped'] = $flags !== null && (bool)($flags & 0x2);
$throttling['soft_temp_limit'] = $flags !== null && (bool)($flags & 0x8);