2021-03-21 23:31:45 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
*/
|
|
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
|
|
#ifdef RT_USING_RTGUI
|
|
|
|
|
#include <rtgui/rtgui.h>
|
|
|
|
|
#include <rtgui/rtgui_server.h>
|
|
|
|
|
#include <rtgui/rtgui_system.h>
|
|
|
|
|
|
|
|
|
|
#include <rtgui/widgets/view.h>
|
|
|
|
|
#include <rtgui/widgets/workbench.h>
|
|
|
|
|
|
|
|
|
|
#include "adc.h"
|
|
|
|
|
#include "cpuusage.h"
|
|
|
|
|
|
|
|
|
|
extern rt_uint16_t adc_value;
|
|
|
|
|
static rt_uint8_t index = 0 ;
|
|
|
|
|
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
|
|
|
|
{
|
2021-03-21 23:31:45 +08:00
|
|
|
|
if (event->type == RTGUI_EVENT_PAINT)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
struct rtgui_rect rect;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
|
|
|
|
if (dc == RT_NULL)
|
2013-01-08 22:40:58 +08:00
|
|
|
|
return RT_FALSE;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_widget_get_rect(widget, &rect);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
rect.x2 -= 1; rect.y2 -= 1;
|
|
|
|
|
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1);
|
|
|
|
|
rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2);
|
|
|
|
|
|
|
|
|
|
rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2);
|
|
|
|
|
rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2 + 1);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
|
|
|
|
/* shrink border */
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_rect_inflate(&rect, -1);
|
|
|
|
|
|
|
|
|
|
/* draw text */
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rtgui_widget_get_rect(widget, &rect);
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y1 += 25;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, " FM3 Easy Kit Demo", &rect);
|
|
|
|
|
rect.y1 += 10;
|
|
|
|
|
rtgui_dc_draw_text(dc, " rt-thread / RTGUI", &rect);
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_dc_end_drawing(dc, RT_TRUE);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
return RT_FALSE;
|
|
|
|
|
}
|
2013-01-08 22:40:58 +08:00
|
|
|
|
else if (event->type == RTGUI_EVENT_KBD)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
|
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
|
|
|
|
if (ekbd->type == RTGUI_KEYDOWN)
|
|
|
|
|
{
|
|
|
|
|
char key_str[16];
|
|
|
|
|
switch (ekbd->key)
|
|
|
|
|
{
|
|
|
|
|
case RTGUIK_LEFT:
|
|
|
|
|
rt_sprintf(key_str, "%s", "L");
|
|
|
|
|
break;
|
|
|
|
|
case RTGUIK_RIGHT:
|
|
|
|
|
rt_sprintf(key_str, "%s", "R");
|
|
|
|
|
break;
|
|
|
|
|
case RTGUIK_DOWN:
|
|
|
|
|
rt_sprintf(key_str, "%s", "D");
|
|
|
|
|
break;
|
|
|
|
|
case RTGUIK_UP:
|
|
|
|
|
rt_sprintf(key_str, "%s", "U");
|
2021-03-21 23:31:45 +08:00
|
|
|
|
break;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
default:
|
|
|
|
|
rt_sprintf(key_str, "%s", "S");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
2021-03-21 23:31:45 +08:00
|
|
|
|
if (dc == RT_NULL)
|
2013-01-08 22:40:58 +08:00
|
|
|
|
return RT_FALSE;
|
|
|
|
|
rect.x1 = 118;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y1 = 1;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rect.x2 = 127;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y2 = 10;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
rtgui_dc_draw_text(dc, key_str, &rect);
|
2017-11-12 22:05:26 +08:00
|
|
|
|
rtgui_dc_end_drawing(dc, RT_TRUE);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
else if (ekbd->type == RTGUI_KEYUP)
|
|
|
|
|
{
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
2021-03-21 23:31:45 +08:00
|
|
|
|
if (dc == RT_NULL)
|
2013-01-08 22:40:58 +08:00
|
|
|
|
return RT_FALSE;
|
|
|
|
|
rect.x1 = 118;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y1 = 1;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rect.x2 = 127;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y2 = 10;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
//rtgui_dc_draw_text(dc, key_str, &rect);
|
2017-11-12 22:05:26 +08:00
|
|
|
|
rtgui_dc_end_drawing(dc, RT_TRUE);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (event->type == RTGUI_EVENT_COMMAND)
|
|
|
|
|
{
|
|
|
|
|
char str[16];
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
|
struct rtgui_event_command* ecmd;
|
|
|
|
|
rt_uint8_t major,minor;
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
2021-03-21 23:31:45 +08:00
|
|
|
|
if (dc == RT_NULL)
|
2013-01-08 22:40:58 +08:00
|
|
|
|
return RT_FALSE;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
|
ecmd = (struct rtgui_event_command*)event;
|
|
|
|
|
switch (ecmd->command_id)
|
2021-03-21 23:31:45 +08:00
|
|
|
|
{
|
2013-01-08 22:40:58 +08:00
|
|
|
|
case ADC_UPDATE:
|
|
|
|
|
rect.x1 = 1;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y1 = 1;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rect.x2 = 117;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y2 = 10;
|
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
rt_sprintf(str, "ADC = %d mv", adc_value);
|
|
|
|
|
rtgui_dc_draw_text(dc, str, &rect);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
break;
|
|
|
|
|
case CPU_UPDATE:
|
|
|
|
|
cpu_usage_get(&major, &minor);
|
|
|
|
|
rect.x1 = 1;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y1 = 12;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rect.x2 = 127;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y2 = 22;
|
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
rt_sprintf(str, "CPU : %d.%d%", major, minor);
|
|
|
|
|
rtgui_dc_draw_text(dc, str, &rect);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rect.y1 = 23;
|
|
|
|
|
rect.y2 = 63;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
index++;
|
|
|
|
|
if (index == 127)
|
2021-03-21 23:31:45 +08:00
|
|
|
|
{
|
2013-01-08 22:40:58 +08:00
|
|
|
|
index = 1;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (major>40)
|
|
|
|
|
rtgui_dc_draw_vline(dc, index, rect.y1, rect.y2);
|
|
|
|
|
else
|
|
|
|
|
rtgui_dc_draw_vline(dc, index, rect.y2-major, rect.y2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_dc_end_drawing(dc, RT_TRUE);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
return rtgui_view_event_handler(widget, event);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void info_entry(void* parameter)
|
|
|
|
|
{
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rt_mq_t mq;
|
|
|
|
|
struct rtgui_view* view;
|
|
|
|
|
struct rtgui_workbench* workbench;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
mq = rt_mq_create("qInfo", 256, 4, RT_IPC_FLAG_FIFO);
|
|
|
|
|
rtgui_thread_register(rt_thread_self(), mq);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
workbench = rtgui_workbench_create("info", "workbench");
|
|
|
|
|
if(workbench == RT_NULL)
|
2013-01-08 22:40:58 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
view = rtgui_view_create("view");
|
|
|
|
|
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
|
2013-01-08 22:40:58 +08:00
|
|
|
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(view)) = black;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_workbench_add_view(workbench, view);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
/* this view can be focused */
|
|
|
|
|
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
|
|
|
|
/* set widget focus */
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_widget_focus(RTGUI_WIDGET(view));
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_view_show(view, RT_FALSE);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_workbench_event_loop(workbench);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
|
2021-03-21 23:31:45 +08:00
|
|
|
|
rtgui_thread_deregister(rt_thread_self());
|
|
|
|
|
rt_mq_delete(mq);
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rt_thread_t info_tid;
|
|
|
|
|
void info_init()
|
|
|
|
|
{
|
|
|
|
|
info_tid = rt_thread_create("info",
|
|
|
|
|
info_entry, RT_NULL,
|
|
|
|
|
2048, 25, 10);
|
|
|
|
|
|
|
|
|
|
if (info_tid != RT_NULL) rt_thread_startup(info_tid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rtgui_startup()
|
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t rect;
|
2021-03-21 23:31:45 +08:00
|
|
|
|
|
|
|
|
|
/* GUIϵͳ<CFB5><CDB3>ʼ<EFBFBD><CABC> */
|
2013-01-08 22:40:58 +08:00
|
|
|
|
rtgui_system_server_init();
|
2021-03-21 23:31:45 +08:00
|
|
|
|
|
2013-01-08 22:40:58 +08:00
|
|
|
|
/* register dock panel */
|
|
|
|
|
rect.x1 = 0;
|
|
|
|
|
rect.y1 = 0;
|
|
|
|
|
rect.x2 = 128;
|
|
|
|
|
rect.y2 = 64;
|
|
|
|
|
rtgui_panel_register("info", &rect);
|
|
|
|
|
rtgui_panel_set_default_focused("info");
|
2021-03-21 23:31:45 +08:00
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD>info workbench */
|
|
|
|
|
info_init();
|
2013-01-08 22:40:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|