File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ playSoundEffect KEYWORD2
2525#########################################################
2626
2727SFE_QWIIC_BUZZER_DEFAULT_ADDRESS LITERAL1
28+ SFE_QWIIC_BUZZER_DEVICE_ID LITERAL1
2829kSfeQwiicBuzzerRegId LITERAL1
2930kSfeQwiicBuzzerRegFirmwareMinor LITERAL1
3031kSfeQwiicBuzzerRegFirmwareMajor LITERAL1
Original file line number Diff line number Diff 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
3955sfeTkError_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+
4566sfeTkError_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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments