diff --git a/main.py b/main.py index 5547c7a..7d75ca1 100644 --- a/main.py +++ b/main.py @@ -85,9 +85,13 @@ class MAT: if self.history.is_empty(): self.control_logger.error("未预期的没有可用的历史记录") return ret + if self.crazy < 3: + self._display_status(im, ret, rate, val) + return ret + # === 状态进入逻辑 === - if now - self._start_time<17: + if now - self._start_time<10: self._display_status(im, ret, rate, val) return ret # 1. middle: predictor返回middle立即进入slow状态 @@ -199,7 +203,7 @@ class MAT: rate = val/tot if self.history.base is not None: base = self.history.base - thr = (base*5, base*10, base*30) + thr = (base*5, base*9, 0.75) if rate < thr[0]: return "transport",rate elif rate mid_time: - should_push = True - elif self.state.is_about_mode() and time.time() - self.ch340.start > end_time: - should_push = True - - if should_push: - speed = self.speeds[self.state.mode.value] - self.volume_logger.info(f"当前体积: {self.total_volume:.2f} ml, 加入速度: {speed:.2f} ml/次") - self.ch340_push(speed) - self.total_volume += speed + if self.crazy < 3: + match self.crazy: + case 0: + self.control_logger.info("crazy 0") + self.ch340_pull() + self.ch340.speed = 1.00 + self.ch340.push_async(vol=12) + self.crazy = 1 + case 1: + self.control_logger.info("crazy 1") + self.ch340.pull_async(vol=12) + self.crazy = 2 + case 2: + self.control_logger.info("crazy 2") + self.ch340.push_async(vol=8) + self.total_volume = 20 + cnt = 2 + self.crazy = 3 + else: + if 12 * cnt - self.total_volume < 0.5: + self.ch340_pull() + cnt += 1 + time.sleep(0.01) + + # 简化的推送逻辑 + should_push = False + if self.state.is_fast_mode(): + should_push = True + elif self.state.is_slow_mode() and time.time() - self.ch340.start > mid_time: + should_push = True + elif self.state.is_about_mode() and time.time() - self.ch340.start > end_time: + should_push = True + + if should_push: + speed = self.speeds[self.state.mode.value] + self.volume_logger.info(f"当前体积: {self.total_volume:.2f} ml, 加入速度: {speed:.2f} ml/次") + self.ch340_push(speed) + self.total_volume += speed if self._pred() is None: self.control_logger.error("预测失败,跳过当前帧") diff --git a/utils.py b/utils.py index f3ed303..eda6549 100644 --- a/utils.py +++ b/utils.py @@ -23,7 +23,7 @@ class HistoryRecord: class History: """滑动窗口历史记录管理类""" - def __init__(self, max_window_size: float = 5.0, base_time = 5.0, display: bool = True): + def __init__(self, max_window_size: float = 5.0, base_time = 5.0, display: bool = False): """ 初始化历史记录管理器 @@ -290,6 +290,8 @@ class State: # 状态检查标志 self.in_middle_check = False self.in_end_check = False + self.about_check = False + self.about_first_flag = False # 时间记录 self.middle_detected_time = None @@ -333,7 +335,7 @@ class State: def exit_about_with_middle(self): """about状态随middle一起退出""" if self.mode == self.Mode.ABOUT: - self.mode = self.Mode.FAST + self.mode = self.Mode.SLOW def should_check_middle_exit(self, current_time): """检查是否应该进行middle退出检查""" @@ -355,9 +357,10 @@ class State: def get_status_text(self): """获取状态显示文本""" status = [] - if self.in_middle_check: + current_time = time.time() + if self.in_middle_check and current_time - self.middle_detected_time > self.bounce_time: status.append("MIDCHK") - if self.in_end_check: + if self.in_end_check and current_time - self.end_detected_time > self.end_bounce_time: status.append("ENDCHK") return ", " + ", ".join(status) if status else ""