터치 패널 Qt 프로토타입 추가
This commit is contained in:
1 parent
892e37e72d
commit
44ed804121
4 files changed
+458
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
define('CONTROL_API_LIBRARY', true);
|
||||
require_once __DIR__ . '/../public/api.php';
|
||||
|
||||
function touch_panel_json(array $payload, int $code = 0): never
|
||||
{
|
||||
fwrite(STDOUT, json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
exit($code);
|
||||
}
|
||||
|
||||
try {
|
||||
$command = (string)($argv[1] ?? 'status');
|
||||
|
||||
if ($command === 'status') {
|
||||
touch_panel_json([
|
||||
'ok' => true,
|
||||
'data' => collect_snapshot(false),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($command === 'fan') {
|
||||
$mode = (string)($argv[2] ?? 'auto');
|
||||
$pwm = max(0, min(255, (int)($argv[3] ?? 120)));
|
||||
if (!in_array($mode, ['auto', 'manual', 'off'], true)) {
|
||||
touch_panel_json([
|
||||
'ok' => false,
|
||||
'error' => 'bad_mode',
|
||||
], 2);
|
||||
}
|
||||
|
||||
set_control_state($mode, $pwm);
|
||||
add_fan_action(
|
||||
'touch_panel_fan_set',
|
||||
$mode,
|
||||
$pwm,
|
||||
'qt touch panel fan control',
|
||||
true
|
||||
);
|
||||
|
||||
touch_panel_json([
|
||||
'ok' => true,
|
||||
'data' => collect_snapshot(false),
|
||||
]);
|
||||
}
|
||||
|
||||
touch_panel_json([
|
||||
'ok' => false,
|
||||
'error' => 'unknown_command',
|
||||
], 2);
|
||||
} catch (Throwable $e) {
|
||||
touch_panel_json([
|
||||
'ok' => false,
|
||||
'error' => 'exception',
|
||||
'message' => $e->getMessage(),
|
||||
], 1);
|
||||
}
|
||||
Reference in new issue
Block a user