问题描述
我正在逐步编写冗长的脚本,然后慢慢添加各种硬件。
我发现PIL库需要一段时间才能运行并将文本字符串写入minipitft spi tft显示器。
我正在流式传输和阅读Wiimote读数,大约每半秒钟一次,然后将这些读数传递给控制灯光,声音和运动。我遇到的问题是,在处理draw.text时增加的延迟会暂停整个脚本。
对于脚本的其他部分,我正在使用subprocess.popen在后台播放声音。
不幸的是,在这种情况下,我尝试推送的文本基于同时True:循环中的读数。
所以让我们做一个例子:
# -*- coding: utf-8 -*-
import time
import subprocess
import digitalio
import board
from PIL import Image,ImageDraw,ImageFont
import adafruit_rgb_display.st7789 as st7789
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None
BAUdratE = 64000000
spi = board.SPI()
disp = st7789.ST7789( spi,cs=cs_pin,dc=dc_pin,rst=reset_pin,baudrate=BAUdratE,width=240,height=240,x_offset=0,y_offset=80,)
# button i2c assy
import busio
from i2c_button import I2C_Button
i2c = busio.I2C(board.SCL,board.SDA)
button = I2C_Button(i2c)
height = disp.width # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new("RGB",(width,height))
rotation = 180
draw = ImageDraw.Draw(image)
draw.rectangle((0,width,height),outline=0,fill=(0,0))
disp.image(image,rotation)
padding = -2
top = padding
bottom = height - padding
x = 0
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",20)
backlight = digitalio.DigitalInOut(board.D22)
backlight.switch_to_output()
backlight.value = True
while True:
print(button.status)
state = button.status[2]
print(state)
# Draw a black filled Box to clear the image.
draw.rectangle((0,fill=0)
# Shell scripts for system monitoring from here:
# https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and- cpu-load
cmd = "hostname -I | cut -d' ' -f1"
IP = "IP: " + subprocess.check_output(cmd,shell=True).decode("utf-8")
cmd = "cat /sys/class/thermal/thermal_zone0/temp | awk '{printf \"cpu Temp: %.1f C\",$(NF-0) / 1000}'" # pylint: disable=line-too-long
Temp = subprocess.check_output(cmd,shell=True).decode("utf-8")
text = "hello world"
y = top
draw.text((x,y),text,font=font,fill="#FFFFFF")
y += font.getsize(text)[1]
# display image.
disp.image(image,rotation)
time.sleep(0.1)
What is the best way to to draw the text as a subprocess piped instance within the script?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)