Skip to content

Commit 3c42f28

Browse files
committed
update and cleanup of examples - remove *non* arduino things
1 parent fa84815 commit 3c42f28

File tree

4 files changed

+110
-66
lines changed

4 files changed

+110
-66
lines changed

examples/Example01_NavigationI2C/Example01_NavigationI2C.ino

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* ---------------------------------------------------------------------------------
88
*/
99

10-
/* Example using the SparkFun FPC2534 Fingerprint sensor library to demonstrate navigation mode
10+
/*
11+
* Example using the SparkFun FPC2534 Fingerprint sensor library to demonstrate navigation mode
1112
* of the sensor. This example uses the I2C interface to communicate with the sensor.
1213
*
1314
* Example Setup:
@@ -48,16 +49,17 @@
4849
//----------------------------------------------------------------------------
4950
// UPDATE THESE DEFINES TO MATCH YOUR HARDWARE SETUP
5051
//
51-
// These are the pins the IRQ and RST pins of the sensor are connected to
52+
// These are the pins the IRQ and RST pins of the sensor are connected to the microcontroller.
53+
//
5254
// NOTE: The IRQ pin must be an interrupt-capable pin on your microcontroller
5355
//
54-
// Example pins for various SparkFun boards:
56+
// Example pins tested for various SparkFun boards:
5557

56-
// esp32 thing plus
58+
// ESP32 thing plus
5759
// #define IRQ_PIN 16
5860
// #define RST_PIN 21
5961

60-
// esp32 thing plus C
62+
// ESP32 thing plus C
6163
// #define IRQ_PIN 32
6264
// #define RST_PIN 14
6365

@@ -196,10 +198,7 @@ static void on_navigation(uint16_t gesture)
196198
// Fill in the library callback structure with our callback functions
197199
//
198200
// This is passed to the library so it knows what functions to call when events occur.
199-
static const sfDevFPC2534Callbacks_t cmd_cb = {.on_error = on_error,
200-
.on_version = on_version,
201-
.on_navigation = on_navigation,
202-
.on_is_ready_change = on_is_ready_change};
201+
static sfDevFPC2534Callbacks_t cmd_cb = {0};
203202

204203
//------------------------------------------------------------------------------------
205204
// reset_sensor()
@@ -264,6 +263,12 @@ void setup()
264263
}
265264
Serial.println("[STARTUP]\tFPC2534 initialized.");
266265

266+
// Setup our callback functions structure
267+
cmd_cb.on_error = on_error;
268+
cmd_cb.on_version = on_version;
269+
cmd_cb.on_navigation = on_navigation;
270+
cmd_cb.on_is_ready_change = on_is_ready_change;
271+
267272
// set the callbacks for the sensor library to call
268273
mySensor.setCallbacks(cmd_cb);
269274

examples/Example02_EnrollI2C/Example02_EnrollI2C.ino

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@
6565
//----------------------------------------------------------------------------
6666
// UPDATE THESE DEFINES TO MATCH YOUR HARDWARE SETUP
6767
//
68-
// These are the pins the IRQ and RST pins of the sensor are connected to
68+
// These are the pins the IRQ and RST pins of the sensor are connected to the microcontroller.
69+
//
6970
// NOTE: The IRQ pin must be an interrupt-capable pin on your microcontroller
7071
//
7172
// Example pins for various SparkFun boards:
72-
73-
// esp32 thing plus
73+
//
74+
// ESP32 thing plus
7475
// #define IRQ_PIN 16
7576
// #define RST_PIN 21
7677

77-
// esp32 thing plus C
78+
// ESP32 thing plus C
7879
// #define IRQ_PIN 32
7980
// #define RST_PIN 14
8081

@@ -154,7 +155,9 @@ static void drawMenu()
154155
Serial.println(" Starting finger enrollment - place finger and remove a finger on the sensor to enroll "
155156
"a fingerprint");
156157
mySensor.setLED(true);
157-
fpc_id_type_t id = {.type = ID_TYPE_GENERATE_NEW, .id = 0};
158+
fpc_id_type_t id = {0};
159+
id.type = ID_TYPE_GENERATE_NEW;
160+
id.id = 0;
158161
fpc_result_t rc = mySensor.requestEnroll(id);
159162
if (rc != FPC_RESULT_OK)
160163
{
@@ -176,7 +179,9 @@ static void drawMenu()
176179
else
177180
{
178181
Serial.println(" Deleting all templates on the fingerprint sensor");
179-
fpc_id_type_t id = {.type = ID_TYPE_ALL, .id = 0};
182+
fpc_id_type_t id = {0};
183+
id.type = ID_TYPE_ALL;
184+
id.id = 0;
180185
fpc_result_t rc = mySensor.requestDeleteTemplate(id);
181186
if (rc != FPC_RESULT_OK)
182187
{
@@ -200,7 +205,10 @@ static void drawMenu()
200205
Serial.print(" Place a finger on the sensor for validation");
201206

202207
// Send ID request to the sensor - compair to all templates
203-
fpc_id_type_t id = {.type = ID_TYPE_ALL, .id = 0};
208+
fpc_id_type_t id = {0};
209+
id.type = ID_TYPE_ALL;
210+
id.id = 0;
211+
204212
fpc_result_t rc = mySensor.requestIdentify(id, 1);
205213
if (rc != FPC_RESULT_OK)
206214
{
@@ -371,13 +379,8 @@ static void on_status(uint16_t event, uint16_t state)
371379
//------------------------------------------------------------------------------------
372380
// Callbacks
373381
//
374-
// Define our command callbacks the library will call on events from the sensor
375-
static const sfDevFPC2534Callbacks_t cmd_cb = {.on_error = on_error,
376-
.on_status = on_status,
377-
.on_enroll = on_enroll,
378-
.on_identify = on_identify,
379-
.on_list_templates = on_list_templates,
380-
.on_is_ready_change = on_is_ready_change};
382+
// Define our command callbacks structure - callback methods are assigned in setup
383+
static sfDevFPC2534Callbacks_t cmd_cb = {0};
381384

382385
//------------------------------------------------------------------------------------
383386
// reset_sensor()
@@ -446,6 +449,14 @@ void setup()
446449
}
447450
Serial.println("[STARTUP]\tFPC2534 initialized.");
448451

452+
// setup our callback functions structure
453+
cmd_cb.on_error = on_error;
454+
cmd_cb.on_status = on_status;
455+
cmd_cb.on_enroll = on_enroll;
456+
cmd_cb.on_identify = on_identify;
457+
cmd_cb.on_list_templates = on_list_templates;
458+
cmd_cb.on_is_ready_change = on_is_ready_change;
459+
449460
// set the callbacks for the sensor library to call
450461
mySensor.setCallbacks(cmd_cb);
451462

examples/Example03_NavigationUART/Example03_NavigationUART.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
// #define UART_RX 32
2121
// #define UART_TX 14
2222

23+
//----------------------------------------------------------------------------------
24+
// NOTE:
25+
// This example makes use of the Serial1 hardware serial port for communication with the FPC2534. If the board
26+
// being used does not have a Serial1 port, you will need to modify the code to use SoftwareSerial or another
27+
// serial port available on your board.
28+
//
29+
2330
// State flags to manage sensor startup/state
2431
bool startNavigation = true;
2532

examples/Example04_EnrollUART/Example04_EnrollUART.ino

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,30 @@
2121
//----------------------------------------------------------------------------------
2222
// Define the pins being used for operation
2323
//
24-
// The FPC2534 uses one pin for reset, and for I2C requires an interrupt pin to signal
25-
// when data is available to read.
24+
// The FPC2534 uses one pin for reset, No interrupt pin is needed for UART operation
2625
//
2726
// The following pin definitions were used for testing - but can be modified as needed.
2827
//
2928
// ESP32 thing plus
30-
// #define IRQ_PIN 16
3129
// #define RST_PIN 21
3230

3331
// ESP32 thing plus C
34-
// #define IRQ_PIN 32
3532
// #define RST_PIN 14
3633

3734
// RP2350 thing plus
38-
// #define IRQ_PIN 11
3935
#define RST_PIN 12
4036

4137
// IoT RedBoard - RP2350
42-
// #define IRQ_PIN 28
4338
// #define RST_PIN 29
4439

45-
// TODO: WTF on the uart / serial layer
46-
// #define UART_RX 32
47-
// #define UART_TX 14
40+
//----------------------------------------------------------------------------------
41+
// NOTE:
42+
// This example makes use of the Serial1 hardware serial port for communication with the FPC2534. If the board
43+
// being used does not have a Serial1 port, you will need to modify the code to use SoftwareSerial or another
44+
// serial port available on your board.
45+
//
4846

47+
// variable used to keep track of the number of enrolled templates on the sensor
4948
uint16_t numberOfTemplates = 0;
5049

5150
// Declare our sensor object
@@ -111,11 +110,17 @@ static void drawMenu()
111110
Serial.println(" Starting finger enrollment - place finger and remove a finger on the sensor to enroll "
112111
"a fingerprint");
113112
mySensor.setLED(true);
114-
fpc_id_type_t id = {.type = ID_TYPE_GENERATE_NEW, .id = 0};
113+
fpc_id_type_t id;
114+
id.type = ID_TYPE_GENERATE_NEW;
115+
id.id = 0;
115116
fpc_result_t rc = mySensor.requestEnroll(id);
116117
if (rc != FPC_RESULT_OK)
117-
Serial.printf("[ERROR]\tFailed to start enroll - error: %d\n\r", rc);
118-
Serial.print("\t samples remaining 12..");
118+
{
119+
Serial.print("[ERROR]\tFailed to start enroll - error: ");
120+
Serial.println(rc);
121+
}
122+
else
123+
Serial.print("\t samples remaining 12..");
119124
}
120125
else if (chIn == '2')
121126
{
@@ -128,10 +133,15 @@ static void drawMenu()
128133
else
129134
{
130135
Serial.println(" Deleting all templates on the fingerprint sensor");
131-
fpc_id_type_t id = {.type = ID_TYPE_ALL, .id = 0};
136+
fpc_id_type_t id = {0};
137+
id.type = ID_TYPE_ALL;
138+
id.id = 0;
132139
fpc_result_t rc = mySensor.requestDeleteTemplate(id);
133140
if (rc != FPC_RESULT_OK)
134-
Serial.printf("[ERROR]\tFailed to delete templates - error: %d\n\r", rc);
141+
{
142+
Serial.print("[ERROR]\tFailed to delete templates - error: ");
143+
Serial.println(rc);
144+
}
135145
else
136146
numberOfTemplates = 0;
137147
}
@@ -147,10 +157,15 @@ static void drawMenu()
147157
else
148158
{
149159
Serial.print(" Place a finger on the sensor for validation...");
150-
fpc_id_type_t id = {.type = ID_TYPE_ALL, .id = 0};
160+
fpc_id_type_t id = {0};
161+
id.type = ID_TYPE_ALL;
162+
id.id = 0;
151163
fpc_result_t rc = mySensor.requestIdentify(id, 1);
152164
if (rc != FPC_RESULT_OK)
153-
Serial.printf("[ERROR]\tFailed to start identity - error: %d\n\r", rc);
165+
{
166+
Serial.print("[ERROR]\tFailed to start identity - error: ");
167+
Serial.println(rc);
168+
}
154169
}
155170
}
156171
else
@@ -169,7 +184,8 @@ static void drawMenu()
169184
static void on_error(uint16_t error)
170185
{
171186
// hal_set_led_status(HAL_LED_STATUS_ERROR);
172-
Serial.printf("[ERROR]\tSensor Error Code: %d\n\r", error);
187+
Serial.print("[ERROR]\tSensor Error Code: ");
188+
Serial.println(error);
173189
// this could indicated the sensor communications is out of synch - a reset might be needed
174190
reset_sensor();
175191
}
@@ -191,25 +207,31 @@ static void on_is_ready_change(bool isReady)
191207
// Request the templates on the device ...
192208
fpc_result_t rc = mySensor.requestListTemplates();
193209
if (rc != FPC_RESULT_OK)
194-
Serial.printf("[ERROR]\tFailed to get template list - error: %d\n\r", rc);
210+
{
211+
Serial.println("[ERROR]\tFailed to get template list - error: ");
212+
Serial.println(rc);
213+
}
195214
}
196215
}
197216

198217
//----------------------------------------------------------------------------
199218
static void on_identify(bool is_match, uint16_t id)
200219
{
201-
Serial.printf(" %sMATCH %s", is_match ? "" : "NO ");
220+
221+
Serial.print(is_match ? " NO " : " ");
222+
Serial.print("MATCH");
202223
if (is_match)
203-
Serial.printf(" {Template ID: %d}", id);
224+
{
225+
Serial.print(" {Template ID: ");
226+
Serial.print(id);
227+
Serial.print("}");
228+
}
204229
Serial.println();
205230
}
206231
//----------------------------------------------------------------------------
207232
static void on_enroll(uint8_t feedback, uint8_t samples_remaining)
208233
{
209234

210-
// Serial.printf("[INFO]\t\tEnroll samples remaining: %d, feedback: %s (%d)\n\r", samples_remaining,
211-
// mySensor.getEnrollFeedBackString(feedback), feedback);
212-
213235
if (samples_remaining == 0)
214236
{
215237
Serial.println("..done!");
@@ -229,7 +251,6 @@ static void on_enroll(uint8_t feedback, uint8_t samples_remaining)
229251
static void on_list_templates(uint16_t num_templates, uint16_t *template_ids)
230252
{
231253
numberOfTemplates = num_templates;
232-
// Serial.printf("[INFO]\t\tNumber of templates on the sensor: %d\n\r", num_templates);
233254

234255
isInitialized = true;
235256
// lets draw the menu!
@@ -240,7 +261,6 @@ static void on_list_templates(uint16_t num_templates, uint16_t *template_ids)
240261
// on_status()
241262
static void on_status(uint16_t event, uint16_t state)
242263
{
243-
// Serial.printf("[STATUS]\tEvent: 0x%04X, State: 0x%04X\n\r", event, state);
244264

245265
// Check the system state, to determine when to draw the menu.
246266
//
@@ -275,28 +295,14 @@ static void on_status(uint16_t event, uint16_t state)
275295
drawTheMenu = true; // just in
276296
}
277297
}
278-
279-
// if checking identity and we get an image ready event - the device hangs until finger up
280-
// Let's prompt the user to remove the finger
281-
// NOTE on UART this is okay - just part of ID sequence - using I2C this seems to hang the process
282-
//
283-
// else if (mySensor.currentMode() == STATE_IDENTIFY && event == EVENT_IMAGE_READY)
284-
// {
285-
// Serial.println("[INFO]\t\tUnable to perform ID check - remove finger and try again");
286-
// }
287298
else if (mySensor.currentMode() == STATE_ENROLL && event == EVENT_FINGER_LOST)
288299
{
289300
Serial.print(".");
290301
}
291302
}
292303

293-
// Define our command callbacks the library will call on events from the sensor
294-
static const sfDevFPC2534Callbacks_t cmd_cb = {.on_error = on_error,
295-
.on_status = on_status,
296-
.on_enroll = on_enroll,
297-
.on_identify = on_identify,
298-
.on_list_templates = on_list_templates,
299-
.on_is_ready_change = on_is_ready_change};
304+
// Define our command callback struct - functions are set in the setup function
305+
static sfDevFPC2534Callbacks_t cmd_cb = {0};
300306

301307
//------------------------------------------------------------------------------------
302308
// reset_sensor()
@@ -332,8 +338,14 @@ void setup()
332338
Serial.println("----------------------------------------------------------------");
333339
Serial.println();
334340

335-
// RP2350 call.
341+
// The internal UART buffer can fill up quickly and overflow. As such, increase its size.
342+
// This example is supporting ESP32 and RP2040 based boards - adjust as needed for other platforms.
343+
#if defined(ARDUINO_ARCH_RP2040)
336344
Serial1.setFIFOSize(512);
345+
#elif defined(ESP32)
346+
Serial1.setRxBufferSize(512);
347+
#endif
348+
337349
Serial1.begin(921600, SERIAL_8N1);
338350
delay(100);
339351
for (uint32_t startMS = millis(); !Serial1 && (millis() - startMS < 5000);) // Wait for the serial port to be ready
@@ -353,6 +365,14 @@ void setup()
353365
}
354366
Serial.println("[STARTUP]\tFPC2534 initialized.");
355367

368+
// setup our callback functions structure
369+
cmd_cb.on_error = on_error;
370+
cmd_cb.on_status = on_status;
371+
cmd_cb.on_enroll = on_enroll;
372+
cmd_cb.on_identify = on_identify;
373+
cmd_cb.on_list_templates = on_list_templates;
374+
cmd_cb.on_is_ready_change = on_is_ready_change;
375+
356376
// set the callbacks for the sensor library to call
357377
mySensor.setCallbacks(cmd_cb);
358378

@@ -372,7 +392,8 @@ void loop()
372392
fpc_result_t rc = mySensor.processNextResponse();
373393
if (rc != FPC_RESULT_OK && rc != FPC_PENDING_OPERATION)
374394
{
375-
Serial.printf("[ERROR] Processing Error: %d\n\r", rc);
395+
Serial.print("[ERROR] Processing Error: ");
396+
Serial.println(rc);
376397
// Hmm - reset the sensor and start again?
377398
reset_sensor();
378399
}

0 commit comments

Comments
 (0)