Skip to content

Commit e77f497

Browse files
committed
Fixed order
1 parent 30465f4 commit e77f497

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Wii-Nunchuk/Nunchuk.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ static void nunchuk_init() {
6868
// Change TWI speed for nuchuk, which uses Fast-TWI (400kHz)
6969
// Normally this will be set in twi_init(), but this hack works without modifying the original source
7070
Wire.setClock(400000);
71-
71+
7272
// delay(1);
7373

7474
#ifdef NUNCHUK_DISABLE_ENCRYPTION
7575
I2C_START(NUNCHUK_ADDRESS);
7676
I2C_WRITE(0xF0);
7777
I2C_WRITE(0x55);
7878
I2C_STOP();
79-
// delay(1)
79+
// delay(1);
8080
I2C_START(NUNCHUK_ADDRESS);
8181
I2C_WRITE(0xFB);
8282
I2C_WRITE(0x00);
8383
I2C_STOP();
84-
// delay(1)
84+
// delay(1);
8585
#else
8686
I2C_START(NUNCHUK_ADDRESS);
8787
I2C_WRITE(0x40);
8888
I2C_WRITE(0x00);
8989
I2C_STOP();
90-
// delay(1)
90+
// delay(1);
9191
#endif
9292

9393
#ifdef NUNCHUK_DEBUG
@@ -132,19 +132,18 @@ static inline uint8_t nunchuk_decode_byte(uint8_t x) {
132132
*/
133133
static uint8_t nunchuk_read() {
134134

135-
I2C_START(NUNCHUK_ADDRESS);
136-
I2C_WRITE(0x00);
137-
#ifdef NUNCHUK_DELAY
138-
delayMicroseconds(100);
139-
#endif
140-
I2C_STOP();
141-
142135
uint8_t i;
143136
Wire.requestFrom(NUNCHUK_ADDRESS, 6);
144137
//delayMicroseconds(10);
145138
for (i = 0; i < 6 && Wire.available(); i++) {
146139
nunchuk_data[i] = nunchuk_decode_byte(I2C_READ());
147140
}
141+
I2C_START(NUNCHUK_ADDRESS);
142+
I2C_WRITE(0x00);
143+
#ifdef NUNCHUK_DELAY
144+
delayMicroseconds(100);
145+
#endif
146+
I2C_STOP();
148147
return i == 6;
149148
}
150149

0 commit comments

Comments
 (0)