Skip to content

Commit 91b4491

Browse files
committed
device ID
-deviceId will read device ID from qwiic buzzer -also added in a check into the begin function
1 parent 6d293a4 commit 91b4491

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ playSoundEffect KEYWORD2
2525
#########################################################
2626

2727
SFE_QWIIC_BUZZER_DEFAULT_ADDRESS LITERAL1
28+
SFE_QWIIC_BUZZER_DEVICE_ID LITERAL1
2829
kSfeQwiicBuzzerRegId LITERAL1
2930
kSfeQwiicBuzzerRegFirmwareMinor LITERAL1
3031
kSfeQwiicBuzzerRegFirmwareMajor LITERAL1

src/sfeQwiicBuzzer.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,24 @@ sfeTkError_t sfeQwiicBuzzer::begin(sfeTkII2C *theBus)
3232
// Set bus pointer
3333
_theBus = theBus;
3434

35-
// Just check if the device is connected, no other setup is needed
36-
return isConnected();
35+
sfeTkError_t err;
36+
err = isConnected();
37+
// Check whether the ping was successful
38+
if (err != kSTkErrOk)
39+
return err;
40+
41+
uint8_t readDeviceId;
42+
err = deviceId(readDeviceId);
43+
// Check whether the read was successful
44+
if (err != kSTkErrOk)
45+
return err;
46+
47+
// check that device ID matches
48+
if (readDeviceId != SFE_QWIIC_BUZZER_DEVICE_ID)
49+
return kSTkErrFail;
50+
51+
// Done!
52+
return kSTkErrOk;
3753
}
3854

3955
sfeTkError_t sfeQwiicBuzzer::isConnected()
@@ -42,6 +58,11 @@ sfeTkError_t sfeQwiicBuzzer::isConnected()
4258
return _theBus->ping();
4359
}
4460

61+
sfeTkError_t sfeQwiicBuzzer::deviceId(uint8_t &deviceId)
62+
{
63+
return _theBus->readRegisterByte(kSfeQwiicBuzzerRegId, deviceId);
64+
}
65+
4566
sfeTkError_t sfeQwiicBuzzer::configureBuzzer(const uint16_t toneFrequency, const uint16_t duration, const uint8_t volume)
4667
{
4768
// All of the necessary configuration register address are in sequencial order

src/sfeQwiicBuzzer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "sfeQwiicBuzzerPitches.h"
3333

3434
#define SFE_QWIIC_BUZZER_DEFAULT_ADDRESS 0x34
35+
#define SFE_QWIIC_BUZZER_DEVICE_ID 0x5E
3536
#define SFE_QWIIC_BUZZER_RESONANT_FREQUENCY 2730
3637
#define SFE_QWIIC_BUZZER_VOLUME_OFF 0
3738
#define SFE_QWIIC_BUZZER_VOLUME_MIN 1
@@ -56,6 +57,11 @@ class sfeQwiicBuzzer
5657
/// @return 0 for succuss, negative for errors, positive for warnings
5758
sfeTkError_t isConnected();
5859

60+
/// @brief Reads the Device ID of the Qwiic Buzzer
61+
/// @param deviceId uint8_t variable where the read results will be stored
62+
/// @return 0 for succuss, negative for errors, positive for warnings
63+
sfeTkError_t deviceId(uint8_t &deviceId);
64+
5965
/// @brief Configures the Qwiic Buzzer without causing the buzzer to buzz.
6066
/// This allows configuration in silence (before you may want to buzz).
6167
/// It is also useful in combination with saveSettings(), and then later

0 commit comments

Comments
 (0)