Skip to content

Commit

Permalink
Add read button as user gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
DMS Host committed Jun 24, 2024
1 parent 34196c2 commit 5b6b294
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
73 changes: 40 additions & 33 deletions static/main.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
const ndef = new NDEFReader();
let ignoreRead = false;

function read(data) {
ignoreRead = true;
return new Promise((resolve, reject) => {
ndef.addEventListener(
"reading",
(event) => {
console.log("reading");
},
{ once: false },
);
});
}

const content = document.getElementById("content");
let count = 0;

async function runApplication() {
while (true) {
await ndef.scan();

count++;

content.textContent = `Scanned items = ${count}`;
const sleepTimer = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 500);
const content = document.getElementById("read-button");

content.addEventListener("click", triggerRead);

function triggerRead() {

const ndef = new NDEFReader();
let ignoreRead = false;

function read(data) {
ignoreRead = true;
return new Promise((resolve, reject) => {
ndef.addEventListener(
"reading",
(event) => {
console.log("reading");
},
{ once: false },
);
});
}

const content = document.getElementById("content");
let count = 0;

async function runApplication() {
while (true) {
await ndef.scan();

count++;

content.textContent = `Scanned items = ${count}`;
const sleepTimer = new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 500);
});

await sleepTimer;
await sleepTimer;
}
}
}

runApplication();
runApplication();
}
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<body style="margin: 0; padding:0;">
<h1>NFC Reader</h1>
<div id="content"></div>
<button id="read-button">Read NFC tag</button>
</body>

</html>

0 comments on commit 5b6b294

Please sign in to comment.