터치 디스플레이 밝기 제어 추가
This commit is contained in:
+102
@@ -3488,6 +3488,29 @@ function touch_display_file(string $kind): string
|
||||
return $kind === 'cmdline' ? '/boot/firmware/cmdline.txt' : '/boot/firmware/config.txt';
|
||||
}
|
||||
|
||||
function touch_display_backlight_path(): ?string
|
||||
{
|
||||
$candidates = glob('/sys/class/backlight/*') ?: [];
|
||||
foreach ($candidates as $path) {
|
||||
if (is_readable($path . '/brightness') && is_readable($path . '/max_brightness')) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
$fallback = '/sys/devices/platform/axi/1000120000.pcie/1f00088000.i2c/i2c-10/10-0045/backlight/10-0045';
|
||||
return is_readable($fallback . '/brightness') && is_readable($fallback . '/max_brightness') ? $fallback : null;
|
||||
}
|
||||
|
||||
function touch_display_read_int(?string $path): ?int
|
||||
{
|
||||
if ($path === null || !is_readable($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$raw = trim((string)@file_get_contents($path));
|
||||
return is_numeric($raw) ? (int)$raw : null;
|
||||
}
|
||||
|
||||
function touch_display_read_file(string $kind): string
|
||||
{
|
||||
$path = touch_display_file($kind);
|
||||
@@ -3532,6 +3555,21 @@ function touch_display_write_file(string $path, string $content): void
|
||||
}
|
||||
}
|
||||
|
||||
function touch_display_write_value(string $path, string $value): void
|
||||
{
|
||||
if (function_exists('posix_geteuid') && posix_geteuid() === 0) {
|
||||
if (@file_put_contents($path, $value) === false) {
|
||||
throw new RuntimeException(basename($path) . ' 저장에 실패했습니다.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$result = sh(['/bin/sh', '-c', 'printf %s ' . escapeshellarg($value) . ' > ' . escapeshellarg($path)], true, 5);
|
||||
if ($result['code'] !== 0) {
|
||||
throw new RuntimeException(trim($result['out']) !== '' ? trim($result['out']) : basename($path) . ' 저장에 실패했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
function touch_display_active_config_lines(string $config): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
@@ -3606,6 +3644,11 @@ function touch_display_status(): array
|
||||
$modes = is_readable($modesPath)
|
||||
? array_values(array_filter(array_map('trim', file($modesPath, FILE_IGNORE_NEW_LINES) ?: [])))
|
||||
: [];
|
||||
$backlightPath = touch_display_backlight_path();
|
||||
$brightness = touch_display_read_int($backlightPath !== null ? $backlightPath . '/brightness' : null);
|
||||
$actualBrightness = touch_display_read_int($backlightPath !== null ? $backlightPath . '/actual_brightness' : null);
|
||||
$maxBrightness = touch_display_read_int($backlightPath !== null ? $backlightPath . '/max_brightness' : null);
|
||||
$blPower = touch_display_read_int($backlightPath !== null ? $backlightPath . '/bl_power' : null);
|
||||
|
||||
return [
|
||||
'connector' => 'DSI-1',
|
||||
@@ -3618,6 +3661,16 @@ function touch_display_status(): array
|
||||
'current_mode' => $modes[0] ?? '800x480',
|
||||
'framebuffer' => is_dir('/sys/class/graphics/fb0') ? 'fb0' : '-',
|
||||
'touch_input' => trim((string)shell_exec("for e in /sys/class/input/event*/device/name; do cat \"\$e\" 2>/dev/null; done | grep -i 'ft5x06' | head -n 1")) ?: '-',
|
||||
'backlight' => [
|
||||
'available' => $backlightPath !== null,
|
||||
'path' => $backlightPath,
|
||||
'brightness' => $brightness,
|
||||
'actual_brightness' => $actualBrightness,
|
||||
'max_brightness' => $maxBrightness,
|
||||
'percent' => $maxBrightness !== null && $maxBrightness > 0 && $brightness !== null ? round($brightness / $maxBrightness * 100, 1) : null,
|
||||
'power' => $blPower,
|
||||
'enabled' => $blPower === null || $blPower === 0,
|
||||
],
|
||||
'config' => [
|
||||
'display_auto_detect' => touch_display_config_flag($lines, 'display_auto_detect'),
|
||||
'manual_overlay' => (bool)$overlay['enabled'],
|
||||
@@ -3637,6 +3690,36 @@ function touch_display_status(): array
|
||||
];
|
||||
}
|
||||
|
||||
function touch_display_set_runtime(array $input): array
|
||||
{
|
||||
$backlightPath = touch_display_backlight_path();
|
||||
if ($backlightPath === null) {
|
||||
throw new RuntimeException('백라이트 제어 장치를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$maxBrightness = touch_display_read_int($backlightPath . '/max_brightness') ?? 255;
|
||||
$brightness = max(0, min($maxBrightness, (int)($input['brightness'] ?? $maxBrightness)));
|
||||
$enabled = touch_display_bool($input['backlight_enabled'] ?? '1');
|
||||
|
||||
touch_display_write_value($backlightPath . '/brightness', (string)$brightness);
|
||||
if (is_writable($backlightPath . '/bl_power') || is_readable($backlightPath . '/bl_power')) {
|
||||
touch_display_write_value($backlightPath . '/bl_power', $enabled ? '0' : '4');
|
||||
}
|
||||
|
||||
add_fan_action(
|
||||
'touch_display_runtime',
|
||||
null,
|
||||
null,
|
||||
'brightness=' . $brightness . '/' . $maxBrightness . ', backlight_enabled=' . ($enabled ? '1' : '0'),
|
||||
true
|
||||
);
|
||||
|
||||
return [
|
||||
'reboot_required' => false,
|
||||
'display' => touch_display_status(),
|
||||
];
|
||||
}
|
||||
|
||||
function touch_display_comment_directives(string $config, array $patterns): string
|
||||
{
|
||||
$lines = preg_split('/\R/', $config) ?: [];
|
||||
@@ -4043,6 +4126,25 @@ function control_api_dispatch(): void
|
||||
]);
|
||||
}
|
||||
|
||||
if ($action === 'touch_display_runtime_save') {
|
||||
$raw = (string)($_POST['runtime'] ?? '{}');
|
||||
$runtime = json_decode($raw, true);
|
||||
if (!is_array($runtime)) {
|
||||
json_out([
|
||||
'ok' => false,
|
||||
'error' => 'bad_display_runtime',
|
||||
], 400);
|
||||
}
|
||||
|
||||
$result = touch_display_set_runtime($runtime);
|
||||
$data = collect_snapshot(false);
|
||||
$data['touch_display_runtime_save'] = $result;
|
||||
json_out([
|
||||
'ok' => true,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($action === 'fan') {
|
||||
$mode = (string)($_POST['mode'] ?? 'auto');
|
||||
$pwm = max(0, min(255, (int)($_POST['pwm'] ?? 120)));
|
||||
|
||||
Reference in New Issue
Block a user