diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..e439582 --- /dev/null +++ b/.github/workflows/githubci.yml @@ -0,0 +1,34 @@ +name: Arduino Library CI + +on: [pull_request, push, repository_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: adafruit/ci-arduino + path: ci + + - name: pre-install + run: bash ci/actions_install.sh + + - name: test platforms + run: python3 ci/build_platform.py main_platforms + + - name: clang + run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . + + - name: doxygen + env: + GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} + PRETTYNAME : "Adafruit Fingerprint Arduino Library" + run: bash ci/doxy_gen_and_deploy.sh + + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0957e9d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: c -sudo: false - -# Blacklist -branches: - except: - - gh-pages - -env: - global: - - PRETTYNAME="Adafruit Fingerprint Arduino Library" -# Optional, will default to "$TRAVIS_BUILD_DIR/Doxyfile" -# - DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile - -before_install: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) - -#install: -# - arduino --install-library "Adafruit ILI9341","Adafruit GFX Library" - -script: - - build_main_platforms - -# Generate and deploy documentation -after_success: - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh) - - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh) \ No newline at end of file diff --git a/Adafruit_Fingerprint.cpp b/Adafruit_Fingerprint.cpp old mode 100755 new mode 100644 index 272b553..ac14d00 --- a/Adafruit_Fingerprint.cpp +++ b/Adafruit_Fingerprint.cpp @@ -19,27 +19,33 @@ //#define FINGERPRINT_DEBUG #if ARDUINO >= 100 - #define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__) +#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__) #else - #define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE) +#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE) #endif -#define SERIAL_WRITE_U16(v) SERIAL_WRITE((uint8_t)(v>>8)); SERIAL_WRITE((uint8_t)(v & 0xFF)); - -#define GET_CMD_PACKET(...) \ - uint8_t data[] = {__VA_ARGS__}; \ - Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), data); \ - writeStructuredPacket(packet); \ - if (getStructuredPacket(&packet) != FINGERPRINT_OK) return FINGERPRINT_PACKETRECIEVEERR; \ - if (packet.type != FINGERPRINT_ACKPACKET) return FINGERPRINT_PACKETRECIEVEERR; +#define SERIAL_WRITE_U16(v) \ + SERIAL_WRITE((uint8_t)(v >> 8)); \ + SERIAL_WRITE((uint8_t)(v & 0xFF)); + +#define GET_CMD_PACKET(...) \ + uint8_t data[] = {__VA_ARGS__}; \ + Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), \ + data); \ + writeStructuredPacket(packet); \ + if (getStructuredPacket(&packet) != FINGERPRINT_OK) \ + return FINGERPRINT_PACKETRECIEVEERR; \ + if (packet.type != FINGERPRINT_ACKPACKET) \ + return FINGERPRINT_PACKETRECIEVEERR; -#define SEND_CMD_PACKET(...) GET_CMD_PACKET(__VA_ARGS__); return packet.data[0]; +#define SEND_CMD_PACKET(...) \ + GET_CMD_PACKET(__VA_ARGS__); \ + return packet.data[0]; /*************************************************************************** PUBLIC FUNCTIONS ***************************************************************************/ - #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) /**************************************************************************/ /*! @@ -48,7 +54,8 @@ @param password 32-bit integer password (default is 0) */ /**************************************************************************/ -Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password) { +Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss, + uint32_t password) { thePassword = password; theAddress = 0xFFFFFFFF; @@ -66,7 +73,8 @@ Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password */ /**************************************************************************/ -Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password) { +Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs, + uint32_t password) { thePassword = password; theAddress = 0xFFFFFFFF; @@ -84,17 +92,20 @@ Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password */ /**************************************************************************/ void Adafruit_Fingerprint::begin(uint32_t baudrate) { - delay(1000); // one second delay to let the sensor 'boot up' + delay(1000); // one second delay to let the sensor 'boot up' - if (hwSerial) hwSerial->begin(baudrate); + if (hwSerial) + hwSerial->begin(baudrate); #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) - if (swSerial) swSerial->begin(baudrate); + if (swSerial) + swSerial->begin(baudrate); #endif } /**************************************************************************/ /*! - @brief Verifies the sensors' access password (default password is 0x0000000). A good way to also check if the sensors is active and responding + @brief Verifies the sensors' access password (default password is + 0x0000000). A good way to also check if the sensors is active and responding @returns True if password is correct */ /**************************************************************************/ @@ -103,9 +114,9 @@ boolean Adafruit_Fingerprint::verifyPassword(void) { } uint8_t Adafruit_Fingerprint::checkPassword(void) { - GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD, - (uint8_t)(thePassword >> 24), (uint8_t)(thePassword >> 16), - (uint8_t)(thePassword >> 8), (uint8_t)(thePassword & 0xFF)); + GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD, (uint8_t)(thePassword >> 24), + (uint8_t)(thePassword >> 16), (uint8_t)(thePassword >> 8), + (uint8_t)(thePassword & 0xFF)); if (packet.data[0] == FINGERPRINT_OK) return FINGERPRINT_OK; else @@ -128,20 +139,24 @@ uint8_t Adafruit_Fingerprint::getImage(void) { /**************************************************************************/ /*! @brief Ask the sensor to convert image to feature template - @param slot Location to place feature template (put one in 1 and another in 2 for verification to create model) + @param slot Location to place feature template (put one in 1 and another in + 2 for verification to create model) @returns FINGERPRINT_OK on success @returns FINGERPRINT_IMAGEMESS if image is too messy @returns FINGERPRINT_PACKETRECIEVEERR on communication error - @returns FINGERPRINT_FEATUREFAIL on failure to identify fingerprint features - @returns FINGERPRINT_INVALIDIMAGE on failure to identify fingerprint features + @returns FINGERPRINT_FEATUREFAIL on failure to identify + fingerprint features + @returns FINGERPRINT_INVALIDIMAGE on failure to identify + fingerprint features */ uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) { - SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ,slot); + SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ, slot); } /**************************************************************************/ /*! - @brief Ask the sensor to take two print feature template and create a model + @brief Ask the sensor to take two print feature template and create a + model @returns FINGERPRINT_OK on success @returns FINGERPRINT_PACKETRECIEVEERR on communication error @returns FINGERPRINT_ENROLLMISMATCH on mismatch of fingerprints @@ -150,18 +165,19 @@ uint8_t Adafruit_Fingerprint::createModel(void) { SEND_CMD_PACKET(FINGERPRINT_REGMODEL); } - /**************************************************************************/ /*! @brief Ask the sensor to store the calculated model for later matching @param location The model location # @returns FINGERPRINT_OK on success @returns FINGERPRINT_BADLOCATION if the location is invalid - @returns FINGERPRINT_FLASHERR if the model couldn't be written to flash memory + @returns FINGERPRINT_FLASHERR if the model couldn't be written + to flash memory @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) { - SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF)); + SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8), + (uint8_t)(location & 0xFF)); } /**************************************************************************/ @@ -173,12 +189,14 @@ uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) { @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ uint8_t Adafruit_Fingerprint::loadModel(uint16_t location) { - SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF)); + SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8), + (uint8_t)(location & 0xFF)); } /**************************************************************************/ /*! - @brief Ask the sensor to transfer 256-byte fingerprint template from the buffer to the UART + @brief Ask the sensor to transfer 256-byte fingerprint template from the + buffer to the UART @returns FINGERPRINT_OK on success @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ @@ -192,11 +210,13 @@ uint8_t Adafruit_Fingerprint::getModel(void) { @param location The model location # @returns FINGERPRINT_OK on success @returns FINGERPRINT_BADLOCATION if the location is invalid - @returns FINGERPRINT_FLASHERR if the model couldn't be written to flash memory + @returns FINGERPRINT_FLASHERR if the model couldn't be written + to flash memory @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ uint8_t Adafruit_Fingerprint::deleteModel(uint16_t location) { - SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF), 0x00, 0x01); + SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(location >> 8), + (uint8_t)(location & 0xFF), 0x00, 0x01); } /**************************************************************************/ @@ -204,7 +224,8 @@ uint8_t Adafruit_Fingerprint::deleteModel(uint16_t location) { @brief Ask the sensor to delete ALL models in memory @returns FINGERPRINT_OK on success @returns FINGERPRINT_BADLOCATION if the location is invalid - @returns FINGERPRINT_FLASHERR if the model couldn't be written to flash memory + @returns FINGERPRINT_FLASHERR if the model couldn't be written + to flash memory @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ uint8_t Adafruit_Fingerprint::emptyDatabase(void) { @@ -213,7 +234,9 @@ uint8_t Adafruit_Fingerprint::emptyDatabase(void) { /**************************************************************************/ /*! - @brief Ask the sensor to search the current slot 1 fingerprint features to match saved templates. The matching location is stored in fingerID and the matching confidence in confidence + @brief Ask the sensor to search the current slot 1 fingerprint features to + match saved templates. The matching location is stored in fingerID and + the matching confidence in confidence @returns FINGERPRINT_OK on fingerprint match success @returns FINGERPRINT_NOTFOUND no match made @returns FINGERPRINT_PACKETRECIEVEERR on communication error @@ -238,7 +261,8 @@ uint8_t Adafruit_Fingerprint::fingerFastSearch(void) { /**************************************************************************/ /*! - @brief Ask the sensor for the number of templates stored in memory. The number is stored in templateCount on success. + @brief Ask the sensor for the number of templates stored in memory. The + number is stored in templateCount on success. @returns FINGERPRINT_OK on success @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ @@ -255,24 +279,28 @@ uint8_t Adafruit_Fingerprint::getTemplateCount(void) { /**************************************************************************/ /*! - @brief Set the password on the sensor (future communication will require password verification so don't forget it!!!) + @brief Set the password on the sensor (future communication will require + password verification so don't forget it!!!) @param password 32-bit password code @returns FINGERPRINT_OK on success @returns FINGERPRINT_PACKETRECIEVEERR on communication error */ /**************************************************************************/ uint8_t Adafruit_Fingerprint::setPassword(uint32_t password) { - SEND_CMD_PACKET(FINGERPRINT_SETPASSWORD, (password >> 24), (password >> 16), (password >> 8), password); + SEND_CMD_PACKET(FINGERPRINT_SETPASSWORD, (password >> 24), (password >> 16), + (password >> 8), password); } /**************************************************************************/ /*! - @brief Helper function to process a packet and send it over UART to the sensor + @brief Helper function to process a packet and send it over UART to the + sensor @param packet A structure containing the bytes to transmit */ /**************************************************************************/ -void Adafruit_Fingerprint::writeStructuredPacket(const Adafruit_Fingerprint_Packet & packet) { +void Adafruit_Fingerprint::writeStructuredPacket( + const Adafruit_Fingerprint_Packet &packet) { SERIAL_WRITE_U16(packet.start_code); SERIAL_WRITE(packet.address[0]); SERIAL_WRITE(packet.address[1]); @@ -283,8 +311,8 @@ void Adafruit_Fingerprint::writeStructuredPacket(const Adafruit_Fingerprint_Pack uint16_t wire_length = packet.length + 2; SERIAL_WRITE_U16(wire_length); - uint16_t sum = ((wire_length)>>8) + ((wire_length)&0xFF) + packet.type; - for (uint8_t i=0; i< packet.length; i++) { + uint16_t sum = ((wire_length) >> 8) + ((wire_length)&0xFF) + packet.type; + for (uint8_t i = 0; i < packet.length; i++) { SERIAL_WRITE(packet.data[i]); sum += packet.data[i]; } @@ -295,63 +323,68 @@ void Adafruit_Fingerprint::writeStructuredPacket(const Adafruit_Fingerprint_Pack /**************************************************************************/ /*! - @brief Helper function to receive data over UART from the sensor and process it into a packet + @brief Helper function to receive data over UART from the sensor and + process it into a packet @param packet A structure containing the bytes received @param timeout how many milliseconds we're willing to wait @returns FINGERPRINT_OK on success - @returns FINGERPRINT_TIMEOUT or FINGERPRINT_BADPACKET on failure + @returns FINGERPRINT_TIMEOUT or + FINGERPRINT_BADPACKET on failure */ /**************************************************************************/ -uint8_t Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet * packet, uint16_t timeout) { +uint8_t +Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet *packet, + uint16_t timeout) { uint8_t byte; - uint16_t idx=0, timer=0; + uint16_t idx = 0, timer = 0; - while(true) { - while(!mySerial->available()) { + while (true) { + while (!mySerial->available()) { delay(1); - timer++; - if( timer >= timeout) { + timer++; + if (timer >= timeout) { #ifdef FINGERPRINT_DEBUG - Serial.println("Timed out"); + Serial.println("Timed out"); #endif - return FINGERPRINT_TIMEOUT; + return FINGERPRINT_TIMEOUT; } } byte = mySerial->read(); #ifdef FINGERPRINT_DEBUG - Serial.print("<- 0x"); Serial.println(byte, HEX); + Serial.print("<- 0x"); + Serial.println(byte, HEX); #endif switch (idx) { - case 0: - if (byte != (FINGERPRINT_STARTCODE >> 8)) - continue; - packet->start_code = (uint16_t)byte << 8; - break; - case 1: - packet->start_code |= byte; - if (packet->start_code != FINGERPRINT_STARTCODE) - return FINGERPRINT_BADPACKET; - break; - case 2: - case 3: - case 4: - case 5: - packet->address[idx-2] = byte; - break; - case 6: - packet->type = byte; - break; - case 7: - packet->length = (uint16_t)byte << 8; - break; - case 8: - packet->length |= byte; - break; - default: - packet->data[idx-9] = byte; - if((idx-8) == packet->length) - return FINGERPRINT_OK; - break; + case 0: + if (byte != (FINGERPRINT_STARTCODE >> 8)) + continue; + packet->start_code = (uint16_t)byte << 8; + break; + case 1: + packet->start_code |= byte; + if (packet->start_code != FINGERPRINT_STARTCODE) + return FINGERPRINT_BADPACKET; + break; + case 2: + case 3: + case 4: + case 5: + packet->address[idx - 2] = byte; + break; + case 6: + packet->type = byte; + break; + case 7: + packet->length = (uint16_t)byte << 8; + break; + case 8: + packet->length |= byte; + break; + default: + packet->data[idx - 9] = byte; + if ((idx - 8) == packet->length) + return FINGERPRINT_OK; + break; } idx++; } diff --git a/Adafruit_Fingerprint.h b/Adafruit_Fingerprint.h index dcf2d8e..159220c 100644 --- a/Adafruit_Fingerprint.h +++ b/Adafruit_Fingerprint.h @@ -19,10 +19,10 @@ #include "Arduino.h" #if defined(__AVR__) || defined(ESP8266) - #include +#include #elif defined(FREEDOM_E300_HIFIVE1) - #include - #define SoftwareSerial SoftwareSerial32 +#include +#define SoftwareSerial SoftwareSerial32 #endif #define FINGERPRINT_OK 0x00 @@ -73,41 +73,44 @@ //#define FINGERPRINT_DEBUG -#define DEFAULTTIMEOUT 1000 ///< UART reading timeout in milliseconds +#define DEFAULTTIMEOUT 1000 ///< UART reading timeout in milliseconds ///! Helper class to craft UART packets struct Adafruit_Fingerprint_Packet { -/**************************************************************************/ -/*! - @brief Create a new UART-borne packet - @param type Command, data, ack type packet - @param length Size of payload - @param data Pointer to bytes of size length we will memcopy into the internal buffer -*/ -/**************************************************************************/ - - Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t * data) { + /**************************************************************************/ + /*! + @brief Create a new UART-borne packet + @param type Command, data, ack type packet + @param length Size of payload + @param data Pointer to bytes of size length we will memcopy into the + internal buffer + */ + /**************************************************************************/ + + Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t *data) { this->start_code = FINGERPRINT_STARTCODE; this->type = type; this->length = length; - address[0] = 0xFF; address[1] = 0xFF; - address[2] = 0xFF; address[3] = 0xFF; - if(length<64) + address[0] = 0xFF; + address[1] = 0xFF; + address[2] = 0xFF; + address[3] = 0xFF; + if (length < 64) memcpy(this->data, data, length); else memcpy(this->data, data, 64); } - uint16_t start_code; ///< "Wakeup" code for packet detection - uint8_t address[4]; ///< 32-bit Fingerprint sensor address - uint8_t type; ///< Type of packet - uint16_t length; ///< Length of packet - uint8_t data[64]; ///< The raw buffer for packet payload + uint16_t start_code; ///< "Wakeup" code for packet detection + uint8_t address[4]; ///< 32-bit Fingerprint sensor address + uint8_t type; ///< Type of packet + uint16_t length; ///< Length of packet + uint8_t data[64]; ///< The raw buffer for packet payload }; ///! Helper class to communicate with and keep state for fingerprint sensors class Adafruit_Fingerprint { - public: +public: #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password = 0x0); #endif @@ -128,21 +131,23 @@ class Adafruit_Fingerprint { uint8_t fingerFastSearch(void); uint8_t getTemplateCount(void); uint8_t setPassword(uint32_t password); - void writeStructuredPacket(const Adafruit_Fingerprint_Packet & p); - uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet * p, uint16_t timeout=DEFAULTTIMEOUT); + void writeStructuredPacket(const Adafruit_Fingerprint_Packet &p); + uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet *p, + uint16_t timeout = DEFAULTTIMEOUT); /// The matching location that is set by fingerFastSearch() uint16_t fingerID; - /// The confidence of the fingerFastSearch() match, higher numbers are more confidents + /// The confidence of the fingerFastSearch() match, higher numbers are more + /// confidents uint16_t confidence; /// The number of stored templates in the sensor, set by getTemplateCount() uint16_t templateCount; - private: +private: uint8_t checkPassword(void); uint32_t thePassword; uint32_t theAddress; - uint8_t recvPacket[20]; + uint8_t recvPacket[20]; Stream *mySerial; #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1) diff --git a/README.md b/README.md index 1a5a5cb..6076f6e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Adafruit Fingerprint Sensor Library [![Build Status](https://travis-ci.org/adafruit/Adafruit-Fingerprint-Sensor-Library.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit-Fingerprint-Sensor-Library) +# Adafruit-Fingerprint-Sensor-Library [![Build Status](https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library/actions) @@ -16,4 +16,4 @@ Adafruit invests time and resources providing this open source code, please supp Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information -All text above must be included in any redistribution \ No newline at end of file +All text above must be included in any redistribution diff --git a/library.properties b/library.properties index e1a6aa2..ad847c3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit Fingerprint Sensor Library -version=1.1.3 +version=1.1.4 author=Adafruit maintainer=Adafruit sentence=Arduino library for interfacing to the fingerprint sensor in the Adafruit shop @@ -7,3 +7,4 @@ paragraph=Arduino library for interfacing to the fingerprint sensor in the Adafr category=Sensors url=https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library architectures=* +depends=Adafruit ILI9341, Adafruit GFX Library