|
# -*- coding: utf-8 -*- |
|
|
|
""" |
|
このスクリプトはNekonium walletのQRコードをキャプチャして認識し、QRコードを生成してAS-289R2 プリンタシールドで印刷します |
|
""" |
|
|
|
import os |
|
import sys |
|
import subprocess |
|
import json |
|
import time |
|
import PIL |
|
import qrcode |
|
import serial |
|
import wiringpi as wp |
|
|
|
argvs = sys.argv |
|
QR = qrcode.QRCode( |
|
version=1, |
|
error_correction=qrcode.constants.ERROR_CORRECT_L, |
|
box_size=6, |
|
border=4, |
|
) |
|
QR.add_data(argvs[1]) |
|
QR.make(fit=True) |
|
image = QR.make_image(fill_color="white", back_color="black") |
|
image.save('/work/qr.bmp') |
|
check = subprocess.call(['convert', '/work/qr.bmp', '-colorspace', 'Gray', |
|
'-geometry', '225', '-threshold', '35000', '-colors', '2', '/work/qrcode.bmp']) |
|
check = subprocess.call(['composite', '-gravity', 'center', '-compose', |
|
'over', '/work/qrcode.bmp', 'nekonium_mono.bmp', '/work/neko.bmp']) |
|
check = subprocess.call( |
|
['convert', '-append', '/work/neko.bmp', 'nekonium_logo.bmp', '/work/nekoqr.bmp']) |
|
check = subprocess.call(['convert', '/work/nekoqr.bmp', '-colorspace', 'Gray', |
|
'-geometry', '384', '-threshold', '35000', '-colors', '2', '/work/nekoqrcode.bmp']) |
|
|
|
# AS-289R2 Initialize |
|
ser = serial.Serial("/dev/ttyS0", baudrate=38400, timeout=2) |
|
# CMD DC2 F |
|
ser.write(bytes([0x12])) |
|
ser.write(bytes([0x46])) |
|
ser.write(bytes([0x36])) |
|
# Get BMP(384px 384px 1bpp) |
|
file = open('/work/nekoqrcode.bmp', 'rb') |
|
file.seek(10) |
|
offset = ord(file.read(1)) |
|
file.seek(22) |
|
height = ord(file.read(1)) |
|
height += ord(file.read(1)) * 256 |
|
print("Offset:", offset) |
|
print("Height:", height) |
|
# Output CMD |
|
ser.write(b"Wallet address:") |
|
ser.write(argvs[1].encode('utf-8')) |
|
ser.write(b"\r") |
|
|
|
ser.write(bytes([0x1C])) |
|
ser.write(bytes([0x2A])) |
|
ser.write(bytes([0x65])) |
|
n1 = height / 256 |
|
n2 = height % 256 |
|
print(n1, n2) |
|
ser.write(bytes([int(n1)])) |
|
ser.write(bytes([int(n2)])) |
|
for num in range(height): |
|
line = height * 48 + offset - ((num + 1) * 48) |
|
file.seek(line) |
|
for subnum in range(48): |
|
x = ord(file.read(1)) ^ 0xFF |
|
ser.write(bytes([x])) |
|
for feed in range(6): |
|
ser.write(bytes([0x0D])) |
|
file.close() |
|
|
|
ser.write(b"Merry Christmas!!\r") |
|
ser.write(b"2017/12/25\r") |
|
ser.write(b"by Candy Mechatronics\r") |
|
|
|
for feed in range(20): |
|
ser.write(bytes([0x0D])) |