Skip to content

Commit

Permalink
feat: Adapted robertdijk's code
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowtter committed Sep 12, 2023
2 parents 6228713 + b64495e commit 0cfb617
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 44 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: pre-commit

on:
push:
branches: ["**"]
pull_request:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install libpcsclite-dev
run: sudo apt-get install libpcsclite-dev
- uses: actions/setup-python@v4
with:
python-version: "3.8"
cache: "pip"
- run: pip install -r requirements-dev.txt
- uses: pre-commit/action@v3.0.0
41 changes: 41 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pytest

on:
push:
branches: ["**"]
pull_request:
branches: [master]

jobs:
pytest:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install libpcsclite-dev
run: sudo apt-get install libpcsclite-dev
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- run: pip install -r requirements-dev.txt
- run: pytest
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
py-acr122u/

# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
Expand Down Expand Up @@ -150,4 +148,4 @@ atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
fabric.properties
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: end-of-file-fixer
stages: [commit]
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
require_serial: true
name: Coding style (Black)
language_version: python3.8
stages: [commit]
exclude: ^legacy-backend.*$
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
require_serial: true
name: isort
args: ["--profile", "black"]
stages: [commit]
exclude: ^legacy-backend.*$
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# PY-ACR122U

<img src="http://downloads.acs.com.hk/product-website-image/acr38-image.jpg" width="150" height="150">
[![PyPI - Version](https://img.shields.io/pypi/v/py122u)](https://pypi.org/project/py122u/)
[![PyPI - License](https://img.shields.io/pypi/l/py122u)](https://pypi.org/project/py122u/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/py122u)](https://pypi.org/project/py122u/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/py122u)](https://pypi.org/project/py122u/)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/py122u)](https://pypi.org/project/py122u/)

This is a python library for the ACR122U NFC reader

## Installation
- git clone https://github.com/Flowtter/py-acr122u.git
- cd py-acr122u
- pip install -r requirements.txt

```shell
pip install py122u
```

## Usage

```python
from src import nfc

from py122u import nfc

reader = nfc.Reader()
reader.connect()
reader.print_data(reader.get_uid())
reader.info()
```
- python main.py
4 changes: 3 additions & 1 deletion Example/write_and_read.py → example/write_and_read.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from src import nfc
from py122u import nfc

reader = nfc.Reader()
reader.connect()

reader.load_authentication_data(0x01, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
reader.authentication(0x00, 0x61, 0x01)
Expand Down Expand Up @@ -29,5 +30,6 @@ def read(r, position, number):
def read_16(r, position, number):
return r.read_binary_blocks(position, number)


write(reader, 0x01, 0x20, [0x00 for i in range(16)])
print(read(reader, 0x01, 0x20))
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "py122u"
version = "2.3.5"
description = "This is a python library for the ACR122U NFC reader"
readme = "README.md"
authors = [{ name = "Brice PARENT", email = "briceparent.it@gmail.com"}, { name = "Robert van Dijk", email = "contact@robertvandijk.nl" }]
license = { file = "LICENSE" }
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
keywords = ["nfc", "acr", "acr122u"]
dependencies = [
"pyscard>=2.0.7",
]
requires-python = ">=3.8"

[project.optional-dependencies]
dev = ["black", "bumpver", "isort", "pip-tools", "pytest", "pytest-mock"]

[project.urls]
Homepage = "https://github.com/Flowtter/py-acr122u"

[tool.bumpver]
current_version = "2.3.5"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "Bump version {old_version} -> {new_version}"
commit = true
tag = true
push = false

[tool.bumpver.file_patterns]
"pyproject.toml" = [
'current_version = "{version}"',
'version = "{version}"',
]
"src/py122u/__init__.py" = ["{version}"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
"integration",
]
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
testpaths = tests
python_files = *.py
addopts = -vv --showlocals
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements.txt
black
isort
pytest
pytest-mock
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyscard
pyscard
5 changes: 0 additions & 5 deletions src/main.py

This file was deleted.

1 change: 1 addition & 0 deletions src/py122u/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "2.3.5"
12 changes: 12 additions & 0 deletions src/error.py → src/py122u/error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Error(Exception):
"""Base class for exceptions in this module."""

pass


Expand Down Expand Up @@ -45,3 +46,14 @@ class InstructionFailed(Error):

def __init__(self, message):
self.message = message


class BitOutOfRange(Error):
"""Exception raised when you try to set a bit that does not exsist
Attributes:
message -- explanation of the error
"""

def __init__(self, message):
self.message = message
Loading

0 comments on commit 0cfb617

Please sign in to comment.