diff --git a/Cargo.toml b/Cargo.toml index a97417c..098ed48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2024" [dependencies] rppal = "0.17" +raslib = "*" diff --git a/src/moduleTests/fanTest.rs b/src/moduleTests/fanTest.rs index 8c41ab2..5949768 100644 --- a/src/moduleTests/fanTest.rs +++ b/src/moduleTests/fanTest.rs @@ -4,21 +4,6 @@ use std::time::Duration; use rppal::gpio::Gpio; let gpio = Gpio::new()?; -let mut fanFiveVoltRail = gpio.get(2)?.into_output(); +let mut examplePin = gpio.get(0)?.into_output(); -// Quick toggle fans 5 seconds long, 0.5s interval - -let mut i = 0; - -while i < 11 { - fanFiveVoltRail.set_high(); - thread::sleep(Duration::from_secs(0.5)); - fanFiveVoltRail.set_low(); - i = i + 1 -} - -// Run fans for five more seconds constant - -fanFiveVoltRail.set_high(); -thread::sleep(Duration::from_secs(5)); -fanFiveVoltRail.set_low(); +//TODO: Add relay switching \ No newline at end of file diff --git a/src/moduleTests/lightTest.rs b/src/moduleTests/lightTest.rs index 56bf4f3..9d389ef 100644 --- a/src/moduleTests/lightTest.rs +++ b/src/moduleTests/lightTest.rs @@ -7,10 +7,8 @@ let gpio = Gpio::new()?; let mut indicatorLeftBack = gpio.get(21)?.into_output(); let mut indicatorRightBack = gpio.get(22)?.into_output(); -let mut brakeLeftBack = gpio.get(23)?.into_output(); -let mut brakeRightBack = gpio.get(24)?.into_output(); -let mut frontLeftHead = gpio.get(25)?.into_output(); -let mut frontRightHead = gpio.get(26)?.into_output(); +let mut brakeLights = gpio.get(23)?.into_output(); +let mut headLights = gpio.get(25)?.into_output(); // Blink both indicators @@ -51,35 +49,35 @@ i = 0; // Hold brake lights and blink twice -brakeLeftBack.set_high(); -brakeRightBack.set_high(); +brakeLights.set_high(); +brakeLights.set_high(); thread::sleep(Duration::from_secs(3)); -brakeLeftBack.set_low(); -brakeRightBack.set_low(); +brakeLights.set_low(); +brakeLights.set_low(); while i < 3 { - brakeLeftBack.set_high(); - brakeRightBack.set_high(); + brakeLights.set_high(); + brakeLights.set_high(); thread::sleep(Duration::from_secs(0.7)) - brakeLeftBack.set_low(); - brakeRigthBack.set_low(); + brakeLights.set_low(); + brakeLights.set_low(); } i = 0; // Turn on headlights and flash twice -frontLeftHead.set_high(); -frontRightHead.set_high(); +headLights.set_high(); +headLights.set_high(); thread::sleep(Duration::from_secs(3)) -frontLeftHead.set_low(); -frontRightHead.set_low(); +headLights.set_low(); +headLights.set_low(); while i < 3 { - frontLeftHead.set_high(); - frontRightHead.set_high(); + headLights.set_high(); + headLights.set_high(); thread::sleep(Duration::from_secs(0.7)) - frontLeftHead.set_low(); - frontRightHead.set_low(); + headLights.set_low(); + headLights.set_low(); } diff --git a/src/moduleTests/motorTest.rs b/src/moduleTests/motorTest.rs new file mode 100644 index 0000000..b926e9f --- /dev/null +++ b/src/moduleTests/motorTest.rs @@ -0,0 +1,50 @@ +use raslib::L298n; +use std::thread; +use std::time::Duration; + +// struct L298n { +// in1: Gpio, +// in2: Gpio, +// ena: Gpio, +// } + +fn main() -> Result<(), std::io::Error> { + let mut motorFrontLeft = L298n::new(0, 0, 0); + let mut motorFrontRight = L298n::new(0, 0, 0); + let mut motorBackLeft = L298n::new(0, 0, 0); + let mut motorBackRight = L298n::new(0, 0, 0); + + // Front left test + + motorFrontLeft.forward()?; + thread::sleep(Duration::from_secs(2)); + motorFrontLeft.backward()?; + thread::sleep(Duration::from_secs(2)); + motorFrontLeft.stop()?; + + // Front right test + + motorFrontRight.forward()?; + thread::sleep(Duration::from_secs(2)); + motorFrontRight.backward()?; + thread::sleep(Duration::from_secs(2)); + motorFrontRight.stop()?; + + // Back left test + + motorBackLeft.forward()?; + thread::sleep(Duration::from_secs(2)); + motorBackLeft.backward()?; + thread::sleep(Duration::from_secs(2)); + motorBackLeft.stop()?; + + // Back right test + + motorBackRight.forward()?; + thread::sleep(Duration::from_secs(2)); + motorBackRight.backward()?; + thread::sleep(Duration::from_secs(2)); + motorBackRight.stop()?; + + Ok(()) +} \ No newline at end of file diff --git a/src/moduleTests/ultrasonicTest.rs b/src/moduleTests/ultrasonicTest.rs new file mode 100644 index 0000000..2858c47 --- /dev/null +++ b/src/moduleTests/ultrasonicTest.rs @@ -0,0 +1,45 @@ +use hc_sr04::{HcSr04, Unit}; + +let mut ultrasonicFront = HcSr04::new( + 7, // TRIGGER + 1, // ECHO + Some(23_f32) +).unwrap(); + +let mut ultrasonicLeft = HcSr04::new( + 0, + 4, + Some(23_f32) +).unwrap(); + +let mut ultrasonicRight = HcSr04::new( + 2, + 5, + Some(23_f32) +).unwrap(); + +let mut ultrasonicBack = HcSr04::new( + 3, + 6, + Some(23_f32) +).unwrap(); + +match ultrasonicFront.measure_distance(Unit::Meters).unwrap() { + Some(dist) => println!("[FRONT] Distance: {.2}m", dist), + None => println!("Object out of range"), +} + +match ultrasonicLeft.measure_distance(Unit::Meters).unwrap() { + Some(dist) => println!("[LEFT] Distance: {.2}m", dist), + None => println!("Object out of range"), +} + +match ultrasonicRight.measure_distance(Unit::Meters).unwrap() { + Some(dist) => println!("[RIGHT] Distance: {.2}m", dist), + None => println!("Object out of range"), +} + +match ultrasonicBack.measure_distance(Unit::Meters).unwrap() { + Some(dist) => println!("[BACK] Distance: {.2}m", dist), + None => println!("Object out of range"), +} \ No newline at end of file