@@ -48,32 +48,29 @@ bool QwiicButton::isConnected()
48
48
49
49
uint8_t QwiicButton::deviceID ()
50
50
{
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
52
52
}
53
53
54
54
bool QwiicButton::checkDeviceID ()
55
55
{
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
58
57
}
59
58
60
59
uint8_t QwiicButton::getDeviceType ()
61
60
{
62
61
if (isConnected ())
63
62
{ // only try to get the device ID if the device will acknowledge
64
63
uint8_t id = deviceID ();
65
- if (id == DEV_ID )
64
+ if (id == SFE_QWIIC_BUTTON_DEV_ID )
66
65
return 1 ;
67
- // if (id == DEV_ID_SW)
68
- // return 2;
69
66
}
70
67
return 0 ;
71
68
}
72
69
73
70
uint16_t QwiicButton::getFirmwareVersion ()
74
71
{
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 );
77
74
return version;
78
75
}
79
76
@@ -85,7 +82,7 @@ bool QwiicButton::setI2Caddress(uint8_t address)
85
82
return 1 ; // error immediately if the address is out of legal range
86
83
}
87
84
88
- bool success = writeSingleRegister (I2C_ADDRESS , address);
85
+ bool success = writeSingleRegister (SFE_QWIIC_BUTTON_I2C_ADDRESS , address);
89
86
90
87
if (success == true )
91
88
{
@@ -109,122 +106,122 @@ uint8_t QwiicButton::getI2Caddress()
109
106
bool QwiicButton::isPressed ()
110
107
{
111
108
statusRegisterBitField statusRegister;
112
- statusRegister.byteWrapped = readSingleRegister (BUTTON_STATUS );
109
+ statusRegister.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_BUTTON_STATUS );
113
110
return statusRegister.isPressed ;
114
111
}
115
112
116
113
bool QwiicButton::hasBeenClicked ()
117
114
{
118
115
statusRegisterBitField statusRegister;
119
- statusRegister.byteWrapped = readSingleRegister (BUTTON_STATUS );
116
+ statusRegister.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_BUTTON_STATUS );
120
117
return statusRegister.hasBeenClicked ;
121
118
}
122
119
123
120
uint16_t QwiicButton::getDebounceTime ()
124
121
{
125
- return readDoubleRegister (BUTTON_DEBOUNCE_TIME );
122
+ return readDoubleRegister (SFE_QWIIC_BUTTON_BUTTON_DEBOUNCE_TIME );
126
123
}
127
124
128
125
uint8_t QwiicButton::setDebounceTime (uint16_t time)
129
126
{
130
- return writeDoubleRegisterWithReadback (BUTTON_DEBOUNCE_TIME , time );
127
+ return writeDoubleRegisterWithReadback (SFE_QWIIC_BUTTON_BUTTON_DEBOUNCE_TIME , time );
131
128
}
132
129
133
130
/* ------------------- Interrupt Status/Configuration ---------------- */
134
131
uint8_t QwiicButton::enablePressedInterrupt ()
135
132
{
136
133
interruptConfigBitField interruptConfigure;
137
- interruptConfigure.byteWrapped = readSingleRegister (INTERRUPT_CONFIG );
134
+ interruptConfigure.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG );
138
135
interruptConfigure.pressedEnable = 1 ;
139
- return writeSingleRegisterWithReadback (INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
136
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
140
137
}
141
138
142
139
uint8_t QwiicButton::disablePressedInterrupt ()
143
140
{
144
141
interruptConfigBitField interruptConfigure;
145
- interruptConfigure.byteWrapped = readSingleRegister (INTERRUPT_CONFIG );
142
+ interruptConfigure.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG );
146
143
interruptConfigure.pressedEnable = 0 ;
147
- return writeSingleRegisterWithReadback (INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
144
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
148
145
}
149
146
150
147
uint8_t QwiicButton::enableClickedInterrupt ()
151
148
{
152
149
interruptConfigBitField interruptConfigure;
153
- interruptConfigure.byteWrapped = readSingleRegister (INTERRUPT_CONFIG );
150
+ interruptConfigure.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG );
154
151
interruptConfigure.clickedEnable = 1 ;
155
- return writeSingleRegisterWithReadback (INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
152
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
156
153
}
157
154
158
155
uint8_t QwiicButton::disableClickedInterrupt ()
159
156
{
160
157
interruptConfigBitField interruptConfigure;
161
- interruptConfigure.byteWrapped = readSingleRegister (INTERRUPT_CONFIG );
158
+ interruptConfigure.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG );
162
159
interruptConfigure.clickedEnable = 0 ;
163
- return writeSingleRegisterWithReadback (INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
160
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
164
161
}
165
162
166
163
bool QwiicButton::available ()
167
164
{
168
165
statusRegisterBitField buttonStatus;
169
- buttonStatus.byteWrapped = readSingleRegister (BUTTON_STATUS );
166
+ buttonStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_BUTTON_STATUS );
170
167
return buttonStatus.eventAvailable ;
171
168
}
172
169
173
170
uint8_t QwiicButton::clearEventBits ()
174
171
{
175
172
statusRegisterBitField buttonStatus;
176
- buttonStatus.byteWrapped = readSingleRegister (BUTTON_STATUS );
173
+ buttonStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_BUTTON_STATUS );
177
174
buttonStatus.isPressed = 0 ;
178
175
buttonStatus.hasBeenClicked = 0 ;
179
176
buttonStatus.eventAvailable = 0 ;
180
- return writeSingleRegisterWithReadback (BUTTON_STATUS , buttonStatus.byteWrapped );
177
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_BUTTON_STATUS , buttonStatus.byteWrapped );
181
178
}
182
179
183
180
uint8_t QwiicButton::resetInterruptConfig ()
184
181
{
185
182
interruptConfigBitField interruptConfigure;
186
183
interruptConfigure.pressedEnable = 1 ;
187
184
interruptConfigure.clickedEnable = 1 ;
188
- return writeSingleRegisterWithReadback (INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
185
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_INTERRUPT_CONFIG , interruptConfigure.byteWrapped );
189
186
statusRegisterBitField buttonStatus;
190
187
buttonStatus.eventAvailable = 0 ;
191
- return writeSingleRegisterWithReadback (BUTTON_STATUS , buttonStatus.byteWrapped );
188
+ return writeSingleRegisterWithReadback (SFE_QWIIC_BUTTON_BUTTON_STATUS , buttonStatus.byteWrapped );
192
189
}
193
190
194
191
/* ------------------------- Queue Manipulation ---------------------- */
195
192
// pressed queue manipulation
196
193
bool QwiicButton::isPressedQueueFull ()
197
194
{
198
195
queueStatusBitField pressedQueueStatus;
199
- pressedQueueStatus.byteWrapped = readSingleRegister (PRESSED_QUEUE_STATUS );
196
+ pressedQueueStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS );
200
197
return pressedQueueStatus.isFull ;
201
198
}
202
199
203
200
bool QwiicButton::isPressedQueueEmpty ()
204
201
{
205
202
queueStatusBitField pressedQueueStatus;
206
- pressedQueueStatus.byteWrapped = readSingleRegister (PRESSED_QUEUE_STATUS );
203
+ pressedQueueStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS );
207
204
return pressedQueueStatus.isEmpty ;
208
205
}
209
206
210
207
unsigned long QwiicButton::timeSinceLastPress ()
211
208
{
212
- return readQuadRegister (PRESSED_QUEUE_FRONT );
209
+ return readQuadRegister (SFE_QWIIC_BUTTON_PRESSED_QUEUE_FRONT );
213
210
}
214
211
215
212
unsigned long QwiicButton::timeSinceFirstPress ()
216
213
{
217
- return readQuadRegister (PRESSED_QUEUE_BACK );
214
+ return readQuadRegister (SFE_QWIIC_BUTTON_PRESSED_QUEUE_BACK );
218
215
}
219
216
220
217
unsigned long QwiicButton::popPressedQueue ()
221
218
{
222
219
unsigned long tempData = timeSinceFirstPress (); // grab the oldest value on the queue
223
220
224
221
queueStatusBitField pressedQueueStatus;
225
- pressedQueueStatus.byteWrapped = readSingleRegister (PRESSED_QUEUE_STATUS );
222
+ pressedQueueStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_PRESSED_QUEUE_STATUS );
226
223
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
228
225
229
226
return tempData; // return the value we popped
230
227
}
@@ -233,44 +230,44 @@ unsigned long QwiicButton::popPressedQueue()
233
230
bool QwiicButton::isClickedQueueFull ()
234
231
{
235
232
queueStatusBitField clickedQueueStatus;
236
- clickedQueueStatus.byteWrapped = readSingleRegister (CLICKED_QUEUE_STATUS );
233
+ clickedQueueStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS );
237
234
return clickedQueueStatus.isFull ;
238
235
}
239
236
240
237
bool QwiicButton::isClickedQueueEmpty ()
241
238
{
242
239
queueStatusBitField clickedQueueStatus;
243
- clickedQueueStatus.byteWrapped = readSingleRegister (CLICKED_QUEUE_STATUS );
240
+ clickedQueueStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS );
244
241
return clickedQueueStatus.isEmpty ;
245
242
}
246
243
247
244
unsigned long QwiicButton::timeSinceLastClick ()
248
245
{
249
- return readQuadRegister (CLICKED_QUEUE_FRONT );
246
+ return readQuadRegister (SFE_QWIIC_BUTTON_CLICKED_QUEUE_FRONT );
250
247
}
251
248
252
249
unsigned long QwiicButton::timeSinceFirstClick ()
253
250
{
254
- return readQuadRegister (CLICKED_QUEUE_BACK );
251
+ return readQuadRegister (SFE_QWIIC_BUTTON_CLICKED_QUEUE_BACK );
255
252
}
256
253
257
254
unsigned long QwiicButton::popClickedQueue ()
258
255
{
259
256
unsigned long tempData = timeSinceFirstClick ();
260
257
queueStatusBitField clickedQueueStatus;
261
- clickedQueueStatus.byteWrapped = readSingleRegister (CLICKED_QUEUE_STATUS );
258
+ clickedQueueStatus.byteWrapped = readSingleRegister (SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS );
262
259
clickedQueueStatus.popRequest = 1 ;
263
- writeSingleRegister (CLICKED_QUEUE_STATUS , clickedQueueStatus.byteWrapped );
260
+ writeSingleRegister (SFE_QWIIC_BUTTON_CLICKED_QUEUE_STATUS , clickedQueueStatus.byteWrapped );
264
261
return tempData;
265
262
}
266
263
267
264
/* ------------------------ LED Configuration ------------------------ */
268
265
bool QwiicButton::LEDconfig (uint8_t brightness, uint16_t cycleTime, uint16_t offTime, uint8_t granularity)
269
266
{
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);
274
271
return success;
275
272
}
276
273
0 commit comments