Skip to content

Commit

Permalink
Check both feature sets during linting
Browse files Browse the repository at this point in the history
- Update checks workflow and precommit hooks
- Resolve clippy lint issues
  • Loading branch information
taesungh committed Jun 1, 2024
1 parent 58f1813 commit 5e42dc1
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 44 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/run-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ jobs:
- name: Run cargo fmt
run: cargo fmt --all -- --check

- name: Lint pod operation
- name: Lint pod operation (w/o rpi)
run: cargo clippy -- -D warnings

- name: Lint pod operation (w/ rpi)
run: cargo clippy --features rpi -- -D warnings

- name: Build Pod Operation Program (debug)
run: cargo build --target $TARGET --config target.$TARGET.linker=\"aarch64-linux-gnu-gcc\"

Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.cargo.features": [
// "rpi"
]
}
2 changes: 1 addition & 1 deletion pod-operation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "This Rust package is for the main program to be run on the pod. The program runs a finite-state machine to operate the pod components and acts as a Socket.IO server to communicate with the control station.",
"scripts": {
"lint": "cargo clippy",
"lint": "cargo clippy && cargo clippy --features rpi",
"format": "cargo fmt",
"test": "cargo test"
},
Expand Down
2 changes: 1 addition & 1 deletion pod-operation/src/components/brakes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(not(feature = "gpio"))]
use crate::utils::mock::OutputPin;
use crate::utils::mock::gpio::OutputPin;
#[cfg(feature = "gpio")]
use rppal::gpio::{Gpio, OutputPin};

Expand Down
2 changes: 1 addition & 1 deletion pod-operation/src/components/high_voltage_system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(not(feature = "gpio"))]
use crate::utils::mock::OutputPin;
use crate::utils::mock::gpio::OutputPin;
#[cfg(feature = "gpio")]
use rppal::gpio::{Gpio, OutputPin};

Expand Down
8 changes: 6 additions & 2 deletions pod-operation/src/components/inverter_board.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "inverter")]
use rppal::uart::{Parity, Uart};

use tracing::info;
use tracing::debug;

#[cfg(feature = "inverter")]
mod serial_constants {
Expand Down Expand Up @@ -31,6 +31,10 @@ impl InverterBoard {
#[cfg(feature = "inverter")]
pub fn send_control(&mut self, velocity: f32, throttle: f32) {
let message = format!("{velocity} {throttle}\n");
debug!(
"Sending inverter control message: {} {}",
velocity, throttle
);
self.uart.write(message.as_bytes()).unwrap();
}

Expand All @@ -42,7 +46,7 @@ impl InverterBoard {
/// Combine velocity and throttle into a space-separated string message
#[cfg(not(feature = "inverter"))]
pub fn send_control(&mut self, velocity: f32, throttle: f32) {
info!(
debug!(
"Mocking inverter sending message: {} {}",
velocity, throttle
);
Expand Down
1 change: 1 addition & 0 deletions pod-operation/src/components/lidar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl Lidar {
.expect("Failed to initialize I2C device");
let lidar_lite = LidarLiteV3::new(i2cdev).expect("Failed to initialize LidarLiteV3");

info!("Initialized LidarLite");
Lidar { lidar_lite }
}

Expand Down
3 changes: 2 additions & 1 deletion pod-operation/src/components/lim_current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ impl LimCurrent {
let mut adc = Ads1x1x::new_ads1015(i2cdev, device_address);
adc.set_full_scale_range(FullScaleRange::Within4_096V)
.unwrap();
info!("Configured ADS1015 for for LimCurrent");
LimCurrent { ads1015: adc }
}

#[cfg(not(feature = "ads1015"))]
pub fn new(device_address: SlaveAddr) -> Self {
info!("Mocking ADS at {:?} for LimCurrnt", device_address);
info!("Mocking ADS at {:?} for LimCurrent", device_address);
LimCurrent {}
}

Expand Down
1 change: 1 addition & 0 deletions pod-operation/src/components/lim_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl LimTemperature {
pub fn new(device_address: SlaveAddr) -> Self {
let i2cdev = I2c::new().unwrap();
let adc = Ads1x1x::new_ads1015(i2cdev, device_address);
info!("Configured ADS1015 for for LimTemperature");
LimTemperature {
// ads1015: Mutex::new(adc),
ads1015: adc,
Expand Down
2 changes: 1 addition & 1 deletion pod-operation/src/components/signal_light.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(not(feature = "gpio"))]
use crate::utils::mock::OutputPin;
use crate::utils::mock::gpio::OutputPin;
#[cfg(feature = "gpio")]
use rppal::gpio::{Gpio, OutputPin};

Expand Down
75 changes: 39 additions & 36 deletions pod-operation/src/utils/mock.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
use tracing::info;

/// Pin logic levels, copied from rppal::gpio
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[repr(u8)]
pub enum Level {
Low = 0,
High = 1,
}

/// Mock for GPIO InputPin
pub struct InputPin {
pub(crate) pin: u8,
}

impl InputPin {
pub fn read(&self) -> Level {
info!("Mocking reading pin {} as low", self.pin);
Level::Low
#[cfg(not(feature = "gpio"))]
pub mod gpio {
use tracing::info;

/// Pin logic levels, copied from rppal::gpio
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[repr(u8)]
pub enum Level {
Low = 0,
High = 1,
}

pub fn is_low(&self) -> bool {
info!("Mocking reading pin {} as low", self.pin);
true
/// Mock for GPIO InputPin
pub struct InputPin {
pub(crate) pin: u8,
}

pub fn is_high(&self) -> bool {
info!("Mocking reading pin {} as low", self.pin);
false
impl InputPin {
pub fn read(&self) -> Level {
info!("Mocking reading pin {} as low", self.pin);
Level::Low
}

pub fn is_low(&self) -> bool {
info!("Mocking reading pin {} as low", self.pin);
true
}

pub fn is_high(&self) -> bool {
info!("Mocking reading pin {} as low", self.pin);
false
}
}
}

/// Mock for GPIO OutputPin
pub struct OutputPin {
pub(crate) pin: u8,
}

impl OutputPin {
pub fn set_low(&self) {
info!("Mocking pin {} to low", self.pin);
/// Mock for GPIO OutputPin
pub struct OutputPin {
pub(crate) pin: u8,
}

pub fn set_high(&self) {
info!("Mocking pin {} to high", self.pin);
impl OutputPin {
pub fn set_low(&self) {
info!("Mocking pin {} to low", self.pin);
}

pub fn set_high(&self) {
info!("Mocking pin {} to high", self.pin);
}
}
}

0 comments on commit 5e42dc1

Please sign in to comment.