mirror of
https://github.com/xodio/xod.git
synced 2026-02-20 02:01:20 +01:00
chore(stdlib): update xod-dev/pn532-nfc
This commit is contained in:
committed by
Evgeny Kochetkov
parent
f65b8328db
commit
14ca2264fb
@@ -1,13 +1,8 @@
|
||||
struct State {
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
auto uidA = getValue<input_IN1>(ctx);
|
||||
auto uidB = getValue<input_IN2>(ctx);
|
||||
bool eq = memcmp(uidA.items, uidB.items, sizeof(uidA.items)) == 0;
|
||||
emitValue<output_OUT>(ctx, eq);
|
||||
node {
|
||||
void evaluate(Context ctx) {
|
||||
auto uidA = getValue<input_IN1>(ctx);
|
||||
auto uidB = getValue<input_IN2>(ctx);
|
||||
bool eq = memcmp(uidA.items, uidB.items, sizeof(uidA.items)) == 0;
|
||||
emitValue<output_OUT>(ctx, eq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,27 @@
|
||||
struct State {
|
||||
};
|
||||
node {
|
||||
meta {
|
||||
struct Type {
|
||||
uint8_t items[7];
|
||||
|
||||
struct TagUID {
|
||||
uint8_t items[7];
|
||||
static Type empty() {
|
||||
Type emptyUid;
|
||||
memset(emptyUid.items, 0, 7);
|
||||
return emptyUid;
|
||||
};
|
||||
|
||||
static TagUID empty() {
|
||||
TagUID emptyUid;
|
||||
memset(emptyUid.items, 0, 7);
|
||||
return emptyUid;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
void evaluate(Context ctx) {
|
||||
Type uid;
|
||||
uid.items[0] = (uint8_t)getValue<input_IN1>(ctx);
|
||||
uid.items[1] = (uint8_t)getValue<input_IN2>(ctx);
|
||||
uid.items[2] = (uint8_t)getValue<input_IN3>(ctx);
|
||||
uid.items[3] = (uint8_t)getValue<input_IN4>(ctx);
|
||||
uid.items[4] = (uint8_t)getValue<input_IN5>(ctx);
|
||||
uid.items[5] = (uint8_t)getValue<input_IN6>(ctx);
|
||||
uid.items[6] = (uint8_t)getValue<input_IN7>(ctx);
|
||||
|
||||
using Type = TagUID;
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
TagUID uid;
|
||||
uid.items[0] = (uint8_t)getValue<input_IN1>(ctx);
|
||||
uid.items[1] = (uint8_t)getValue<input_IN2>(ctx);
|
||||
uid.items[2] = (uint8_t)getValue<input_IN3>(ctx);
|
||||
uid.items[3] = (uint8_t)getValue<input_IN4>(ctx);
|
||||
uid.items[4] = (uint8_t)getValue<input_IN5>(ctx);
|
||||
uid.items[5] = (uint8_t)getValue<input_IN6>(ctx);
|
||||
uid.items[6] = (uint8_t)getValue<input_IN7>(ctx);
|
||||
|
||||
emitValue<output_UID>(ctx, uid);
|
||||
emitValue<output_UID>(ctx, uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
#pragma XOD evaluate_on_pin disable
|
||||
#pragma XOD evaluate_on_pin enable input_PAIR
|
||||
|
||||
struct State {
|
||||
};
|
||||
node {
|
||||
void evaluate(Context ctx) {
|
||||
if (!isInputDirty<input_PAIR>(ctx))
|
||||
return;
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
auto nfc = getValue<input_DEV>(ctx);
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
if (!isInputDirty<input_PAIR>(ctx))
|
||||
return;
|
||||
uint8_t uidLength;
|
||||
uint8_t readedUid[12];
|
||||
bool res = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, readedUid, &uidLength);
|
||||
|
||||
auto nfc = getValue<input_DEV>(ctx);
|
||||
|
||||
uint8_t uidLength;
|
||||
uint8_t readedUid[12];
|
||||
bool res = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, readedUid, &uidLength);
|
||||
|
||||
if (res) {
|
||||
ValueType<output_UID>::T uid;
|
||||
memset(readedUid + uidLength, 0, 12 - uidLength);
|
||||
memcpy(uid.items, readedUid, 7);
|
||||
emitValue<output_UID>(ctx, uid);
|
||||
emitValue<output_OK>(ctx, 1);
|
||||
} else {
|
||||
emitValue<output_UID>(ctx, ValueType<output_UID>::T::empty());
|
||||
emitValue<output_NA>(ctx, 1);
|
||||
if (res) {
|
||||
typeof_UID uid;
|
||||
memset(readedUid + uidLength, 0, 12 - uidLength);
|
||||
memcpy(uid.items, readedUid, 7);
|
||||
emitValue<output_UID>(ctx, uid);
|
||||
emitValue<output_OK>(ctx, 1);
|
||||
} else {
|
||||
emitValue<output_UID>(ctx, remove_pointer<typeof_UID>::type::empty());
|
||||
emitValue<output_NA>(ctx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,32 @@
|
||||
#pragma XOD require "https://github.com/adafruit/Adafruit_BusIO"
|
||||
#pragma XOD require "https://github.com/adafruit/Adafruit-PN532"
|
||||
|
||||
// clang-format off
|
||||
{{#global}}
|
||||
#include <Adafruit_PN532.h>
|
||||
{{/global}}
|
||||
// clang-format on
|
||||
|
||||
struct State {
|
||||
uint8_t mem[sizeof(Adafruit_PN532)];
|
||||
};
|
||||
|
||||
using Type = Adafruit_PN532*;
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
if (!isSettingUp()) return;
|
||||
|
||||
auto state = getState(ctx);
|
||||
auto irq = getValue<input_IRQ>(ctx);
|
||||
|
||||
Type nfc = new (state->mem) Adafruit_PN532(irq, NOT_A_PORT);
|
||||
|
||||
// Initialize the device
|
||||
nfc->begin();
|
||||
// Ensure the device is working
|
||||
uint32_t versiondata = nfc->getFirmwareVersion();
|
||||
if (!versiondata) {
|
||||
raiseError(ctx);
|
||||
return;
|
||||
node {
|
||||
meta {
|
||||
using Type = Adafruit_PN532*;
|
||||
}
|
||||
// Configure the device
|
||||
nfc->setPassiveActivationRetries(0x01);
|
||||
nfc->SAMConfig();
|
||||
|
||||
emitValue<output_DEV>(ctx, nfc);
|
||||
static_assert(isValidDigitalPort(constant_input_IRQ), "must be a valid digital port");
|
||||
|
||||
Adafruit_PN532 nfc = Adafruit_PN532(constant_input_IRQ, NOT_A_PORT);
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
if (!isSettingUp()) return;
|
||||
|
||||
// Initialize the device
|
||||
nfc.begin();
|
||||
// Ensure the device is working
|
||||
uint32_t versiondata = nfc.getFirmwareVersion();
|
||||
if (!versiondata) {
|
||||
raiseError(ctx);
|
||||
return;
|
||||
}
|
||||
// Configure the device
|
||||
nfc.setPassiveActivationRetries(0x01);
|
||||
nfc.SAMConfig();
|
||||
|
||||
emitValue<output_DEV>(ctx, &nfc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +2,25 @@
|
||||
#pragma XOD evaluate_on_pin enable input_READ
|
||||
#pragma XOD error_raise enable
|
||||
|
||||
struct State {
|
||||
};
|
||||
node {
|
||||
void evaluate(Context ctx) {
|
||||
if (!isInputDirty<input_READ>(ctx))
|
||||
return;
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
auto nfc = getValue<input_DEV>(ctx);
|
||||
uint8_t page = (uint8_t)getValue<input_PAGE>(ctx);
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
if (!isInputDirty<input_READ>(ctx))
|
||||
return;
|
||||
uint8_t data[4];
|
||||
uint8_t success = nfc->mifareultralight_ReadPage(page, data);
|
||||
|
||||
auto nfc = getValue<input_DEV>(ctx);
|
||||
uint8_t page = (uint8_t)getValue<input_PAGE>(ctx);
|
||||
|
||||
uint8_t data[4];
|
||||
uint8_t success = nfc->mifareultralight_ReadPage(page, data);
|
||||
|
||||
if (success) {
|
||||
emitValue<output_OUT1>(ctx, data[0]);
|
||||
emitValue<output_OUT2>(ctx, data[1]);
|
||||
emitValue<output_OUT3>(ctx, data[2]);
|
||||
emitValue<output_OUT4>(ctx, data[3]);
|
||||
emitValue<output_OK>(ctx, 1);
|
||||
} else {
|
||||
raiseError(ctx);
|
||||
if (success) {
|
||||
emitValue<output_OUT1>(ctx, data[0]);
|
||||
emitValue<output_OUT2>(ctx, data[1]);
|
||||
emitValue<output_OUT3>(ctx, data[2]);
|
||||
emitValue<output_OUT4>(ctx, data[3]);
|
||||
emitValue<output_OK>(ctx, 1);
|
||||
} else {
|
||||
raiseError(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
struct State {
|
||||
};
|
||||
node {
|
||||
void evaluate(Context ctx) {
|
||||
auto uid = getValue<input_UID>(ctx);
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
auto uid = getValue<input_UID>(ctx);
|
||||
|
||||
emitValue<output_OUT1>(ctx, uid.items[0]);
|
||||
emitValue<output_OUT2>(ctx, uid.items[1]);
|
||||
emitValue<output_OUT3>(ctx, uid.items[2]);
|
||||
emitValue<output_OUT4>(ctx, uid.items[3]);
|
||||
emitValue<output_OUT5>(ctx, uid.items[4]);
|
||||
emitValue<output_OUT6>(ctx, uid.items[5]);
|
||||
emitValue<output_OUT7>(ctx, uid.items[6]);
|
||||
emitValue<output_OUT1>(ctx, uid.items[0]);
|
||||
emitValue<output_OUT2>(ctx, uid.items[1]);
|
||||
emitValue<output_OUT3>(ctx, uid.items[2]);
|
||||
emitValue<output_OUT4>(ctx, uid.items[3]);
|
||||
emitValue<output_OUT5>(ctx, uid.items[4]);
|
||||
emitValue<output_OUT6>(ctx, uid.items[5]);
|
||||
emitValue<output_OUT7>(ctx, uid.items[6]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +2,25 @@
|
||||
#pragma XOD evaluate_on_pin enable input_UPD
|
||||
#pragma XOD error_raise enable
|
||||
|
||||
struct State {
|
||||
};
|
||||
node {
|
||||
void evaluate(Context ctx) {
|
||||
if (!isInputDirty<input_UPD>(ctx))
|
||||
return;
|
||||
|
||||
// clang-format off
|
||||
{{ GENERATED_CODE }}
|
||||
// clang-format on
|
||||
auto nfc = getValue<input_DEV>(ctx);
|
||||
uint8_t page = (uint8_t)getValue<input_PAGE>(ctx);
|
||||
uint8_t data[4] = {
|
||||
getValue<input_IN1>(ctx),
|
||||
getValue<input_IN2>(ctx),
|
||||
getValue<input_IN3>(ctx),
|
||||
getValue<input_IN4>(ctx)
|
||||
};
|
||||
uint8_t success = nfc->mifareultralight_WritePage(page, data);
|
||||
|
||||
void evaluate(Context ctx) {
|
||||
if (!isInputDirty<input_UPD>(ctx))
|
||||
return;
|
||||
|
||||
auto nfc = getValue<input_DEV>(ctx);
|
||||
uint8_t page = (uint8_t)getValue<input_PAGE>(ctx);
|
||||
uint8_t data[4] = {
|
||||
getValue<input_IN1>(ctx),
|
||||
getValue<input_IN2>(ctx),
|
||||
getValue<input_IN3>(ctx),
|
||||
getValue<input_IN4>(ctx)
|
||||
};
|
||||
uint8_t success = nfc->mifareultralight_WritePage(page, data);
|
||||
|
||||
if (success) {
|
||||
emitValue<output_OK>(ctx, 1);
|
||||
} else {
|
||||
raiseError(ctx);
|
||||
if (success) {
|
||||
emitValue<output_OK>(ctx, 1);
|
||||
} else {
|
||||
raiseError(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user