contiki中的CTK部件显示调试

平时使用单片机显示屏时用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();
}
/*-----------------------------------------------------------------------------------*/


下一步找到键盘的接口,以进行更进一步的调试。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值