### 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 ``` -------------------------------- ### 设置断点并调试 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 ``` -------------------------------- ### 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") ```