Skip to content

Commit 5a36824

Browse files
committed
Fixes to comments and some formatting
1 parent d100f66 commit 5a36824

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void setup()
2828
{
2929
// Start serial
3030
Serial.begin(115200);
31-
Serial.println("Ultrasonic Distance Sensor Example 1 - Basic Distance Sensing");
31+
Serial.println("Ultrasonic Distance Sensor Example 1 - Basic Readings");
3232

3333
Wire.begin();
3434

examples/Example4_ChangeAddress/Example4_ChangeAddress.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
QwiicUltrasonic myUltrasonic;
2121
// If you're using the older version of the Ultrasonic Distance
2222
// sensor, then uncomment the line below and comment out the line above.
23+
// You can check the version in copper by the "R" on the front of the board.
24+
// Newer versions are >v10 and older versions simply do not have a version number.
2325
//QwiicUltrasonic myUltrasonic(kQwiicUltrasonicFWOld);
2426

2527
// Here we set the device address. Note that an older version of the Qwiic

src/sfeQwiicUltrasonic.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ sfeTkError_t sfeQwiicUltrasonic::begin(sfeTkII2C *theBus)
1919
return kSTkErrFail;
2020

2121
// Check the device address
22-
if(_fwVersion == kQwiicUltrasonicFWOld)
22+
if (_fwVersion == kQwiicUltrasonicFWOld)
2323
{
24-
2524
if (theBus->address() < kQwiicUltrasonicMinAddress || theBus->address() > kQwiicUltrasonicMaxAddress)
2625
{
2726
// An older version of the firmware used 0x00 as the default address.
@@ -70,7 +69,7 @@ sfeTkError_t sfeQwiicUltrasonic::changeAddress(uint8_t &address)
7069

7170
sfeTkError_t err;
7271

73-
if(_fwVersion == kQwiicUltrasonicFWOld)
72+
if (_fwVersion == kQwiicUltrasonicFWOld)
7473
{
7574
// Old firmware only supports a limited range of addresses.
7675
if (address < kQwiicUltrasonicMinAddress || address > kQwiicUltrasonicMaxAddress)
@@ -79,7 +78,7 @@ sfeTkError_t sfeQwiicUltrasonic::changeAddress(uint8_t &address)
7978
// Write the new address to the device. The first bit must be set to 1
8079
err = _theBus->writeByte(address | 0x80);
8180
}
82-
else if(_fwVersion == kQwiicUltrasonicFWLatest)
81+
else if (_fwVersion == kQwiicUltrasonicFWLatest)
8382
{
8483
size_t numBytes = 2;
8584
// Latest firmware versions supports all of the available I2C addresses.
@@ -90,13 +89,14 @@ sfeTkError_t sfeQwiicUltrasonic::changeAddress(uint8_t &address)
9089
address <<= 1;
9190
const uint8_t toWrite[2] = {kUltrasonicAddressChangeCommand, address};
9291

93-
//Write the new address to the device
92+
// Write the new address to the device
9493
err = _theBus->writeRegion(toWrite, numBytes);
9594
}
96-
else {
97-
//There was some error setting the version in the constructor
98-
//return an error.
99-
return kSTkErrOk;
95+
else
96+
{
97+
// There was some error setting the version in the constructor
98+
// return an error.
99+
return kSTkErrFail;
100100
}
101101

102102
// Check whether the write was successful

src/sfeQwiicUltrasonic.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#pragma once
1313

1414
#include "SparkFun_Toolkit.h"
15+
#include <cstdint>
1516

1617
// Available I2C addresses of the Qwiic Ultrasonic
1718
const uint8_t kQwiicUltrasonicDefaultAddress = 0x2F;
1819

19-
const uint8_t kQwiicUltrasonicFWLatest = 0x01;
20-
const uint8_t kQwiicUltrasonicFWOld = 0x10;
20+
// Firmware versions. The later hardware version is v10 and so the "latest" here
21+
// refers to that. The previous version is randomnly given the value v01.
22+
const uint8_t kQwiicUltrasonicFWLatest = 0x10;
23+
const uint8_t kQwiicUltrasonicFWOld = 0x01;
2124

2225
// These addresses are the min and max (respectively) of valid I2C addresses that can
2326
// be used for the newest revision of the Qwiic Ultrasonic sensor.
@@ -35,15 +38,17 @@ class sfeQwiicUltrasonic
3538
{
3639
public:
3740
/// @brief Default constructor
41+
///
3842
sfeQwiicUltrasonic() : _theBus(nullptr), _fwVersion(kQwiicUltrasonicFWLatest)
3943
{
4044
}
4145

42-
/// @brief Default constructor
43-
sfeQwiicUltrasonic(const uint8_t fwVersion) : _theBus(nullptr), _fwVersion(fwVersion)
44-
{
45-
}
46-
46+
/// @brief Alternate constructor
47+
/// @param fwVersion Firmware version of the Qwiic Ultrasonic Sensor. If using an older version
48+
/// of the sensor, the list of available I2C addresses differs.
49+
sfeQwiicUltrasonic(const uint8_t fwVersion) : _theBus(nullptr), _fwVersion(fwVersion)
50+
{
51+
}
4752

4853
/// @brief Begins the Qwiic Ultrasonic sensor
4954
/// @param theBus I2C bus to use for communication

0 commit comments

Comments
 (0)