Created
January 5, 2025 17:15
-
-
Save xueliu/04fa7ad8fabea22310da9b76a1d8185b to your computer and use it in GitHub Desktop.
hf_14a_read.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local reader = require('hf_reader') | |
local reader14443A = require('read14a') | |
local getopt = require('getopt') | |
local ansicolors = require('ansicolors') | |
-- require("socket") | |
copyright = '' | |
author = '' | |
version = 'v1.0.2' | |
desc = [[ | |
This script reads only 14443A HF cards and outputs their UID. The script runs continuously until user press Enter. | |
]] | |
example = [[ | |
1. script run hf_14a_read | |
]] | |
usage = [[ | |
script run hf_14a_read | |
]] | |
arguments = [[ | |
-h - this help | |
]] | |
local function sleep(n) | |
-- socket.slect(nil, nil, n) | |
os.execute("sleep " .. n) | |
end | |
--- | |
-- This is only meant to be used when errors occur | |
local function dbg(args) | |
if not DEBUG then return end | |
if type(args) == 'table' then | |
local i = 1 | |
while args[i] do | |
dbg(args[i]) | |
i = i+1 | |
end | |
else | |
print('###', args) | |
end | |
end | |
--- | |
-- This is only meant to be used when errors occur | |
local function oops(err) | |
print('ERROR:', err) | |
core.clearCommandBuffer() | |
return nil, err | |
end | |
--- | |
-- Usage help | |
local function help() | |
print(copyright) | |
print(author) | |
print(version) | |
print(desc) | |
print(ansicolors.cyan..'Usage'..ansicolors.reset) | |
print(usage) | |
print(ansicolors.cyan..'Arguments'..ansicolors.reset) | |
print(arguments) | |
print(ansicolors.cyan..'Example usage'..ansicolors.reset) | |
print(example) | |
end | |
--- | |
-- Main function | |
local function main(args) | |
-- Arguments for the script | |
for o, a in getopt.getopt(args, 'h') do | |
if o == 'h' then return help() end | |
end | |
-- print("Starting to read 14443A cards. Press Ctrl+C to stop.") | |
print("Waiting for card... press <Enter> to quit") | |
while not core.kbd_enter_pressed() do | |
local info, err = reader14443A.read() | |
if info then | |
print( string.format( "UID: %s", tostring(info.uid) ) ) | |
sleep(1) | |
end | |
end | |
print("Aborted by user") | |
end | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment