问题描述:准备做手表 开机以后 屏幕左右滑动可以切换不同的画面
1–尝试 HelloSlide 滑动扑克牌 但是没有单片机案例放弃
2–尝试在代码中增加一个 uilayer.CPP 文件 这样一个CPP负责一个画面 代码调用画面切换
编译有很多问题 类似如下
._build\nrf52840_xxaa.axf: Error: L6200E: Symbol c_theme:😒_bmp_map multiply defined (by uilayer.o and uicode.o).
._build\nrf52840_xxaa.axf: Error: L6200E: Symbol c_dialog::ms_the_dialogs multiply defined (by uilayer.o and uicode.o).
._build\nrf52840_xxaa.axf: Error: L6200E: Symbol c_theme:😒_font_map multiply defined (by uilayer.o and uicode.o).
._build\nrf52840_xxaa.axf: Error: L6200E: Symbol g_number_board_children multiply defined (by uilayer.o and uicode.o).
3–规避上面编译的问题 准备把所有画面代码都写在 uicode.cpp
目前单片机跑的是 HELLONOTOUCH
准备做2个画面 都是 HELLONOTOUCH 稍微做了一点改动 以示区别
代码如下
任务中:
extern void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op,char pageid);
extern void sendKey2HelloNoTouch(unsigned int key);
static void guiTask(void *pvParameters)
{
my_gfx_op.draw_pixel = gfx_draw_pixel;
my_gfx_op.fill_rect = NULL;//gfx_fill_rect;
startHelloParticle( NULL, 240, 240, 2, &my_gfx_op,pageid);
int i=0,pageid=2;
for (; ;)
{
sendKey2HelloNoTouch(0);//Forward focus //virtual void on_navigate(NAVIGATION_KEY key)
vTaskDelay(1000);
sendKey2HelloNoTouch(2);//Click
vTaskDelay(1000);;
if(i==5)
{
if(pageid==1) pageid=2;
else pageid=1;
startHelloParticle( NULL, 240, 240, 2, &my_gfx_op,pageid);
i=0;
}
测试 上面部分 没有问题 可以切换画面
问题是 : 首先是去 pageid=2 等一会在去 pageid=1
设计的时候 pageid=1 画面有三行数据 pageid=2 画面有二行数据
实际在进入到pageid=1的时候看到GUI依然保持二行数据 第三行没有描出来
uicode.cpp修改如下
#define GUILITE_ON //Do not define this macro once more!!!
#include "GuiLite.h"
#include <stdlib.h>
#include <stdio.h>
#define UI_WIDTH 240
#define UI_HEIGHT 240
#include "nrf_delay.h"
void delay_ms(unsigned short nms)
{
nrf_delay_ms(nms);
}
define widgets & map message
enum WND_ID
{
ID_ROOT = 1,
ID_LABEL1,
ID_LABEL2,
ID_LABEL3,
ID_BUTTON1,
ID_BUTTON2,
ID_BUTTON3
};
class c_myUI : public c_wnd
{
virtual void on_init_children()
{
((c_button*)get_wnd_ptr(ID_BUTTON1))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked);
((c_button*)get_wnd_ptr(ID_BUTTON2))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked);
((c_button*)get_wnd_ptr(ID_BUTTON3))->set_on_click((WND_CALLBACK)&c_myUI::on_clicked);
}
virtual void on_paint(void)
{
c_rect rect;
get_screen_rect(rect);
m_surface->fill_rect(rect, GL_RGB(0, 0, 0), m_z_order);// 全部背景是红色 GL_RGB(255, 0, 0)
}
void on_clicked(int ctrl_id, int param) { // 哪一个按键被点击了
static int sum1, sum2, sum3;
static char str1[8], str2[8], str3[8];
c_button* button = (c_button*)get_wnd_ptr(ctrl_id);
switch (ctrl_id)
{
case ID_BUTTON1:
sprintf(str1, "%d", ++sum1);
button->set_str(str1);
break;
case ID_BUTTON2:
sprintf(str2, "%d", ++sum2);
button->set_str(str2);
break;
case ID_BUTTON3:
sprintf(str3, "%d", ++sum3);
button->set_str(str3);
break;
}
button->show_window();
}
};
layout UI
static c_myUI s_myUI;
static c_label s_label1, s_label2, s_label3;
static c_button s_button1, s_button2, s_button3;
static WND_TREE s_myUI_children[] =
{
{&s_label1, ID_LABEL1, "a: <<", 20, 20, 80, 40, NULL},
{&s_label2, ID_LABEL2, "d: >>", 20, 100, 80, 40, NULL},
{&s_label3, ID_LABEL3, "s: click", 20, 180, 80, 40, NULL},
{&s_button1, ID_BUTTON1, "0", 140, 20, 80, 40, NULL},
{&s_button2, ID_BUTTON2, "0", 140, 100, 80, 40, NULL},
{&s_button3, ID_BUTTON3, "0", 140, 180, 80, 40, NULL},
{ NULL,0,0,0,0,0,0 }
};
static WND_TREE s_myUI_children2[] = // -----------------------------修改点 预计画面只有2行数据
{
{&s_label1, ID_LABEL1, "a: <<", 20, 20, 80, 40, NULL},
{&s_label2, ID_LABEL2, "d: >>", 20, 100, 80, 40, NULL},
{&s_button1, ID_BUTTON1, "0", 140, 20, 80, 40, NULL},
{&s_button2, ID_BUTTON2, "0", 140, 100, 80, 40, NULL},
{ NULL,0,0,0,0,0,0 }
};
start UI
extern const FONT_INFO Consolas_28;
extern const FONT_INFO Consolas_19;
void load_resource(char pageid)//-----------------复制粘贴的
{
if(pageid==1)
{
c_theme::add_font(FONT_DEFAULT, &Consolas_28);
//for button
c_theme::add_color(COLOR_WND_FONT, GL_RGB(255, 255, 243));// 按键以后的颜色
c_theme::add_color(COLOR_WND_NORMAL, GL_RGB(59, 75, 94));
c_theme::add_color(COLOR_WND_PUSHED, GL_RGB(33, 42, 53));
c_theme::add_color(COLOR_WND_FOCUS, GL_RGB(255, 0, 0));//GL_RGB(78, 198, 76)
c_theme::add_color(COLOR_WND_BORDER, GL_RGB(46, 59, 73));
}
else
{
c_theme::add_font(FONT_DEFAULT, &Consolas_19);
//for button
c_theme::add_color(COLOR_WND_FONT, GL_RGB(255, 255, 243));// 按键以后的颜色
c_theme::add_color(COLOR_WND_NORMAL, GL_RGB(59, 75, 94));
c_theme::add_color(COLOR_WND_PUSHED, GL_RGB(33, 42, 53));
c_theme::add_color(COLOR_WND_FOCUS, GL_RGB(78, 198, 76));
c_theme::add_color(COLOR_WND_BORDER, GL_RGB(46, 59, 73));
}
}
static c_display* s_display;
static c_surface* s_surface;
void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op ,char pageid)
{
load_resource(pageid);
if (phy_fb)
{
static c_surface surface(UI_WIDTH, UI_HEIGHT, color_bytes, Z_ORDER_LEVEL_0);
static c_display display(phy_fb, screen_width, screen_height, &surface);
s_surface = &surface;
s_display = &display;
}
else
{//for MCU without framebuffer
static c_surface_no_fb surface_no_fb(UI_WIDTH, UI_HEIGHT, color_bytes, gfx_op, Z_ORDER_LEVEL_0);
static c_display display(phy_fb, screen_width, screen_height, &surface_no_fb);
s_surface = &surface_no_fb;
s_display = &display;
}
if(pageid==1)
{
s_myUI.set_surface(s_surface);
s_myUI.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_myUI_children);
s_myUI.show_window();
}
else if(pageid==2)
{
s_myUI.set_surface(s_surface);
s_myUI.connect(NULL, ID_ROOT, 0, 0, 0, UI_WIDTH, UI_HEIGHT, s_myUI_children2);-----------------修改点
s_myUI.show_window();
}
}
interface for all platform
extern "C" void startHelloParticle(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op,char pageid) {
create_ui(phy_fb, width, height, color_bytes, gfx_op, pageid);
}
extern "C" void sendTouch2HelloNoTouch(int x, int y, bool is_down)
{
is_down ? s_myUI.on_touch(x, y, TOUCH_DOWN) : s_myUI.on_touch(x, y, TOUCH_UP);
}
extern "C" void sendKey2HelloNoTouch(unsigned int key)
{
s_myUI.on_navigate(NAVIGATION_KEY(key));
}
extern void* getUiOfHelloNoTouch(int* width, int* height, bool force_update = false)
{
if (s_display)
{
return s_display->get_updated_fb(width, height, force_update);
}
return NULL;
}
int captureUiOfHelloNoTouch()
{
return s_display->snap_shot("snap_short.bmp");
}
问题解答:
在画面切换的时候 确实需要一些其他操作