Fix warnings
This commit is contained in:
parent
b47a27cb86
commit
d3da56b3e5
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
|||
use std::sync::Mutex;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Axis {
|
||||
|
@ -42,7 +42,6 @@ pub enum GamepadEvent {
|
|||
/// ```
|
||||
pub struct Gamepad {
|
||||
speed_setpoint: Mutex<(f32, f32, f32)>,
|
||||
terminator: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
impl Gamepad {
|
||||
|
@ -50,21 +49,24 @@ impl Gamepad {
|
|||
///
|
||||
/// The tasks are terminated on drop.
|
||||
pub async fn new() -> Result<Arc<Self>, gilrs::Error> {
|
||||
let (terminate_tx, mut terminate_rx) = oneshot::channel();
|
||||
let (gamepad_tx, gamepad_rx) = mpsc::channel(8);
|
||||
let res = Arc::new(Gamepad {
|
||||
speed_setpoint: Mutex::new((0.0, 0.0, 0.0)),
|
||||
terminator: terminate_tx,
|
||||
});
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let mut gilrs = Gilrs::new().unwrap();
|
||||
for (_id, gamepad) in gilrs.gamepads() {
|
||||
println!("{} is {:?}", gamepad.name(), gamepad.power_info());
|
||||
}
|
||||
while let Err(oneshot::error::TryRecvError::Empty) = terminate_rx.try_recv() {
|
||||
loop {
|
||||
sleep(Duration::from_millis(1));
|
||||
if let Some(event) = gilrs.next_event() {
|
||||
Self::map_event(event).map(|event| gamepad_tx.blocking_send(event));
|
||||
if let Some(internal_event) = Self::map_event(event) {
|
||||
if gamepad_tx.blocking_send(internal_event).is_err() {
|
||||
// receiver dropped
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod gamepad;
|
||||
pub mod jogger;
|
||||
pub mod printer;
|
||||
pub mod spindle;
|
||||
|
|
|
@ -1,38 +1,11 @@
|
|||
#![warn(rust_2018_idioms)]
|
||||
use futures::never::Never;
|
||||
use i2c_linux::I2c;
|
||||
use red::gamepad;
|
||||
use red::jogger;
|
||||
use red::printer::Printer;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use tokio_serial::SerialPortInfo;
|
||||
|
||||
const DEFAULT_TTY: &str = "/dev/ttyUSB0";
|
||||
const I2C_ADDRESS_EXTENDER: u8 = 25;
|
||||
const I2C_REGISTER_SPINDLE_SPEED: u8 = 0;
|
||||
|
||||
// available i2c functionality on the device as reported from
|
||||
// the i2c library
|
||||
// TENBIT_ADDR
|
||||
// SMBUS_PEC
|
||||
// SMBUS_QUICK
|
||||
// SMBUS_READ_BYTE
|
||||
// SMBUS_WRITE_BYTE
|
||||
// SMBUS_READ_BYTE_DATA
|
||||
// SMBUS_WRITE_BYTE_DATA
|
||||
// SMBUS_READ_WORD_DATA
|
||||
// SMBUS_WRITE_WORD_DATA
|
||||
// SMBUS_PROC_CALL
|
||||
// SMBUS_WRITE_BLOCK_DATA
|
||||
// SMBUS_READ_I2C_BLOCK
|
||||
// SMBUS_WRITE_I2C_BLOCK
|
||||
// SMBUS_BYTE
|
||||
// SMBUS_BYTE_DATA
|
||||
// SMBUS_WORD_DATA
|
||||
// SMBUS_I2C_BLOCK
|
||||
// SMBUS_EMUL
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Never {
|
||||
println!("Entering App");
|
||||
|
@ -54,30 +27,3 @@ async fn main() -> Never {
|
|||
.unwrap();
|
||||
jogger::jog(gamepad, printer).await
|
||||
}
|
||||
|
||||
async fn write_to_spindle() -> Never {
|
||||
let mut i2c = I2c::from_path("/dev/i2c-0").unwrap();
|
||||
let mut value = 0;
|
||||
println!("functionality: {:?}", i2c.i2c_functionality());
|
||||
i2c.smbus_set_slave_address(I2C_ADDRESS_EXTENDER.into(), false)
|
||||
.unwrap();
|
||||
loop {
|
||||
value = u16::MAX - value;
|
||||
match i2c.smbus_write_word_data(I2C_REGISTER_SPINDLE_SPEED, value) {
|
||||
Ok(()) => println!("Wrote {} successfully", value),
|
||||
Err(e) => println!("Error writing to device: {}", e),
|
||||
};
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn write_to_printer() -> Never {
|
||||
let mut printer = Printer::connect(DEFAULT_TTY).await.unwrap();
|
||||
printer.auto_home(true, true, true).await.unwrap();
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
|
||||
printer.move_relative(50.0, 50.0, 5.0, None).await.unwrap();
|
||||
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
|
||||
printer.move_relative(25.0, 25.0, 5.0, None).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
43
red/src/spindle/mod.rs
Normal file
43
red/src/spindle/mod.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use futures::never::Never;
|
||||
use i2c_linux::I2c;
|
||||
use std::time::Duration;
|
||||
|
||||
const I2C_ADDRESS_EXTENDER: u8 = 25;
|
||||
const I2C_REGISTER_SPINDLE_SPEED: u8 = 0;
|
||||
|
||||
// available i2c functionality on the device as reported from
|
||||
// the i2c library
|
||||
// TENBIT_ADDR
|
||||
// SMBUS_PEC
|
||||
// SMBUS_QUICK
|
||||
// SMBUS_READ_BYTE
|
||||
// SMBUS_WRITE_BYTE
|
||||
// SMBUS_READ_BYTE_DATA
|
||||
// SMBUS_WRITE_BYTE_DATA
|
||||
// SMBUS_READ_WORD_DATA
|
||||
// SMBUS_WRITE_WORD_DATA
|
||||
// SMBUS_PROC_CALL
|
||||
// SMBUS_WRITE_BLOCK_DATA
|
||||
// SMBUS_READ_I2C_BLOCK
|
||||
// SMBUS_WRITE_I2C_BLOCK
|
||||
// SMBUS_BYTE
|
||||
// SMBUS_BYTE_DATA
|
||||
// SMBUS_WORD_DATA
|
||||
// SMBUS_I2C_BLOCK
|
||||
// SMBUS_EMUL
|
||||
|
||||
pub async fn write_to_spindle() -> Never {
|
||||
let mut i2c = I2c::from_path("/dev/i2c-0").unwrap();
|
||||
let mut value = 0;
|
||||
println!("functionality: {:?}", i2c.i2c_functionality());
|
||||
i2c.smbus_set_slave_address(I2C_ADDRESS_EXTENDER.into(), false)
|
||||
.unwrap();
|
||||
loop {
|
||||
value = u16::MAX - value;
|
||||
match i2c.smbus_write_word_data(I2C_REGISTER_SPINDLE_SPEED, value) {
|
||||
Ok(()) => println!("Wrote {} successfully", value),
|
||||
Err(e) => println!("Error writing to device: {}", e),
|
||||
};
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue