diff --git a/src/hardware/pounder/attenuators.rs b/src/hardware/pounder/attenuators.rs index 092338e..ef22814 100644 --- a/src/hardware/pounder/attenuators.rs +++ b/src/hardware/pounder/attenuators.rs @@ -35,7 +35,7 @@ pub trait AttenuatorInterface { // The lowest 2 bits of the 8-bit shift register on the attenuator are ignored. Shift the // attenuator code into the upper 6 bits of the register value. Note that the attenuator // treats inputs as active-low, so the code is inverted before writing. - channels[channel as usize] = (!attenuation_code) << 2; + channels[channel as usize] = !(attenuation_code << 2); self.transfer_attenuators(&mut channels)?; // Finally, latch the output of the updated channel to force it into an active state. diff --git a/src/hardware/pounder/mod.rs b/src/hardware/pounder/mod.rs index 2e95141..9e4c228 100644 --- a/src/hardware/pounder/mod.rs +++ b/src/hardware/pounder/mod.rs @@ -41,10 +41,10 @@ pub enum Error { #[derive(Debug, Copy, Clone)] #[allow(dead_code)] pub enum Channel { - In0, - In1, - Out0, - Out1, + In0 = 0, + Out0 = 1, + In1 = 2, + Out1 = 3, } #[derive(Serialize, Deserialize, Copy, Clone, Debug)] @@ -340,12 +340,7 @@ impl AttenuatorInterface for PounderDevices { /// Args: /// * `channel` - The attenuator channel to latch. fn latch_attenuator(&mut self, channel: Channel) -> Result<(), Error> { - let pin = match channel { - Channel::In0 => 0, - Channel::Out0 => 1, - Channel::In1 => 2, - Channel::Out1 => 3, - }; + let pin = channel as u8; self.mcp23017 .write_gpio(mcp23017::Port::GPIOB, 0x2f & !(1 << pin)) .map_err(|_| Error::I2c)?;