# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Connect to the printer

# +
import ppa6

printer = ppa6.Printer('00:15:83:15:bc:5f', ppa6.PrinterType.A6p)
printer.connect()
printer.reset()
# -

# # Get information about printer

print(f'Name: {printer.getDeviceName()}')
print(f'S/N: {printer.getDeviceSerialNumber()}')
print(f'F/W: {printer.getDeviceFirmware()}')
print(f'Battery: {printer.getDeviceBattery()}%')
print(f'H/W: {printer.getDeviceHardware()}')
print(f'MAC: {printer.getDeviceMAC()}')
print(f'Full: {printer.getDeviceFull()}')

# # Sample print

printer.writeASCII('Hello World?\n')
printer.printBreak(100)

# # Print random image

# +
imarray = numpy.random.rand(printer.getRowWidth(),printer.getRowWidth(), 3) * 255
im = Image.fromarray(imarray.astype('uint8')).convert('L')

# Set print concentration
printer.setConcentration(1)

# Print image & break
printer.printImage(im)
printer.printBreak(100)


# -

# # Infinite print using generator

# +
# Ping-pong slider
def slider():
    direct = True
    pos = 0
    while True:
        s = '00' * pos + 'ff' + '00' * (printer.getRowBytes() - pos - 1)
        if direct:
            pos = pos + 1
            if pos == printer.getRowBytes() - 1:
                direct = False
        else:
            pos = pos - 1
            if pos == 0:
                direct = True
        yield bytes.fromhex(s)

# Infinite printing, slow
printer.printRowBytesIterator(slider(), 0.25)


# -

# # Print using generator in limited page length

# +
# Ping-pong slider
def slider():
    direct = True
    pos = 0
    while True:
        s = '00' * pos + 'ff' + '00' * (printer.getRowBytes() - pos - 1)
        if direct:
            pos = pos + 1
            if pos == printer.getRowBytes() - 1:
                direct = False
        else:
            pos = pos - 1
            if pos == 0:
                direct = True
        yield bytes.fromhex(s)

# Print on page 200 px length
printer.printRowBytesIteratorOfSize(slider(), 200, 0.01)
printer.printBreak(100)

# +
import random

# Random byte rows
def rand():
    while True:
        s = ''.join([random.choice('0123456789abcdef') for n in range(printer.getRowWidth())])
        yield s

# Print on page 200 px length
printer.printRowBytesIteratorOfSize(rand(), 200, 0.01)
printer.printBreak(100)

StarcoderdataJupyterScriptsDedupFiltered