SparkFun Fingerprint Sensor - FPC2534 Pro  v0.9.9-3-g5d0d172
Library for the SparkFun Fingerprint Sensor - FPC2534 Pro
Loading...
Searching...
No Matches
sfDevFPC2534.h
Go to the documentation of this file.
1
13// Header file for the main class of the library.
14
15#pragma once
16
17// from the FPC SDK
18#include "fpc_api.h"
19
20// The interface definition for communication classes
21#include "sfDevFPC2534IComm.h"
22
23// This library is dependent on Arduino framework
24#include <Arduino.h>
25
26// Define the LED pin on the FPC2534 board
27const uint8_t SPARKFUN_FPC2534_LED_PIN = 1;
28
29// The design pattern that the library implements follows the standard implementation
30// pattern of the FPC SDK - response from the sensor is delivered via callback functions.
31//
32// Define a struct that can hold all the callback functions
33// that the library can call on events from the sensor
34
37typedef struct
38{
39 void (*on_error)(uint16_t error);
40 void (*on_status)(uint16_t event, uint16_t state);
41 void (*on_version)(char *version);
42 void (*on_enroll)(uint8_t feedback, uint8_t samples_remaining);
43 void (*on_identify)(bool is_match, uint16_t id);
44 void (*on_list_templates)(uint16_t num_templates, uint16_t *template_ids);
45 void (*on_navigation)(uint16_t gesture);
46 void (*on_gpio_control)(uint8_t state);
47 void (*on_system_config_get)(fpc_system_config_t *cfg);
48 void (*on_bist_done)(uint16_t test_verdict);
49 void (*on_data_transfer_done)(uint8_t *data, size_t size);
50 void (*on_mode_change)(uint16_t new_mode);
51 void (*on_finger_change)(bool present);
52 void (*on_is_ready_change)(bool isReady);
53
55
59{
60 public:
62
69
76
86
98
105
112
123
130
136 // fpc_result_t requestCryptoKey(void);
137
147 fpc_result_t startNavigationMode(uint8_t orientation);
148
157
169 fpc_result_t requestSetGPIO(uint8_t pin, uint8_t mode, uint8_t state);
170
180 fpc_result_t requestGetGPIO(uint8_t pin);
181
192
203
204 // /**
205 // * @brief Populate and transfer a CMD_PUT_TEMPLATE_DATA request
206 // *
207 // * Send template to device.
208 // *
209 // * @param id Template id.
210 // * @param data Pointer to template data.
211 // * @param size Size of template data.
212 // *
213 // * @return Result Code
214 // */
215 // fpc_result_t requestPutTemplateData(uint16_t id, uint8_t *data, size_t size);
216
217 // /**
218 // * @brief Populate and transfer a CMD_GET_TEMPLATE_DATA request.
219 // *
220 // * Read template from device. This function will allocate memory for the template and
221 // * return data and size in the callback function (on_data_transfer_done).
222 // *
223 // * @param id Template id.
224 // *
225 // * @return Result Code
226 // */
227 // fpc_result_t requestGetTemplateData(uint16_t id);
228
237
244 uint16_t currentMode(void) const
245 {
246 return _current_state & (STATE_ENROLL | STATE_IDENTIFY | STATE_NAVIGATION);
247 }
248
255 bool isFingerPresent(void) const
256 {
257 return _finger_present;
258 }
259
265 // for the library to actually work, user provided callbacks are needed ...
267 {
268 _callbacks = callbacks;
269 }
270
278 {
279 _comm = &comm;
280 return true;
281 }
282
288 bool isReady(void) const
289 {
290 return (_current_state & STATE_APP_FW_READY) == STATE_APP_FW_READY;
291 }
292
298 bool isDataAvailable(void) const
299 {
300 if (_comm == nullptr)
301 return false;
302 return _comm->dataAvailable();
303 }
304
309 void clearData(void)
310 {
311 if (_comm != nullptr)
312 _comm->clearData();
313 }
320 fpc_result_t setLED(bool on = true);
321
322 // Process the next response from the device
323 // If flushNone is true, it will skip over any EVENT_NONE events
324
331 fpc_result_t processNextResponse(bool flushNone);
333 {
334 return processNextResponse(false);
335 };
336
337 private:
338 // NOTE:
339 // In general, messages are received from the device, identified and sent to the
340 // appropriate parser function.
341
342 fpc_result_t sendCommand(fpc_cmd_hdr_t &cmd, size_t size);
343 fpc_result_t parseStatusCommand(fpc_cmd_hdr_t *, size_t);
344 fpc_result_t parseVersionCommand(fpc_cmd_hdr_t *, size_t);
345 fpc_result_t parseEnrollStatusCommand(fpc_cmd_hdr_t *, size_t);
346 fpc_result_t parseIdentifyCommand(fpc_cmd_hdr_t *, size_t);
347 fpc_result_t parseListTemplatesCommand(fpc_cmd_hdr_t *, size_t);
348 fpc_result_t parseNavigationEventCommand(fpc_cmd_hdr_t *, size_t);
349 fpc_result_t parseGPIOControlCommand(fpc_cmd_hdr_t *, size_t);
350 fpc_result_t parseGetSystemConfigCommand(fpc_cmd_hdr_t *, size_t);
351 fpc_result_t parseBISTCommand(fpc_cmd_hdr_t *, size_t);
352 fpc_result_t parseCommand(uint8_t *frame_payload, size_t payload_size);
353
354 bool checkForNoneEvent(uint8_t *payload, size_t size);
355 fpc_result_t flushNoneEvent(void);
356
357 // internal pointer to the communication interface. The comm device being used (I2C, Serial) is abstract
358 // to the library via this interface.
359 sfDevFPC2534IComm *_comm = nullptr;
360
361 // Internal copy of the callback functions
362 sfDevFPC2534Callbacks_t _callbacks;
363
364 // current state of the sensor
365 uint16_t _current_state = 0;
366
367 // Is a finger present?
368 bool _finger_present = false;
369};
Core class implementing FPC2534 functionality independent of communication protocol.
Definition: sfDevFPC2534.h:59
void clearData(void)
Clear any available data from the device.
Definition: sfDevFPC2534.h:309
bool isReady(void) const
Check if the device firmware is ready.
Definition: sfDevFPC2534.h:288
fpc_result_t startNavigationMode(uint8_t orientation)
Populate and transfer a CMD_SET_CRYPTO_KEY request.
Definition: sfDevFPC2534.cpp:130
fpc_result_t requestEnroll(fpc_id_type_t &id)
Request to start an enrollment operation.
Definition: sfDevFPC2534.cpp:65
uint16_t currentMode(void) const
Get the current operating mode of the device.
Definition: sfDevFPC2534.h:244
fpc_result_t processNextResponse(void)
Definition: sfDevFPC2534.h:332
sfDevFPC2534()
Definition: sfDevFPC2534.cpp:16
fpc_result_t requestSetGPIO(uint8_t pin, uint8_t mode, uint8_t state)
Send GPIO control command to the device.
Definition: sfDevFPC2534.cpp:149
fpc_result_t requestListTemplates(void)
Send a list templates command to the device.
Definition: sfDevFPC2534.cpp:102
bool isDataAvailable(void) const
Check if data is available to read from the device.
Definition: sfDevFPC2534.h:298
fpc_result_t setLED(bool on=true)
Set the state of the on-board LED.
Definition: sfDevFPC2534.cpp:695
fpc_result_t setSystemConfig(fpc_system_config_t *cfg)
Set the system configuration on the device.
Definition: sfDevFPC2534.cpp:175
bool initialize(sfDevFPC2534IComm &comm)
initialize the library with a communication interface.
Definition: sfDevFPC2534.h:277
fpc_result_t requestAbort(void)
Send an abort command to the device.
Definition: sfDevFPC2534.cpp:87
fpc_result_t startBuiltInSelfTest(void)
Start the BuiltIn Self Test. (BIST )
Definition: sfDevFPC2534.cpp:141
fpc_result_t factoryReset(void)
Send a factory reset command to the device.
Definition: sfDevFPC2534.cpp:197
bool isFingerPresent(void) const
Check if a finger is currently present on the sensor.
Definition: sfDevFPC2534.h:255
fpc_result_t requestStatus(void)
Request the status from the device.
Definition: sfDevFPC2534.cpp:47
fpc_result_t sendReset(void)
Request to send a reset command to the device.
Definition: sfDevFPC2534.cpp:122
fpc_result_t requestGetGPIO(uint8_t pin)
Respond to a GPIO get state command to the device.
Definition: sfDevFPC2534.cpp:164
fpc_result_t requestVersion(void)
Request the version from the device.
Definition: sfDevFPC2534.cpp:56
fpc_result_t requestGetSystemConfig(uint8_t type)
Request the system configuration from the device.
Definition: sfDevFPC2534.cpp:186
void setCallbacks(const sfDevFPC2534Callbacks_t &callbacks)
Set the callback functions for the library to call on events. This is required.
Definition: sfDevFPC2534.h:266
fpc_result_t requestIdentify(fpc_id_type_t &id, uint16_t tag)
Request to start an identification operation.
Definition: sfDevFPC2534.cpp:75
fpc_result_t requestDeleteTemplate(fpc_id_type_t &id)
Request to delete a template.
Definition: sfDevFPC2534.cpp:111
Definition: sfDevFPC2534IComm.h:19
virtual void clearData(void)=0
virtual bool dataAvailable(void)=0
FPC AllKey Pro API.
#define STATE_NAVIGATION
Definition: fpc_api.h:202
#define STATE_ENROLL
Definition: fpc_api.h:200
#define STATE_IDENTIFY
Definition: fpc_api.h:201
uint16_t fpc_result_t
Definition: fpc_api.h:33
#define STATE_APP_FW_READY
System States (Bitmap).
Definition: fpc_api.h:193
const uint8_t SPARKFUN_FPC2534_LED_PIN
Definition: sfDevFPC2534.h:27
Command Header.
Definition: fpc_api.h:123
Template ID specifier payload.
Definition: fpc_api.h:348
System Configuration parameters.
Definition: fpc_api.h:649
Struct holding all callback function pointers for sfDevFPC2534 events.
Definition: sfDevFPC2534.h:38