Skip to content

Commit

Permalink
v0.3
Browse files Browse the repository at this point in the history
Fixed printASCII duplicating newline,
Fixed requirements.txt,
Fixed -i, -t options ignored,
Added qr code printing function,
Updated description for getDeviceFull with info about side effects.
  • Loading branch information
bitrate16 committed Mar 26, 2021
1 parent ec92543 commit 96bed38
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Install module and run

```
usage: ppa6 [-h] -m MAC [-c [0-2]] [-b [0-255]] [-p {A6,A6p,A6+}] [-n]
(-t TEXT | -s STREAM | -i IMAGE | -e)
(-t TEXT | -s | -i IMAGE | -q QR | -e)
Print on a Peripage A6 / A6+ via bluetooth
Expand All @@ -124,10 +124,10 @@ optional arguments:
-t TEXT, --text TEXT ASCII text that should be printed. Add a line break at
the end of the string to avoid it being cut. String
can be empty, so just page break will be printed
-s STREAM, --stream STREAM
Reads an input from stdin and prints as ASCII text
-s, --stream Reads an input from stdin and prints as ASCII text
-i IMAGE, --image IMAGE
Path to the image that should be printed
-q QR, --qr QR String for QR code print
-e, --introduce Ask the printer to introduce himself
```

Expand Down
Binary file added dist/ppa6-0.2.tar.gz
Binary file not shown.
Binary file added dist/ppa6-0.3.tar.gz
Binary file not shown.
42 changes: 36 additions & 6 deletions ppa6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
# Copyright (c) 2021 bitrate16

__title__ = 'Peripage A6/A6+ buetooth printing utility'
__version__ = '0.1'
__version__ = '0.3'
__author__ = 'bitrate16'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2021 bitrate16'

import time
import math
import qrcode
import socket
import bluetooth

Expand Down Expand Up @@ -261,9 +262,11 @@ def getDeviceFull(self):
which means that it's name is 'PeriPage+DF7A', mac is 00:F5:73:25:AC:9F,
connected to mac C5:12:81:19:2C:51, F/W V2.11_304dpi, S/N A6491571121, battery
level 84%.
Use with care. This command has sub effect causing the printed images to corrupt
shifting horisontally and adding a █ character to ASCII buffer.
"""

return self.askPrinter(bytes.fromhex('10ff70f1'))
return self.askPrinter(bytes.fromhex('10ff70f100'))

def getRowBytes(self):
"""
Expand Down Expand Up @@ -452,7 +455,7 @@ def printlnASCII(self, text='\n', delay=0.25):
slices string into pieces of size getRowCharacters() and waits till new piece being
printed.
This function acts as println. This function will print out the data stored in the
buffer of printASCII()
buffer of printASCII().
:param text: string containing ASCII characters
:type text: str
Expand All @@ -463,6 +466,10 @@ def printlnASCII(self, text='\n', delay=0.25):
# Remove non-ASCII & control (except \n)
text = ''.join([i for i in text if (31 < ord(i) or ord(i) == 10) and ord(i) < 127])

## Remove last '\n' to avoid it's duplication
#if len(text) > 0 and text[-1] == '\n':
# text = text[:-1]
#
# Check for empty and print out newline
text = self.printBuffer + text
if len(text) == 0:
Expand Down Expand Up @@ -524,6 +531,16 @@ def printASCII(self, text='\n', delay=0.25):
return

endLineBreak = text[-1] == '\n'

# Remove last '\n' to avoid it's duplication
if len(text) > 0 and text[-1] == '\n':
if len(text) == 1:
self.printBreak(30)
time.sleep(delay)
return

text = text[:-1]

lines = text.split('\n')

for i, l in enumerate(lines):
Expand Down Expand Up @@ -623,7 +640,7 @@ def printImageRowBytesList(self, imagebytes, delay=0.01):
:param imagebytes: array of bytes containing rows of the image
:type imagebytes: list
:param delay: delay between sending each row
:param delay: delay between sending each row of the image
:type delay: float
"""

Expand Down Expand Up @@ -671,7 +688,7 @@ def printImageBytes(self, imagebytes, delay=0.01):
:param imagebytes: bytes containing rows of the image
:type imagebytes: bytes
:param delay: delay between sending each row
:param delay: delay between sending each row of the image
:type delay: float
"""

Expand Down Expand Up @@ -706,7 +723,7 @@ def printImage(self, img, delay=0.01, resample=Image.NEAREST):
:param img: image to print
:type img: Image
:param delay: delay between sending each row
:param delay: delay between sending each row of the image
:type delay: float
:param resample: image resampling mode (Image.NEAREST, Image.BILINEAR, Image.BICUBIC, Image.ANTIALIAS)
"""
Expand All @@ -719,6 +736,19 @@ def printImage(self, img, delay=0.01, resample=Image.NEAREST):
imgbytes = img.tobytes()
self.printImageBytes(imgbytes)

def printQR(self, text, delay=0.01, resample=Image.NEAREST):
"""
Generates QR code from specified string and prints it out.
:param text: Text for qr code
:tapy text: str
:param delay: delay between sending each row of the image
:type delay: float
:param resample: image resampling mode (Image.NEAREST, Image.BILINEAR, Image.BICUBIC, Image.ANTIALIAS)
"""

self.printImage(qrcode.make(text, border=0), delay, resample)

def printRowBytesIterator(self, rowiterator, delay=0.25):
"""
Allows printing image using iterator / generator that should return bytes
Expand Down
17 changes: 16 additions & 1 deletion ppa6/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def main():
group.add_argument('-t', '--text', help='ASCII text that should be printed. Add a line break at the end of the string to avoid it being cut. String can be empty, so just page break will be printed', type=str)
group.add_argument('-s', '--stream', help='Reads an input from stdin and prints as ASCII text', action='store_true')
group.add_argument('-i', '--image', help='Path to the image that should be printed', type=str)
group.add_argument('-q', '--qr', help='String for QR code print', type=str)
group.add_argument('-e', '--introduce', help='Ask the printer to introduce himself', action='store_true')

args = parser.parse_args()
Expand All @@ -47,7 +48,7 @@ def main():
printer.disconnect()
sys.exit(0)

elif 'stream' in args and args.stream is not None:
elif 'stream' in args and args.stream:

if 'concentration' in args:
printer.setConcentration(args.concentration)
Expand Down Expand Up @@ -107,6 +108,20 @@ def main():
printer.printBreak(args.breaksize)

sys.exit(0)

elif 'qr' in args and args.qr is not None:

if 'concentration' in args:
printer.setConcentration(args.concentration)

printer.reset()

printer.printQR(args.qr, resample=Image.ANTIALIAS)

if 'breaksize' in args and args.breaksize > 0:
printer.printBreak(args.breaksize)

sys.exit(0)

else:

Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PyBluez==0.23
Pillow==8.1.2
argparse==1.1
argparse==1.1
PyBluez>=0.23
qrcode>=6.1
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
setup(
name = 'ppa6',
packages = ['ppa6'],
version = '0.1',
version = '0.3',
license='MIT',
description = 'Utility for printing on Peripage A6/A6+ via bluetooth',
author = 'bitrate16',
author_email = 'bitrate16@gmail.com',
url = 'https://github.com/bitrate16/ppa6-python',
download_url = 'https://github.com/bitrate16/ppa6-python/archive/v0.1.tar.gz',
download_url = 'https://github.com/bitrate16/ppa6-python/archive/v0.3.tar.gz',
keywords = ['PERIPAGE', 'BLUETOOTH', 'THERMAL PRINTER', 'PRINTER'],
install_requires=[
'PyBluez>=0.23',
'Pillow>=8.1.2',
'argparse>=1.1',
'qrcode>=6.1',
],
classifiers=[
'Development Status :: 4 - Beta', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
Expand Down

0 comments on commit 96bed38

Please sign in to comment.