### start_timer example with timer event
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Example of starting a timer from a button click and handling the timer event to increment a value.
```xml
```
--------------------------------
### More array examples
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_array.md
Comprehensive example demonstrating various array operations: push, pop, clear, insert, remove, get, set, join, and printing size and capacity.
```js
var a = array_create()
assert(array_push(a,1,2,3) == 3)
assert(array_push(a,"a","b","c") == 3)
assert(array_pop(a), "c")
assert(array_pop(a), "b")
assert(array_pop(a), "a")
assert(array_pop(a), "3")
assert(array_pop(a), "2")
assert(array_pop(a), "1")
assert(value_is_valid(array_pop(a)))
assert(array_clear(a))
assert(a.size == 0)
assert(array_insert(a, 0, 'a'))
assert(array_insert(a, 1, 'b'))
assert(array_insert(a, 2, 'c'))
assert(array_insert(a, 3, 'd'))
assert(a.size == 4)
assert(array_remove(a, 0))
assert(array_get(a, 0) == 'b')
assert(array_set(a, 0, 'bbb'))
assert(array_get(a, 0) == 'bbb')
assert(array_set(a, 0, 'b'))
assert(array_get(a, 1) == 'c')
assert(array_set(a, 1, 'ccc'))
assert(array_get(a, 1) == 'ccc')
assert(array_set(a, 1, 'c'))
assert(array_join(a, ',') == 'b,c,d')
print(a.size, a.capacity)
```
--------------------------------
### Run preview_ui command
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/how_to_use_packed_image.md
Runs the preview_ui tool with the UI file to test the packed image example.
```bash
./bin/preview_ui design/default/ui/image_packed.xml
```
--------------------------------
### release.py usage and example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/scripts/README.md
Shows the usage and an example for the release tool release.py, which copies runtime files to the release directory. The example uses demoui.exe as the executable name.
```bash
python scripts/release.py [exe name]
```
```bash
python scripts/release.py demoui.exe
```
--------------------------------
### fs_get_disk_info() example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_fs.md
Example usage of fs_get_disk_info, retrieving disk info for "/sd" and printing free_kb and total_kb.
```js
var a = fs_get_disk_info("/sd");
print(join(": ","free_kb",a.free_kb));
print(join(": ","total_kb",a.total_kb));
```
--------------------------------
### send_key example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Example of sending key events from button clicks.
```xml
```
--------------------------------
### Install openmax_base library
Source: https://github.com/artinchip/luban-lite/blob/main/packages/artinchip/mpp/middle_media/base/CMakeLists.txt
Installs the openmax_base target to the full library directory when CMAKE_INSTALL_FULL_LIBDIR is defined.
```cmake
if(DEFINED CMAKE_INSTALL_FULL_LIBDIR)
install(TARGETS openmax_base RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
endif() # CMAKE_INSTALL_FULL_LIBDIR
```
--------------------------------
### choose_folder usage example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Example call to choose_folder with an initial directory, then prints the returned folder name.
```javascript
var foldername = choose_folder('./')
print(foldername)
```
--------------------------------
### widget_create example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Example of creating a label widget dynamically and setting its text and name properties.
```js
var a = widget_lookup('window', 'foobar', true)
if(value_is_null(a)) {
a = widget_create('label', 'window.view', 0, 0, 0, 0)
assert(!value_is_null(a))
widget_set(a, 'text', 'Dynamic created')
assert(widget_get(a, 'text') == 'Dynamic created')
widget_set(a, 'name', 'foobar')
assert(widget_get(a, 'name') == 'foobar')
} else {
print("foobar exist");
}
```
--------------------------------
### Install Resource Files to Board
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
Enable the file system image to install AWTK resource files to the board's /rodata directory. This is the default configuration and is required for the application to start normally.
```sh
Application options -->
[*] Using File System Image 0 -->
(packages/third-party/awtk-ui/user_apps/awtk-demo-chart/rtos_res/)
```
--------------------------------
### 启动 qemu
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
运行 start-qemu.sh 启动 qemu 模拟器。
```bash
./start-qemu.sh
```
--------------------------------
### choose_file usage example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Example call to choose_file with filters and initial directory, then prints the returned file name.
```javascript
var filename = choose_files('.png.jpg.gif', './')
print(filename)
```
--------------------------------
### 修改 start-qemu.sh 以支持调试
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
修改 start-qemu.sh,增加 -s -S 参数,使 qemu 启动 gdbserver 并等待 gdb 连接,用于调试内核。
```bash
#!/bin/sh
(
BINARIES_DIR="${0%/*}/"
cd ${BINARIES_DIR}
if [ "${1}" = "serial-only" ]; then
EXTRA_ARGS='-nographic'
else
EXTRA_ARGS='-serial stdio'
fi
export PATH="/opt/qemu/buildroot-2021.02.2/output/host/bin:${PATH}"
exec qemu-system-arm -M vexpress-a9 -smp 1 -m 256 -kernel zImage -dtb vexpress-v2p-ca9.dtb -drive file=rootfs.ext2,if=sd,format=raw -append "console=ttyAMA0,115200 rootwait root=/dev/mmcblk0" -net nic,model=lan9118 -net user ${EXTRA_ARGS} -s -S
)
```
--------------------------------
### array_size example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_array.md
Example usage of array_size: creates an array and gets its size.
```js
var a = array_create_with_str("2,1,3", ",", "int");
var b = array_size(a);
```
--------------------------------
### 开机自启动代码示例 (rk_run.c)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
根据 AWTK_START_UP 宏定义,决定开机自启动或通过 test_awtk 命令手动执行。
```c
#ifdef AWTK_START_UP
INIT_APP_EXPORT(awtk_init); /* 开机启动后执行 awtk_init函数 */
#else
MSH_CMD_EXPORT_ALIAS(awtk_init, test_awtk, awtk chart demo); /* test_awtk 是命令, 后面是说明 */
#endif
```
--------------------------------
### array_sum example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_array.md
Example usage of array_sum: creates an array from a string and gets its sum.
```js
var a = array_create_with_str("2,1,3", ",", "int");
var b = array_sum(a);
```
--------------------------------
### More file system examples
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_fs.md
Comprehensive examples covering file write, read, append, rename, copy, remove, stat, binary operations, path operations, and printing various paths.
```js
assert(file_write("test.txt", "hello"))
assert(file_exist("test.txt"))
assert(file_get_size("test.txt")==5)
assert(file_read_text("test.txt") == "hello")
assert(file_write_append("test.txt","world"))
assert(file_read_text("test.txt") == "helloworld")
assert(file_rename("test.txt","rename.txt"))
assert(!file_exist("test.txt"))
assert(file_read_text("rename.txt") == "helloworld")
assert(file_copy("rename.txt","copy.txt"))
assert(file_read_text("copy.txt") == "helloworld")
assert(file_remove("copy.txt"))
assert(!file_exist("copy.txt"))
var a = file_stat("rename.txt")
print(join(": ","dev",a.dev))
print(join(": ","ino",a.ino))
print(join(": ","mode",a.mode))
print(join(": ","nlink",a.nlink))
print(join(": ","uid",a.uid))
print(join(": ","rdev",a.rdev))
print(join(": ","size",a.size))
print(join(": ","atime",a.atime))
print(join(": ","mtime",a.mtime))
print(join(": ","ctime",a.ctime))
print(join(": ","is_dir",a.is_dir))
print(join(": ","is_link",a.is_link))
print(join(": ","is_reg_file",a.is_reg_file))
assert(file_remove("rename.txt"))
assert(!file_exist("rename.txt"))
assert(file_write("test.bin", "hello", 5))
assert(file_exist("test.bin"))
assert(file_get_size("test.bin")==5)
a = file_read_binary("test.bin")
assert(value_get_binary_size(a) == 5)
assert(file_remove("test.bin"))
assert(!file_exist("test.bin"))
assert(file_write("test.bin", a))
assert(file_exist("test.bin"))
assert(file_get_size("test.bin")==5)
assert(file_remove("test.bin"))
assert(path_create("a/b/c"))
assert(path_exist("a/b/c"))
assert(path_remove("a/b/c"))
assert(!path_exist("a/b/c"))
assert(path_rename("a/b","a/bbb"))
assert(!path_exist("a/b"))
assert(path_exist("a/bbb"))
assert(file_write("a/test.txt", "hello"))
a = path_list("a")
assert(a.size==2)
var b = array_get(a,0)
var c = array_get(a,1)
assert(b.name=="bbb")
assert(c.name=="test.txt")
assert(path_remove("a"))
assert(!path_exist("a"))
print(path_get_exe())
print(path_get_cwd())
print(path_get_temp())
print(path_get_app_root())
print(path_get_user_storage_root())
unset(a)
unset(b)
unset(c)
```
--------------------------------
### array_avg example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_array.md
Example usage of array_avg: creates an array from a string and gets its average value.
```js
var a = array_create_with_str("2,1,3", ",", "int");
var b = array_avg(a);
```
--------------------------------
### 创建工作目录
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
创建并切换到 /opt/qemu 目录,用于存放后续的 buildroot 和 AWTK 相关文件。需要将 yourusername.yourgroup 替换为实际用户和组。
```bash
sudo mkdir /opt/qemu
sudo chown yourusername.yourgroup /opt/qemu
cd /opt/qemu
```
--------------------------------
### array_max example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_array.md
Example usage of array_max: creates an array from a string and gets its maximum value.
```js
var a = array_create_with_str("2,1,3", ",", "int");
var b = array_max(a);
```
--------------------------------
### choose_files usage example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Example call to choose_files with filters and initial directory, then prints the size of the returned file list.
```javascript
var files = choose_files('.png.jpg.gif', './')
print(files.size)
```
--------------------------------
### Ubuntu 安装依赖(apt-get install)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/README_zh.md
在 Ubuntu(版本 >=16)上安装 scons 和依赖软件包。
```bash
sudo apt-get install gcc g++ scons libsndio-dev libgtk-3-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev libasound2-dev libibus-1.0-dev fcitx-libs-dev git vim clang-format libharfbuzz-dev nodejs libreadline-dev
```
--------------------------------
### path_get_user_storage_root() example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_fs.md
Example usage of path_get_user_storage_root, printing the user storage root path.
```js
print(path_get_user_storage_root());
```
--------------------------------
### CMake configuration for UFFS examples (static-mem-example and flash-if-example)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/uffs/src/example/CMakeLists.txt
Configures include and link directories for the UFFS example executables. Adds static-mem-example and flash-if-example targets, linking them against emu, uffs, emu, platform, and optionally pthread on UNIX. static-mem-example also links apitest_server.
```cmake
IF (UNIX)
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/platform/posix)
ENDIF()
IF (WIN32)
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/platform/win32)
ENDIF()
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/inc)
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/emu)
LINK_DIRECTORIES(${uffs_BINARY_DIR}/src/emu)
LINK_DIRECTORIES(${uffs_BINARY_DIR}/src/uffs)
SET(static_mem_SRCS static-mem-allocate.c)
SET(flash_if_SRCS flash-interface-example.c)
ADD_EXECUTABLE(static-mem-example ${static_mem_SRCS})
ADD_EXECUTABLE(flash-if-example ${flash_if_SRCS})
TARGET_LINK_LIBRARIES(static-mem-example emu uffs emu platform apitest_server)
TARGET_LINK_LIBRARIES(flash-if-example emu uffs emu platform)
IF (UNIX)
TARGET_LINK_LIBRARIES(static-mem-example pthread)
ENDIF ()
```
--------------------------------
### gradient_get_first_color
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/gradient_t.md
Gets the starting color of the gradient. Returns the color.
```APIDOC
## gradient_get_first_color
### Description
Gets the starting color of the gradient. Returns the color.
### Function Signature
```c
color_t gradient_get_first_color (const gradient_t* gradient);
```
### Parameters
- **gradient** (const gradient_t*) - Required - gradient对象。
### Return Value
- **color_t** - 返回颜色。
```
--------------------------------
### 进入 buildroot 输出目录
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
切换到 buildroot 生成的镜像目录。
```bash
cd /opt/qemu/buildroot-2021.02.2/output/images
```
--------------------------------
### Timer event handler example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Timer event example: starts a timer on click and increments a progress bar value until 100, then resets and stops the timer.
```xml
```
--------------------------------
### 设置断点并调试
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
在 gdb 中设置断点 start_kernel 并继续执行,开始调试内核。
```bash
b start_kernel
c
```
--------------------------------
### CMake configuration for lwIP example_app
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/lwip/contrib/ports/unix/example_app/CMakeLists.txt
Builds the example_app executable for the lwIP Unix port. Sets up include directories, compile options, and links against lwIP libraries. Requires the lwIP and contrib directories to be present.
```cmake
cmake_minimum_required(VERSION 3.8)
project(example_app C)
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(LWIP_CONTRIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../lwip)
include(${LWIP_CONTRIB_DIR}/ports/CMakeCommon.cmake)
set (LWIP_DEFINITIONS -DLWIP_DEBUG)
set (LWIP_INCLUDE_DIRS
"${LWIP_DIR}/src/include"
"${LWIP_CONTRIB_DIR}/"
"${LWIP_CONTRIB_DIR}/ports/unix/port/include"
"${LWIP_CONTRIB_DIR}/examples/example_app"
)
include(${LWIP_DIR}/src/Filelists.cmake)
include(${LWIP_CONTRIB_DIR}/Filelists.cmake)
include(${LWIP_CONTRIB_DIR}/ports/unix/Filelists.cmake)
add_executable(example_app ${LWIP_CONTRIB_DIR}/examples/example_app/test.c default_netif.c)
target_include_directories(example_app PRIVATE ${LWIP_INCLUDE_DIRS})
target_compile_options(example_app PRIVATE ${LWIP_COMPILER_FLAGS})
target_compile_definitions(example_app PRIVATE ${LWIP_DEFINITIONS} ${LWIP_MBEDTLS_DEFINITIONS})
target_link_libraries(example_app ${LWIP_SANITIZER_LIBS} lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcontribportunix lwipcore)
add_executable(makefsdata ${lwipmakefsdata_SRCS})
target_compile_options(makefsdata PRIVATE ${LWIP_COMPILER_FLAGS})
target_include_directories(makefsdata PRIVATE ${LWIP_INCLUDE_DIRS})
target_link_libraries(makefsdata ${LWIP_SANITIZER_LIBS})
```
--------------------------------
### time_now_us example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_date_time.md
Gets the current timestamp in microseconds.
```js
var a = time_now_us();
```
--------------------------------
### 运行 release.py 脚本打包项目
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/how_to_release_app.md
在项目目录(如 awtk-hello)中运行此命令,将可执行文件和运行时资源拷贝到当前目录的 release 子目录下。适用于 Linux、Windows、MacOS、Linux_FB,不适用于其它嵌入式系统;对于其它嵌入式系统,可拷贝资源到 T 卡并删除 release/bin 目录。
```bash
python ./scripts/release.py
```
--------------------------------
### 其他 scons 命令 (--run-qemu, --list-size, --pkgs-update)
Source: https://github.com/artinchip/luban-lite/blob/main/doc/luban-lite_user_guide_linux.md
运行 QEMU 目标文件(需先打开 chip->QEMU 配置)、列出所有 .o 文件的 section 大小、下载在线 packages。
```bash
$ cd luban-lite
$ scons --run-qemu // 运行当前编译出来的qemu目标文件,需要先打开chip->QEMU配置
$ scons --list-size // size 命令列出所有 .o 文件的 text/data/bss 各个 section 大小
$ scons --pkgs-update // 下载选择的在线 packages
```
--------------------------------
### time_now_ms example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_date_time.md
Gets the current timestamp in milliseconds.
```js
var a = time_now_ms();
```
--------------------------------
### date_time_get_prop example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_date_time.md
Creates a date object and gets its year property.
```js
var dt = date_time_create();
var year = date_time_get_prop(dt, "year");
```
--------------------------------
### 运行 demo
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_use_in_vmware.md
以管理员模式运行 demo,运行前确保 Ubuntu 以字符模式启动。
```bash
cd awtk-linux-fb
sudo release/bin/demoui
```
--------------------------------
### time_now/time_now_s example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_date_time.md
Gets the current timestamp in seconds using both functions.
```js
var a = time_now();
var b = time_now_s();
```
--------------------------------
### 选择 demo (chart demo 或 official demo)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
在 menuconfig 中选择要运行的 demo,默认使用 chart demo。
```sh
Local packages options -->
Third-party packages options-->
[*] AWTK GUI -->
Select a demo (Use the official demo) --->
(X) Use the chart demo
( ) Use the official demo
```
--------------------------------
### locale_get example: window_manager
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Gets the locale information for the window manager and prints the country and language.
```js
obj = locale_get('window_manager')
print(object_get(obj, 'country'))
print(object_get(obj, 'language'))
```
--------------------------------
### locale_get example: current widget
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Gets the locale information for the current widget and prints the country and language.
```js
obj = locale_get()
print(object_get(obj, 'country'))
print(object_get(obj, 'language'))
```
--------------------------------
### 下载并解压 buildroot
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
下载 buildroot 2021.02.2 并解压,然后进入其目录。
```bash
wget https://buildroot.org/downloads/buildroot-2021.02.2.tar.gz
tar xf buildroot-2021.02.2.tar.gz
cd buildroot-2021.02.2
```
--------------------------------
### preview_ui command example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Command to run preview_ui with a UI XML file.
```bash
./bin/preview_ui.exe design/default/ui/main_fscript.xml
```
--------------------------------
### conf_doc_get_ex
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/conf_doc_t.md
Gets the value of the node at the specified path, starting from a given node. Returns RET_OK on success, otherwise failure.
```APIDOC
## conf_doc_get_ex
### Description
Gets the value of the node at the specified path, starting from a given node.
### Function Signature
```c
ret_t conf_doc_get_ex (conf_doc_t* doc, conf_node_t* node, const char* path, value_t* v);
```
### Parameters
- **doc** (conf_doc_t*) - Required - Document object.
- **node** (conf_node_t*) - Required - Start searching from this node.
- **path** (const char*) - Required - Node path.
- **v** (value_t*) - Required - Used to return the value.
### Return Value
- **ret_t** - Returns RET_OK on success, otherwise failure.
```
--------------------------------
### 编译 buildroot
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
使用 make -j4 编译 buildroot,编译时间较长,需要耐心等待。
```bash
make -j4
```
--------------------------------
### 编辑 grub.cfg 文件
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/vmware_linux_fb.md
使用 vim 编辑 /boot/grub/grub.cfg 以添加自定义启动菜单项。需要 sudo 权限。
```bash
sudo vim /boot/grub/grub.cfg
```
--------------------------------
### Set App Resource Root to /rodata/res
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
Configure the AWTK resource root path to /rodata/res when resources are installed on the board.
```sh
Local packages options -->
Third-party packages options-->
[*] AWTK GUI -->
AWTK common function config -->
(/rodata/res) Set app resource root
```
--------------------------------
### tk_skip_to_num
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/utils_t.md
Skips non-numeric characters in a string and returns the substring starting at the first digit. For example, 'hello123world' returns '123world'.
```APIDOC
## tk_skip_to_num
### Description
Skips non-numeric characters in a string and returns the substring starting at the first digit. For example, 'hello123world' returns '123world'.
### Method
Function
### Signature
`tk_skip_to_num`
### Parameters
- **str** (string) - Required - Input string.
### Return Value
Pointer to the substring starting at the first digit.
```
--------------------------------
### 预览界面描述文件命令 preview_ui
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/demos/README.md
用于预览界面描述文件,示例命令为 ./bin/preview_ui demos/assets/default/raw/ui/main.xml。
```bash
./bin/preview_ui demos/assets/default/raw/ui/main.xml
```
--------------------------------
### C: Close non-modal dialog with window_close
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/dialog_t.md
Use window_close to close a non-modal dialog. The example shows a button click handler that gets the window and calls window_close.
```c
static ret_t on_dialog_btn_click(void* ctx, event_t* evt) {
widget_t* win = widget_get_window(WIDGET(evt->target));
int code = (char*)ctx - (char*)NULL;
window_close(win);
return RET_OK;
}
```
--------------------------------
### Build player_demo executable with CMake
Source: https://github.com/artinchip/luban-lite/blob/main/packages/artinchip/mpp/middle_media/player/CMakeLists.txt
Builds the player_demo executable from player_demo.c, links against base, openmax, media_player, and pthread, sets INSTALL_RPATH to /usr/local/lib, and installs to CMAKE_INSTALL_FULL_BINDIR if defined.
```cmake
include_directories(./include ../base/include ../../base/include)
add_executable(player_demo player_demo.c)
target_link_libraries(player_demo base openmax media_player)
target_link_libraries(player_demo pthread)
set_target_properties(player_demo PROPERTIES INSTALL_RPATH "/usr/local/lib")
#install(TARGETS mpp_test RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(DEFINED CMAKE_INSTALL_FULL_LIBDIR)
install(TARGETS player_demo RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
endif() # CMAKE_INSTALL_FULL_LIBDIR
```
--------------------------------
### Disable File System Image for SD Card
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
Disable the file system image when reading resource files from an SD card instead of installing them to the board.
```sh
Application options -->
[] Using File System Image 0 -->
```
--------------------------------
### C: Close modal dialog with dialog_quit
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/dialog_t.md
Use dialog_quit to close a modal dialog. The example shows a button click handler that gets the window and calls dialog_quit with a code.
```c
static ret_t on_dialog_btn_click(void* ctx, event_t* evt) {
widget_t* win = widget_get_window(WIDGET(evt->target));
int code = (char*)ctx - (char*)NULL;
dialog_quit(win, code);
return RET_OK;
}
```
--------------------------------
### CMake build configuration for example_app and makefsdata
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/lwip/contrib/ports/win32/example_app/CMakeLists.txt
Defines the CMake project for the LWIP example application on Windows. Sets include directories, compiles example_app and makefsdata executables, and links required LWIP libraries.
```cmake
cmake_minimum_required(VERSION 3.8)
project(example_app C)
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(LWIP_CONTRIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../lwip)
include(${LWIP_CONTRIB_DIR}/ports/CMakeCommon.cmake)
set (LWIP_DEFINITIONS -DLWIP_DEBUG)
set (LWIP_INCLUDE_DIRS
"${LWIP_DIR}/src/include"
"${LWIP_CONTRIB_DIR}/"
"${LWIP_CONTRIB_DIR}/ports/win32/include"
"${LWIP_CONTRIB_DIR}/examples/example_app"
)
include(${LWIP_DIR}/src/Filelists.cmake)
include(${LWIP_CONTRIB_DIR}/Filelists.cmake)
include(${LWIP_CONTRIB_DIR}/ports/win32/Filelists.cmake)
add_executable(example_app ${LWIP_CONTRIB_DIR}/examples/example_app/test.c default_netif.c)
target_include_directories(example_app PRIVATE ${LWIP_INCLUDE_DIRS})
target_compile_options(example_app PRIVATE ${LWIP_COMPILER_FLAGS})
target_compile_definitions(example_app PRIVATE ${LWIP_DEFINITIONS} ${LWIP_MBEDTLS_DEFINITIONS})
target_link_libraries(example_app ${LWIP_SANITIZER_LIBS} lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcore lwipcontribportwindows)
add_executable(makefsdata ${lwipmakefsdata_SRCS})
target_compile_options(makefsdata PRIVATE ${LWIP_COMPILER_FLAGS})
target_include_directories(makefsdata PRIVATE ${LWIP_INCLUDE_DIRS})
target_link_libraries(makefsdata ${LWIP_SANITIZER_LIBS} lwipcore lwipcontribportwindows)
```
--------------------------------
### UI file for packed image example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/how_to_use_packed_image.md
Defines a window with a view using the 'image_packed' style and 12 buttons with styles num_1 to num_9, dot, num_0, and backspace.
```xml
```
--------------------------------
### 应用分辨率设置
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
使用 fbset 命令使分辨率配置生效。
```bash
fbset 640x480-60
```
--------------------------------
### 生成 release 版本
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_run_awtk_in_qemu.md
运行 release.sh 生成发布版本。
```bash
./release.sh
```
--------------------------------
### Relative include of header in number_label.c
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/custom_widget_rules.md
Use a relative path when including a header file from the same directory to avoid requiring an include directory setup at compile time. The example shows including 'number_label.h' from 'number_label.c'.
```c
#include "number_label.h"
```
--------------------------------
### Specify sub-image with absolute coordinates
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/how_to_use_packed_image.md
Uses xywh(x,y,w,h) to specify the absolute coordinates of the sub-image. For example, xywh(106,0,106,54) sets the sub-image region to (106,0,106,54).
```xml
```
--------------------------------
### 编译 demo 并抽取资源文件
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_use_in_vmware.md
确保 awtk 和 awtk-linux-fb 在同一级目录,然后执行编译和资源抽取。
```bash
cd awtk-linux-fb
scons
sh release.sh
```
--------------------------------
### FSDEV DP Pull-up Register Configuration
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/cherryusb/docs/source/porting_usbip.rst
Enables the DP pull-up for FSDEV USB IP. Some chips require setting a register instead of an external resistor. This example sets the USB_BCDR_DPPU bit in the BCDR register.
```C
USB->BCDR |= (uint16_t)USB_BCDR_DPPU;
```
--------------------------------
### Style file for packed image example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/how_to_use_packed_image.md
Defines button styles with pressed backgrounds using various sub-image specifications, and a view style using the background image. Demonstrates default usage and explicit xywh/grid methods.
```xml
```
```xml
```
--------------------------------
### window_base_on_paint_begin
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/window_base_t.md
窗口on_paint_begin函数的缺省实现。该函数在绘制开始时调用。
```APIDOC
## window_base_on_paint_begin
### Description
窗口on_paint_begin函数的缺省实现。
### Method
N/A (C function)
### Endpoint
N/A
### Parameters
N/A
### Request Example
N/A
### Response
N/A
### Response Example
N/A
```
--------------------------------
### 开机自启动配置
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
在 menuconfig 中启用开机自启动功能。若未启用,需在命令行输入 test_awtk 手动执行应用。
```sh
Local packages options -->
Third-party packages options-->
[*] AWTK GUI -->
AWTK common function config -->
[*] Self start funcion upon startup
```
--------------------------------
### Inline style property syntax in XML UI files
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/theme.md
In XML UI files, control properties starting with 'style.' define inline styles. The format is 'style.状态.名称' where state can be omitted to mean normal. Example: 'style.normal.font_size="16"' sets the font size for the normal state.
```xml
style.状态.名称
```
```xml
style.normal.font_size="16"
```
```xml
style.font_size="16"
```
--------------------------------
### Bind to network interface and connect to server
Source: https://github.com/artinchip/luban-lite/blob/main/kernel/rt-thread/documentation/sal/sal.md
Complete example that gets a netdev object by name, creates a socket, binds to the interface's IP address, connects to a server, and closes the socket. Exports the 'bing_test' command to MSH. Requires including rtthread.h, arpa/inet.h, and netdev.h.
```c
#include
#include
#include
#define SERVER_HOST "192.168.1.123"
#define SERVER_PORT 1234
static int bing_test(int argc, char **argv)
{
struct sockaddr_in client_addr;
struct sockaddr_in server_addr;
struct netdev *netdev = RT_NULL;
int sockfd = -1;
if (argc != 2)
{
rt_kprintf("bind_test [netdev_name] --bind network interface device by name.\n");
return -RT_ERROR;
}
/* Get the netdev network interface card object by name */
netdev = netdev_get_by_name(argv[1]);
if (netdev == RT_NULL)
{
rt_kprintf("get network interface device(%s) failed.\n", argv[1]);
return -RT_ERROR;
}
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
rt_kprintf("Socket create failed.\n");
return -RT_ERROR;
}
/* Initializes the client address to bind to */
client_addr.sin_family = AF_INET;
client_addr.sin_port = htons(8080);
/* Gets the IP address information in the network interface card object */
client_addr.sin_addr.s_addr = netdev->ip_addr.addr;
rt_memset(&(client_addr.sin_zero), 0, sizeof(client_addr.sin_zero));
if (bind(sockfd, (struct sockaddr *)&client_addr, sizeof(struct sockaddr)) < 0)
{
rt_kprintf("socket bind failed.\n");
closesocket(sockfd);
return -RT_ERROR;
}
rt_kprintf("socket bind network interface device(%s) success!\n", netdev->name);
/* Initializes the server address for the pre-connection */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(SERVER_PORT);
server_addr.sin_addr.s_addr = inet_addr(SERVER_HOST);
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
/* Connect to the server */
if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) < 0)
{
rt_kprintf("socket connect failed!\n");
closesocket(sockfd);
return -RT_ERROR;
}
else
{
rt_kprintf("socket connect success!\n");
}
/* Close the connection */
closesocket(sockfd);
return RT_EOK;
}
#ifdef FINSH_USING_MSH
#include
MSH_CMD_EXPORT(bing_test, bind network interface device test);
#endif /* FINSH_USING_MSH */
```
--------------------------------
### 用 git 下载 AWTK 代码
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/README_zh.md
克隆 AWTK 仓库。国内用户可使用镜像地址 https://hub.fastgit.org/zlgopen/awtk.git。
```bash
git clone https://github.com/zlgopen/awtk.git
```
--------------------------------
### window_set_fullscreen
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/window_t.md
Sets the window to fullscreen. Returns RET_OK on success, otherwise failure.
```APIDOC
## window_set_fullscreen
### Description
Sets the window to fullscreen. Returns RET_OK on success, otherwise failure.
### Function Signature
```c
ret_t window_set_fullscreen (widget_t* widget, bool_t fullscreen);
```
### Parameters
- **widget** (widget_t*) - Required - Window widget.
- **fullscreen** (bool_t) - Required - Whether to set fullscreen.
### Return Value
- **ret_t** - Returns RET_OK on success, otherwise failure.
```
--------------------------------
### widget_start_animator
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/widget_animator.md
Starts or resumes an animation. If widget is NULL, starts all animations with the given name; if name is NULL, starts all animations for the widget; if both are NULL, starts all animations.
```APIDOC
## widget_start_animator
### Description
Starts or resumes an animation. If widget is NULL, starts all animations with the given name; if name is NULL, starts all animations for the widget; if both are NULL, starts all animations.
### Method
Function
### Signature
ret_t widget_start_animator(widget_t* widget, const char* name);
### Parameters
- **widget** (widget_t*) - Required - The widget object.
- **name** (const char*) - Required - Animation name.
### Return Value
- **ret_t** - Returns RET_OK on success, otherwise failure.
### Example
```c
widget_start_animator(NULL, NULL);
```
```
--------------------------------
### 切换到桌面模式
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk-rtos/docs/how_to_use_in_vmware.md
在字符模式下执行,重启后进入桌面模式。
```bash
sudo systemctl set-default graphical.target
sudo reboot
```
--------------------------------
### 使用自定义头部发送 GET 请求
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/webclient/docs/user-guide.md
在发送 GET 请求前,通过 webclient_header_fields_add 添加自定义头部(如 User-Agent),其余流程与默认 GET 相同。
```c
struct webclient_session *session = NULL;
session = webclient_create(1024);
webclient_header_fields_add(session, "User-Agent: RT-Thread HTTP Agent\r\n");
if(webclient_get(session, URI) != 200)
{
LOG_E("error!");
}
while(1)
{
webclient_read(session, buffer, bfsz);
...
}
webclient_close(session);
```
--------------------------------
### Mac 安装依赖(brew install scons sdl2 node)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/README_zh.md
在 Mac 上安装 nodejs、scons 和 sdl2,假定已安装 brew。
```bash
brew install scons sdl2 node
```
--------------------------------
### GET 请求示例 MSH 命令输出
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/webclient/docs/samples.md
在 MSH 中执行 web_get_test 命令,使用默认接口发送 GET 请求并打印响应数据;执行 web_get_test -s 使用简化接口(webclient_request)发送 GET 请求,适用于简短数据收发。
```c
msh />web_get_test
webclient get response data:
RT-Thread is an open source IoT operating system from China, which has strong scalability: from a tiny kernel running on a tiny core, for example ARM Cortex-M0, or Cortex-M3/4/7, to a rich feature system running on MIPS32, ARM Cortex-A8, ARM Cortex-A9 DualCore etc.
msh />web_get_test -s
webclient send get request by simplify request interface.
webclient get response data:
RT-Thread is an open source IoT operating system from China, which has strong scalability: from a tiny kernel running on a tiny core, for example ARM Cortex-M0, or Cortex-M3/4/7, to a rich feature system running on MIPS32, ARM Cortex-A8, ARM Cortex-A9 DualCore etc.
msh />
```
--------------------------------
### 实现 application_init 函数
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/awtk_main.md
定义 AWTK 应用初始化逻辑,返回 RET_OK 表示成功。
```c
ret_t application_init() {
/*do sth.*/
return RET_OK;
}
```
--------------------------------
### Install openmax library
Source: https://github.com/artinchip/luban-lite/blob/main/packages/artinchip/mpp/middle_media/openmax/CMakeLists.txt
Installs the openmax target to the full library directory when CMAKE_INSTALL_FULL_LIBDIR is defined. This makes the built library available for installation.
```cmake
if(DEFINED CMAKE_INSTALL_FULL_LIBDIR)
install(TARGETS openmax RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
endif() # CMAKE_INSTALL_FULL_LIBDIR
```
--------------------------------
### V1.0.0 GET 请求流程(字符串拼接头部)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/webclient/docs/migration-guide.md
V1.0.0 版本发送 GET 请求的旧流程,使用字符串拼接方式添加头部数据,需要手动创建会话结构体、连接、发送头部、处理响应、读取数据并关闭连接。
```c
/* 字符串处理方式拼接头部数据 */
const char header = "xxx";
struct webclient_session *session = RT_NULL;
session = web_malloc(sizeof(struct webclient_session))
webclient_connect(session, URI);
webclient_send_header(session, WEBCLIENT_GET, header, strlen(header));
webclient_handle_response(session);
while(1)
{
webclient_read(session, post_data ,strlen(post_data));
...
}
webclient_close(session);
```
--------------------------------
### theme_get example: window_manager
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_widget.md
Prints the theme of the window manager.
```js
print(theme_get('window_manager'))
```
--------------------------------
### 发送获取部分数据的 GET 请求(Range)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/webclient/docs/user-guide.md
用于断点续传或分片下载。先连接,再添加 Range 头部指定字节范围,然后发送 GET 头部,读取响应数据。
```c
struct webclient_session *session = NULL;
session = webclient_create(1024);
webclient_connect(session, URI);
webclient_header_fields_add(session, "Range: bytes=%d-%d\r\n", 0, 99);
webclient_send_header(session, WEBCLIENT_GET);
while(1)
{
webclient_read(session, buffer, bfsz);
...
}
webclient_close(session);
```
--------------------------------
### 选择 LCD 刷新模式 (swap_ex mode)
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/README.md
在 menuconfig 中选择 LCD 刷新模式,默认使用 swap_ex 模式,推荐使用。
```sh
Local packages options -->
Third-party packages options-->
[*] AWTK GUI -->
AWTK common function config -->
Select lcd refresh mode (swap_ex mode) --->
```
--------------------------------
### 使用 get 函数判断变量有效性
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript.md
使用 get 函数获取变量,配合 value_is_valid 判断变量是否存在。
```js
print("abc is valid? ", value_is_valid(get(abc)))
var abc=123
print("abc is valid? ", value_is_valid(get(abc)))
print(get(abc) + 321)
```
--------------------------------
### Install dependencies with npm install
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/tools/word_gen/README.md
Run in the current directory to install required Node.js dependencies before generating word data.
```bash
npm install
```
--------------------------------
### widget_init
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/manual/widget_t.md
初始化控件。仅在子类控件构造函数中使用。
```APIDOC
## widget_init
### Description
初始化控件。仅在子类控件构造函数中使用。
### Method
N/A
### Endpoint
N/A
### Parameters
N/A
### Request Example
N/A
### Response
N/A
### Response Example
N/A
```
--------------------------------
### 使用默认头部发送 GET 请求
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/webclient/docs/user-guide.md
使用 webclient_create 创建会话,webclient_get 发送 GET 请求并检查状态码,循环读取响应数据,最后关闭会话。
```c
struct webclient_session *session = NULL;
session = webclient_create(1024);
if(webclient_get(session, URI) != 200)
{
LOG_E("error!");
}
while(1)
{
webclient_read(session, buffer, bfsz);
...
}
webclient_close(session);
```
--------------------------------
### cksum example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_crc.md
Example call to cksum with a string argument.
```js
cksum("hello")
```
--------------------------------
### crc32 example
Source: https://github.com/artinchip/luban-lite/blob/main/packages/third-party/awtk-ui/awtk/docs/fscript_crc.md
Example call to crc32 with a string argument.
```js
crc32("hello")
```