lvgl在PC上模拟自己的代码

背景

  • 使用官方VScode模拟器项目
  • 使用lvgl8.0代码
  • 使用macos系统
  • 也就是我仓库lvgl_sim_vscode前提之下

建立自己的代码文件

  1. 在lv_examples/src下新建文件夹lv_myapp
  2. lv_examples/src/lv_myapp新建lv_myapp.c和lv_myapp.h

lv_myapp.h中代码如下

/**
 * @file lv_myapp.h
 *
 */

#ifndef LV_MYAPP_H
#define LV_MYAPP_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 * GLOBAL PROTOTYPES
 **********************/
void lv_myapp(void);

/**********************
 *      MACROS
 **********************/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*LV_MYAPP_H*/

lv_myapp.c中代码如下

#include "../../lv_demo.h"

void lv_myapp(void)
{
    lv_obj_t *scr = lv_scr_act();
    lv_obj_t *label1 = lv_label_create(scr);
    lv_label_set_text(label1,"I am fzxhub!");
    lv_obj_align(label1,LV_ALIGN_CENTER,0,0);

}

引用自己头文件

在lv_examples/lv_demo.h中添加自己的头文件

#include "src/lv_demo_widgets/lv_demo_widgets.h"
#include "src/lv_demo_benchmark/lv_demo_benchmark.h"
#include "src/lv_demo_stress/lv_demo_stress.h"
#include "src/lv_demo_keypad_encoder/lv_demo_keypad_encoder.h"
#include "src/lv_demo_music/lv_demo_music.h"
#include "src/lv_myapp/lv_myapp.h"

在main.c中调用自己的代码

在hal_init();之后调用自己的函数即可,然后运行可查看效果。/

  /*Initialize LVGL*/
  lv_init();

  /*Initialize the HAL (display, input devices, tick) for LVGL*/
  hal_init();

//  lv_example_switch_1();
//  lv_example_calendar_1();
//  lv_example_btnmatrix_2();
//  lv_example_checkbox_1();
//  lv_example_colorwheel_1();
//  lv_example_chart_6();
//  lv_example_table_2();
//  lv_example_scroll_2();
//  lv_example_textarea_1();
//  lv_example_msgbox_1();
//  lv_example_dropdown_2();
//  lv_example_btn_1();
//  lv_example_scroll_1();
//  lv_example_tabview_1();
//  lv_example_tabview_1();
//  lv_example_flex_3();
//  lv_example_label_1();

//  lv_demo_widgets();
//  lv_demo_keypad_encoder();
//  lv_demo_benchmark();
//  lv_demo_stress();
//  lv_demo_music();
    lv_myapp();
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值