首先,我只是想提一下,我并不确定在正确的StackExchange上询问了这个问题,因为它涉及很多不同的主题,我可能需要在其他地方问它。我相信它归结为Python(pygame
)和SDL之间的某个问题。
我做了什么:
fbi
(直接写入帧缓冲区)。来自dmesg
:
[ 12.377397] graphics fb1: fb_st7735r frame buffer, 128x160, 40 KiB video memory, 4 KiB DMA buffer memory, fps=20, spi0.0 at 32 MHz
问题:
我现在要测试的是使用pygame
在我的TFT上显示一个时钟,我得到的代码是(从http://gerfficient.com/2014/02/12/connecting-1-8-tft-lcd-to-raspberry-pi/借来的):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import time
import pygame
time_stamp_prev=0
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ['SDL_VIDEODRIVER']="fbcon"
def displaytext(text,size,line,color,clearscreen):
if clearscreen:
screen.fill((0,0,0))
font = pygame.font.Font(None,size)
text = font.render(text,0,color)
rotated = pygame.transform.rotate(text,90)
textpos = rotated.get_rect()
textpos.centery = 80
if line == 1:
textpos.centerx = 99
screen.blit(rotated,textpos)
elif line == 2:
textpos.centerx = 61
screen.blit(rotated,textpos)
elif line == 3:
textpos.centerx = 25
screen.blit(rotated,textpos)
def main():
global screen
pygame.init()
pygame.mouse.set_visible(0)
size = width,height = 128,160
screen = pygame.display.set_mode(size)
while True:
displaytext(time.strftime("%d.%m.%Y",time.gmtime()),40,1,(255,255,255),True)
displaytext(time.strftime("%H:%M:%S",time.gmtime()),40,2,(255,255,255),False)
displaytext("gerfficient.com",20,3,(100,100,255),False)
pygame.display.flip()
time.sleep(1)
if __name__ == '__main__':
main()
我得到的错误是:
Traceback (most recent call last):
File "test.py", line 19, in <module>
pygame.display.set_mode()
pygame.error: No video mode large enough for 128x160
当我通过pygame
显示更多信息并运行print pygame.display.Info()
时,我得到:
<VideoInfo(hw = 1, wm = 0,video_mem = 40
blit_hw = 0, blit_hw_CC = 0, blit_hw_A = 0,
blit_sw = 0, blit_sw_CC = 0, blit_sw_A = 0,
bitsize = 16, bytesize = 2,
masks = (63488, 2016, 31, 0),
shifts = (11, 5, 0, 0),
losses = (3, 2, 3, 8),
current_w = 128, current_h = 160
>
fbset -i -fb /dev/fb1
的输出:
mode "128x160"
geometry 128 160 128 160 16
timings 0 0 0 0 0 0 0
nonstd 1
rgba 5/11,6/5,5/0,0/0
endmode
Frame buffer device information:
Name : fb_st7735r
Address : 0
Size : 40960
Type : PACKED PIXELS
Visual : TRUECOLOR
XPanStep : 0
YPanStep : 0
YWrapStep : 0
LineLength : 256
Accelerator : No
检查两个SDL环境变量时,它们设置正确。
似乎当我使用/dev/fb1
(TFT)作为帧缓冲设备时,pygame / SDL会选择该信息,但仍然无法通过pygame
使用它。
就是说,我通过Raspbian存储库安装了包python-pygame
。
我正在使用的pygame和SDL的版本:
ii python-pygame 1.9.1release+dfsg-8
ii libsdl-image1.2:armhf 1.2.12-2
ii libsdl-mixer1.2:armhf 1.2.12-3
ii libsdl-ttf2.0-0:armhf 2.0.11-2
ii libsdl1.2-dev 1.2.15-5
ii libsdl1.2debian:armhf 1.2.15-5
答案 0 :(得分:2)
更改
size = width,height = 128,160
到
size = width,height = 160,128
答案 1 :(得分:0)
问题解决了,我所做的就是重启RPi,从那时起TFT屏幕与pygame模块完美配合。
我认为问题可能发生在Python和我已用于此项目的内核模块fbtft之间,或者可能是我安装和初始化内核模块的方式。这只是我的推测。
我没有提到我使用第三方驱动程序包的事实,我的愚蠢,这里有一个小提示,我在dmesg输出中使用这些驱动程序,但仅此而已。
我将使用此信息更新问题。
答案 2 :(得分:0)
您很可能错过了 /etc/fb.modes 中的模式项。
我遇到了128x128显示器的问题。
您可以通过
获取模式{
"swagger": "2.0",
"info": {
"description": "desc",
"title": "TestAPI",
"version": "1.0"
},
"schemes": [
"https"
],
"paths": {
"/": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "test",
"headers": {
"Content-type": {
"type": "string"
}
}
}
},
"x-amazon-apigateway-integration" : {
"type" : "aws",
"uri" : "[REDACTED]",
"credentials" : "[REDACTED]",
"httpMethod" : "POST",
"requestTemplates" : {
"application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
},
"requestParameters" : {
"integration.request.querystring.stage" : "method.request.querystring.version",
"integration.request.querystring.provider" : "method.request.querystring.vendor"
},
"responses" : {
"2\\d{2}" : {
"statusCode" : "200",
"responseParameters" : {
"method.response.header.requestId" : "integration.response.header.cid"
},
"responseTemplates" : {
"application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
}
},
"302" : {
"statusCode" : "302",
"responseParameters" : {
"method.response.header.Location" : "integration.response.body.redirect.url"
}
},
"default" : {
"statusCode" : "400",
"responseParameters" : {
"method.response.header.test-method-response-header" : "'static value'"
}
}
}
}
}
}
}
}
然后将其输出放入 /etc/fb.modes 。
希望有帮助...