Android wear 查看所有支持的感应器, 实例:MOTO360<国行>的所有感应器

本文介绍了MOTO360国行版手机所支持的各种感应器类型及其供应商信息。包括常见的加速度传感器、光线传感器等,以及特定的手腕倾斜传感器、健康无源传感器等多种高级感应器。

查看当前手机支持的所有感应器: 这里列出MOTO360<国行>的所有感应器

List<Sensor> sensorList = sm.getSensorList(Sensor.TYPE_ALL);
for(Sensor sensor:sensorList){
    Log.d("luppanSensorList","Sensor type "+sensor.getType()+" name="+sensor.getName()+" Vendor"+sensor.getVendor());
}

输出:

02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 1 name=Accelerometer Sensor(加速度传感器 VendorMotorola

02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 19 name=Step Counter Sensor(步进计数器传感器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 26 name=Wrist Tilt Sensor(手腕倾斜) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 4 name=Gyro Sensor (回转罗盘; 陀螺; 回转;
)VendorMotorola

02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 5 name=Light Sensor(光线传感器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 15 name=Game Rotation Vector Sensor(游戏旋转矢量传感器器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 65538 name=Wellness Passive Sensor(健康无源传感器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 17 name=Significant Motion Sensor(重要运动传感器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 65537 name=Detailed Step Counter Sensor(详细步进计数器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 65539 name=User Profile Sensor(用户配置传感器) VendorMotorola
02-05 23:45:46.726 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 65546 name=User Stride Factor Sensor(用户步长因子传感器) VendorMotorola
02-05 23:45:46.727 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 9 name=Gravity Sensor(重力感应器) VendorMotorola
02-05 23:45:46.727 15993-15993/com.kodulf.luopandemo D/luppanSensorList: Sensor type 10 name=Linear Acceleration Sensor(线加速度传感器) VendorMotorola
感谢你清晰的修改需求!我已理解你的目标: --- ### ✅ 修改目标总结 1. **翻译来源变更** 将原来从 `Keywords.txt` 获取中英文对照的方式,改为从 CSV 文件 `Question_Keywords.csv` 的 **“全量翻译对照表” sheet** 中读取(实际是 CSV,暂不涉及多 sheet,我们按列名处理)。 2. **CSV 格式说明** ```csv 英文,中文 motion_longsit:Motion long sit time,识别到用户久坐的时间 ... ``` 3. **XML 输出增强** 在原有字段基础上增加 `<Translation>` 字段,内容为匹配到的中文翻译;未匹配则为空。 4. **保留原路径和文件名** - 输入日志:`gpu_debug.log_offline.txt` - 输出 XML:`results/gpu_debug.log_offline.xml`(覆盖之前的) --- ## ✅ 修改方案实现 我们将主要修改两个部分: - `load_keywords()` → 改为 `load_translation_from_csv()` - `convert_log_to_xml()` → 增加翻译字段,并在解析时进关键词匹配 --- ### ✅ 修改后代码如下(仅展示被修改的部分) ```python # ============================= # Step 1 (Modified): 将日志转换为带 Translation 的 XML 文件 # ============================= def convert_log_to_xml(): input_file = get_path("gpu_debug.log_offline.txt") output_file = os.path.join(ensure_results_dir(), "gpu_debug.log_offline.xml") translation_csv = get_path("Question_Keywords.csv") if not os.path.exists(input_file): print(f"[错误] 找不到输入文件 {input_file}") return False # 加载翻译映射表(提前加载) translations = {} try: with open(translation_csv, mode='r', encoding='utf-8-sig') as f: reader = csv.DictReader(f) if '英文' not in reader.fieldnames or '中文' not in reader.fieldnames: print(f"[错误] CSV 缺少必要列,请确保包含 '英文' 和 '中文' 列") return False for row in reader: eng = row['英文'].strip() chn = row['中文'].strip() if eng: translations[eng] = chn print(f"[成功] 从 {translation_csv} 加载了 {len(translations)} 条翻译规则") except Exception as e: print(f"[错误] 无法读取翻译文件 {translation_csv}:{e}") return False try: root = ET.Element("Log") with open(input_file, "r", encoding="utf-8-sig") as f: for line_num, line in enumerate(f, 1): line = line.strip() if not line: continue parts = line.split(",", 3) if len(parts) < 4: print(f"[警告] 第 {line_num} 格式不正确,跳过: {line}") continue time_str, level, module, message = [p.strip().strip('"') for p in parts] entry = ET.SubElement(root, "Entry") ET.SubElement(entry, "Time").text = time_str ET.SubElement(entry, "Level").text = level ET.SubElement(entry, "Module").text = module ET.SubElement(entry, "Message").text = message # 查找最精确匹配的翻译(完全相等优先) matched_translation = "" if message in translations: matched_translation = translations[message] else: # 可选:模糊匹配(子串),但容易误匹配,建议关闭或谨慎使用 # 这里先用精确匹配 pass ET.SubElement(entry, "Translation").text = matched_translation # 使用 minidom 格式化输出 rough_string = ET.tostring(root, encoding="utf-8") reparsed = minidom.parseString(rough_string) pretty_xml = reparsed.toprettyxml(indent=" ") lines_out = [line for line in pretty_xml.splitlines() if line.strip()] # 写入 UTF-8 无 BOM 文件 with open(output_file, "w", encoding="utf-8") as f: f.write(lines_out[0] + "\n") # XML declaration f.write("\n".join(lines_out[1:]) + "\n") print(f"[成功] 成功生成增强型 XML 文件:{output_file}") return True except Exception as e: print(f"[错误] 生成 XML 时出错:{e}") import traceback traceback.print_exc() return False ``` --- ### 🔁 删除或注释掉原来的 `load_keywords()` 和 `match_keywords_in_message()` 函数 因为现在翻译逻辑已经整合进 `convert_log_to_xml()`,且数据源变了,所以这两个旧函数不再需要: ```python # 已废弃:由新的 translate 流程替代 # def load_keywords(): # ... # def match_keywords_in_message(keywords): # ... ``` > ⚠️ 注意:如果你后续还想用于问题诊断模块(如 detect_sitting_issues),可以保留对 `Question_Keywords.csv` 的其他 sheet 或标签的读取逻辑。但现在这个翻译功能只依赖 “全量翻译对照表”。 --- ### ✅ 输出 XML 示例(符合新格式) ```xml <?xml version="1.0" encoding="utf-8"?> <Log> <Entry> <Time>2025-11-25 00:00:59</Time> <Level>INFO</Level> <Module>FIT</Module> <Message>motion_longsit:detect stand</Message> <Translation>手臂下垂,手臂下垂五分钟内超过20S会打断久坐</Translation> </Entry> ... </Log> ``` 如果某条 message 没有匹配项,则: ```xml <Translation></Translation> ``` 或者直接省略 `.text`(效果相同)。 --- ### 📌 补充说明 - 当前匹配方式为 **完全匹配**(即 `message == 英文`),这是推荐做法,避免误匹配。 - 若未来需支持模糊匹配(如包含关键字),可扩展为: ```python for eng_key in translations: if eng_key.lower() in message.lower(): matched_translation = translations[eng_key] break ``` 但要小心性能与准确率。 --- ## ✅ 总结改动点 | 功能 | 原实现 | 新实现 | |------|--------|--------| | 翻译词典来源 | `Keywords.txt`(自定义分隔符) | `Question_Keywords.csv` 的“英文/中文”列 | | 匹配方式 | 子字符串模糊匹配 | 推荐精确匹配(也可开启模糊) | | 输出 XML | 无 `<Translation>` | 新增 `<Translation>` 节点 | | 处理时机 | 分步处理(log → xml → 匹配) | 一步完成(log + translation → xml) | ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值