Revision 9a8e8b26

View differences:

Adafruit_BNO055.cpp
36 36

  
37 37
/*!
38 38
 *  @brief  Instantiates a new Adafruit_BNO055 class
39
 *  @param  sensorID
40
 *          sensor ID
41
 *  @param  address
42
 *          i2c address
39 43
 */
40
Adafruit_BNO055::Adafruit_BNO055() {}
44
Adafruit_BNO055::Adafruit_BNO055(int32_t sensorID, uint8_t address,
45
                                 TwoWire *theWire) {
46
  _sensorID = sensorID;
47
  _address = address;
48
}
41 49

  
42 50
/*!
43 51
 *  @brief  Sets up the HW
......
56 64
 *            OPERATION_MODE_M4G,
57 65
 *            OPERATION_MODE_NDOF_FMC_OFF,
58 66
 *            OPERATION_MODE_NDOF]
59
 *  @param  *theWire
60
 *          Wire object
61 67
 *  @return true if process is successful
62 68
 */
63
bool Adafruit_BNO055::begin() {
64
  _wire = &Wire;
65
#if defined(ARDUINO_SAMD_ZERO) && !(ARDUINO_SAMD_FEATHER_M0)
69
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode) {
70
#if defined(ARDUINO_SAMD_ZERO) && (_address == BNO055_ADDRESS_A)
66 71
#error                                                                         \
67 72
    "On an arduino Zero, BNO055's ADR pin must be high. Fix that, then delete this line."
68 73
  _address = BNO055_ADDRESS_B;
69
#else
70
  _address = BNO055_ADDRESS_A;
71 74
#endif
72 75

  
73
  return init(OPERATION_MODE_NDOF);
74
}
75

  
76
/*!
77
 *  @brief  Sets up the HW
78
 *  @param  mode
79
 *          mode values
80
 *           [OPERATION_MODE_CONFIG,
81
 *            OPERATION_MODE_ACCONLY,
82
 *            OPERATION_MODE_MAGONLY,
83
 *            OPERATION_MODE_GYRONLY,
84
 *            OPERATION_MODE_ACCMAG,
85
 *            OPERATION_MODE_ACCGYRO,
86
 *            OPERATION_MODE_MAGGYRO,
87
 *            OPERATION_MODE_AMG,
88
 *            OPERATION_MODE_IMUPLUS,
89
 *            OPERATION_MODE_COMPASS,
90
 *            OPERATION_MODE_M4G,
91
 *            OPERATION_MODE_NDOF_FMC_OFF,
92
 *            OPERATION_MODE_NDOF]
93
 *  @param  *theWire
94
 *          Wire object
95
 *  @return true if process is successful
96
 */
97
bool Adafruit_BNO055::begin(adafruit_bno055_opmode_t mode, uint8_t address,
98
                            TwoWire *theWire) {
99
  _wire = theWire;
100
  _address = address;
101

  
102
  return init(mode);
103
}
104

  
105
bool Adafruit_BNO055::init(adafruit_bno055_opmode_t mode) {
106 76
  /* Enable I2C */
107 77
  _wire->begin();
108 78

  
109
  /* BNO055 clock stretches for 500us or more! */
79
  // BNO055 clock stretches for 500us or more!
110 80
#ifdef ESP8266
111
  /* Allow for 1000us of clock stretching */
112
<<<<<<< HEAD
113
  _wire->setClockStretchLimit(1000);
114
=======
115
  Wire.setClockStretchLimit(1000);
116
>>>>>>> 75f03d2e1fd440e7febc0de8c47a52bab09c51b0
81
  _wire->setClockStretchLimit(1000); // Allow for 1000us of clock stretching
117 82
#endif
118 83

  
119 84
  /* Make sure we have the right device */
120 85
  uint8_t id = read8(BNO055_CHIP_ID_ADDR);
121 86
  if (id != BNO055_ID) {
122
    /* hold on for boot */
123
    delay(1000);
87
    delay(1000); // hold on for boot
124 88
    id = read8(BNO055_CHIP_ID_ADDR);
125 89
    if (id != BNO055_ID) {
126
      /* still not? ok bail */
127
      return false;
90
      return false; // still not? ok bail
128 91
    }
129 92
  }
130 93

  
......
144 107

  
145 108
  write8(BNO055_PAGE_ID_ADDR, 0);
146 109

  
147
  /* Set the output units
148
     uint8_t unitsel = (0 << 7) | // Orientation = Android
149
                       (0 << 4) | // Temperature = Celsius
150
                       (0 << 2) | // Euler = Degrees
151
                       (1 << 1) | // Gyro = Rads
152
                       (0 << 0);  // Accelerometer = m/s^2
153
     write8(BNO055_UNIT_SEL_ADDR, unitsel);
154
   */
110
  /* Set the output units */
111
  /*
112
  uint8_t unitsel = (0 << 7) | // Orientation = Android
113
                    (0 << 4) | // Temperature = Celsius
114
                    (0 << 2) | // Euler = Degrees
115
                    (1 << 1) | // Gyro = Rads
116
                    (0 << 0);  // Accelerometer = m/s^2
117
  write8(BNO055_UNIT_SEL_ADDR, unitsel);
118
  */
155 119

  
156 120
  /* Configure axis mapping (see section 3.4) */
121
  /*
122
  write8(BNO055_AXIS_MAP_CONFIG_ADDR, REMAP_CONFIG_P2); // P0-P7, Default is P1
123
  delay(10);
124
  write8(BNO055_AXIS_MAP_SIGN_ADDR, REMAP_SIGN_P2); // P0-P7, Default is P1
125
  delay(10);
126
  */
127

  
157 128
  write8(BNO055_SYS_TRIGGER_ADDR, 0x0);
158 129
  delay(10);
159 130
  /* Set the requested operating mode (see section 3.3) */
Adafruit_BNO055.h
280 280
    VECTOR_GRAVITY = BNO055_GRAVITY_DATA_X_LSB_ADDR
281 281
  } adafruit_vector_type_t;
282 282

  
283
  Adafruit_BNO055();
283
  Adafruit_BNO055(int32_t sensorID = -1, uint8_t address = BNO055_ADDRESS_A,
284
                  TwoWire *theWire = &Wire);
284 285

  
285
  bool begin();
286
  bool begin(adafruit_bno055_opmode_t mode,
287
             uint8_t address, TwoWire *wire);
288
  bool init(adafruit_bno055_opmode_t mode);
286
  bool begin(adafruit_bno055_opmode_t mode = OPERATION_MODE_NDOF);
289 287
  void setMode(adafruit_bno055_opmode_t mode);
290 288
  void setAxisRemap(adafruit_bno055_axis_remap_config_t remapcode);
291 289
  void setAxisSign(adafruit_bno055_axis_remap_sign_t remapsign);

Also available in: Unified diff