当前位置:网站首页>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
边栏推荐
- June 12, 2022: if there are n*n pieces in an n*n square chessboard, each grid can have exactly one piece. But now some pieces are gathered on a grid, such as 2030100300. The above two-dimensional arra
- 面试必刷算法TOP101之单调栈 TOP31
- 景联文科技:数据标注行业现状及解决方案
- Vue3 route cache component status and set transition animation
- 不间断管理设计
- 【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
- MongoDB系列之SQL和NoSQL的区别
- The new business outlet of beautiful Tiantian second mode will be popular in the Internet e-commerce market
- MySQL系列之分库分表学习笔记
- 在 localStorage 中上传和检索存储图像
猜你喜欢

15、 IO stream (I)

Br tool backup recovery

百货中心供应链管理系统

智能文娱稳步发展,景联文科技提供数据采集标注服务

Yolov5 analysis | parameters and performance indicators

【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真

Computer network interview questions

WWDC2022最大的亮点: MetalFX

Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge

The innovative public platoon mode team invites users to split, beautiful every second, and links the 2+1 new business model
随机推荐
【RS-422与RS-485】RS-422与RS-485串行接口标准
TiDB Lightning
对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
FSM状态机
[Collection des questions d'examen les plus complètes de Tencent Ali] (quatre côtés: 3 tours de technologie + 1 tour de RH)
Brief introduction to basic usage of echart
[turn to] FPGA interview questions
基于SSM实现水果商城批发平台
Upper computer development (code debugging of firmware download software)
Detailed Mr Atlas of hip joint (Reprinted)
15、 IO stream (I)
上位机开发(固件下载软件之软件测试)
Byte (nine)
時間格式化工具----moment.js(網頁時間實時展示)
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard
Machine learning notes - supervised learning memo list
Test development programmers, are you still confused? You can't define yourself as a yard farmer
Uploading and retrieving stored images in localstorage
我的理财产品显示清算中是什么意思?
测试开发程序员,你还在迷茫吗?不能把自己定义为码农......