1- /* SparkFun Ulrasonic Distance Sensor
2- *
3- * Product:
1+ /* SparkFun Ulrasonic Distance Sensor
2+ *
3+ * Product:
44 * * SparkFun Qwiic Ultrasonic Distance Sensor - HC-SR04 (SEN-1XXXX)
55 * * https://www.sparkfun.com/1XXXX
6- *
6+ *
77 * SPDX-License-Identifier: MIT
88 *
99 * Copyright (c) 2024 SparkFun Electronics
1212#pragma once
1313
1414#include " SparkFun_Toolkit.h"
15- #include < stdint.h>
1615
1716// Available I2C addresses of the Qwiic Ultrasonic
1817const uint8_t kQwiicUltrasonicDefaultAddress = 0x2F ;
18+
19+ const uint8_t kQwiicUltrasonicFWLatest = 0x01 ;
20+ const uint8_t kQwiicUltrasonicFWOld = 0x10 ;
21+
1922// These addresses are the min and max (respectively) of valid I2C addresses that can
2023// be used for the newest revision of the Qwiic Ultrasonic sensor.
21- const uint8_t kQwiicI2CAddressMin = 0x08 ;
22- const uint8_t kQwiicI2CAddressMax = 0x7F ;
24+ const uint8_t kQwiicUltrasonicI2CAddressMin = 0x08 ;
25+ const uint8_t kQwiicUltrasonicI2CAddressMax = 0x7F ;
2326// Available I2C addresses of the Qwiic Ultrasonic
24- const uint8_t kQwiicUltrasonicAddresses [] = {0x20 , 0x21 , 0x22 , 0x23 , 0x24 , 0x25 , 0x26 , 0x27 ,
25- 0x28 , 0x29 , 0x2A , 0x2B , 0x2C , 0x2D , 0x2E , 0x2F };
26- const uint8_t kQwiicUltrasonicNumAddresses = sizeof (kQwiicUltrasonicAddresses ) / sizeof (uint8_t );
27- const uint8_t kQwiicUltrasonicMinAddress = kQwiicUltrasonicAddresses [0 ];
28- const uint8_t kQwiicUltrasonicMaxAddress = kQwiicUltrasonicAddresses [15 ];;
27+ const uint8_t kQwiicUltrasonicMinAddress = 0x20 ;
28+ const uint8_t kQwiicUltrasonicMaxAddress = 0x2F ;
29+ ;
2930// I2C commands
3031const uint8_t kUltrasonicDistanceReadCommand = 0x01 ;
3132const uint8_t kUltrasonicAddressChangeCommand = 0x04 ;
@@ -34,10 +35,16 @@ class sfeQwiicUltrasonic
3435{
3536 public:
3637 // / @brief Default constructor
37- sfeQwiicUltrasonic () : _theBus(nullptr )
38+ sfeQwiicUltrasonic () : _theBus(nullptr ), _fwVersion( kQwiicUltrasonicFWLatest )
3839 {
3940 }
4041
42+ // / @brief Default constructor
43+ sfeQwiicUltrasonic (uint8_t fwVersion) : _theBus(nullptr ), _fwVersion(fwVersion)
44+ {
45+ }
46+
47+
4148 // / @brief Begins the Qwiic Ultrasonic sensor
4249 // / @param theBus I2C bus to use for communication
4350 // / @return 0 for succuss, negative for errors, positive for warnings
@@ -55,17 +62,15 @@ class sfeQwiicUltrasonic
5562 // / @brief Changes the I2C address of older Qwiic Ultrasonic sensors.
5663 // / @param address New address, must be in the range 0x20 to 0x2F
5764 // / @return 0 for succuss, negative for errors, positive for warnings
58- sfeTkError_t changeAddress (const uint8_t &address);
59-
60- // / @brief Changes the I2C address of the latest revision of the Qwiic Ultrasonic sensor.
61- // / @param address New address, must be in the range 0x20 to 0x2F
62- // / @return 0 for succuss, negative for errors, positive for warnings
63- sfeTkError_t updateAddress (uint8_t &address);
65+ sfeTkError_t changeAddress (uint8_t &address);
6466
6567 // / @brief Gets the current I2C address being used by the library for the Qwiic Ultrasonic sensor
6668 // / @return The current I2C address, 7-bit unshifted
6769 uint8_t getAddress ();
6870
6971 protected:
7072 sfeTkII2C *_theBus;
73+
74+ private:
75+ uint8_t _fwVersion = 0x00 ;
7176};
0 commit comments