Skip to content
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

Disabling default LED behavior? #73

Open
NAsejevs opened this issue Mar 17, 2019 · 0 comments
Open

Disabling default LED behavior? #73

NAsejevs opened this issue Mar 17, 2019 · 0 comments

Comments

@NAsejevs
Copy link

Is there a way to disable the current default LED (what I think is built in) behavior? What I mean by that is when you scan a card, the LED turns green. Once you take it off, the LED turns red. You can of course send custom LED commands to the reader using reader.led(), however, in my case, I want the LED to remain red and only turn green only once a card is applied, read, an API call has been made and a response has been received. If an error is encountered in either the card reading process or if no API response is received, I would like the LED to remain red.

So far, this is what I have:

nfc.on('reader', reader => {
	reader.aid = "F222222222";

	reader.connect(CONNECT_MODE_DIRECT).then(() => {
		reader.setBuzzerOutput(false);
		reader.inAutoPoll();
		reader.disconnect();
	});

	console.log("reader connected");

		reader.on('card', card => {
			const uid = card.uid;

			axios.post(serverURL + "cardScanned", {
				uid,
			}, requestConfig).then((res) => {
				console.log("server responded with: ", res);
				reader.led(0b01011101, [0x05, 0x05, 0x01, 0x01]).catch((e) => {
					console.log("LED ERROR: ", e);
				});
			}).catch((e) => {
				console.log("AXIOS ERROR: ", e);
			});
		});
 
		reader.on('card.off', card => {
			console.log("card removed");
		});
 
		reader.on('error', err => {
			console.log("ERROR: ", err);
		});
 
		reader.on('end', () => {
			console.log("reader removed");
		});
 
});
 
nfc.on('error', err => {
	console.log("ERROR: ", err);
});

This sort of has the effect that I need, however, the issue is that once I read a card, the LED immediately turns green and only after a few miliseconds, the axios response is received, and the LED blinks again.

How do I disable the default LED behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant