Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive common traits for public types + warnings fixes #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Relax lifetime constraint on `I2CTransfer::transfer` `msgs` reference
- Relax lifetime constraint on `I2CTransfer::transfer` `msgs` reference.
- Derived common traits for public types.

## [v0.6.1] - 2024-05-09

Expand Down
4 changes: 4 additions & 0 deletions examples/nunchuck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod nunchuck {
// TODO: Move Nunchuck code out to be an actual sensor and add tests

#[derive(Debug)]
#[allow(dead_code)]
pub struct NunchuckReading {
pub joystick_x: u8,
pub joystick_y: u8,
Expand Down Expand Up @@ -186,9 +187,12 @@ mod nunchuck {
#[cfg(any(target_os = "linux", target_os = "android"))]
use nunchuck::*;

#[cfg(any(target_os = "linux", target_os = "android"))]
use docopt::Docopt;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::env::args;

#[cfg(any(target_os = "linux", target_os = "android"))]
const USAGE: &str = "
Reading Wii Nunchuck data via Linux i2cdev.

Expand Down
15 changes: 9 additions & 6 deletions examples/pca9956b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ extern crate docopt;
extern crate i2cdev;

#[cfg(any(target_os = "linux", target_os = "android"))]
use i2cdev::core::{I2CMessage, I2CTransfer};
#[cfg(any(target_os = "linux", target_os = "android"))]
use i2cdev::linux::{LinuxI2CBus, LinuxI2CMessage};

use docopt::Docopt;
use std::env::args;
use i2cdev::{
core::{I2CMessage, I2CTransfer},
linux::{LinuxI2CBus, LinuxI2CMessage},
};

#[cfg(any(target_os = "linux", target_os = "android"))]
const USAGE: &str = "
Reads registers from a PCA9956B IC via Linux i2cdev.

Expand All @@ -32,13 +31,17 @@ Options:
--version Show version.
";

#[cfg(any(target_os = "linux", target_os = "android"))]
const ADDR: u16 = 0x20;

#[cfg(not(any(target_os = "linux", target_os = "android")))]
fn main() {}

#[cfg(any(target_os = "linux", target_os = "android"))]
fn main() {
use docopt::Docopt;
use std::env::args;

let args = Docopt::new(USAGE)
.and_then(|d| d.argv(args()).parse())
.unwrap_or_else(|e| e.exit());
Expand Down
14 changes: 8 additions & 6 deletions examples/sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ extern crate byteorder;
extern crate docopt;
extern crate i2cdev;

#[cfg(any(target_os = "linux", target_os = "android"))]
use docopt::Docopt;
use sensors::adxl345_accelerometer::*;
use sensors::mpl115a2_barometer::*;
use sensors::{Accelerometer, Barometer, Thermometer};
use std::env::args;
use std::thread;
use std::time::Duration;
#[cfg(any(target_os = "linux", target_os = "android"))]
use sensors::{
adxl345_accelerometer::*, mpl115a2_barometer::*, Accelerometer, Barometer, Thermometer,
};

#[cfg(any(target_os = "linux", target_os = "android"))]
use std::{env::args, thread, time::Duration};

#[cfg(any(target_os = "linux", target_os = "android"))]
use i2cdev::linux::*;
Expand Down
2 changes: 2 additions & 0 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ use std::path::Path;
pub use core::I2CMessage;

/// Concrete linux I2C device
#[derive(Debug)]
pub struct LinuxI2CDevice {
devfile: File,
slave_address: u16,
pec: bool,
}

/// Linux I2C bus
#[derive(Debug)]
pub struct LinuxI2CBus {
devfile: File,
}
Expand Down
3 changes: 2 additions & 1 deletion src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::io;
pub type I2CResult<T> = io::Result<T>;

/// Mock I2C device register map
#[derive(Debug, Clone, Copy)]
pub struct I2CRegisterMap {
registers: [u8; 0xFF],
offset: usize,
Expand Down Expand Up @@ -67,7 +68,7 @@ impl I2CRegisterMap {
}

/// Mock I2C device exposing a register map
#[derive(Default)]
#[derive(Default, Debug, Clone, Copy)]
pub struct MockI2CDevice {
/// I2C register map
pub regmap: I2CRegisterMap,
Expand Down