当前位置:网站首页>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
边栏推荐
- If the key in redis data is in Chinese
- 【马尔科夫链-蒙特卡罗】马尔科夫链-蒙特卡罗方法对先验分布进行抽样
- 智能金融再升级,景联文科技提供数据采集标注服务
- [weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background
- Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?
- 10 Honest Facts I Want To Share With All Junior Developers
- Recently, the popular social e-commerce marketing model, blind box e-commerce, how beautiful every second is accurately drained
- Detailed Mr Atlas of hip joint (Reprinted)
- Cocos released the oppo game prompt "subcontracting failed"
- 2022-06-12:在N*N的正方形棋盤中,有N*N個棋子,那麼每個格子正好可以擁有一個棋子。 但是現在有些棋子聚集到一個格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二維數組代錶,一
猜你喜欢
![[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](/img/95/a86b461c547bab41b2053073275d24.png)
[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

NFV基本概述

微隔离(MSG)

The causes of font and style enlargement when the applet is horizontal have been solved

How to make a development board from scratch? Illustrated and illustrated, step by step operation for you to see.

Byte (nine)

Tidb statistics

Jinglianwen Technology: current situation and solutions of data annotation industry

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

Tidb index optimization
随机推荐
学习Mysql基础第一天
Host computer development (Architecture Design of firmware download software)
Tidb implementation plan -- I
As the new trend of blind box e-commerce, how can the platform use blind box play to drain at low cost?
Why does TCP establish three handshakes and four waves
The new retail market has set off blind box e-commerce. Can the new blind box marketing model bring dividends to businesses?
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard
Application of DS18B20 temperature sensor based on FPGA
Soup side (8)
New Taishan crowdfunding business diversion fission growth model in 2022
Byte (nine)
如何从头自己制作开发板?图文并茂,一步步操作给你看。
树莓派高级开发——“IO口驱动代码的编写“ 包含总线地址、物理_虚拟地址、BCM2835芯片手册知识
尝试使用RenderDoc查看UE的Shader代码
Yolov5 analysis | parameters and performance indicators
JS case Xiaomi second kill countdown New Year Countdown
Br tool backup recovery
Can flush open a stock account? Is it safe?
Intelligent entertainment has developed steadily, and jinglianwen technology provides data collection and labeling services
AIO Introduction (VIII)