From 1fee4649244dd9e1282510ef585cd3c5510a2eec Mon Sep 17 00:00:00 2001 From: linyimin <18316471919@139.com> Date: Thu, 13 Aug 2026 11:20:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8E=B7=E5=8F=96=E7=94=B5=E9=87=8F?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.yaml | 2 +- power.py | 21 +++++++++++---------- version.py | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app.yaml b/app.yaml index 772ceba..fed7347 100644 --- a/app.yaml +++ b/app.yaml @@ -1,6 +1,6 @@ id: t11 name: t11 -version: 2.16.3 +version: 2.16.4 author: t11 icon: '' desc: t11 diff --git a/power.py b/power.py index 102b713..315f3e4 100644 --- a/power.py +++ b/power.py @@ -5,10 +5,11 @@ 提供电压、电流监测和充电状态检测 """ import config +import os +import subprocess from logger_manager import logger_manager from maix import time as maix_time - _INA226_PRESENT = None @@ -85,8 +86,8 @@ def get_bus_voltage(): def get_current(): """ 读取电流(单位:mA) - 正数表示充电,负数表示放电 - + 当前电源板实测:正数表示放电,负数表示充电。 + INA226 电流计算公式: Current = (Current Register Value) × Current_LSB Current_LSB = 0.001 × CALIBRATION_VALUE / 4096 @@ -96,13 +97,13 @@ def get_current(): return 0.0 raw = read_register(config.REG_CURRENT) # INA226 电流寄存器是16位有符号整数 - # 最高位是符号位:0=正(充电),1=负(放电) + # 最高位是符号位;电流方向含义取决于电源板的采样电阻接线方向。 # 计算 Current_LSB(根据 CALIBRATION_VALUE) current_lsb = 0.001 * config.CALIBRATION_VALUE / 4096 # 单位:A # 处理有符号数:如果最高位为1,转换为负数 - if raw & 0x8000: # 最高位为1,表示负数(放电) + if raw & 0x8000: signed_raw = raw - 0x10000 # 转换为有符号整数 - else: # 最高位为0,表示正数(充电) + else: signed_raw = raw # 转换为毫安 current_ma = signed_raw * current_lsb * 1000 @@ -119,17 +120,17 @@ def get_current(): def is_charging(threshold_ma=10.0): """ 检测是否在充电(通过电流方向判断) - + Args: threshold_ma: 电流阈值(毫安),超过此值认为在充电,默认10mA - + Returns: True: 正在充电 False: 未充电或读取失败 """ try: current = get_current() - is_charge = current > threshold_ma + is_charge = current < -abs(float(threshold_ma)) return is_charge except Exception as e: logger = logger_manager.logger @@ -159,7 +160,7 @@ def voltage_to_percent(voltage): return 0 if v <= 0: return 0 - return int(int(_BATTERY_MONITOR.get_soc(v) * 10) / 10) # 截断而不是四舍五入 + return int(int(_BATTERY_MONITOR.get_soc(v) * 10) / 10) # 截断而不是四舍五入 class BatteryMonitor: diff --git a/version.py b/version.py index c1c3049..9172252 100644 --- a/version.py +++ b/version.py @@ -4,6 +4,6 @@ 应用版本号 每次 OTA 更新时,只需要更新这个文件中的版本号 """ -VERSION = '2.16.3' +VERSION = '2.16.4'