Skip to content

Commit fb83826

Browse files
authored
Merge pull request #52 from eldruin/code-formatting
Format code and check formatting on CI
2 parents 28c852d + c39540e commit fb83826

File tree

9 files changed

+202
-177
lines changed

9 files changed

+202
-177
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ os:
66
- osx
77

88
script:
9+
- rustup component add rustfmt
910
- cargo build --verbose
1011
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cargo test --verbose; fi
12+
- cargo fmt -- --check

examples/nunchuck.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use i2cdev::linux::*;
2222
#[cfg(any(target_os = "linux", taret_os = "android"))]
2323
mod nunchuck {
2424
use std::error::Error;
25+
use std::fmt;
2526
use std::thread;
2627
use std::time::Duration;
27-
use std::fmt;
2828

2929
use i2cdev::core::I2CDevice;
3030

@@ -130,11 +130,10 @@ mod nunchuck {
130130
let mut buf: [u8; 6] = [0; 6];
131131

132132
// tell the nunchuck to prepare a sample
133-
try!(
134-
self.i2cdev
135-
.smbus_write_byte(0x00)
136-
.map_err(NunchuckError::Error)
137-
);
133+
try!(self
134+
.i2cdev
135+
.smbus_write_byte(0x00)
136+
.map_err(NunchuckError::Error));
138137

139138
// now, read it!
140139
thread::sleep(Duration::from_millis(10));
@@ -196,8 +195,8 @@ mod nunchuck {
196195
#[cfg(any(target_os = "linux", target_os = "android"))]
197196
use nunchuck::*;
198197

199-
use std::env::args;
200198
use docopt::Docopt;
199+
use std::env::args;
201200

202201
const USAGE: &'static str = "
203202
Reading Wii Nunchuck data via Linux i2cdev.

examples/pca9956b.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.extern crate i2cdev;
88

9-
extern crate i2cdev;
109
extern crate docopt;
10+
extern crate i2cdev;
1111

1212
#[cfg(any(target_os = "linux", target_os = "android"))]
13-
use i2cdev::core::{I2CTransfer, I2CMessage};
13+
use i2cdev::core::{I2CMessage, I2CTransfer};
1414
#[cfg(any(target_os = "linux", target_os = "android"))]
1515
use i2cdev::linux::{LinuxI2CBus, LinuxI2CMessage};
1616

17-
use std::env::args;
1817
use docopt::Docopt;
18+
use std::env::args;
1919

2020
const USAGE: &str = "
2121
Reads registers from a PCA9956B IC via Linux i2cdev.

examples/sensors.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ extern crate byteorder;
1717
extern crate docopt;
1818
extern crate i2cdev;
1919

20-
use std::thread;
21-
use std::time::Duration;
22-
use std::env::args;
2320
use docopt::Docopt;
24-
use sensors::{Accelerometer, Barometer, Thermometer};
25-
use sensors::mpl115a2_barometer::*;
2621
use sensors::adxl345_accelerometer::*;
22+
use sensors::mpl115a2_barometer::*;
23+
use sensors::{Accelerometer, Barometer, Thermometer};
24+
use std::env::args;
25+
use std::thread;
26+
use std::time::Duration;
2727

2828
#[cfg(any(target_os = "linux", target_os = "android"))]
2929
use i2cdev::linux::*;
@@ -101,8 +101,8 @@ mod sensors {
101101

102102
pub mod adxl345_accelerometer {
103103
use super::*;
104-
use i2cdev::core::I2CDevice;
105104
use byteorder::{ByteOrder, LittleEndian};
105+
use i2cdev::core::I2CDevice;
106106

107107
// TODO: read/write data format (for now, assumed 0x00)
108108

@@ -173,12 +173,8 @@ mod sensors {
173173
i2cdev.smbus_write_byte_data(REGISTER_POWER_CTL, 0x00)?;
174174

175175
// configure some defaults
176-
try!(
177-
i2cdev.smbus_write_byte_data(
178-
REGISTER_BW_RATE,
179-
ADXL345DataRate::RATE_1600HZ as u8
180-
)
181-
);
176+
try!(i2cdev
177+
.smbus_write_byte_data(REGISTER_BW_RATE, ADXL345DataRate::RATE_1600HZ as u8));
182178
i2cdev.smbus_write_byte_data(REGISTER_DATA_FORMAT, 0x08)?;
183179
i2cdev.smbus_write_byte_data(REGISTER_OFSX, 0xFD)?;
184180
i2cdev.smbus_write_byte_data(REGISTER_OFSY, 0x03)?;
@@ -226,11 +222,11 @@ mod sensors {
226222

227223
pub mod mpl115a2_barometer {
228224
use super::*;
225+
use byteorder::{BigEndian, ByteOrder};
226+
use i2cdev::core::I2CDevice;
227+
use std::error::Error;
229228
use std::thread;
230229
use std::time::Duration;
231-
use std::error::Error;
232-
use i2cdev::core::I2CDevice;
233-
use byteorder::{BigEndian, ByteOrder};
234230

235231
pub const MPL115A2_I2C_ADDR: u16 = 0x60; // appears to always be this
236232

@@ -398,29 +394,31 @@ mod sensors {
398394

399395
#[cfg(test)]
400396
mod tests {
401-
use super::*;
402397
use super::calc_coefficient;
403-
use sensors::*;
398+
use super::*;
404399
use mock::MockI2CDevice;
400+
use sensors::*;
405401

406402
macro_rules! assert_almost_eq {
407-
($left:expr, $right:expr) => ({
403+
($left:expr, $right:expr) => {{
408404
match (&($left), &($right)) {
409405
(left_val, right_val) => {
410406
if (*left_val - *right_val).abs() > 0.0001 {
411407
panic!("assertion failed: ({:?} != {:?})", *left_val, *right_val);
412408
}
413409
}
414410
}
415-
})
411+
}};
416412
}
417413

418414
fn make_dev(mut i2cdev: MockI2CDevice) -> MPL115A2BarometerThermometer<MockI2CDevice> {
419415
(&mut i2cdev.regmap).write_regs(
420416
0x04,
421417
&[
422-
74, 98 /* A0 */, 165, 150 /* B1 */, 182, 106 /* B2 */, 63,
423-
232,
418+
74, 98, /* A0 */
419+
165, 150, /* B1 */
420+
182, 106, /* B2 */
421+
63, 232,
424422
],
425423
); // C12
426424
MPL115A2BarometerThermometer::new(i2cdev).unwrap()
@@ -455,7 +453,6 @@ mod sensors {
455453
let mut dev = make_dev(i2cdev);
456454
assert_almost_eq!(dev.temperature_celsius().unwrap(), 21.448599);
457455
}
458-
459456
}
460457
}
461458
}

src/core.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ pub trait I2CDevice {
105105
/// Write a block of up to 32 bytes from a device
106106
///
107107
/// Uses write_i2c_block_data instead write_block_data.
108-
fn smbus_write_i2c_block_data(&mut self, register: u8, values: &[u8]) -> Result<(), Self::Error>;
108+
fn smbus_write_i2c_block_data(
109+
&mut self,
110+
register: u8,
111+
values: &[u8],
112+
) -> Result<(), Self::Error>;
109113

110114
/// Select a register, send 1 to 31 bytes of data to it, and reads
111115
/// 1 to 31 bytes of data from it.

0 commit comments

Comments
 (0)