Skip to content

Commit 5228708

Browse files
committed
v2.0.6 - Change register enum to avoid clash with ESP32 v2.0.4
1 parent 54ca41b commit 5228708

File tree

4 files changed

+60
-63
lines changed

4 files changed

+60
-63
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Qwiic Button and Qwiic Switch Library
2-
version=2.0.5
2+
version=2.0.6
33
author=SparkFun Electronics <[email protected]>
44
maintainer=Fischer Moseley <[email protected]>
55
sentence=Communicates and configures the SparkFun Qwiic Button and Switch.

src/SparkFun_Qwiic_Button.cpp

+39-42
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,29 @@ bool QwiicButton::isConnected()
4848

4949
uint8_t QwiicButton::deviceID()
5050
{
51-
return readSingleRegister(ID); //read and return the value in the ID register
51+
return readSingleRegister(SFE_QWIIC_BUTTON_ID); //read and return the value in the ID register
5252
}
5353

5454
bool QwiicButton::checkDeviceID()
5555
{
56-
// return ((deviceID() == DEV_ID_SW) || (deviceID() == DEV_ID_BTN)); //Return true if the device ID matches either the button or the switch
57-
return (deviceID() == DEV_ID); //Return true if the device ID matches
56+
return (deviceID() == SFE_QWIIC_BUTTON_DEV_ID); //Return true if the device ID matches
5857
}
5958

6059
uint8_t QwiicButton::getDeviceType()
6160
{
6261
if (isConnected())
6362
{ //only try to get the device ID if the device will acknowledge
6463
uint8_t id = deviceID();
65-
if (id == DEV_ID)
64+
if (id == SFE_QWIIC_BUTTON_DEV_ID)
6665
return 1;
67-
// if (id == DEV_ID_SW)
68-
// return 2;
6966
}
7067
return 0;
7168
}
7269

7370
uint16_t QwiicButton::getFirmwareVersion()
7471
{
75-
uint16_t version = (readSingleRegister(FIRMWARE_MAJOR)) << 8;
76-
version |= readSingleRegister(FIRMWARE_MINOR);
72+
uint16_t version = (readSingleRegister(SFE_QWIIC_BUTTON_FIRMWARE_MAJOR)) << 8;
73+
version |= readSingleRegister(SFE_QWIIC_BUTTON_FIRMWARE_MINOR);
7774
return version;
7875
}
7976

@@ -85,7 +82,7 @@ bool QwiicButton::setI2Caddress(uint8_t address)
8582
return 1; //error immediately if the address is out of legal range
8683
}
8784

88-
bool success = writeSingleRegister(I2C_ADDRESS, address);
85+
bool success = writeSingleRegister(SFE_QWIIC_BUTTON_I2C_ADDRESS, address);
8986

9087
if (success == true)
9188
{
@@ -109,122 +106,122 @@ uint8_t QwiicButton::getI2Caddress()
109106
bool QwiicButton::isPressed()
110107
{
111108
statusRegisterBitField statusRegister;
112-
statusRegister.byteWrapped = readSingleRegister(BUTTON_STATUS);
109+
statusRegister.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_BUTTON_STATUS);
113110
return statusRegister.isPressed;
114111
}
115112

116113
bool QwiicButton::hasBeenClicked()
117114
{
118115
statusRegisterBitField statusRegister;
119-
statusRegister.byteWrapped = readSingleRegister(BUTTON_STATUS);
116+
statusRegister.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_BUTTON_STATUS);
120117
return statusRegister.hasBeenClicked;
121118
}
122119

123120
uint16_t QwiicButton::getDebounceTime()
124121
{
125-
return readDoubleRegister(BUTTON_DEBOUNCE_TIME);
122+
return readDoubleRegister(SFE_QWIIC_BUTTON_BUTTON_DEBOUNCE_TIME);
126123
}
127124

128125
uint8_t QwiicButton::setDebounceTime(uint16_t time)
129126
{
130-
return writeDoubleRegisterWithReadback(BUTTON_DEBOUNCE_TIME, time);
127+
return writeDoubleRegisterWithReadback(SFE_QWIIC_BUTTON_BUTTON_DEBOUNCE_TIME, time);
131128
}
132129

133130
/*------------------- Interrupt Status/Configuration ---------------- */
134131
uint8_t QwiicButton::enablePressedInterrupt()
135132
{
136133
interruptConfigBitField interruptConfigure;
137-
interruptConfigure.byteWrapped = readSingleRegister(INTERRUPT_CONFIG);
134+
interruptConfigure.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG);
138135
interruptConfigure.pressedEnable = 1;
139-
return writeSingleRegisterWithReadback(INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
136+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
140137
}
141138

142139
uint8_t QwiicButton::disablePressedInterrupt()
143140
{
144141
interruptConfigBitField interruptConfigure;
145-
interruptConfigure.byteWrapped = readSingleRegister(INTERRUPT_CONFIG);
142+
interruptConfigure.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG);
146143
interruptConfigure.pressedEnable = 0;
147-
return writeSingleRegisterWithReadback(INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
144+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
148145
}
149146

150147
uint8_t QwiicButton::enableClickedInterrupt()
151148
{
152149
interruptConfigBitField interruptConfigure;
153-
interruptConfigure.byteWrapped = readSingleRegister(INTERRUPT_CONFIG);
150+
interruptConfigure.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG);
154151
interruptConfigure.clickedEnable = 1;
155-
return writeSingleRegisterWithReadback(INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
152+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
156153
}
157154

158155
uint8_t QwiicButton::disableClickedInterrupt()
159156
{
160157
interruptConfigBitField interruptConfigure;
161-
interruptConfigure.byteWrapped = readSingleRegister(INTERRUPT_CONFIG);
158+
interruptConfigure.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG);
162159
interruptConfigure.clickedEnable = 0;
163-
return writeSingleRegisterWithReadback(INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
160+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
164161
}
165162

166163
bool QwiicButton::available()
167164
{
168165
statusRegisterBitField buttonStatus;
169-
buttonStatus.byteWrapped = readSingleRegister(BUTTON_STATUS);
166+
buttonStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_BUTTON_STATUS);
170167
return buttonStatus.eventAvailable;
171168
}
172169

173170
uint8_t QwiicButton::clearEventBits()
174171
{
175172
statusRegisterBitField buttonStatus;
176-
buttonStatus.byteWrapped = readSingleRegister(BUTTON_STATUS);
173+
buttonStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_BUTTON_STATUS);
177174
buttonStatus.isPressed = 0;
178175
buttonStatus.hasBeenClicked = 0;
179176
buttonStatus.eventAvailable = 0;
180-
return writeSingleRegisterWithReadback(BUTTON_STATUS, buttonStatus.byteWrapped);
177+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_BUTTON_STATUS, buttonStatus.byteWrapped);
181178
}
182179

183180
uint8_t QwiicButton::resetInterruptConfig()
184181
{
185182
interruptConfigBitField interruptConfigure;
186183
interruptConfigure.pressedEnable = 1;
187184
interruptConfigure.clickedEnable = 1;
188-
return writeSingleRegisterWithReadback(INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
185+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_INTERRUPT_CONFIG, interruptConfigure.byteWrapped);
189186
statusRegisterBitField buttonStatus;
190187
buttonStatus.eventAvailable = 0;
191-
return writeSingleRegisterWithReadback(BUTTON_STATUS, buttonStatus.byteWrapped);
188+
return writeSingleRegisterWithReadback(SFE_QWIIC_BUTTON_BUTTON_STATUS, buttonStatus.byteWrapped);
192189
}
193190

194191
/*------------------------- Queue Manipulation ---------------------- */
195192
//pressed queue manipulation
196193
bool QwiicButton::isPressedQueueFull()
197194
{
198195
queueStatusBitField pressedQueueStatus;
199-
pressedQueueStatus.byteWrapped = readSingleRegister(PRESSED_QUEUE_STATUS);
196+
pressedQueueStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS);
200197
return pressedQueueStatus.isFull;
201198
}
202199

203200
bool QwiicButton::isPressedQueueEmpty()
204201
{
205202
queueStatusBitField pressedQueueStatus;
206-
pressedQueueStatus.byteWrapped = readSingleRegister(PRESSED_QUEUE_STATUS);
203+
pressedQueueStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS);
207204
return pressedQueueStatus.isEmpty;
208205
}
209206

210207
unsigned long QwiicButton::timeSinceLastPress()
211208
{
212-
return readQuadRegister(PRESSED_QUEUE_FRONT);
209+
return readQuadRegister(SFE_QWIIC_BUTTON_PRESSED_QUEUE_FRONT);
213210
}
214211

215212
unsigned long QwiicButton::timeSinceFirstPress()
216213
{
217-
return readQuadRegister(PRESSED_QUEUE_BACK);
214+
return readQuadRegister(SFE_QWIIC_BUTTON_PRESSED_QUEUE_BACK);
218215
}
219216

220217
unsigned long QwiicButton::popPressedQueue()
221218
{
222219
unsigned long tempData = timeSinceFirstPress(); //grab the oldest value on the queue
223220

224221
queueStatusBitField pressedQueueStatus;
225-
pressedQueueStatus.byteWrapped = readSingleRegister(PRESSED_QUEUE_STATUS);
222+
pressedQueueStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS);
226223
pressedQueueStatus.popRequest = 1;
227-
writeSingleRegister(PRESSED_QUEUE_STATUS, pressedQueueStatus.byteWrapped); //remove the oldest value from the queue
224+
writeSingleRegister(SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS, pressedQueueStatus.byteWrapped); //remove the oldest value from the queue
228225

229226
return tempData; //return the value we popped
230227
}
@@ -233,44 +230,44 @@ unsigned long QwiicButton::popPressedQueue()
233230
bool QwiicButton::isClickedQueueFull()
234231
{
235232
queueStatusBitField clickedQueueStatus;
236-
clickedQueueStatus.byteWrapped = readSingleRegister(CLICKED_QUEUE_STATUS);
233+
clickedQueueStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS);
237234
return clickedQueueStatus.isFull;
238235
}
239236

240237
bool QwiicButton::isClickedQueueEmpty()
241238
{
242239
queueStatusBitField clickedQueueStatus;
243-
clickedQueueStatus.byteWrapped = readSingleRegister(CLICKED_QUEUE_STATUS);
240+
clickedQueueStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS);
244241
return clickedQueueStatus.isEmpty;
245242
}
246243

247244
unsigned long QwiicButton::timeSinceLastClick()
248245
{
249-
return readQuadRegister(CLICKED_QUEUE_FRONT);
246+
return readQuadRegister(SFE_QWIIC_BUTTON_CLICKED_QUEUE_FRONT);
250247
}
251248

252249
unsigned long QwiicButton::timeSinceFirstClick()
253250
{
254-
return readQuadRegister(CLICKED_QUEUE_BACK);
251+
return readQuadRegister(SFE_QWIIC_BUTTON_CLICKED_QUEUE_BACK);
255252
}
256253

257254
unsigned long QwiicButton::popClickedQueue()
258255
{
259256
unsigned long tempData = timeSinceFirstClick();
260257
queueStatusBitField clickedQueueStatus;
261-
clickedQueueStatus.byteWrapped = readSingleRegister(CLICKED_QUEUE_STATUS);
258+
clickedQueueStatus.byteWrapped = readSingleRegister(SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS);
262259
clickedQueueStatus.popRequest = 1;
263-
writeSingleRegister(CLICKED_QUEUE_STATUS, clickedQueueStatus.byteWrapped);
260+
writeSingleRegister(SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS, clickedQueueStatus.byteWrapped);
264261
return tempData;
265262
}
266263

267264
/*------------------------ LED Configuration ------------------------ */
268265
bool QwiicButton::LEDconfig(uint8_t brightness, uint16_t cycleTime, uint16_t offTime, uint8_t granularity)
269266
{
270-
bool success = writeSingleRegister(LED_BRIGHTNESS, brightness);
271-
success &= writeSingleRegister(LED_PULSE_GRANULARITY, granularity);
272-
success &= writeDoubleRegister(LED_PULSE_CYCLE_TIME, cycleTime);
273-
success &= writeDoubleRegister(LED_PULSE_OFF_TIME, offTime);
267+
bool success = writeSingleRegister(SFE_QWIIC_BUTTON_LED_BRIGHTNESS, brightness);
268+
success &= writeSingleRegister(SFE_QWIIC_BUTTON_LED_PULSE_GRANULARITY, granularity);
269+
success &= writeDoubleRegister(SFE_QWIIC_BUTTON_LED_PULSE_CYCLE_TIME, cycleTime);
270+
success &= writeDoubleRegister(SFE_QWIIC_BUTTON_LED_PULSE_OFF_TIME, offTime);
274271
return success;
275272
}
276273

src/SparkFun_Qwiic_Button.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Distributed as-is; no warranty is given.
2626
#include <Arduino.h>
2727
#include "registers.h"
2828

29-
#define DEFAULT_QWIIC_BUTTON_ADDRESS 0x6F //default I2C address of the button
30-
#define DEV_ID 0x5D //device ID of the Qwiic Button
29+
#define SFE_QWIIC_BUTTON_DEFAULT_ADDRESS 0x6F //default I2C address of the button
30+
#define SFE_QWIIC_BUTTON_DEV_ID 0x5D //device ID of the Qwiic Button
3131

3232
class QwiicButton
3333
{
@@ -37,7 +37,7 @@ class QwiicButton
3737

3838
public:
3939
//Device status
40-
bool begin(uint8_t address = DEFAULT_QWIIC_BUTTON_ADDRESS, TwoWire &wirePort = Wire); //Sets device I2C address to a user-specified address, over whatever port the user specifies.
40+
bool begin(uint8_t address = SFE_QWIIC_BUTTON_DEFAULT_ADDRESS, TwoWire &wirePort = Wire); //Sets device I2C address to a user-specified address, over whatever port the user specifies.
4141
bool isConnected(); //Returns true if the button/switch will acknowledge over I2C, and false otherwise
4242
uint8_t deviceID(); //Return the 8-bit device ID of the attached device.
4343
bool checkDeviceID(); //Returns true if the device ID matches that of either the button or the switch

src/registers.h

+17-17
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ Distributed as-is; no warranty is given.
2323
//Register Pointer Map
2424
enum Qwiic_Button_Register : uint8_t
2525
{
26-
ID = 0x00,
27-
FIRMWARE_MINOR = 0x01,
28-
FIRMWARE_MAJOR = 0x02,
29-
BUTTON_STATUS = 0x03,
30-
INTERRUPT_CONFIG = 0x04,
31-
BUTTON_DEBOUNCE_TIME = 0x05,
32-
PRESSED_QUEUE_STATUS = 0x07,
33-
PRESSED_QUEUE_FRONT = 0x08,
34-
PRESSED_QUEUE_BACK = 0x0C,
35-
CLICKED_QUEUE_STATUS = 0x10,
36-
CLICKED_QUEUE_FRONT = 0x11,
37-
CLICKED_QUEUE_BACK = 0x15,
38-
LED_BRIGHTNESS = 0x19,
39-
LED_PULSE_GRANULARITY = 0x1A,
40-
LED_PULSE_CYCLE_TIME = 0x1B,
41-
LED_PULSE_OFF_TIME = 0x1D,
42-
I2C_ADDRESS = 0x1F,
26+
SFE_QWIIC_BUTTON_ID = 0x00,
27+
SFE_QWIIC_BUTTON_FIRMWARE_MINOR = 0x01,
28+
SFE_QWIIC_BUTTON_FIRMWARE_MAJOR = 0x02,
29+
SFE_QWIIC_BUTTON_BUTTON_STATUS = 0x03,
30+
SFE_QWIIC_BUTTON_INTERRUPT_CONFIG = 0x04,
31+
SFE_QWIIC_BUTTON_BUTTON_DEBOUNCE_TIME = 0x05,
32+
SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS = 0x07,
33+
SFE_QWIIC_BUTTON_PRESSED_QUEUE_FRONT = 0x08,
34+
SFE_QWIIC_BUTTON_PRESSED_QUEUE_BACK = 0x0C,
35+
SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS = 0x10,
36+
SFE_QWIIC_BUTTON_CLICKED_QUEUE_FRONT = 0x11,
37+
SFE_QWIIC_BUTTON_CLICKED_QUEUE_BACK = 0x15,
38+
SFE_QWIIC_BUTTON_LED_BRIGHTNESS = 0x19,
39+
SFE_QWIIC_BUTTON_LED_PULSE_GRANULARITY = 0x1A,
40+
SFE_QWIIC_BUTTON_LED_PULSE_CYCLE_TIME = 0x1B,
41+
SFE_QWIIC_BUTTON_LED_PULSE_OFF_TIME = 0x1D,
42+
SFE_QWIIC_BUTTON_I2C_ADDRESS = 0x1F,
4343
};
4444

4545
typedef union {

0 commit comments

Comments
 (0)