b_mod_gui

数据结构

typedef struct bGUIStruct
{
    const uint32_t     lcd_dev_no;
    const uint32_t     touch_dev_no;
    const int          touch_type;
    const uint16_t     lcd_x_size;
    const uint16_t     lcd_y_size;
    uint8_t            lcd_disp_dir;
    uint16_t           touch_ad_x[2];
    uint16_t           touch_ad_y[2];
    UG_GUI             gui_handle;
    struct bGUIStruct *pnext;
} bGUIStruct_t;

typedef bGUIStruct_t bGUIInstance_t;

#define TOUCH_TYPE_RES (0)
#define TOUCH_TYPE_CAP (1)

#define LCD_DISP_H (0)
#define LCD_DISP_V (1)

#define bGUI_ADD_DEVICE(_lcd_dev_no, _touch_dev_no, _x_size, _y_size, _touch_type) \
    static bGUIInstance_t gui_##_lcd_dev_no = {                                    \
        .lcd_dev_no   = _lcd_dev_no,                                               \
        .touch_dev_no = _touch_dev_no,                                             \
        .touch_type   = _touch_type,                                               \
        .lcd_x_size   = _x_size,                                                   \
        .lcd_y_size   = _y_size,                                                   \
        .pnext        = NULL,                                                      \
    };                                                                             \
    bGUIRegist(&gui_##_lcd_dev_no);

接口介绍

此模块支持多个屏使用uGUI。UI设计使用ugui.h文件提供的接口。

// 建议不要直接调用此接口,使用 bGUI_ADD_DEVICE 代替
int bGUIRegist(bGUIInstance_t *pInstance);

// 通过屏的dev_no获取GUI句柄
int bGUIGetHandle(uint32_t lcd_dev_no, UG_GUI **p_gui_handle);

// 选择当前操作的目标
int bGUISelect(uint32_t lcd_dev_no);

// 设置电阻屏触摸的AD值范围
int bGUITouchRange(uint32_t lcd_dev_no, uint16_t x_ad_min, uint16_t x_ad_max, uint16_t y_ad_min,
                   uint16_t y_ad_max);

// 设置屏幕显示方向,默认是LCD_DISP_V
int bGUIDispDir(uint32_t lcd_dev_no, uint8_t dir);

// 如果将汉字字库存放在FLASH,通过此接口传入dev_no
int bGUISetFontDevice(uint32_t dev_no);

使用例子

void TouchTest()
{
    UG_GUI *p_gui = NULL;
    bGUIGetHandle(bTFT, &p_gui);
    if (p_gui)
    {
        if (p_gui->touch.state == TOUCH_STATE_PRESSED)
        {
            b_log("x:%d y:%d \r\n", p_gui->touch.xp, p_gui->touch.yp);
        }
    }
}

int main()
{
    ......
    bInit();
    bGUI_ADD_DEVICE(bTFT, bTOUCH, 240, 320, TOUCH_TYPE_RES);
    bGUI_ADD_DEVICE(bOLED, NULL, 128, 64, 0);

    bGUITouchRange(bTFT, 476, 3952, 338, 3592);

    bGUISelect(bTFT);
    UG_FillScreen(C_BLACK);
    UG_PutString(0, 0, "hello world");
    UG_PutString(0, 100, "babyos ssd1289");
    bGUISelect(bOLED);
    UG_FillScreen(0);
    UG_PutString(0, 0, "hello world");
    UG_PutString(0, 20, "babyos oled");
    bGUISelect(bTFT);
    bGUIDispDir(bTFT, LCD_DISP_H);
    UG_PutString(0, 20, "babyos oled tft");
    while (1)
    {
        bExec();
        //测试触摸
        BOS_PERIODIC_TASK(TouchTest, 500);
    }
}