@@ -22,7 +22,9 @@ Nunchuck (which has an i2c interface).
22
22
23
23
Here's a real quick example showing the guts of how you create a
24
24
device and start talking to it... This device only requires basic
25
- functions (read/write) which are done via the Read/Write traits.
25
+ functions (read/write) which are done via the Read/Write traits (if
26
+ you actually want to use the Wii Nunchuck you should use
27
+ [ ` i2cdev::sensors::nunchuck::Nunchuck ` ] [ nunchuck ] :
26
28
27
29
``` rust
28
30
extern crate i2cdev;
@@ -31,18 +33,21 @@ use std::thread;
31
33
32
34
const NUNCHUCK_SLAVE_ADDR : u16 = 0x52 ;
33
35
34
- // real code should not use unwrap() so liberally
36
+ // real code should probably not use unwrap()
35
37
fn i2cfun () -> Result <(), I2CError > {
36
38
let mut dev = try ! (I2CDevice :: new (" /dev/i2c-1" , NUNCHUCK_SLAVE_ADDR ));
39
+
40
+ // init sequence
37
41
try ! (self . i2cdev. smbus_write_byte_data (0xF0 , 0x55 ));
38
- try ! (self . i2cdev- smbus_write_byte_data (0xFB , 0x00 ))
42
+ try ! (self . i2cdev. smbus_write_byte_data (0xFB , 0x00 ));
39
43
thread :: sleep_ms (100 );
44
+
40
45
loop {
41
46
let mut buf : [u8 : 6 ] = [0 : 6 ];
42
- self . i2cdev. write_all ( & [ 0x00 ] ). unwrap ();
47
+ self . i2cdev. smbus_write_byte ( 0x00 ). unwrap ();
43
48
thread :: sleep_ms (10 );
44
49
self . i2cdev. read (& mut buf ). unwrap ();
45
- println! (" Reading: {:?}" , buf );
50
+ println! (" Reading: {:?}" , buf );
46
51
}
47
52
}
48
53
```
@@ -66,6 +71,8 @@ pub trait I2CSMBus {
66
71
}
67
72
```
68
73
74
+ [ nunchuck ] : http://rust-embedded.github.io/rust-i2cdev/i2cdev/sensors/nunchuck/struct.Nunchuck.html
75
+
69
76
Features
70
77
--------
71
78
0 commit comments