fix: 获取电量错误

This commit is contained in:
2026-08-13 11:20:29 +08:00
parent 06994c5905
commit 1fee464924
3 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
id: t11
name: t11
version: 2.16.3
version: 2.16.4
author: t11
icon: ''
desc: t11
+7 -6
View File
@@ -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,7 +86,7 @@ def get_bus_voltage():
def get_current():
"""
读取电流(单位:mA
正数表示电,负数表示放电
当前电源板实测:正数表示电,负数表示充电。
INA226 电流计算公式:
Current = (Current Register Value) × Current_LSB
@@ -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
@@ -129,7 +130,7 @@ def is_charging(threshold_ma=10.0):
"""
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
+1 -1
View File
@@ -4,6 +4,6 @@
应用版本号
每次 OTA 更新时,只需要更新这个文件中的版本号
"""
VERSION = '2.16.3'
VERSION = '2.16.4'