Skip to content

Commit 97a13e5

Browse files
Worked on errors
Deleted unneeded files, updated functions unsure of, worked on many errors
1 parent 6e3dfea commit 97a13e5

File tree

6 files changed

+201
-234
lines changed

6 files changed

+201
-234
lines changed
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
// TODO: Add includes as needed
21
#include "SparkFun_Qwiic_XM125_Arduino_Library.h"
32

4-
// TODO: Change Template
5-
TemplateClass myDevice;
3+
SfeXM125 sensor;
4+
5+
// I2C default address
6+
uint8_t i2cAddress = SFE_XM125_I2C_ADDRESS;
67

78
void setup()
89
{
910
// Start serial
1011
Serial.begin(115200);
11-
Serial.println("Template Example 1 - Basic Uasge"); // TODO: Update
12+
Serial.println("XM125 Example 1: Basic Distance Readings");
13+
Serial.println("");
1214

1315
// TODO: Check return value of begin
14-
myDevice.begin();
16+
sensor.begin();
1517

16-
// TODO: Add other setup code if needed. Most setup should be done in begin()
18+
// If begin is successful (0), then start example
19+
if(sensor.begin(i2cAddress, Wire) == 1)
20+
{
21+
Serial.println("Begin");
22+
}
23+
else // Otherwise, infinite loop
24+
{
25+
Serial.println("Device failed to setup - Freezing code.");
26+
while(1); // Runs forever
27+
}
1728
}
1829

1930
void loop()
2031
{
21-
// Request Distance Data to the device
22-
32+
// Request Distance Data from the device
33+
34+
delay(100);
2335
}
Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,30 @@
1-
#include "sfe_bus.h"
2-
#include "sfeXM125Regs.h"
1+
#include "sfeQwiicXM125.h"
2+
#include <Arduino.h>
3+
#include <Wire.h>
34

4-
// Add any definitions hereby
5-
6-
7-
class QwDevXM125
5+
class SfeXM125 : public QwDevXM125
86
{
97
public:
108

11-
//
12-
///////////////////////////////////////////////////////////////////////
13-
// begin()
14-
//
15-
//
16-
// This method follows the standard startup pattern in SparkFun Arduino
17-
// libraries.
18-
//
19-
// Parameter Description
20-
// --------- ----------------------------
21-
// wirePort optional. The Wire port. If not provided, the default port is used
22-
// address optional. I2C Address. If not provided, the default address is used.
23-
// retval true on success, false on startup failure
24-
//
25-
// This method is overridden, implementing two versions.
26-
//
27-
// Version 1:
28-
// User skips passing in an I2C object which then defaults to Wire.
29-
bool begin(uint8_t deviceAddress = SFE_XM125_I2C_ADDRESS)
9+
SfeXM125()
3010
{
31-
// Setup I2C object and pass into the superclass
32-
setCommunicationBus(_i2cBus, deviceAddress);
33-
34-
// Initialize the I2C buss class i.e. setup default Wire port
35-
_i2cBus.init();
36-
37-
// Initialize the system - return results
38-
return this->QwDevXM125::init();
3911
}
4012

41-
//Version 2:
42-
// User passes in an I2C object and an address (optional).
43-
bool begin(TwoWire &wirePort, uint8_t deviceAddress = SFE_XM125_I2C_ADDRESS)
13+
/// @brief Sets up Arduino I2C driver using the specified I2C address then calls the super class begin.
14+
/// @param address Address of the I2C device.
15+
/// @return True if successful, false otherwise.
16+
bool begin(uint8_t deviceAddress = SFE_XM125_I2C_ADDRESS, TwoWire &wirePort = Wire)
4417
{
45-
// Setup I2C object and pass into the superclass
46-
setCommunicationBus(_i2cBus, deviceAddress);
47-
4818
// Give the I2C port provided by the user to the I2C bus class.
49-
_i2cBus.init(wirePort, true);
19+
_i2cBus.init(wirePort, deviceAddress);
5020

5121
// Initialize the system - return results
52-
return this->QwDevXM125::init();
22+
return this->QwDevXM125::begin(&_i2cBus);
5323
}
5424

5525
private:
5626

5727
// I2C bus class
58-
sfe_XM125::QwI2C _i2cBus;
59-
60-
61-
62-
}
28+
sfeTkArdI2C _i2cBus;
29+
//QwDevXM125::QwI2C _i2cBus; // original code
30+
};

src/SparkFun_Toolkit.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)