modify: DI 输入监听
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""全局常量与默认值。"""
|
||||
|
||||
import os
|
||||
|
||||
# ---- input 事件协议(IN1/event 后端用)----
|
||||
EV_KEY = 0x01
|
||||
KEY_UP = 103
|
||||
VALUE_RELEASE = 0
|
||||
VALUE_PRESS = 1
|
||||
VALUE_REPEAT = 2
|
||||
|
||||
DEFAULT_EVENT_DEVICE = "/dev/input/event1"
|
||||
GPIO_KEYS_NAME = "gpio-keys"
|
||||
|
||||
# ---- IN 通道编号 ----
|
||||
IN1_INDEX = 1
|
||||
IN2_INDEX = 2
|
||||
|
||||
# IN2 硬件信息(用于 --check 复算)
|
||||
IN2_GPIO_NUM = 483
|
||||
IN2_GPIOCHIP = 480
|
||||
|
||||
# ---- sysfs 状态文件候选路径 ----
|
||||
# 按 in_index 分组,每个通道可以有多个候选路径,按顺序尝试
|
||||
STATUS_CANDIDATES = {
|
||||
1: [
|
||||
"/sys/bus/platform/devices/gpio-in-1/gpio_status",
|
||||
"/dev/tv_gpioin_1",
|
||||
# SE9 若有其它路径,加到这里
|
||||
],
|
||||
2: [
|
||||
"/sys/bus/platform/devices/gpio-in-2/gpio_status",
|
||||
"/dev/tv_gpioin_2",
|
||||
],
|
||||
}
|
||||
|
||||
STATUS_FILE_ENV = "DI_STATUS_FILE" # 测试用覆盖
|
||||
LOG_DIR_ENV = "DI_LOG_DIR"
|
||||
|
||||
DEVICETREE_BASE = "/sys/firmware/devicetree/base"
|
||||
|
||||
DEBOUNCE = 2 # 连续多少次采样一致才确认跳变
|
||||
DEFAULT_INTERVAL = 0.02 # 轮询间隔秒
|
||||
|
||||
|
||||
def candidate_status_files(in_index: int):
|
||||
"""返回某通道的所有候选状态文件路径(含环境变量覆盖)。"""
|
||||
paths = []
|
||||
env = os.environ.get(STATUS_FILE_ENV)
|
||||
if env:
|
||||
paths.append(env)
|
||||
paths.extend(STATUS_CANDIDATES.get(in_index, []))
|
||||
return paths
|
||||
|
||||
|
||||
def find_status_file(in_index: int):
|
||||
"""找到第一个可读的状态文件;找不到返回 None。"""
|
||||
for p in candidate_status_files(in_index):
|
||||
if os.access(p, os.R_OK):
|
||||
return p
|
||||
return None
|
||||
Reference in New Issue
Block a user