#!/usr/bin/env python2
"""
Barebones example of FBInk usage through Python's cFFI module
"""
# To get a Py3k-like print function
from __future__ import print_function
import sys
# Load the wrapper module, it's linked against FBInk, so the dynamic loader will take care of pulling in the actual FBInk library
from _fbink import ffi, lib as FBInk
# Let's check which FBInk version we're using...
# NOTE: ffi.string() returns a bytes on Python 3, not a str, hence the extra decode
print("Loaded FBInk {}".format(ffi.string(FBInk.fbink_version()).decode("ascii")))
# And now we're good to go! Let's print "Hello World" in the center of the screen...
# Setup the config...
fbink_cfg = ffi.new("FBInkConfig *")
fbink_cfg.is_centered = False
fbink_cfg.is_halfway = True
fbink_cfg.is_cleared = True
fbink_cfg.is_verbose = True
fbink_ot_cfg = ffi.new("FBInkOTConfig *")
fbink_ot_cfg.size_pt = 24
"""
# Open the FB...
fbfd = FBInk.fbink_open()
if fbfd == -1:
raise SystemExit("Failed to open the framebuffer, aborting . . .")
# Initialize FBInk...
if FBInk.fbink_init(fbfd, fbink_cfg) < 0:
raise SystemExit("Failed to initialize FBInk, aborting . . .")
# Do stuff!
if FBInk.fbink_print(fbfd, b"Hello World", fbink_cfg) < 0:
print("Failed to print that string!", file=sys.stderr)
# And now we can wind things down...
if FBInk.fbink_close(fbfd) < 0:
raise SystemExit("Failed to close the framebuffer, aborting . . .")
"""
# Or, the same but in a slightly more Pythonic approach ;).
fbfd = FBInk.fbink_open()
try:
FBInk.fbink_init(fbfd, fbink_cfg)
FBInk.fbink_add_ot_font("BigBlue_Terminal.ttf", FBInk.FNT_REGULAR)
string = u"Success \uf632 or \ufadf or \ufae0 or \ufc8f or \uf633 or \uf4a1" // \uf633
string += u"\n"
string += u"Error \uf071 or \uf525 or \uf529 or \uf421 or \ufb8f" // \uf071
string += u"\n"
string += u"Wait \uf252 or \ufa1e or \uf49b" // \uf252
string += u"\n"
string += u"Python \ue73c or \ue235 or \uf81f or \ue606" // \ue73c
string += u"\n"
string += u"USBNet \ue795 or \uf68c or \ufcb5 or \uf489" // \uf68c
string += u"\n"
string += u"Bridge \uf270 or \uf52c or \ue286 or \uf5a6 or \ue214" // \ue286 (AMZ: \uf270)
string += u"\n"
string += u":( \uf119 or \uf6f7" // \uf119
string += u"\n"
string += u"Linux \uf17c or \uf31a or \uf83c" // \uf17c
string += u"\n"
string += u":) \uf118 or \uf6f4" // \uf118
string += u"\n"
string += u"Tools \ue20f or \ufbf6 or \uf992 or \ufab6 or \uf425" // \uf425
string += u"\n"
string += u"MRPI \ufcdd or \ufcde or \uf8d5 or \uf962 or \ufac3 or \uf487 or \uf427" // \uf8d5 (KUAL: \uf962)
string = string.encode("utf-8")
# NOTE: On Python 3, cFFI maps char to bytes, not str
FBInk.fbink_print_ot(fbfd, string, fbink_ot_cfg, fbink_cfg, ffi.NULL)
finally:
FBInk.fbink_free_ot_fonts()
FBInk.fbink_close(fbfd)

ITZHIHONH
- 粉丝: 59
最新资源
- 进一步推进事业单位人事管理信息化建设的思路.doc
- 基于计算机专业学生毕业论文质量的提高对策分析.docx
- 基于数字孪生的智慧城市建设发展研究.docx
- 校园网络信息安全监控系统的设计与实现.docx
- 51单片机数字电压表方案设计书.doc
- 基于单片机的路灯控制系统方案设计书开题报告.doc
- 网络营销各小组出的考试题.doc
- 企业如何做好网络分销.ppt
- 生物监测与生物安全研讨会文集
- PLC控制机械手课程设计方案作业.doc
- 华师17春秋学期《C语言程序设计B》在线作业.doc
- 基于Python和Elasticsearch构建的分布式网络爬虫与全文检索系统-网络爬虫-数据抓取-搜索引擎-索引构建-数据分析-信息检索-知识管理-企业搜索-学术研究-数据挖掘-.zip
- 高级语言程序设计课程分析.ppt
- 三务合一新模式信息化平台建设监理招标v2商务.doc
- 完整的NOKIA-5110液晶51单片机驱动程序.doc
- 电子通信行业的技术标准与企业创新.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


