터치 패널 사이드바 축소와 팬 표시 오류 수정

This commit is contained in:
seo committed 2026-07-30 04:43:39 +09:00
1 parent 5bfac4429a
commit e99fe1021a
2 files changed
+103 -43

No files matched your search

+64 -2
View File
@@ -4,6 +4,68 @@ declare(strict_types=1);
define('CONTROL_API_LIBRARY', true);
require_once __DIR__ . '/../public/api.php';
function touch_panel_snapshot(array $snapshot): array
{
$network = is_array($snapshot['network'] ?? null) ? $snapshot['network'] : [];
$wifi = is_array($snapshot['wifi'] ?? null) ? $snapshot['wifi'] : [];
$system = is_array($snapshot['system'] ?? null) ? $snapshot['system'] : [];
$fan = is_array($snapshot['fan'] ?? null) ? $snapshot['fan'] : [];
$touch = is_array($snapshot['touch_display'] ?? null) ? $snapshot['touch_display'] : [];
$interfaces = [];
foreach (($network['interfaces'] ?? []) as $row) {
if (!is_array($row) || !isset($row['name'])) {
continue;
}
$interfaces[] = [
'name' => $row['name'],
'state' => $row['state'] ?? null,
'carrier' => $row['carrier'] ?? null,
'rx_errors' => $row['rx_errors'] ?? 0,
'tx_errors' => $row['tx_errors'] ?? 0,
'rx_dropped' => $row['rx_dropped'] ?? 0,
'tx_dropped' => $row['tx_dropped'] ?? 0,
];
}
$clients = [];
foreach (($wifi['clients'] ?? []) as $client) {
if (!is_array($client)) {
continue;
}
$clients[] = [
'band' => $client['band'] ?? null,
];
}
return [
'ok' => (bool)($snapshot['ok'] ?? true),
'generated_at' => $snapshot['generated_at'] ?? null,
'fan' => [
'mode' => $fan['mode'] ?? 'auto',
'pwm' => $fan['pwm'] ?? 0,
'percent' => $fan['percent'] ?? 0,
'rpm' => $fan['rpm'] ?? 0,
'control_temp_c' => $fan['control_temp_c'] ?? null,
'policy_ok' => $fan['policy_ok'] ?? true,
],
'system' => [
'hostname' => $system['hostname'] ?? null,
'temp_c' => $system['temp_c'] ?? null,
],
'network' => [
'default_interface' => $network['default_interface'] ?? null,
'interfaces' => $interfaces,
],
'wifi' => [
'clients' => $clients,
],
'touch_display' => [
'connected' => $touch['connected'] ?? false,
],
];
}
function touch_panel_json(array $payload, int $code = 0): never
{
fwrite(STDOUT, json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL);
@@ -16,7 +78,7 @@ try {
if ($command === 'status') {
touch_panel_json([
'ok' => true,
'data' => collect_snapshot(false),
'data' => touch_panel_snapshot(collect_snapshot(false)),
]);
}
@@ -41,7 +103,7 @@ try {
touch_panel_json([
'ok' => true,
'data' => collect_snapshot(false),
'data' => touch_panel_snapshot(collect_snapshot(false)),
]);
}