linux应用程序_1_文本浏览器_4_display_1_disp_manager

linux应用程序_1_文本浏览器_4_display_1_disp_manager

抽象显示结构体依据:

应含有设备名字、分辨率、像素深度

应具备设备初始化、显示像素、清屏等功能

应具有链表,同其他结构体建立联系

抽象出显示结构体

typedef struct DispOpr {
	char *pcName;
	int iXres;
	int iYres;
	int iBpp;
	int (*DeviceInit)(void);
	int (*DeviceExit)(void);
	int (*ShowPixel)(int iPenX, int iPenY, unsigned int dwColor);
	int (*CleanScreen)(unsigned int dwBackColor);
	struct DispOpr *ptNext;
}T_DispOpr, *PT_DispOpr;

注册:

将显示结构体存入显示链表

int RegisterDispOpr(PT_DispOpr ptDispOpr)
{
	PT_DispOpr ptDispOprTmp;

	if(!g_ptDispOpr)
	{
		g_ptDispOpr = ptDispOpr;
		return 0;
	}

	ptDispOprTmp = g_ptDispOpr;

	while(ptDispOprTmp->ptNext)
	{
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	ptDispOprTmp->ptNext = ptDispOpr;
	ptDispOpr->ptNext = NULL;

	DBG_PRINT("display:\r\n");
	ptDispOprTmp = g_ptDispOpr->ptNext;
	
	DBG_PRINT("%s,%s\r\n",g_ptDispOpr->pcName,ptDispOprTmp->pcName);

	return 0;
}

获取显示结构体:

根据名字取出目前支持的显示结构体

PT_DispOpr GetDispOpr(char *pcName)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;

	
	while(ptDispOprTmp)
	{
		if(strcmp(ptDispOprTmp->pcName, pcName) == 0)
		{
			return ptDispOprTmp;
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	return NULL;
}

显示初始化:

注册各个显示结构体

int DisplaysInit(void)
{
	int iError = 1;
	
	iError  = FBInit();
	
#ifdef 	ONPC
	iError |= OnpucInit();
#endif

	return iError;
}

退出显示:

对于不同设备有不同操作

对LCD    :这里不做任何事情(可以关闭LCD控制器、电源等)

对控制台:需要从图片模式切换到文本模式

void DisplayExit(void)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;
	
	while(ptDispOprTmp)
	{		
		if(ptDispOprTmp->DeviceExit)
		{
			ptDispOprTmp->DeviceExit();
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}	
}

完整代码:

disp_manager.h

#ifndef __DISP_MANAGER_H
#define __DISP_MANAGER_H


typedef struct DispOpr {
	char *pcName;
	int iXres;
	int iYres;
	int iBpp;
	int (*DeviceInit)(void);
	int (*DeviceExit)(void);
	int (*ShowPixel)(int iPenX, int iPenY, unsigned int dwColor);
	int (*CleanScreen)(unsigned int dwBackColor);
	struct DispOpr *ptNext;
}T_DispOpr, *PT_DispOpr;

int FBInit(void);
int OnpucInit(void);


int RegisterDispOpr(PT_DispOpr ptDispOpr);
PT_DispOpr GetDispOpr(char *pcName);
void ShowDispOpr(void);
int DisplaysInit(void);
void DisplayExit(void);

#endif

disp_manager.c

#include <config.h>
#include <disp_manager.h>
#include <string.h>
#include <stdio.h>

PT_DispOpr g_ptDispOpr;


int RegisterDispOpr(PT_DispOpr ptDispOpr)
{
	PT_DispOpr ptDispOprTmp;

	if(!g_ptDispOpr)
	{
		g_ptDispOpr = ptDispOpr;
		return 0;
	}

	ptDispOprTmp = g_ptDispOpr;

	while(ptDispOprTmp->ptNext)
	{
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	ptDispOprTmp->ptNext = ptDispOpr;
	ptDispOpr->ptNext = NULL;

	DBG_PRINT("display:\r\n");
	ptDispOprTmp = g_ptDispOpr->ptNext;
	
	DBG_PRINT("%s,%s\r\n",g_ptDispOpr->pcName,ptDispOprTmp->pcName);

	return 0;
}

PT_DispOpr GetDispOpr(char *pcName)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;

	
	while(ptDispOprTmp)
	{
		if(strcmp(ptDispOprTmp->pcName, pcName) == 0)
		{
			return ptDispOprTmp;
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
	return NULL;
}

void ShowDispOpr(void)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;
	int iCnt = 0;

	printf("\r\n");	
	printf("supported display:\r\n");
	while(ptDispOprTmp)
	{
		printf("%02d : %s\r\n",++iCnt, ptDispOprTmp->pcName);
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}
}

int DisplaysInit(void)
{
	int iError = 1;
	
	iError  = FBInit();

#ifdef ONPC
	iError |= OnpucInit();
#endif

	return iError;
}

void DisplayExit(void)
{
	PT_DispOpr ptDispOprTmp = g_ptDispOpr;
	
	while(ptDispOprTmp)
	{		
		if(ptDispOprTmp->DeviceExit)
		{
			ptDispOprTmp->DeviceExit();
		}
		ptDispOprTmp = ptDispOprTmp->ptNext;
	}	
}
发布了71 篇原创文章 · 获赞 4 · 访问量 7228

猜你喜欢

转载自blog.csdn.net/floatinglong/article/details/86635085