From 9b40b5dfdde7d19115f6b42b817b7ccb133a702e Mon Sep 17 00:00:00 2001 From: Ivan Li Date: Sun, 11 Sep 2022 21:37:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20UPS=20=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=AE=A1=E8=84=9A=E7=8A=B6=E6=80=81=E6=9C=AA=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dc_out_controller.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/dc_out_controller.rs b/src/dc_out_controller.rs index 98e9020..14edd85 100644 --- a/src/dc_out_controller.rs +++ b/src/dc_out_controller.rs @@ -47,7 +47,6 @@ impl DcOutControllerState { } fn handle_adapter_down(&mut self) { - info!("status: {:?}", self); match self.status { DcOutStatus::On => { self.status = DcOutStatus::WaitingOff; @@ -208,7 +207,7 @@ impl DcOutController { match pin.lock() { Ok(pin) => { - if let Err(err) = Self::output_ctl(state, pin) { + if let Err(err) = Self::output_ctl(&mut state, pin) { warn!("Put Control Pin State Failed. {}", err); } } @@ -222,7 +221,6 @@ impl DcOutController { } else { warn!("DC_OUT_STATE_EVENT_LOOP is None"); } - debug!("status: {:?}", state); }) .map_err(|err| anyhow::anyhow!("Subscribe Voltage Failed. {}", err))?; self.voltage_subscription = Some(voltage_subscription); @@ -232,14 +230,14 @@ impl DcOutController { anyhow::Ok(()) } fn output_ctl( - mut state: DcOutControllerState, + state: &mut DcOutControllerState, mut pin: MutexGuard, ) -> anyhow::Result<()> { - if DcOutStatus::Off == state.status && state.pin_state == PinState::Low { + if DcOutStatus::Off == state.status { pin.set_high() .map_err(|err| anyhow::anyhow!("Set DC Output Control Pin High Failed. {}", err))?; state.pin_state = PinState::High; - } else if DcOutStatus::On == state.status && state.pin_state == PinState::High { + } else if DcOutStatus::On == state.status { pin.set_low() .map_err(|err| anyhow::anyhow!("Set DC Output Control Pin Low Failed. {}", err))?; state.pin_state = PinState::Low;