Reputation: 19
Would be grateful for some help here with my Rust code! I'm trying to set up the MCP 3002 SPI chip with the
raspberry pi 5 using the spidev crate, to show the output from the MCP3002 on an egui screen. I need to
replace the OK(-1)
which is the output from the io::Result
with a wildcard, such that I can then output
this as a string to the egui screen. The code ONLY compiles and outputs to the egui screen if I put
an integer into the OK()
such as OK(2)
, but the egui screen will only show the integer after
the Ok
that I put between the ()
brackets. No matter what I try, I can't get the wildcard to work,
I have tried OK(_)
and many other combinations and when using the (_)
the compiler responds with
the error "in expressions, _
can only be used on the left-hand side of an assignment".
Here is the code:
//Here is the code:
fn full_duplex(spi: &mut Spidev) -> io::Result<i8> {
let tx_buf = [0x0D, 0x02];
//let pop = io::Result<i8> ;
//let pop = io::Result();
let mut rx_buf = [0, 1]; //array size 1 and the type is i8
let mut transfer = SpidevTransfer::read_write(&tx_buf, &mut rx_buf);
spi.transfer(&mut transfer)?;
//println!("{:?}", rx_buf);
//Ok(u8)
//Ok(io::Result::<i8>)
//Ok(_:i8)
//Ok(-1000..=1000)
//Ok(())
//Ok(<i8>::2)
//Ok(<i8>:2)
//Ok(i8:2)
Ok(_)
}
Upvotes: 1
Views: 30