您的位置:首页 > 其它

contiki中的CTK部件显示调试

2015-08-09 20:38 197 查看
平时使用单片机显示屏时用192x64的比较多,而CTK中支持多窗口、鼠标、窗口关闭按钮等都可以通过定义去掉,只使用其中的Label、Text、Button就能构成一个简单的人机画面,通过对示例的分析,构建出了下面的一个例子,能用gcc在Linux下编译,在屏幕缓冲区中记录并输出显示的结果。先上图!



首先:修改Contiki_conf.h

加入下面三行

#define PLATFORM_BUILD

//2015-08-07 19:43 对屏显的宽度及高度进行定义

#define LIBCONIO_CONF_SCREEN_WIDTH 24

#define LIBCONIO_CONF_SCREEN_HEIGHT 4

修改下面的定义,将其功能屏蔽

#define CTK_CONF_MOUSE_SUPPORT 0

//2015-08-09 05:53 是否支持多个Window,如为1,则显示边框

#define CTK_CONF_WINDOWS 0

#define CTK_CONF_WINDOWMOVE 0

#define CTK_CONF_WINDOWCLOSE 0

#define CTK_CONF_ICONS 0

#define CTK_CONF_ICON_BITMAPS 0

#define CTK_CONF_ICON_TEXTMAPS 0

#define CTK_CONF_MENUS 0

编写ctk_arch.c如下:

/*

* =====================================================================================

*

* Filename: ctk_arch.c

*

* Description:

*

* Version: 1.0

* Created: 2015年08月05日 21时17分49秒

* Revision: none

* Compiler: gcc

*

* Author: YOUR NAME (),

* Company:

*

* =====================================================================================

*/

#include "ctk_arch.h"

char screen_char[LIBCONIO_CONF_SCREEN_WIDTH][LIBCONIO_CONF_SCREEN_HEIGHT];

unsigned char screen_color[LIBCONIO_CONF_SCREEN_WIDTH][LIBCONIO_CONF_SCREEN_HEIGHT];

unsigned char screen_reversed[LIBCONIO_CONF_SCREEN_WIDTH][LIBCONIO_CONF_SCREEN_HEIGHT];

/*---------------------------------------------------------------------------*/

void ctk_arch_draw_char(char c, unsigned char xpos, unsigned char ypos,

unsigned char reversed, unsigned char color) {

if(xpos < LIBCONIO_CONF_SCREEN_WIDTH && ypos < LIBCONIO_CONF_SCREEN_HEIGHT){

screen_char[xpos][ypos] = c;

screen_color[xpos][ypos] = color;

screen_reversed[xpos][ypos] = reversed;

}

}

/*---------------------------------------------------------------------------*/

char

ctk_arch_getkey(void)

{

return 0;

}

/*-----------------------------------------------------------------------------------*/

unsigned char

ctk_arch_keyavail(void)

{

return 0;

}

void ctk_window_dump(){

unsigned char x,y;

printf("\nScreen text:");

for(y=0;y<LIBCONIO_CONF_SCREEN_HEIGHT;y++){

printf("\n{");

for(x=0;x<LIBCONIO_CONF_SCREEN_WIDTH;x++){

printf("%c",screen_char[x][y]);

}

printf("}");

}

printf("\nScreen color:");

for(y=0;y<LIBCONIO_CONF_SCREEN_HEIGHT;y++){

printf("\n{");

for(x=0;x<LIBCONIO_CONF_SCREEN_WIDTH;x++){

printf("%x,",screen_color[x][y]);

}

printf("}");

}

printf("\nScreen reversed:");

for(y=0;y<LIBCONIO_CONF_SCREEN_HEIGHT;y++){

printf("\n{");

for(x=0;x<LIBCONIO_CONF_SCREEN_WIDTH;x++){

printf("%x,",screen_reversed[x][y]);

}

printf("}");

}

printf("\n");

}

修改ctk_conio.c,将ctk_draw_window这个函数最后加一行调试输出代码:

ctk_window_dump();

这样就能在控制台上打印出显示屏中的内容了,可方便对CTK中的各种控件进行显示调试了。

其中窗口的内容about.c如下

#include <string.h>

#include "contiki.h"

static struct ctk_window aboutdialog;

static struct ctk_label aboutlabel1 =

{CTK_LABEL(3, 0, 24, 1, "The Contiki System")};

static struct ctk_label aboutlabel2 =

{CTK_LABEL(3, 1, 24, 1, "A modern, Internet")};

static struct ctk_button aboutclose =

{CTK_BUTTON(9, 3, 5, "Close")};

PROCESS(about_process, "About Contiki");

/*-----------------------------------------------------------------------------------*/

static void

about_quit(void)

{

ctk_window_close(&aboutdialog);

process_exit(&about_process);

}

/*-----------------------------------------------------------------------------------*/

PROCESS_THREAD(about_process, ev, data)

{

unsigned char width;

PROCESS_BEGIN();

width = ctk_desktop_width(NULL);

if(width > 34) {

ctk_window_new(&aboutdialog, 32, 9,"");

} else {

ctk_window_new(&aboutdialog, width - 2, 4,"");

}

CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1);

CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2);

CTK_WIDGET_ADD(&aboutdialog, &aboutclose);

CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose);

ctk_window_open(&aboutdialog);

while(1) {

PROCESS_WAIT_EVENT();

if(ev == PROCESS_EVENT_EXIT) {

about_quit();

PROCESS_EXIT();

} else if(ev == ctk_signal_button_activate) {

if(data == (process_data_t)&aboutclose) {

about_quit();

PROCESS_EXIT();

}

}

}

PROCESS_END();

}

/*-----------------------------------------------------------------------------------*/

下一步找到键盘的接口,以进行更进一步的调试。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: