11#include " GameControllers.h"
22#include < string.h>
33
4- NunchuckController::NunchuckController (unsigned _scl, unsigned _sda) {
5- scl = _scl;
6- sda = _sda;
7- }
8-
94bool NunchuckController::begin () {
10- if (wire == NULL ) {
11- #ifdef NUNCHUCK_SOFT_I2C
12- wire = new SoftWire (scl, sda, SOFT_STANDARD);
13- #else
14- #error Hardware I2C has trouble with hotplugging.
15- wire = new TwoWire (1 , 0 ); // I2C_FAST_MODE);
16- #endif
17- wire->begin ();
18- }
5+ wire.begin ();
196
207#ifdef MANUAL_DECRYPT
218 if (!sendBytes (0x40 ,0x00 )) {
@@ -35,10 +22,10 @@ bool NunchuckController::begin() {
3522}
3623
3724uint8_t NunchuckController::sendBytes (uint8_t location, uint8_t value) {
38- wire-> beginTransmission (i2cAddress);
39- wire-> write (location);
40- wire-> write (value);
41- return 0 == wire-> endTransmission ();
25+ wire. beginTransmission (i2cAddress);
26+ wire. write (location);
27+ wire. write (value);
28+ return 0 == wire. endTransmission ();
4229}
4330
4431uint16_t NunchuckController::rescale (uint8_t x) {
@@ -52,23 +39,23 @@ uint16_t NunchuckController::rescale(uint8_t x) {
5239}
5340
5441bool NunchuckController::read (GameControllerData_t* data) {
55- wire-> beginTransmission (i2cAddress);
56- wire-> write (0x00 );
57- if (0 !=wire-> endTransmission ())
42+ wire. beginTransmission (i2cAddress);
43+ wire. write (0x00 );
44+ if (0 !=wire. endTransmission ())
5845 return 0 ;
5946
6047 delayMicroseconds (500 );
6148#ifdef SERIAL_DEBUG
6249// Serial.println("Requested");
6350#endif
6451
65- wire-> requestFrom (i2cAddress, 6 );
52+ wire. requestFrom (i2cAddress, 6 );
6653 int count = 0 ;
67- while (wire-> available () && count<6 ) {
54+ while (wire. available () && count<6 ) {
6855#ifdef MANUAL_DECRYPT
69- buffer[count++] = ((uint8_t )0x17 ^(uint8_t )wire-> read ()) + (uint8_t )0x17 ;
56+ buffer[count++] = ((uint8_t )0x17 ^(uint8_t )wire. read ()) + (uint8_t )0x17 ;
7057#else
71- buffer[count++] = wire-> read ();
58+ buffer[count++] = wire. read ();
7259#endif
7360 }
7461 if (count < 6 )
@@ -90,5 +77,3 @@ bool NunchuckController::read(GameControllerData_t* data) {
9077
9178 return true ;
9279}
93-
94-
0 commit comments