本文整理汇总了Python中Adafruit_Thermal.begin方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_Thermal.begin方法的具体用法?Python Adafruit_Thermal.begin怎么用?Python Adafruit_Thermal.begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_Thermal
的用法示例。
在下文中一共展示了Adafruit_Thermal.begin方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_printer
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
def get_printer(heat=200):
global printer
if printer:
return printer
else:
# open the printer itself
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(200)
示例2: genAndPrintKeys
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
def genAndPrintKeys(remPubKey, remPrivKey, numCopies, password):
#open serial number file which tracks the serial number
# snumfile = open('serialnumber.txt', 'r+')
# snum = snumfile.read()
#open the printer itself
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(200)
#this actually generates the keys. see the file genkeys.py or genkeys_forget.py
import genkeys as btckeys
btckeys.genKeys()
import wallet_enc as WalletEnc
#encrypt the keys if needed
if(password != ""):
privkey = WalletEnc.pw_encode(btckeys.pubkey, btckeys.privkey, password)
else:
privkey = btckeys.privkey
rememberKeys = False
sqlitePubKey = ""
sqlitePrivKey = ""
strToWrite = ""
if remPubKey:
strToWrite = "\nPublic Key: "+btckeys.pubkey
sqlitePubKey = btckeys.pubkey
rememberKeys = True
if remPrivKey:
strToWrite = strToWrite + "\nPrivate Key: "+privkey
sqlitePrivKey = privkey
rememberKeys = True
if rememberKeys == True:
#store it in a flat file on the sd card
f = open("keys.txt", 'a+')
strToWrite = strToWrite
f.write(strToWrite);
f.write("\n---------------------------------\n")
f.close()
#do the actual printing
for x in range(0, numCopies):
#piper.print_keypair(pubkey, privkey, leftBorderText)
print_keypair(btckeys.pubkey, privkey)
示例3: print_seed
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
def print_seed(seed):
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(200)
printer.println(seed)
printer.feed(3)
printer.sleep() # Tell printer to sleep
printer.wake() # Call wake() before printing again, even if reset
printer.setDefault() # Restore printer to defaults
示例4: Adafruit_Thermal
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
from __future__ import print_function
import RPi.GPIO as GPIO
import subprocess, time, Image, socket
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
# Print greeting image
# Because the hello/goodbye images are overall fairly light, we can
# get away with using a darker heat time for these, then reset to the
# default afterward.
ht = printer.defaultHeatTime * 2
if(ht > 255): ht = 255
printer.begin(ht) # Set temporary dark heat time
image_file = Image.open('gfx/partlycloudy.gif')
image_100 = image_file.resize((100,100),Image.ANTIALIAS)
image_200 = image_file.resize((200,200),Image.ANTIALIAS)
image_file = image_file.convert('L')
image_100 = image_100.convert('L')
image_200 = image_200.convert('L')
printer.print("Image 50x50")
printer.printImage(image_file, True)
printer.feed(3)
printer.print("Image 100x100")
printer.printImage(image_100, True)
printer.feed(3)
printer.print("Image 200x200")
printer.printImage(image_200, True)
printer.feed(3)
示例5: clamp
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
toRet = clamp(toRet, outMin, outMax)
return toRet
def clamp(val, tmin, tmax):
if val > tmax:
val = tmax
if val < tmin:
val = tmin
return val
uart.setup("UART2")
adc.setup()
atexit.register(exit_handler)
printer = Adafruit_Thermal("/dev/ttyO2", 19200, timeout=5)
printer.begin()
printer.upsideDownOn()
printer.feed(3)
printer.print(parse('i am awake and I am APPLE (light)'))
printer.feed(1)
rPast = 0
rMax = 0 # all-time max sensor reading
rMin = 100000 # all-time min sensor reading
WINDOW_SIZE = 30 # size of moving-window avg
noop = 0 # number of intervals passed without a trigger
noop_threshold = 480
emission_threshold = 0.1 # changed this for vcnl4000, used to be 0.7
while True:
checkSensor()
time.sleep(0.5)
示例6: Adafruit_Thermal
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
#
# Prints a series of black bars with increasing "heat time" settings.
# Because printed sections have different "grip" characteristics than
# blank paper, as this progresses the paper will usually at some point
# jam -- either uniformly, making a short bar, or at one side or the
# other, making a wedge shape. In some cases, the Pi may reset for
# lack of power.
#
# Whatever the outcome, take the last number printed BEFORE any
# distorted bar and enter in in Adafruit_Thermal.py as defaultHeatTime
# (around line 53).
#
# You may need to pull on the paper as it reaches the jamming point,
# and/or just abort the program, press the feed button and take the
# last good number.
from __future__ import print_function
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/ttyO2", 19200, timeout=5)
for i in range(0,256,15):
printer.begin(i)
printer.println(i) # Print heat time
printer.inverseOn()
printer.print('{:^32}'.format('')) # Print 32 spaces (inverted)
printer.inverseOff()
printer.begin() # Reset heat time to default
printer.feed(4)
示例7: hold
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
import RPi.GPIO as GPIO
import subprocess, time, Image, socket, random
from Adafruit_Thermal import *
buttonPin = 18
holdTime = 2 # Duration for button hold (shutdown)
tapTime = 0.01 # Debounce time for button taps
nextInterval = 0.0 # Time of next recurring operation
dailyFlag = False # Set after daily trigger occurs
lastId = '1' # State information passed to/from interval script
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
# Initialization
# Use Broadcom pin numbers (not Raspberry Pi pin numbers) for GPIO
GPIO.setmode(GPIO.BCM)
# Enable LED and button (w/pull-up on latter)
GPIO.setup(buttonPin, GPIO.IN)
prevButtonState = GPIO.input(buttonPin)
# Main loop
printer.begin(255)
while(True):
buttonState = GPIO.input(buttonPin)
if buttonState != True:
reve ='reves/reve-'+ str(random.randint(1,3)) +'.png'
printer.printImage(Image.open(reve), True)
printer.feed(2)
示例8: print_keypair
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
def print_keypair(pubkey, privkey):
# Specify System Font Location and a font to use
fontLocation = "/usr/share/fonts/truetype/droid/DroidSansMono.ttf"
# open the printer itself
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(200)
finalImgName = "btc"
coinName = "btc"
printCoinName = finalImgName == "blank"
finalImgName += "-wallet"
# load a blank image of the paper wallet with no QR codes or keys on it which we will draw on
if len(privkey) > 51:
finalImgName += "-enc"
else:
finalImgName += "-blank"
finalImgName += ".bmp"
finalImgFolder = "/home/pi/DIY-Piper/Images/"
finalImg = Image.open(finalImgFolder + finalImgName)
# ---begin the public key qr code generation and drawing section---
# we begin the QR code creation process
# feel free to change the error correct level as you see fit
qr = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=0)
qr.add_data(pubkey)
qr.make(fit=True)
pubkeyImg = qr.make_image()
# resize the qr code to match our design
pubkeyImg = pubkeyImg.resize((175, 175), Image.NEAREST)
font = ImageFont.truetype(fontLocation, 60)
draw = ImageDraw.Draw(finalImg)
if printCoinName:
draw.text((45, 400), coinName, font=font, fill=(0, 0, 0))
font = ImageFont.truetype(fontLocation, 20)
startPos = (110, 38)
charDist = 15
lineHeight = 23
lastCharPos = 0
keyLength = len(pubkey)
while keyLength % 17 != 0:
pubkey += " "
keyLength = len(pubkey)
# draw 2 lines of 17 characters each. keyLength always == 34 so keylength/17 == 2
for x in range(0, keyLength / 17):
lastCharPos = 0
# print a line
for y in range(0, 17):
theChar = pubkey[(x * 17) + y]
charSize = draw.textsize(theChar, font=font)
# if y is 0 then this is the first run of this loop, and we should use startPos[0] for the x coordinate instead of the lastCharPos
if y == 0:
draw.text((startPos[0], startPos[1] + (lineHeight * x)), theChar, font=font, fill=(0, 0, 0))
lastCharPos = startPos[0] + charSize[0] + (charDist - charSize[0])
else:
draw.text((lastCharPos, startPos[1] + (lineHeight * x)), theChar, font=font, fill=(0, 0, 0))
lastCharPos = lastCharPos + charSize[0] + (charDist - charSize[0])
# draw the QR code on the final image
finalImg.paste(pubkeyImg, (150, 106))
# ---end the public key qr code generation and drawing section---
# ---begin the private key qr code generation and drawing section---
# we begin the QR code creation process
# feel free to change the error correct level as you see fit
qr = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=0)
qr.add_data(privkey)
qr.make(fit=True)
privkeyImg = qr.make_image()
# resize the qr code to match our design
privkeyImg = privkeyImg.resize((220, 220), Image.NEAREST)
# draw the QR code on the final image
finalImg.paste(privkeyImg, (125, 560))
startPos = (110, 807)
charDist = 15
lineHeight = 23
lastCharPos = 0
keyLength = len(privkey)
while keyLength % 17 != 0:
privkey += " "
keyLength = len(privkey)
#.........这里部分代码省略.........
示例9: Adafruit_Thermal
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
#!/usr/bin/python
from __future__ import print_function
import RPi.GPIO as GPIO
import subprocess, time, Image, socket
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(60)
printer.printImage(Image.open('gfx/hello.png'), True)
printer.print('Hello World blabla blabla blabla')
printer.feed(3)
示例10: forecast
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
# Dumps one forecast line to the printer
def forecast(idx):
tag = 'yweather:forecast'
day = dom.getElementsByTagName(tag)[idx].getAttribute('day')
lo = dom.getElementsByTagName(tag)[idx].getAttribute('low')
hi = dom.getElementsByTagName(tag)[idx].getAttribute('high')
cond = dom.getElementsByTagName(tag)[idx].getAttribute('text')
printer.print(day + ': low ' + lo )
printer.print(deg)
printer.print(' high ' + hi)
printer.print(deg)
printer.println(' ' + cond)
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(heatTime=200)
deg = chr(0xf8) # Degree symbol on thermal printer
# Fetch forecast data from Yahoo!, parse resulting XML
dom = parseString(urllib.urlopen(
'http://weather.yahooapis.com/forecastrss?w=' + WOEID).read())
# Print heading
printer.inverseOn()
printer.print('{:^32}'.format(
dom.getElementsByTagName('description')[0].firstChild.data))
printer.inverseOff()
# Print current conditions
printer.boldOn()
printer.print('{:^32}'.format('Current conditions:'))
示例11: get_printer
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
def get_printer(heat=200):
# open the printer itself
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(heat)
return printer
示例12: Adafruit_Thermal
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import begin [as 别名]
#!/usr/bin/env python
import Image, os, sys
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.begin(75) # Increase the heat
image_path = sys.argv[1]
os.system('convert ' + image_path + ' -resize 382x764 tmp.png')
printer.printImage(Image.open('tmp.png'), True)
printer.feed(2)
os.system('rm tmp.png')
printer.sleep() # Tell printer to sleep
printer.wake() # Call wake() before printing again, even if reset
printer.setDefault() # Restore printer to defaults