v0.2:重写项目。 #6
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user