Skip to content

Commit 37d0098

Browse files
committed
cleanup the conf samples - sync code - set still fails for unknown reasons
1 parent 1ec08f1 commit 37d0098

File tree

2 files changed

+150
-188
lines changed

2 files changed

+150
-188
lines changed

examples/Example07_ConfigI2C/Example07_ConfigI2C.ino

Lines changed: 74 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,13 @@
99
*/
1010

1111
/*
12-
* Example using the SparkFun FPC2534 Fingerprint sensor library to demonstrate the fingerprint
13-
* enrollment and identification of the sensor. The example provides the user with the following options:
14-
* - Enroll a new fingerprint
15-
* - Delete all existing fingerprints
16-
* - Validate a fingerprint
12+
* Example using the SparkFun FPC2534 Fingerprint sensor library to demonstrate the configuration
13+
* capabilities of the sensor. The example retrieves the current system configuration from the sensor,
14+
* modifies one of the configuration values, and sends the updated configuration back to the sensor.
1715
*
18-
* This version of this example uses the SPI interface to communicate with the sensor.
16+
* NOTE: Currently, the set of the updated values fails.
1917
*
20-
* Example Setup:
21-
* - Connect the SparkFun Qwiic FPC2534 Fingerprint sensor to your microcontroller using hook-up wires ...
22-
* setup for SPI communication. Note the CS PIN number - this needs to be defined below.
23-
* - Connect the RST pin on the sensor to a digital pin on your microcontroller. This is used by the
24-
* example to "reset the sensor" on startup.
25-
* - Connect the IRQ pin on the sensor to a digital pin on your microcontroller. The sensor triggers
26-
* an interrupt on this pin when it has data to send.
27-
* - Update the IRQ_PIN and RST_PIN defines below to match the pins you are using.
28-
*
29-
* Operation:
30-
* - The sensor object is initialized with the CS pin and the interrupt pin. This examples uses the default SPI bus.
31-
* - The example registers several callback functions with the sensor library. These functions are called as
32-
* messages are received from the sensor.
33-
* - Once running, the example prevents a menu with the following options:
34-
* 1) Enroll a new fingerprint
35-
* 2) Erase all existing fingerprint templates
36-
* 3) Validate a fingerprint
37-
*
38-
* Once an optoin is selected (enter the menu number), the example performs the requested operation.
39-
*
40-
* - When registering a new fingerprint, the example prompts the user to place and remove their finger repeatedly
41-
* until the fingerprint is fully enrolled. The example prints out the number of samples remaining as
42-
* reported by the sensor. Normally 12 samples are needed to fully enroll a fingerprint.
43-
* - When deleting all fingerprints, the example sends the delete command to the sensor. If successful,
44-
* the example resets its internal count of enrolled fingerprints to zero.
45-
* - When validating a fingerprint, the example prompts the user to place their finger on the sensor.
46-
* If the fingerprint matches an enrolled fingerprint, the example prints out the ID of the matched
47-
* fingerprint template.
18+
* This version of this example uses the I2C interface to communicate with the sensor.
4819
*
4920
*---------------------------------------------------------------------------------
5021
*/
@@ -159,13 +130,9 @@ static void on_is_ready_change(bool isReady)
159130
//
160131
static void on_status(uint16_t event, uint16_t state)
161132
{
162-
Serial.print("[STATUS]\tEvent: 0x");
163-
Serial.print(event, HEX);
164-
Serial.print(" State: 0x");
165-
Serial.println(state, HEX);
166-
167133
deviceIdle = (event == EVENT_IDLE);
168134
}
135+
//----------------------------------------------------------------------------
169136
static void update_config(fpc_system_config_t &new_config)
170137
{
171138
// The current values haven't been received yet
@@ -209,6 +176,8 @@ static void print_config(fpc_system_config_t &cfg)
209176
Serial.println(cfg.finger_scan_interval_ms);
210177
Serial.print(" System Flags:\t\t\t 0x");
211178
Serial.println(cfg.sys_flags, HEX);
179+
Serial.print(" Allows Factory Reset:\t\t ");
180+
Serial.println((cfg.sys_flags & CFG_SYS_FLAG_ALLOW_FACTORY_RESET) ? "Yes" : "No");
212181
Serial.print(" UART Delay Before IRQ (ms):\t ");
213182
Serial.println(cfg.uart_delay_before_irq_ms);
214183
Serial.print(" UART Baudrate:\t\t 0x");
@@ -248,16 +217,18 @@ void on_system_config_get(fpc_system_config_t *cfg)
248217
}
249218
else if (configState == CONFIG_VERIFY)
250219
{
251-
// verify the set worked
220+
// verify the config set worked
252221
if (cfg->idfy_max_consecutive_fails == the_config.idfy_max_consecutive_fails + 1)
253-
{
254222
Serial.println("[INFO]\t\tConfiguration update verified successfully.");
255-
configState = CONFIG_RESET;
256-
}
257223
else
258224
{
225+
Serial.println();
259226
Serial.println("[ERROR]\tConfiguration update verification failed.");
227+
Serial.println();
260228
}
229+
230+
// back to entry state
231+
configState = CONFIG_RESET;
261232
}
262233
}
263234
//------------------------------------------------------------------------------------
@@ -284,7 +255,62 @@ void reset_sensor(void)
284255
digitalWrite(RST_PIN, HIGH); // Set reset pin high
285256
delay(250); // Wait for sensor to initialize
286257
}
258+
//------------------------------------------------------------------------------------
259+
// Process the simple sequece of steps for the demo.
260+
261+
void process_demo_steps(void)
262+
{
287263

264+
// if we have the config, and haven't updated it yet, do so now
265+
if (configState == CONFIG_RECEIVED)
266+
{
267+
// update the max fails value
268+
update_config_max_fails(the_config.idfy_max_consecutive_fails + 1);
269+
270+
configState = CONFIG_SET;
271+
}
272+
else if (configState == CONFIG_SET)
273+
{
274+
// Get the new value of the config to verify the set worked
275+
Serial.println("[INFO]\t\tRequesting system configuration...");
276+
// Request the configuration from the connected device.
277+
fpc_result_t rc = mySensor.requestGetSystemConfig(FPC_SYS_CFG_TYPE_DEFAULT);
278+
if (rc != FPC_RESULT_OK)
279+
{
280+
Serial.print("[ERROR]\tGet config request failed - error: ");
281+
Serial.println(rc);
282+
}
283+
else
284+
configState = CONFIG_VERIFY;
285+
}
286+
else if (configState == CONFIG_RESET)
287+
{
288+
// Reset to defaults
289+
fpc_result_t rc = mySensor.setSystemConfig(&the_config);
290+
if (rc != FPC_RESULT_OK)
291+
{
292+
Serial.print("[ERROR]\tSet config request failed - error: ");
293+
Serial.println(rc);
294+
}
295+
else
296+
Serial.println("[INFO]\t\tSet config to the original value");
297+
configState = CONFIG_COMPLETE;
298+
}
299+
else if (configState == CONFIG_COMPLETE)
300+
{
301+
// Get the new value of the config to verify the set worked
302+
Serial.println("[INFO]\t\tRequesting final configuration...");
303+
// Request the configuration from the connected device.
304+
fpc_result_t rc = mySensor.requestGetSystemConfig(FPC_SYS_CFG_TYPE_DEFAULT);
305+
if (rc != FPC_RESULT_OK)
306+
{
307+
Serial.print("[ERROR]\tGet config request failed - error: ");
308+
Serial.println(rc);
309+
}
310+
else
311+
configState = CONFIG_EXIT;
312+
}
313+
}
288314
//------------------------------------------------------------------------------------
289315
// setup()
290316
//
@@ -300,7 +326,10 @@ void setup()
300326
}
301327
Serial.println();
302328
Serial.println("----------------------------------------------------------------");
303-
Serial.println(" SparkFun FPC2534 Fingerprint Config Example - SPI");
329+
Serial.println(" SparkFun FPC2534 Fingerprint Config Example - I2C");
330+
Serial.println();
331+
Serial.println(" **NOTE** Currently the `setSystemConfig` command fails to set the updated values.");
332+
Serial.println();
304333
Serial.println("----------------------------------------------------------------");
305334
Serial.println();
306335

@@ -364,56 +393,7 @@ void loop()
364393
reset_sensor();
365394
}
366395
else if (deviceIdle)
367-
{
368-
// if we have the config, and haven't updated it yet, do so now
369-
if (configState == CONFIG_RECEIVED)
370-
{
371-
// update the max fails value
372-
update_config_max_fails(the_config.idfy_max_consecutive_fails + 1);
373-
configState = CONFIG_SET;
374-
}
375-
else if (configState == CONFIG_SET)
376-
{
377-
// Get the new value of the config to verify the set worked
378-
Serial.println("[INFO]\t\tRequesting system configuration...");
379-
// Request the configuration from the connected device.
380-
fpc_result_t rc = mySensor.requestGetSystemConfig(FPC_SYS_CFG_TYPE_DEFAULT);
381-
if (rc != FPC_RESULT_OK)
382-
{
383-
Serial.print("[ERROR]\tGet config request failed - error: ");
384-
Serial.println(rc);
385-
}
386-
else
387-
configState = CONFIG_VERIFY;
388-
}
389-
else if (configState == CONFIG_RESET)
390-
{
391-
// Reset to defaults
392-
fpc_result_t rc = mySensor.setSystemConfig(&the_config);
393-
if (rc != FPC_RESULT_OK)
394-
{
395-
Serial.print("[ERROR]\tSet config request failed - error: ");
396-
Serial.println(rc);
397-
}
398-
else
399-
Serial.println("[INFO]\t\tSet config to the original value");
400-
configState = CONFIG_COMPLETE;
401-
}
402-
else if (configState == CONFIG_COMPLETE)
403-
{
404-
// Get the new value of the config to verify the set worked
405-
Serial.println("[INFO]\t\tRequesting final configuration...");
406-
// Request the configuration from the connected device.
407-
fpc_result_t rc = mySensor.requestGetSystemConfig(FPC_SYS_CFG_TYPE_DEFAULT);
408-
if (rc != FPC_RESULT_OK)
409-
{
410-
Serial.print("[ERROR]\tGet config request failed - error: ");
411-
Serial.println(rc);
412-
}
413-
else
414-
configState = CONFIG_EXIT;
415-
}
416-
}
396+
process_demo_steps();
417397

418398
delay(200);
419399
}

0 commit comments

Comments
 (0)