当前位置:网站首页>RT thread simulator lvgl control: switch switch button control
RT thread simulator lvgl control: switch switch button control
2022-06-13 06:59:00 【Zhangshizheng】
Preface
switch button : Switch button control , It also uses a lot , Here, I am familiar with the relevant operations
switch There are two states : On and off
Environment building
RT-Thread 4.1.0 Or the latest version
BSP Simulator simulator
LVGL software package
function
- LVGL Draw a picture Switch Switch button , Draw a picture The label shows the status of the switch button
Operation method
Here it is LVGL In the official routine , eureka switch Operation of space , A little familiar with Related large API, To write switch Button test code
Storage location :
simulator\applications\lvgl\demo\lv_switch_01.c
, The code is as follows
#include <rtthread.h>
#include <lvgl.h>
static lv_obj_t *lbl_status = NULL;
static void sw_event_cb(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *sw = lv_event_get_target(e);
if (lv_obj_has_state(sw, LV_STATE_CHECKED))
{
rt_kprintf("%s : power on \r\n", __func__);
lv_label_set_text(lbl_status, "ON");
lv_obj_align_to(lbl_status, sw, LV_ALIGN_OUT_RIGHT_MID, 20, 0); /*Align top of the slider*/
}
else
{
lv_label_set_text(lbl_status, "OFF");
lv_obj_align_to(lbl_status, sw, LV_ALIGN_OUT_RIGHT_MID, 20, 0); /*Align top of the slider*/
rt_kprintf("%s : power off \r\n", __func__);
}
}
/** * Show an example to switch button */
void lv_switch_01_init(void)
{
static rt_bool_t power_flag = RT_FALSE;
lv_obj_t *sw = lv_switch_create(lv_scr_act());
lv_obj_align(sw, LV_ALIGN_TOP_LEFT, 50, 20);
lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_clear_state(sw, LV_STATE_CHECKED);
/* Create a label */
lbl_status = lv_label_create(lv_scr_act());
lv_label_set_text(lbl_status, "OFF");
lv_obj_align_to(lbl_status, sw, LV_ALIGN_OUT_RIGHT_MID, 20, 0);
}
- Call location :
simulator\packages\LVGL-latest\env_support\rt-thread\lv_rt_thread_port.c
, It can also be placed in other places , Add the code file to visual studio 2022 In our project
Compile and run 
- Add to RT-Thread Simulator Visual Studio 2022 In our project , Compile and run , The effect is as follows :
switch Switch button API
Set up switch Default on state :
lv_obj_add_state(sw, LV_STATE_CHECKED);
Set up switch Off by default ( gray ) state :
lv_obj_clear_state(sw, LV_STATE_CHECKED);
switch Whether it is on :
lv_obj_has_state(sw, LV_STATE_CHECKED)
Set up switch State change callback function :
lv_obj_add_event_cb(sw, sw_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
Summary
Switch button Switch Widely used , Such as some power control, etc
Use RT-Thread Simulator debugging LVGL, More efficient and convenient , And related code , It is easy to transplant to embedded hardware circuit board
边栏推荐
- Vue3 route cache component status and set transition animation
- Tidb index optimization
- [system analysis and design] college student association management system
- 杭州网上开户是安全的吗?
- Brief introduction to basic usage of echart
- 景联文科技提供一站式智能家居数据采集标注解决方案
- ML:机器学习模型的稳定性分析简介、常见的解决方法之详细攻略
- Upper computer development (software test of firmware download software)
- Computer network interview questions
- 我的理财产品显示清算中是什么意思?
猜你喜欢
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard
髋关节MR详细图谱(转载)
How to use Wangyou DFM software for cold plate analysis
测试开发程序员,你还在迷茫吗?不能把自己定义为码农......
The causes of font and style enlargement when the applet is horizontal have been solved
【RS-422与RS-485】RS-422与RS-485串行接口标准
Yolov5 analysis | parameters and performance indicators
智能文娱稳步发展,景联文科技提供数据采集标注服务
十五、IO流(一)
[SketchUp 2021] sketch master's image output and rendering style description [edge setting, plane setting, background setting, watermark setting, modeling setting, sky background creating sky, creatin
随机推荐
【转】FPGA面试题
Gold jewelry enterprise operation mode, beautiful tiantians business solution
Xiaomi's one-sided interview questions (self sorting answers)
Jfinal uses freemaker to output map.
What is the new business model of Taishan crowdfunding in 2022?
1154. 一年中的第几天
Pngquant batch bat and parameter description
Introduction and use of dumping
杭州网上开户是安全的吗?
[cloud native | kubernetes] kubernetes configuration
Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?
数字时代进化论
[turn to] FPGA interview questions
[SketchUp 2021] sketch master's image output and rendering style description [edge setting, plane setting, background setting, watermark setting, modeling setting, sky background creating sky, creatin
Smart finance is upgraded again, and jinglianwen technology provides data collection and labeling services
That is, after the negative impact of gcat advertising e-commerce, is there no stable advertising e-commerce platform?
How to make a development board from scratch? Illustrated and illustrated, step by step operation for you to see.
If the key in redis data is in Chinese
[system analysis and design] college student association management system
【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真