Skip to content

Commit b4b6a8b

Browse files
committed
Defines a Version one interface for the distance object -- to maintain backward compatablity
1 parent df1b080 commit b4b6a8b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/SparkFun_Qwiic_XM125_Arduino_Library.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "sfTk/sfDevXM125Core.h"
2323
#include "sfTk/sfDevXM125Distance.h"
2424
#include "sfTk/sfDevXM125Presence.h"
25+
26+
// To support version 1.* API
27+
#include "sfTk/sfDevXM125DistanceV1.h"
2528
// clang-format on
2629

2730
#include <Arduino.h>
@@ -116,3 +119,51 @@ class SparkFunXM125Presence : public sfDevXM125Presence
116119
// I2C bus class
117120
sfTkArdI2C _i2cBus;
118121
};
122+
123+
// Version 1 - for backward compatibility
124+
/**
125+
* @class SparkFunXM125DistanceV1
126+
* @brief Arduino class for the SparkFun Pulsed Coherent Radar Sensor - Acconeer XM125 (Qwiic) for distance detection.
127+
*
128+
* This class is to provide Version 1 compatibility for the SparkFun Pulsed Coherent Radar Sensor - distance detection.
129+
*
130+
* This class provides methods for initializing the sensor, checking connection status, and configuring the device
131+
* for distance detection using I2C communication.
132+
*/
133+
class SparkFunXM125DistanceV1 : public sfDevXM125DistanceV1
134+
{
135+
public:
136+
SparkFunXM125DistanceV1()
137+
{
138+
}
139+
140+
/**
141+
* @brief Sets up Arduino I2C driver using the specified I2C address then calls the super class begin.
142+
*
143+
* @param deviceAddress Address of the I2C device. Default is SFE_XM125_I2C_ADDRESS.
144+
* @param wirePort Wire port of the I2C device. Default is Wire.
145+
* @return True if successful, false otherwise.
146+
*/
147+
bool begin(uint8_t deviceAddress = SFE_XM125_I2C_ADDRESS, TwoWire &wirePort = Wire)
148+
{
149+
// Give the I2C port provided by the user to the I2C bus class.
150+
_i2cBus.init(wirePort, deviceAddress);
151+
152+
// Initialize the system - return results
153+
return this->sfDevXM125DistanceV1::begin(&_i2cBus) == ksfTkErrOk;
154+
}
155+
156+
/**
157+
* @brief Checks if the device is connected.
158+
*
159+
* @return True if the sensor is connected, false otherwise.
160+
*/
161+
bool isConnected()
162+
{
163+
return _i2cBus.ping() == ksfTkErrOk;
164+
}
165+
166+
private:
167+
// I2C bus class
168+
sfTkArdI2C _i2cBus;
169+
};

0 commit comments

Comments
 (0)