Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Usage Example¶
import adafruit_miniqr
qr = adafruit_miniqr.QRCode()
qr.add_data(b'https://www.adafruit.com')
qr.make()
print(qr.matrix)
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Building locally¶
Zip release files¶
To build this library locally you’ll need to install the circuitpython-build-tools package.
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
source .env/bin/activate
Then run the build:
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-miniqr --library_location .
Sphinx documentation¶
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html
. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import sys
import adafruit_miniqr
# For drawing filled rectangles to the console:
out = sys.stdout
WHITE = "\x1b[1;47m \x1b[40m"
BLACK = " "
def prettyprint_QR(matrix):
# white 4-pixel border at top
for _ in range(4):
for _ in range(matrix.width+8):
out.write(WHITE)
print()
for y in range(matrix.height):
out.write(WHITE*4) # 4-pixel border to left
for x in range(matrix.width):
if matrix[x, y]:
out.write(BLACK)
else:
out.write(WHITE)
out.write(WHITE*4) # 4-pixel bporder to right
print()
# white 4-pixel border at bottom
for _ in range(4):
for _ in range(matrix.width+8):
out.write(WHITE)
print()
qr = adafruit_miniqr.QRCode(qr_type=3, error_correct=adafruit_miniqr.L)
qr.add_data(b'https://www.adafruit.com')
qr.make()
print(qr.matrix)
prettyprint_QR(qr.matrix)
|
adafruit_miniqr
¶
A non-hardware dependant miniature QR generator library. All native Python!
- Author(s): ladyada
Implementation Notes¶
Hardware:
- Any!
Software and Dependencies:
- Python 3
-
class
adafruit_miniqr.
QRBitBuffer
¶ Storage class for a length of individual bits
-
get
(index)¶ The bit value at a location
-
get_length_bits
()¶ Size of bit buffer
-
put
(num, length)¶ Add a number of bits from a single integer value
-
put_bit
(bit)¶ Insert one bit at the end of the bit buffer
-
-
class
adafruit_miniqr.
QRBitMatrix
(width, height)¶ A bit-packed storage class for matrices
-
class
adafruit_miniqr.
QRCode
(*, qr_type=None, error_correct=1)¶ The generator class for QR code matrices
-
add_data
(data)¶ Add more data to the QR code, must be bytestring stype
-
make
(*, test=False, mask_pattern=0)¶ Perform the actual generation of the QR matrix. To keep things small and speedy we don’t generate all 8 mask patterns and pick the best. Instead, please pass in a desired mask_pattern, the default mask is 0.
-
-
class
adafruit_miniqr.
QRPolynomial
(num, shift)¶ Structure for creating and manipulating error code polynomials
-
get
(index)¶ The exponent at the index location
-
get_length
()¶ Length of the poly
-
multiply
(e)¶ Multiply two polynomials, returns a new one
-
-
class
adafruit_miniqr.
QRUtil
¶ A selection of bit manipulation tools for QR generation and BCH encoding
-
static
get_BCH_digit
(data)¶ Count digits in data
-
static
get_BCH_type_info
(data)¶ Encode with G15 BCH mask
-
static
get_BCH_type_number
(data)¶ Encode with G18 BCH mask
-
static
get_error_correct_polynomial
(ecc_length)¶ Generate a ecc polynomial
-
static
get_mask
(mask, i, j)¶ Perform matching calculation on two vals for given pattern mask
-
static
get_pattern_position
(qr_type)¶ The mask pattern position array for this QR type
-
static