fix: 修复 UPS 输出管脚状态未更新的问题。

This commit is contained in:
Ivan Li 2022-09-11 21:37:50 +08:00
parent 2f52f142b8
commit 9b40b5dfdd
1 changed files with 4 additions and 6 deletions

View File

@ -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<DcOutPin>,
) -> 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;