我正在Raspberry Pi 3上使用2个显示器,运行不带X的Raspbian(内核4.14)
一个是1280x720分辨率的HDMI,另一个是SPI 720x480分辨率。
两个显示均在引导时显示控制台输出。
我可以使用以下命令在SPI显示器上正确显示随机噪声
cat /dev/urandom >/dev/fb1
我需要使用C ++在SPI显示器上显示图像
我正在运行测试代码,该代码在HDI显示器上显示测试模式 Source Link
问题是,无论我输入什么uint32_t displayNumber = 0; \\=1; =2; etc..
,它始终显示在HDMI显示屏上。
info.width
和info.height
始终显示1920x1080
如果我断开HDMI显示器的连接,然后再次尝试为uint32_t displayNumber = 0;
输入不同的数字,我会得到
info.width
和info.height
始终显示720x480
但是SPI显示屏上仍然没有任何显示。
看来vc_dispmanx_display_open(displayNumber);
不在乎它作为输入参数是什么。
我的问题是,如何正确地将dispmanx
从/dev/fb0
切换到/dev/fb1
?
谢谢
int main(int argc, char *argv[])
{
uint32_t displayNumber = 0;
VC_IMAGE_TYPE_T type = VC_IMAGE_RGBA32;
bcm_host_init();
DISPMANX_DISPLAY_HANDLE_T display
= vc_dispmanx_display_open(displayNumber);
assert(display != 0);
DISPMANX_MODEINFO_T info;
int result = vc_dispmanx_display_get_info(display, &info);
assert(result == 0);
uint32_t vc_image_ptr;
DISPMANX_RESOURCE_HANDLE_T bgResource =
vc_dispmanx_resource_create(type, 1, 1, &vc_image_ptr);
assert(bgResource != 0);
DISPMANX_RESOURCE_HANDLE_T resource =
vc_dispmanx_resource_create(type, 2, 2, &vc_image_ptr);
assert(resource != 0);
VC_RECT_T src_rect;
VC_RECT_T dst_rect;
vc_dispmanx_rect_set(&dst_rect, 0, 0, 1, 1);
uint32_t background = 0;
result = vc_dispmanx_resource_write_data(bgResource,
type,
sizeof(background),
&background,
&dst_rect);
assert(result == 0);
uint32_t image[32];
memset(image, 0, sizeof(image));
image[0] = 0xFF0000FF;
image[1] = 0xFF00FFFF;
image[16] = 0xFFFF0000;
image[17] = 0xFFFFFF00;
vc_dispmanx_rect_set(&dst_rect, 0, 0, 2, 2);
result = vc_dispmanx_resource_write_data(resource,
type,
16 * sizeof(uint32_t),
image,
&dst_rect);
assert(result == 0);
DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0);
assert(update != 0);
VC_DISPMANX_ALPHA_T alpha =
{
DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,
255,
/*alpha 0->255*/
0
};
vc_dispmanx_rect_set(&src_rect, 0, 0, 1, 1);
vc_dispmanx_rect_set(&dst_rect, 0, 0, 0, 0);
DISPMANX_ELEMENT_HANDLE_T bgElement =
vc_dispmanx_element_add(update,
display,
1,
// layer
&dst_rect,
bgResource,
&src_rect,
DISPMANX_PROTECTION_NONE,
&alpha,
NULL,
// clamp
DISPMANX_NO_ROTATE);
assert(bgElement != 0);
vc_dispmanx_rect_set(&src_rect, 0, 0, 2 << 16, 2 << 16);
vc_dispmanx_rect_set(&dst_rect,
(info.width - info.height) / 2,
0,
info.height,
info.height);
DISPMANX_ELEMENT_HANDLE_T element =
vc_dispmanx_element_add(update,
display,
2,
// layer
&dst_rect,
resource,
&src_rect,
DISPMANX_PROTECTION_NONE,
&alpha,
NULL,
// clamp
DISPMANX_NO_ROTATE);
assert(element != 0);
result = vc_dispmanx_update_submit_sync(update);
assert(result == 0);
//---------------------------------------------------------------------
usleep(1000000);
//---------------------------------------------------------------------
update = vc_dispmanx_update_start(0);
assert(update != 0);
result = vc_dispmanx_element_remove(update, element);
assert(result == 0);
result = vc_dispmanx_element_remove(update, bgElement);
assert(result == 0);
result = vc_dispmanx_update_submit_sync(update);
assert(result == 0);
result = vc_dispmanx_resource_delete(resource);
assert(result == 0);
result = vc_dispmanx_resource_delete(bgResource);
assert(result == 0);
result = vc_dispmanx_display_close(display);
assert(result == 0);
return 0;
}