add logger
This commit is contained in:
parent
e8452bef7c
commit
ac7fd5fd4b
14
app.py
14
app.py
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QSettings
|
||||
@ -10,8 +11,21 @@ from themes import THEME_DAY, THEME_NIGHT
|
||||
from ui.language_dialog import LanguageDialog
|
||||
from ui.main_window_new import MainWindowNew
|
||||
|
||||
# Настраиваем логирование
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.StreamHandler(sys.stdout),
|
||||
logging.FileHandler('/tmp/car_ui.log', encoding='utf-8'),
|
||||
]
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run_app():
|
||||
logger.info("Starting Car UI application")
|
||||
app = QApplication(sys.argv)
|
||||
_apply_reset_if_requested()
|
||||
_ensure_language_selected(app)
|
||||
|
||||
@ -2,4 +2,4 @@
|
||||
set -euo pipefail
|
||||
|
||||
export DISPLAY=:0
|
||||
./.venv/bin/python3 ./main.py
|
||||
./.venv/bin/python3 ./main.py 2>&1 | tee debug.log
|
||||
|
||||
@ -4,6 +4,7 @@ import os
|
||||
import select
|
||||
import struct
|
||||
import threading
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
@ -11,6 +12,8 @@ from PySide6.QtCore import QObject, Signal
|
||||
|
||||
import build_info
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Типы событий из Linux input.h
|
||||
EV_MSC = 0x04
|
||||
@ -87,11 +90,13 @@ class IrRemoteService(QObject):
|
||||
def start(self) -> bool:
|
||||
"""Запустить обработку событий ИК-пульта."""
|
||||
if not self._device_path:
|
||||
logger.warning("IR remote device not found")
|
||||
return False
|
||||
|
||||
|
||||
if self._running:
|
||||
return True
|
||||
|
||||
|
||||
logger.info(f"Starting IR remote service, device: {self._device_path}")
|
||||
self._running = True
|
||||
self._thread = threading.Thread(target=self._event_loop, daemon=True)
|
||||
self._thread.start()
|
||||
@ -141,53 +146,67 @@ class IrRemoteService(QObject):
|
||||
"""Обработать скан-код кнопки."""
|
||||
action = self._scancode_to_action.get(scancode)
|
||||
if not action:
|
||||
logger.debug(f"Unknown scancode: {scancode}")
|
||||
return
|
||||
|
||||
|
||||
logger.debug(f"Scancode: {scancode}, action: {action}")
|
||||
|
||||
# Увеличиваем счётчик повторений
|
||||
self._repeat_counts[scancode] = self._repeat_counts.get(scancode, 0) + 1
|
||||
repeat_count = self._repeat_counts[scancode]
|
||||
|
||||
|
||||
# Проверяем, было ли зажатие уже обработано
|
||||
hold_triggered = self._hold_triggered.get(scancode, False)
|
||||
|
||||
|
||||
# Определяем тип события
|
||||
is_repeat = repeat_count > 1
|
||||
is_hold = repeat_count >= build_info.IR_REPEAT_COUNT_FOR_HOLD
|
||||
|
||||
|
||||
logger.debug(f" repeat_count={repeat_count}, is_repeat={is_repeat}, is_hold={is_hold}")
|
||||
|
||||
# Отправляем сигналы
|
||||
if action == "play_pause":
|
||||
# Play/Pause - только клик (первое нажатие)
|
||||
if not is_repeat:
|
||||
logger.info("Emitting play_pause_clicked")
|
||||
self.play_pause_clicked.emit()
|
||||
|
||||
|
||||
elif action in ("volume_up", "volume_down"):
|
||||
# Громкость - клик + зажатие
|
||||
if not is_repeat:
|
||||
if action == "volume_up":
|
||||
logger.info("Emitting volume_up_clicked")
|
||||
self.volume_up_clicked.emit()
|
||||
else:
|
||||
logger.info("Emitting volume_down_clicked")
|
||||
self.volume_down_clicked.emit()
|
||||
|
||||
|
||||
if is_hold and not hold_triggered:
|
||||
self._hold_triggered[scancode] = True
|
||||
if action == "volume_up":
|
||||
logger.info("Emitting volume_up_hold")
|
||||
self.volume_up_hold.emit()
|
||||
else:
|
||||
logger.info("Emitting volume_down_hold")
|
||||
self.volume_down_hold.emit()
|
||||
|
||||
|
||||
elif action in ("next_track", "prev_track"):
|
||||
# Треки - клик + зажатие (перемотка)
|
||||
if not is_repeat:
|
||||
if action == "next_track":
|
||||
logger.info("Emitting next_track_clicked")
|
||||
self.next_track_clicked.emit()
|
||||
else:
|
||||
logger.info("Emitting prev_track_clicked")
|
||||
self.prev_track_clicked.emit()
|
||||
|
||||
|
||||
if is_hold and not hold_triggered:
|
||||
self._hold_triggered[scancode] = True
|
||||
if action == "next_track":
|
||||
logger.info("Emitting next_track_hold")
|
||||
self.next_track_hold.emit()
|
||||
else:
|
||||
logger.info("Emitting prev_track_hold")
|
||||
self.prev_track_hold.emit()
|
||||
|
||||
def reset_button_state(self, scancode: str | None = None) -> None:
|
||||
|
||||
@ -19,6 +19,9 @@ from screens.settings import SettingsScreen
|
||||
from services.bluetooth_service import BluetoothService
|
||||
from services.ir_remote_service import IrRemoteService
|
||||
from controllers.media_controller import MediaController
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MainWindowNew(QMainWindow):
|
||||
@ -172,16 +175,19 @@ class MainWindowNew(QMainWindow):
|
||||
|
||||
def _on_ir_play_pause(self):
|
||||
"""Обработка кнопки Play/Pause с ИК-пульта."""
|
||||
logger.info("IR: Play/Pause clicked")
|
||||
if self._media_controller:
|
||||
self._media_controller.toggle_play()
|
||||
|
||||
def _on_ir_next_track(self):
|
||||
"""Обработка кнопки Next с ИК-пульта."""
|
||||
logger.info("IR: Next track clicked")
|
||||
if self._media_controller:
|
||||
self._media_controller.next_track()
|
||||
|
||||
def _on_ir_prev_track(self):
|
||||
"""Обработка кнопки Prev с ИК-пульта."""
|
||||
logger.info("IR: Prev track clicked")
|
||||
if self._media_controller:
|
||||
self._media_controller.previous_track()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user