修复不关机补充
This commit is contained in:
15
hardware.py
15
hardware.py
@@ -29,7 +29,7 @@ class HardwareManager:
|
||||
self._adc_obj = None # ADC对象
|
||||
self._at_client = None # AT客户端
|
||||
|
||||
self._last_active_time = 0 # 用于记录用户的最后一次活跃的时间
|
||||
self._last_active_ticks = None # 上次活跃时刻(ticks_ms,单调递增,不受校时影响)
|
||||
self._stop_timer = False # 用于停止定时器的标志
|
||||
|
||||
self._initialized = True
|
||||
@@ -111,7 +111,7 @@ class HardwareManager:
|
||||
|
||||
def start_idle_timer(self):
|
||||
self._stop_timer = False
|
||||
self._last_active_time = time.time()
|
||||
self._last_active_ticks = time.ticks_ms()
|
||||
|
||||
def stop_idle_timer(self):
|
||||
self._stop_timer = True
|
||||
@@ -119,12 +119,13 @@ class HardwareManager:
|
||||
def get_idle_time_in_sec(self):
|
||||
if self._stop_timer:
|
||||
return 0
|
||||
diff = time.time() - self._last_active_time
|
||||
if diff < 0:
|
||||
# 时间可能被重置了,重新计时
|
||||
self._last_active_time = time.time()
|
||||
if self._last_active_ticks is None:
|
||||
return 0
|
||||
return diff
|
||||
diff_ms = time.ticks_diff(time.ticks_ms(), self._last_active_ticks)
|
||||
if diff_ms < 0:
|
||||
self._last_active_ticks = time.ticks_ms()
|
||||
return 0
|
||||
return diff_ms / 1000.0
|
||||
|
||||
|
||||
# 创建全局单例实例
|
||||
|
||||
Reference in New Issue
Block a user