-
Notifications
You must be signed in to change notification settings - Fork 6
feat: PN532 NFC reader support #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ docs/tigertag-architecture.md | |
| docs/deep-thoughts.md | ||
| CODE-CLEANUP.md | ||
| docs/writer-ui-plan.md | ||
| .gstack/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /** | ||
| * OpenPrintTag Adafruit PN532 HAL Adapter | ||
| * | ||
| * Provides NFC HAL implementation for Adafruit_PN532 Arduino library. | ||
| * Wraps mifareultralight_ReadPage/WritePage into opt_nfc_hal_t callbacks. | ||
| */ | ||
|
|
||
| #ifndef OPENPRINTTAG_ADAFRUIT_PN532_H | ||
| #define OPENPRINTTAG_ADAFRUIT_PN532_H | ||
|
|
||
| #include "openprinttag_lib.h" | ||
| #include <Adafruit_PN532.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
These are Also applies to: 74-76 🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
| * Read a page from NTAG using Adafruit_PN532. | ||
| * | ||
| * @param ctx Adafruit_PN532 pointer | ||
| * @param page Page number to read | ||
| * @param buf Output buffer (4 bytes) | ||
| * @return OPT_OK on success, OPT_ERR_NFC_READ on failure | ||
| */ | ||
| static inline opt_error_t opt_adafruit_pn532_read_page(void *ctx, uint8_t page, uint8_t *buf) { | ||
| Adafruit_PN532 *pn532 = (Adafruit_PN532 *)ctx; | ||
| /* mifareultralight_ReadPage reads 4 bytes, returns count (non-zero = success) */ | ||
| return pn532->mifareultralight_ReadPage(page, buf) ? OPT_OK : OPT_ERR_NFC_READ; | ||
| } | ||
|
|
||
| /** | ||
| * Write a page to NTAG using Adafruit_PN532. | ||
| * | ||
| * @param ctx Adafruit_PN532 pointer | ||
| * @param page Page number to write | ||
| * @param data Data to write (4 bytes) | ||
| * @return OPT_OK on success, OPT_ERR_NFC_WRITE on failure | ||
| */ | ||
| static inline opt_error_t opt_adafruit_pn532_write_page(void *ctx, uint8_t page, const uint8_t *data) { | ||
| Adafruit_PN532 *pn532 = (Adafruit_PN532 *)ctx; | ||
| /* mifareultralight_WritePage returns true on success */ | ||
| return pn532->mifareultralight_WritePage(page, (uint8_t *)data) ? OPT_OK : OPT_ERR_NFC_WRITE; | ||
| } | ||
|
|
||
| /** | ||
| * Create a HAL structure for Adafruit_PN532. | ||
| * | ||
| * @param pn532 Initialized Adafruit_PN532 instance | ||
| * @return HAL structure ready for use with opt_read_from_nfc/opt_write_to_nfc | ||
| * | ||
| * Example usage: | ||
| * Adafruit_PN532 pn532(SS_PIN, &SPI); | ||
| * pn532.begin(); | ||
| * pn532.SAMConfig(); | ||
| * | ||
| * opt_nfc_hal_t hal = opt_create_adafruit_pn532_hal(&pn532); | ||
| * | ||
| * opt_tag_t tag; | ||
| * opt_init(&tag); | ||
| * opt_read_from_nfc(&tag, &hal, 4, 50); | ||
| * opt_parse_ndef(&tag); | ||
| */ | ||
| static inline opt_nfc_hal_t opt_create_adafruit_pn532_hal(Adafruit_PN532 *pn532) { | ||
| opt_nfc_hal_t hal = { | ||
| .read_page = opt_adafruit_pn532_read_page, | ||
| .write_page = opt_adafruit_pn532_write_page, | ||
| .is_present = NULL, | ||
| .user_ctx = pn532 | ||
| }; | ||
| return hal; | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* OPENPRINTTAG_ADAFRUIT_PN532_H */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ lib_deps = | |
| knolleary/PubSubClient@^2.8 | ||
| codewitch-honey-crisis/htcw_json@^0.2.5 | ||
| adafruit/Adafruit NeoPixel | ||
| adafruit/Adafruit PN532@1.3.4 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 🧩 Analysis chain🌐 Web query:
💡 Result: The latest version of the Adafruit PN532 Arduino library is 1.3.4, released on 2025-02-18. Citations:
🏁 Script executed: # Read the platformio.ini file to see all dependencies and their version pinning styles
cat platformio.iniRepository: SpoolSense/spoolsense_scanner Length of output: 1187 Version pinning is inconsistent with other dependencies. Most dependencies use 🤖 Prompt for AI Agents |
||
| chris--a/Keypad@^3.1.1 | ||
|
|
||
| [env:esp32dev] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -981,6 +981,14 @@ void ApplicationManager::handleKeypadCancel() { | |
|
|
||
| bool ApplicationManager::sendAssignSpool(const char* toolNumber) { | ||
| #ifndef NATIVE_TEST | ||
| // Validate tool number is digits-only (prevent GCode injection) | ||
| for (const char* p = toolNumber; *p; p++) { | ||
| if (*p < '0' || *p > '9') { | ||
| Serial.printf("ApplicationManager: Invalid tool number '%s'\n", toolNumber); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const char* moonrakerUrl = ConfigurationManager::getInstance().getMoonrakerURL(); | ||
| if (!moonrakerUrl || moonrakerUrl[0] == '\0') { | ||
| Serial.println("ApplicationManager: Moonraker URL not configured — cannot assign spool"); | ||
|
|
@@ -989,7 +997,7 @@ bool ApplicationManager::sendAssignSpool(const char* toolNumber) { | |
| } | ||
|
|
||
| extern SemaphoreHandle_t g_httpMutex; | ||
| if (g_httpMutex && xSemaphoreTake(g_httpMutex, pdMS_TO_TICKS(5000)) != pdTRUE) { | ||
| if (g_httpMutex && xSemaphoreTake(g_httpMutex, pdMS_TO_TICKS(3000)) != pdTRUE) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTTP timeout values are significantly shorter than other HTTP operations. The mutex timeout (3000ms) and HTTP timeouts (1000ms connect, 2000ms operation) are much shorter than Proposed timeout alignment- if (g_httpMutex && xSemaphoreTake(g_httpMutex, pdMS_TO_TICKS(3000)) != pdTRUE) {
+ if (g_httpMutex && xSemaphoreTake(g_httpMutex, pdMS_TO_TICKS(5000)) != pdTRUE) {- http.setConnectTimeout(1000);
- http.setTimeout(2000);
+ http.setConnectTimeout(3000);
+ http.setTimeout(5000);Also applies to: 1017-1018 🤖 Prompt for AI Agents |
||
| Serial.println("ApplicationManager: Could not acquire HTTP mutex for ASSIGN_SPOOL"); | ||
| if (lcdManager) lcdManager->updateScreen("Assign failed", "HTTP busy"); | ||
| return false; | ||
|
|
@@ -1006,8 +1014,8 @@ bool ApplicationManager::sendAssignSpool(const char* toolNumber) { | |
|
|
||
| WiFiClient client; | ||
| HTTPClient http; | ||
| http.setConnectTimeout(3000); | ||
| http.setTimeout(5000); | ||
| http.setConnectTimeout(1000); | ||
| http.setTimeout(2000); | ||
| http.begin(client, url); | ||
| http.addHeader("Content-Type", "application/json"); | ||
| int code = http.POST(postBody); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Document potential GPIO conflicts on PSRAM-equipped ESP32-WROOM modules.
GPIO 16 and 17 (
PIN_KEYPAD_ROW2,PIN_KEYPAD_ROW3) are used for PSRAM interface on ESP32-WROVER and some ESP32-WROOM-32D modules. Users with PSRAM-equipped boards may encounter conflicts.Consider adding a note similar to the S3 section:
📝 Committable suggestion
🤖 Prompt for AI Agents