本文整理汇总了Python中Adafruit_Thermal.feed方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_Thermal.feed方法的具体用法?Python Adafruit_Thermal.feed怎么用?Python Adafruit_Thermal.feed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_Thermal
的用法示例。
在下文中一共展示了Adafruit_Thermal.feed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_file
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def upload_file():
if request.method == 'POST':
uploadedFile = request.files['file']
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(Image.open(uploadedFile), True)
printer.feed(10)
redirect("/printer")
示例2: generate_post
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def generate_post():
with open('/home/yuri/mashbotv2/cleaned.txt') as f:
text = f.read()
text_model = markovify.Text(text, state_size=2)
mash_text = text_model.make_short_sentence(129) # was 140
wrapped_text = textwrap.fill(mash_text, 32)
output_text = "@acoluthon " + mash_text
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.setDefault()
printer.justify('L')
printer.feed(3)
printer.boldOn()
printer.setSize('M')
printer.println("Mash Note")
printer.setSize('S')
printer.boldOff()
printer.println(wrapped_text)
printer.feed(2)
# Write the status to a file, for debugging
with open('/home/yuri/mashbotv2/history.txt', 'a') as f:
f.write('mashed: ' + mash_text + ' | tweeted: ' + output_text + '\n')
return output_text
示例3: printout
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def printout():
if request.method == 'POST':
printText=request.form['printtext']
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.println(printText)
printer.feed(10)
redirect("/printer")
示例4: print_password
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def print_password(headerText, ttp):
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 4), "white"), (0, 0))
# create the divider
bottomDividerLineImg = Image.open("/home/pi/Printer/dividerline.bmp")
font = ImageFont.truetype("/usr/share/fonts/ttf/swansea.ttf", 20)
draw = ImageDraw.Draw(bottomDividerLineImg)
rightMarkText = "Piperwallet.com"
rightMarkSize = draw.textsize(rightMarkText, font=font)
leftMarkOrigin = (10, 15)
rightMarkOrigin = (384 - rightMarkSize[0] - 10, 15)
draw.text(leftMarkOrigin, headerText, font=font, fill=(0, 0, 0))
draw.text(rightMarkOrigin, rightMarkText, font=font, fill=(0, 0, 0))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(dividerLine, True)
printer.println("Password: ")
printer.println(ttp)
printer.printImage(bottomDividerLineImg, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例5: printHDMWalletSeed
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def printHDMWalletSeed(headerText, seed, xpub):
qrSize = (170,170)
qrPad = 10
finalImg = Image.new("RGB", (384, qrSize[1]), "white")
finalImg.paste(getQR(seed, qrSize), (qrPad, 0))
finalImg.paste(getQR(xpub, qrSize), (qrSize[0]+qrPad*2+14, 0))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 4), "white"), (0, 0))
printer.printImage(dividerLine, True)
printer.println(headerText)
printer.println("Seed Mnemonic: "+seed+'\n')
printer.println("xpub: "+xpub+'\n')
printer.printImage(finalImg, True)
printer.feed(1)
printer.printImage(dividerLine, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例6: print_image
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def print_image(filename):
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.feed(5)
image = Image.open(filename)
image = image.rotate(90, expand=1)
image = ImageEnhance.Contrast(image).enhance(1.3) # add contrast
printer.printImage(image, True)
printer.feed(5)
示例7: print_seed
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def print_seed(seed):
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.println(seed)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例8: print_seed
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [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
示例9: encodeQRAndPrint
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def encodeQRAndPrint(ttp):
qrSize = (340, 340)
finalImg = Image.new("RGB", (384, 440), "white")
finalImg.paste(getQR(ttp, qrSize), (30, 55))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(finalImg, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例10: __init__
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
class thermal_printer:
def __init__(self):
self.printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
def printImg(self, img, priv_key):
self.printer.feed(3)
self.printer.printImage(img)
# I have some reservation about how to deal with encrypted private key, but need to wait for thermal_printer to look into it.
if len(priv_key) <= 51:
self.printer.printChar(priv_key[:17]+"\n")
self.printer.justify("R")
self.printer.printChar(priv_key[17:34]+"\n")
self.printer.justify("L")
self.printer.printChar(priv_key[34:]+"\m")
else:
self.printer.println(priv_key)
示例11: on_data
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def on_data(self, data):
print(1)
print(data)
print(2)
tweet = json.loads(data.strip())
retweeted = tweet.get('retweeted')
from_self = tweet.get('user',{}).get('id_str','') == account_user_id
if retweeted is not None and not retweeted and not from_self:
tweetId = tweet.get('id_str')
screenName = tweet.get('user',{}).get('screen_name')
tweetText = tweet.get('text')
print(4)
tweetText = tweetText.encode('UTF-8')
print(tweetText)
chatResponse = therapist.respond(tweetText)
print(chatResponse)
print(5)
replyText = '@' + screenName + ' ' + chatResponse
print(6)
#check if repsonse is over 140 char
if len(replyText) > 130:
replyText = replyText[0:127] + '...'
wrappedTweet = textwrap.fill(tweetText, 32)
wrappedReply = textwrap.fill(replyText, 32)
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.println('Tweet ID: ' + tweetId)
printer.println('From: ' + screenName)
printer.println('Tweet Text:')
printer.println(wrappedTweet)
printer.println('Reply Text:')
printer.println(wrappedReply)
printer.feed(3)
# If rate limited, the status posts should be queued up and sent on an interval
twitterApi.update_status(status=replyText, in_reply_to_status_id=tweetId)
print(7)
示例12: encodeQRAndPrintText
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def encodeQRAndPrintText(headerText, ttp):
qrSize = (340, 340)
finalImg = Image.new("RGB", (384, 440), "white")
finalImg.paste(getQR(ttp, qrSize), (30, 55))
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 3), "white"), (0, 0))
printer.printImage(dividerLine, True)
printer.println(headerText)
printer.println(ttp)
printer.printImage(finalImg, True)
printer.println(ttp)
printer.printImage(dividerLine, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例13: splitAndPrint
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def splitAndPrint(ttp, k, n):
print "Thing to split: "+ttp
#first, split it up
secret = Secret.from_printable_ascii(ttp)
shares = secret.split(int(k), int(n))
#now convert to QR codes and print the shares
print shares
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
qrSize = (340, 340)
ctr = 0
qrImg = {}
for shr in shares:
print "Share: "+shr
finalImg = Image.new("RGB", (384, 440), "white")
finalImg.paste(getQR(shr, qrSize), (30, 55))
qrImg[shr] = finalImg
dividerLine = Image.new("RGB", (384, 6), "black")
dividerLine.paste(Image.new("RGB", (384, 3), "white"), (0, 0))
for shr in shares:
printer.printImage(dividerLine, True)
printer.println("This is a share in a "+k+" of "+n+"\nthreshold scheme")
printer.println(shr)
printer.printImage(qrImg[shr], True)
printer.println(shr)
printer.println("Shamir's Secret Sharing")
printer.printImage(dividerLine, True)
printer.feed(3)
printer.setDefault() # Restore printer to defaults
示例14: Adafruit_Thermal
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
#!/usr/bin/python
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.setDefault()
printer.setTimes(33000, 2500)
# CODE39 is the most common alphanumeric barcode
printer.printBarcode("ADAFRUT", printer.CODE39)
printer.setBarcodeHeight(100)
# Print UPC line on product barcodes
printer.printBarcode("123456789123", printer.UPC_A)
# Print the 75x75 pixel logo in adalogo.py
import gfx.adalogo as adalogo
printer.printBitmap(adalogo.width, adalogo.height, adalogo.data)
# Print the 135x135 pixel QR code in adaqrcode.py
import gfx.adaqrcode as adaqrcode
printer.printBitmap(adaqrcode.width, adaqrcode.height, adaqrcode.data)
printer.println("Adafruit!")
printer.feed(1)
printer.sleep() # Tell printer to sleep
printer.wake() # Call wake() before printing again, even if reset
printer.setDefault() # Restore printer to defaults
示例15: printImage
# 需要导入模块: import Adafruit_Thermal [as 别名]
# 或者: from Adafruit_Thermal import feed [as 别名]
def printImage(fileToPrint, result, timeNow, location):
def imageProcessing(fileToPrint):
img = Image.open(fileToPrint)
img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
img = img.filter(ImageFilter.SHARPEN)
img = img.filter(ImageFilter.MedianFilter)
img = img.rotate(180)
return img
def getTimeElapsed(fileToPrint):
text = ''
now = datetime.now()
last = parseTimeStamp(fileToPrint)
timeElapsed = now - last
seconds = int(timeElapsed.seconds)
minutes = int(round(seconds/60))
hours = int(round(seconds/3600))
days = int(timeElapsed.days)
# days and hours
if (days > 0):
if (days == 1):
text += str(days)+'day '
else:
text += str(days)+'days '
if (hours > 0):
if (hours == 1):
text += str(hours)+'hour '
else:
text += str(hours)+'hours '
elif (days == 0):
# hours and minutes
if (hours > 0):
if (hours == 1):
text += str(hours)+'hour '
else:
text += str(hours)+'hours '
minutes = minutes - 60*hours
if (minutes > 0):
if (minutes == 1):
text += str(minutes)+'minute '
else:
text += str(minutes)+'minutes '
else:
# minutes and seconds
if (minutes > 0):
if (minutes == 1):
text += str(minutes)+'minute '
else:
text += str(minutes)+'minutes '
seconds = seconds - minutes*60
if (seconds > 0):
if (seconds == 1):
text += str(seconds)+'second '
else:
text += str(seconds)+'seconds '
# seconds
else:
text += str(seconds)+'seconds '
text += 'ago @'+location
return text
def getTimeNow(timeNow):
text ='Printed at '
timeNow = parseTimeStamp(timeNow)
year = timeNow.year
month = timeNow.month
day = timeNow.day
hour = timeNow.hour
minute = timeNow.minute
text += fmt(year)+'.'+fmt(month)+'.'+fmt(day)+' '
text += fmt(hour)+':'+fmt(minute)
return text
image = imageProcessing(fileToPrint)
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
printer.printImage(image, True) # This does the printing
printer.upsideDownOn()
printer.justify('C')
timeElapsed = getTimeElapsed(result)
printer.println(timeElapsed)
timeNow = getTimeNow(timeNow)
printer.println(timeNow)
printer.upsideDownOff()
printer.feed(3)