Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bccb8a8
Add technical overview for SRIX/ST25TB tags
Senape3000 Jan 2, 2026
3362bab
SRIX Development Notes
Senape3000 Jan 2, 2026
7d5f398
Ignore custom documentation directory
Senape3000 Jan 2, 2026
4589ea4
Update status for T-Embed CC1101 to 'Not Tested'
Senape3000 Jan 2, 2026
e313613
Create RFID API README with usage and details
Senape3000 Jan 2, 2026
8d0da15
Revise RFID API README for new features and usage
Senape3000 Jan 2, 2026
dcc5178
Enhance RFID API README with author and module status
Senape3000 Jan 2, 2026
5dd236f
Example scripts for RFID API
Senape3000 Jan 2, 2026
b849072
Add RFID JavaScript interface functions
Senape3000 Jan 2, 2026
5d81084
Add RFID JavaScript header file
Senape3000 Jan 2, 2026
ce9acc1
Register RFID functions in the interpreter
Senape3000 Jan 2, 2026
49e6c9a
Add RFID module include to interpreter.h
Senape3000 Jan 2, 2026
0ab5f14
Add headless mode functionality to TagOMatic
Senape3000 Jan 2, 2026
4ead143
Add headless mode constructor and JS support methods
Senape3000 Jan 2, 2026
0e2942f
Delete docs_custom directory
Senape3000 Jan 4, 2026
6286fe2
Update rfid_js.h
Senape3000 Jan 4, 2026
af12c0d
Update rfid_js.cpp
Senape3000 Jan 4, 2026
f99cdeb
Bugfix dialog_js.cpp
Senape3000 Jan 4, 2026
9f072f9
Update tag_o_matic.h for JS API
Senape3000 Jan 4, 2026
c0a42e9
Update tag_o_matic.cpp for RFID JS API
Senape3000 Jan 4, 2026
ab0498a
Bugfix PN532.cpp
Senape3000 Jan 4, 2026
91549dc
Bugfix RFID2.cpp
Senape3000 Jan 4, 2026
d209e0f
Update .gitignore
Senape3000 Jan 4, 2026
a4182a3
Update rfid_js.h
Senape3000 Jan 4, 2026
ee03d6d
Update rfid_js.cpp
Senape3000 Jan 4, 2026
d73a385
Merge branch 'BruceDevices:main' into API-JS/RFID
Senape3000 Jan 6, 2026
9cf0312
Update pn532_srix.cpp
Senape3000 Jan 6, 2026
dfdca71
Update pn532_srix.h
Senape3000 Jan 6, 2026
f614f7c
Update srix_tool.cpp
Senape3000 Jan 6, 2026
36606eb
Update srix_tool.h
Senape3000 Jan 6, 2026
6d3152e
Update rfid_js.h
Senape3000 Jan 6, 2026
9ff7169
Update rfid_js.cpp
Senape3000 Jan 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 89 additions & 12 deletions lib/PN532_SRIX/pn532_srix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Lilz
* @license GNU Lesser General Public License v3.0 (see license.txt)
* Refactored by Senape3000 to reuse Adafruit_PN532 constants only
* Refactored by Senape3000 to reuse Adafruit_PN532 constants only (v1.2)
* This is a library for the communication with an I2C PN532 NFC/RFID breakout board.
* adapted from Adafruit's library.
* This library supports only I2C to communicate.
Expand Down Expand Up @@ -68,7 +68,7 @@ bool Arduino_PN532_SRIX::SAMConfig() {

void Arduino_PN532_SRIX::readData(uint8_t *buffer, uint8_t n) {
delay(2);
Wire.requestFrom((uint8_t)PN532_I2C_ADDRESS, (uint8_t)(n + 1));
Wire.requestFrom((uint8_t)PN532_I2C_ADDRESS, (uint8_t)(n + 2));

// Discard RDY byte
Wire.read();
Expand All @@ -83,12 +83,70 @@ void Arduino_PN532_SRIX::readData(uint8_t *buffer, uint8_t n) {
bool Arduino_PN532_SRIX::readACK() {
uint8_t ackBuffer[6];
readData(ackBuffer, 6);
return (memcmp(ackBuffer, pn532ack, 6) == 0);

#ifdef SRIX_LIB_DEBUG
Serial.print("[PN532] ACK Read: ");
for(int i=0; i<6; i++) {
if(ackBuffer[i] < 0x10) Serial.print("0");
Serial.print(ackBuffer[i], HEX);
Serial.print(" ");
}
Serial.println();
#endif

bool result = (memcmp(ackBuffer, pn532ack, 6) == 0);

#ifdef SRIX_LIB_DEBUG
if(!result) Serial.println("[PN532] ❌ ACK Failed");
#endif

return result;
}

bool Arduino_PN532_SRIX::isReady() {
if (_irq == 255) return true; // Polling mode
return (digitalRead(_irq) == LOW);
// --- POLLING MODE (No IRQ pin) ---
if (_irq == 255) {
// Request 1 byte from PN532 (Status Byte)
delayMicroseconds(500);
Wire.requestFrom((uint8_t)PN532_I2C_ADDRESS, (uint8_t)1);

// If no response or bus locked, assume not ready
if (!Wire.available()) {
#ifdef SRIX_LIB_DEBUG
Serial.println("[PN532] isReady: No response from I2C (bus busy or chip offline)");
#endif
return false;
}

// Read status byte
uint8_t status = Wire.read();

#ifdef SRIX_LIB_DEBUG
Serial.print("[PN532] Status byte: 0x");
if(status < 0x10) Serial.print("0");
Serial.print(status, HEX);
Serial.print(" -> ");
Serial.println((status & 0x01) ? "READY" : "BUSY");
#endif

// Check Bit 0 (LSB):
// 1 = Ready
// 0 = Busy
return (status & 0x01);
}

// --- IRQ MODE (Hardware pin) ---
// IRQ pin goes LOW when chip is ready
bool ready = (digitalRead(_irq) == LOW);

#ifdef SRIX_LIB_DEBUG
Serial.print("[PN532] IRQ pin ");
Serial.print(_irq);
Serial.print(": ");
Serial.println(ready ? "LOW (Ready)" : "HIGH (Busy)");
#endif

return ready;
}

bool Arduino_PN532_SRIX::waitReady(uint16_t timeout) {
Expand All @@ -101,7 +159,7 @@ bool Arduino_PN532_SRIX::waitReady(uint16_t timeout) {
}
delay(10);
}

SRIX_LIB_LOG("Ready from waitReady");
return true;
}

Expand All @@ -113,7 +171,7 @@ void Arduino_PN532_SRIX::writeCommand(uint8_t *command, uint8_t commandLength) {

Wire.beginTransmission(PN532_I2C_ADDRESS);

checksum = PN532_PREAMBLE + PN532_PREAMBLE + PN532_STARTCODE2;
checksum = PN532_PREAMBLE + PN532_STARTCODE1 + PN532_STARTCODE2;
Wire.write(PN532_PREAMBLE);
Wire.write(PN532_STARTCODE1);
Wire.write(PN532_STARTCODE2);
Expand All @@ -135,12 +193,27 @@ void Arduino_PN532_SRIX::writeCommand(uint8_t *command, uint8_t commandLength) {
Wire.endTransmission();
}

bool Arduino_PN532_SRIX::sendCommandCheckAck(uint8_t *command, uint8_t commandLength, uint16_t timeout) {
writeCommand(command, commandLength);
bool Arduino_PN532_SRIX::sendCommandCheckAck(uint8_t *command, uint8_t commandLenght, uint16_t timeout) {
// default timeout of one second
// write the command
writeCommand(command, commandLenght);

// Wait for chip to say its ready!
if (!waitReady(timeout)) { return false; }

if (!waitReady(timeout)) return false;
#ifdef SRIX_LIB_DEBUG
Serial.println(F("\nI2C IRQ received"));
#endif

return readACK();
// Check acknowledgement
if (!readACK()) {
#ifdef SRIX_LIB_DEBUG
Serial.println(F("\nNo ACK frame received!"));
#endif
return false;
}

return true; // ACK is valid
}

// ========== PN532 GENERIC FUNCTIONS ==========
Expand Down Expand Up @@ -242,7 +315,11 @@ bool Arduino_PN532_SRIX::SRIX_write_block(uint8_t address, uint8_t *block) {
_packetbuffer[5] = block[2];
_packetbuffer[6] = block[3];

return sendCommandCheckAck(_packetbuffer, 7);
if (!sendCommandCheckAck(_packetbuffer, 7)) {
SRIX_LIB_LOG("[SRIX_LIB] Write FAIL");
return false; }
SRIX_LIB_LOG("[SRIX_LIB] Write OK");
return true;
}

bool Arduino_PN532_SRIX::SRIX_get_uid(uint8_t *buffer) {
Expand Down
14 changes: 13 additions & 1 deletion lib/PN532_SRIX/pn532_srix.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Lilz
* @license GNU Lesser General Public License v3.0 (see license.txt)
* Refactored by Senape3000 to reuse Adafruit_PN532 constants only
* Refactored by Senape3000 to reuse Adafruit_PN532 constants only (v1.2)
* This is a library for the communication with an I2C PN532 NFC/RFID breakout board.
* adapted from Adafruit's library.
* This library supports only I2C to communicate.
Expand All @@ -27,6 +27,18 @@
#include <Arduino.h>
#include <Wire.h>

// Uncomment to enable verbose debug output on Serial
// #define SRIX_LIB_DEBUG

// Helper macro for debug
#ifdef SRIX_LIB_DEBUG
#define SRIX_LIB_LOG(...) Serial.printf(__VA_ARGS__); Serial.println()
#define SRIX_LIB_PRINT(...) Serial.print(__VA_ARGS__)
#else
#define SRIX_LIB_LOG(...)
#define SRIX_LIB_PRINT(...)
#endif

// SRIX4K-specific commands
#define SRIX4K_INITIATE (0x06)
#define SRIX4K_SELECT (0x0E)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/bjs_interpreter/dialog_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ duk_ret_t native_dialogPickFile(duk_context *ctx) {

FS *fs = NULL;
if (SD.exists(filepath)) fs = &SD;
if (LittleFS.exists(filepath)) fs = &LittleFS;
else if (LittleFS.exists(filepath)) fs = &LittleFS; // ← added 'else'
if (fs) { r = loopSD(*fs, true, extension, filepath); }
duk_push_string(ctx, r.c_str());
return 1;
Expand Down Expand Up @@ -172,7 +172,7 @@ duk_ret_t native_dialogViewFile(duk_context *ctx) {
if (!filepath.startsWith("/")) filepath = "/" + filepath; // add "/" if missing
FS *fs = NULL;
if (SD.exists(filepath)) fs = &SD;
if (LittleFS.exists(filepath)) fs = &LittleFS;
else if (LittleFS.exists(filepath)) fs = &LittleFS; // ← add "else if" for SD Priority
if (fs) { viewFile(*fs, filepath); }
return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/bjs_interpreter/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void interpreterHandler(void *pvParameters) {
bduk_register_c_lightfunc(ctx, "load", native_load, 1);
registerGlobals(ctx);
registerMath(ctx);

registerRFID(ctx);
// registerAudio(ctx);
// registerBadUSB(ctx);
// TODO: BLE UART API js wrapper https://github.com/pr3y/Bruce/pull/1133
Expand Down Expand Up @@ -300,6 +300,8 @@ duk_ret_t native_require(duk_context *ctx) {

} else if (filepath == "ir") {
putPropIRFunctions(ctx, obj_idx, 0);
} else if (filepath == "rfid") {
putPropRFIDFunctions(ctx, obj_idx, 0);
} else if (filepath == "keyboard" || filepath == "input") {
putPropKeyboardFunctions(ctx, obj_idx, 0);
} else if (filepath == "math") {
Expand Down
1 change: 1 addition & 0 deletions src/modules/bjs_interpreter/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern char *scriptName;
#include "keyboard_js.h"
#include "math_js.h"
#include "notification_js.h"
#include "rfid_js.h"
#include "serial_js.h"
#include "storage_js.h"
#include "subghz_js.h"
Expand Down
Loading