### Hello World Label Example (C) Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/get_started/index.rst Demonstrates a basic 'hello world' label implementation. This is a foundational example for getting started with UI elements. ```c #include "lv_examples.h" void lv_example_get_started_1(void) { /*Create a label*/ lv_obj_t * label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "Hello world!"); lv_obj_align_center(label, LV_ALIGN_CENTER); } ``` -------------------------------- ### Install LVGL Prerequisites (Linux) Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/tests/README.md Installs the necessary prerequisites for running LVGL tests on a Linux environment. ```sh ./scripts/install-prerequisites.sh ``` -------------------------------- ### TuyaOpen Contribution Guide Source: https://github.com/tuya/tuyaopen/blob/master/README.md Provides instructions for contributing to the TuyaOpen project. It guides potential contributors on how to get started and follow the project's development practices. ```markdown If you are interested in the TuyaOpen and wish to contribute to its development and become a code contributor, please first read the [Contribution Guide](https://tuyaopen.ai/docs/contribute/contribute-guide). ``` -------------------------------- ### Kconfig Configuration Example Source: https://github.com/tuya/tuyaopen/blob/master/boards/add_new_board.md Illustrates how to configure chip choice, board name, board config, and audio driver name within a Kconfig file for menuconfig. ```kconfig # CHIP_CHOICE 为开发板的芯片 # BOARD_CHOICE 为开发板的名称 # BOARD_CONFIG 为选择需要的板级模块 # AUDIO_DRIVER_NAME 为 audio codec 名字 ``` -------------------------------- ### Board Configuration Example (C) Source: https://github.com/tuya/tuyaopen/blob/master/boards/add_new_board.md Defines display types and configures the board's display and I/O expander. ```c // lcd #define DISPLAY_TYPE_UNKNOWN 0 #define DISPLAY_TYPE_OLED_SSD1306 1 #define DISPLAY_TYPE_LCD_SH8601 2 #define BOARD_DISPLAY_TYPE DISPLAY_TYPE_OLED_SSD1306 // io expander #define IO_EXPANDER_TYPE_UNKNOWN 0 #define IO_EXPANDER_TYPE_TCA9554 1 #define BOARD_IO_EXPANDER_TYPE IO_EXPANDER_TYPE_UNKNOWN ``` -------------------------------- ### HTTP Example Execution Log Source: https://github.com/tuya/tuyaopen/blob/master/examples/protocols/mqtt_client/README_CN.md This C code snippet displays the execution log of an example demonstrating the native HTTP interface. It shows the steps of starting an MQTT client, connecting to a broker, subscribing to a topic, publishing messages, and receiving acknowledgments. ```c [01-02 04:09:16 ty D][examples_mqtt_client.c:122] start mqtt client to broker.emqx.io [01-02 04:09:16 ty N][netconn_wired.c:43] wired status changed to 1, old stat: 1 [01-02 04:09:16 ty D][netmgr.c:113] netmgr status changed to 1, old 1, active 2 [01-02 04:09:17 ty D][tcp_transporter.c:102] bind ip:00000000 port:0 ok [01-02 04:09:17 ty I][examples_mqtt_client.c:66] mqtt client connected! try to subscribe tuya/tos-test [01-02 04:09:17 ty D][examples_mqtt_client.c:71] Subscribe topic tuya/tos-test ID:1 [01-02 04:09:18 ty D][mqtt_client_wrapper.c:58] MQTT_PACKET_TYPE_SUBACK id:1 [01-02 04:09:18 ty D][examples_mqtt_client.c:89] Subscribe successed ID:1 [01-02 04:09:18 ty D][examples_mqtt_client.c:95] Publish msg ID:2 [01-02 04:09:18 ty D][mqtt_client_wrapper.c:72] MQTT_PACKET_TYPE_PUBACK id:2 [01-02 04:09:18 ty D][examples_mqtt_client.c:100] PUBACK successed ID:2 [01-02 04:09:18 ty D][examples_mqtt_client.c:101] UnSubscribe topic tuya/tos-test [01-02 04:09:18 ty D][examples_mqtt_client.c:84] recv message TopicName:tuya/tos-test, payload len:32 ``` -------------------------------- ### Example HTTP GET Request Source: https://github.com/tuya/tuyaopen/blob/master/examples/protocols/https_client/README.md An example of an HTTP GET request to httpbin.org, demonstrating the URL and origin IP address. ```APIDOC GET https://httpbin.org/get Request Details: origin: 115.236.167.98 url: https://httpbin.org/get Note: The response content is extensive, and the log can only display the first 1K of data. ``` -------------------------------- ### Basic Image Display Example (C) Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/widgets/image/index.rst Demonstrates the fundamental usage of displaying an image using the LittlevGL library. This example serves as a starting point for image-related functionalities. ```c #include "lv_examples.h" void lv_example_image_1(void) { // Example code for basic image display } ``` -------------------------------- ### Audio and Display Driver Initialization (C) Source: https://github.com/tuya/tuyaopen/blob/master/boards/add_new_board.md Implements audio driver initialization and display hardware setup for ESP32. ```c OPERATE_RET app_audio_driver_init(const char *name) { /* 此处完成 codec 配置 */ return tdd_audio_es8388_codec_register(name, codec); } int board_display_init(void) { /* boards/ESP32/common/lcd 下配置lcd */ return lcd_st7789_init(); } void *board_display_get_panel_io_handle(void) { return lcd_st7789_get_panel_io_handle(); } void *board_display_get_panel_handle(void) { return lcd_st7789_get_panel_handle(); } ``` -------------------------------- ### Install NuttX Prerequisites (Shell) Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/integration/os/nuttx.rst Installs necessary development tools and libraries for building NuttX on a Linux-based system, such as Ubuntu using WSL. This includes compilers, build tools, and version control. ```shell sudo apt-get install automake bison build-essential flex gcc-arm-none-eabi gperf git libncurses5-dev libtool libusb-dev libusb-1.0.0-dev pkg-config kconfig-frontends openocd ``` -------------------------------- ### LVGL Initialization Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/porting/project.rst Provides an example of how to implement a custom global default function for LVGL using thread-local storage (__thread) to enable multi-instance support. This function returns a pointer to a thread-local lv_global_t structure. ```c lv_global_t * lv_global_default(void) { static __thread lv_global_t lv_global; return &lv_global; } ``` -------------------------------- ### NuttX and Apps Repository Setup (Shell) Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/integration/os/nuttx.rst Clones the official NuttX RTOS and NuttX Apps repositories from GitHub into a specified workspace directory. This is the first step in setting up the development environment. ```shell mkdir ~/nuttxspace cd ~/nuttxspace git clone https://github.com/apache/incubator-nuttx nuttx git clone https://github.com/apache/incubator-nuttx-apps apps ``` -------------------------------- ### BLE Initialization and Advertising Source: https://github.com/tuya/tuyaopen/blob/master/examples/ble/ble_peripher/README_CN.md Initializes the BLE stack and starts advertising to make the device discoverable as a peripheral. This is the first step in establishing a BLE connection. ```c [01-01 00:00:00 TUYA D][lr:0x84aa3] ----------bluetooth event callback------- [01-01 00:00:00 TUYA D][lr:0x84aa3]bluetooth event is : 1 [01-01 00:00:00 TUYA D][lr:0x84aa3] init Ble/Bt stack and start advertising ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/tuya/tuyaopen/blob/master/CMakeLists.txt Configures the CMake project by setting example names, versions, libraries, and include directories. It handles platform-specific library configurations, particularly for the Arduino framework and T2 platform. ```cmake set(EXAMPLE_NAME "${TOS_PROJECT_NAME}") message(STATUS "[TOP] Using example [${EXAMPLE_NAME}].") if(NOT DEFINED CONFIG_PROJECT_VERSION) set(CONFIG_PROJECT_VERSION "1.0.0") endif() set(EXAMPLE_LIB "tuyaapp") list(APPEND PLATFORM_NEED_HDIR ${COMPONENT_PUBINC}) string(REPLACE ";" " " PLATFORM_NEED_HDIR "${PLATFORM_NEED_HDIR}") set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB}") if(TOS_FRAMEWORK STREQUAL "arduino") if(PLATFORM_NAME STREQUAL "T2") set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB} stdc++") endif() endif() message(STATUS "[TOP] PLATFORM_NEED_LIBS: ${PLATFORM_NEED_LIBS}") include(${TOS_PROJECT_ROOT}/CMakeLists.txt) target_include_directories(${EXAMPLE_LIB} PUBLIC ${HEADER_DIR} ) target_link_libraries(${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB}) ``` -------------------------------- ### ESP32 LCD Driver Interface Functions Source: https://github.com/tuya/tuyaopen/blob/master/boards/add_new_board.md Describes the essential functions for ESP32 LCD driver implementation in TuyaOpen. `lcd_xxx_init` handles screen initialization, while `lcd_xxx_get_panel_io_handle` and `lcd_xxx_get_panel_handle` provide the necessary panel and panel I/O handles for LVGL setup. ```APIDOC int lcd_xxx_init(void); - Initializes the LCD screen. void *lcd_xxx_get_panel_io_handle(void); - Retrieves the handle for the panel I/O. void *lcd_xxx_get_panel_handle(void); - Retrieves the handle for the panel. These functions are used in `boards/ESP32/common/display/tuya_lvgl.c` for ESP32's LVGL initialization. ``` -------------------------------- ### Project Configuration and Compilation Source: https://github.com/tuya/tuyaopen/blob/master/examples/graphics/lvgl_demo/README.md This snippet outlines the steps to configure, compile, and run the lvgl_demo project using 'tos menuconfig'. It covers driver selection and GPIO pin configuration. ```bash 1. Run `tos menuconfig` to configure the project. 2. Configure the corresponding screen/touch/rotary encoder drivers. 3. Configure the corresponding GPIO pins. 4. Compile the project. 5. Burn and run. ``` -------------------------------- ### Initialize LVGL with SDL Window Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/integration/ide/pc-simulator.rst Initializes the LVGL library and creates an SDL window for display. It also sets up mouse and keyboard input devices. This is a basic setup for using LVGL's SDL support manually. ```c #include #include int main() { lv_init(); lv_display_t *display = lv_sdl_window_create(800, 600); lv_indev_t *mouse = lv_sdl_mouse_create(); lv_indev_t *keyboard = lv_sdl_keyboard_create(); ... while (true) { uint32_t ms_delay = lv_timer_handler(); usleep(ms_delay * 1000); } } ``` -------------------------------- ### Start Echo Server Source: https://github.com/tuya/tuyaopen/blob/master/examples/protocols/tcp_client/README_CN.md This bash command starts a simple echo server using netcat (nc) on port 7. This server is used as the target for the Tuya TCP client example. ```bash sudo nc -lk 7 ``` -------------------------------- ### Hello World Label Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/README.md Demonstrates how to create a simple 'Hello world' label and set its style and alignment on the active screen. This example is available in both C and MicroPython. ```c /*Change the active screen's background color*/ lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x003a57), LV_PART_MAIN); /*Create a white label, set its text and align it to the center*/ lv_obj_t * label = lv_label_create(lv_screen_active()); lv_label_set_text(label, "Hello world"); lv_obj_set_style_text_color(lv_screen_active(), lv_color_hex(0xffffff), LV_PART_MAIN); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); ``` ```micropython # Change the active screen's background color scr = lv.screen_active() scr.set_style_bg_color(lv.color_hex(0x003a57), lv.PART.MAIN) # Create a white label, set its text and align it to the center label = lv.label(lv.screen_active()) label.set_text("Hello world") label.set_style_text_color(lv.color_hex(0xffffff), lv.PART.MAIN) label.align(lv.ALIGN.CENTER, 0, 0) ``` -------------------------------- ### Simple Slider Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/widgets/slider/index.rst Demonstrates the basic implementation of a slider widget. This example is useful for understanding the fundamental setup and usage of sliders. ```c #include "lv_examples.h" #include "lvgl/lvgl.h" void lv_example_slider_1(void) { /*Create a slider*/ lv_obj_t * slider = lv_slider_create(lv_scr_act()); lv_obj_set_width(slider, 200); lv_obj_align(slider, LV_ALIGN_CENTER, 0, 0); /*Set event callback*/ lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); } ``` -------------------------------- ### Transition Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/styles/index.rst Provides examples of implementing transitions. ```c #include "styles/lv_example_style_10.h" ``` -------------------------------- ### Handle Login and States in C Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/others/observer/index.rst Provides an example of managing login processes and their associated states. This is crucial for applications requiring user authentication and tracking different login statuses. ```c #include // Assuming lv_example_observer_2.c contains the relevant code // void lv_example_observer_2(void); int main() { // lv_example_observer_2(); // Call the example function return 0; } ``` -------------------------------- ### Tuya Button Matrix Simple Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/widgets/buttonmatrix/index.rst Demonstrates the basic setup and usage of the Tuya Button Matrix widget. ```c #include "lv_widgets/lv_buttonmatrix.h" void lv_example_buttonmatrix_1(void) { // Example code for simple button matrix // ... } ``` -------------------------------- ### example_wifi_ap Execution Log Source: https://github.com/tuya/tuyaopen/blob/master/examples/wifi/ap/README.md This log captures the startup sequence of the `example_wifi_ap` example. It shows the creation of the Wi-Fi AP, network configuration, and the transmission of 'hello world' messages. It also includes system events like watchdog feeding and station management. ```c [01-01 00:04:50 ty N][example_wifi_ap.c:86] ------ wifi ap example start ------ ap net info ip: 192.168.1.123, mask: 255.255.255.0, gw: 192.168.1.1 ssid:my-wifi, key:12345678, channel: 5 [saap]MM_RESET_REQ [bk]tx_txdesc_flush [saap]ME_CONFIG_REQ [saap]ME_CHAN_CONFIG_REQ [saap]MM_START_REQ [csa]csa_in_progress[0:0]-clear hapd_intf_add_vif,type:3, s:0, id:0 apm start with vif:0 me_set_ps_disable:940 0 0 1 0 0 ------beacon_int_set:100 TU set_active param 0 [msg]APM_STOP_CFM update_ongoing_1_bcn_update vif_idx:0, ch_idx:0, bcmc_idx:1 update_ongoing_1_bcn_update netif_is_added: 0x3f6278 netif_is_added: 0x3f6230 net_wlan_add_netif already exist!, vif_idx:0 mac c8:47:8c: 0: 0: 1 net_wlan_add_netif done!, vif_idx:0 uap_ip_start configuring uap(with IP)def netif is sta [01-01 00:04:52 ty D][example_wifi_ap.c:124] ip_addr:-1062731397 [01-01 00:04:55 ty D][lr:0x88651] feed watchdog [01-01 00:04:57 ty D][example_wifi_ap.c:64] send data:hello world temp_code:59 - adc_code:281 - adc_trend:[19]:290->[20]:280 [01-01 00:05:02 ty D][example_wifi_ap.c:64] send data:hello world [01-01 00:05:07 ty D][example_wifi_ap.c:64] send data:hello world [01-01 00:05:12 ty D][example_wifi_ap.c:64] send data:hello world [01-01 00:05:15 ty D][lr:0x88651] feed watchdog [01-01 00:05:17 ty D][example_wifi_ap.c:64] send data:hello world [01-01 00:05:22 ty D][example_wifi_ap.c:64] send data:hello world [01-01 00:05:27 ty D][example_wifi_ap.c:64] send data:hello world hapd_intf_sta_add:1, vif:0 rc_init: station_id=0 format_mod=0 pre_type=0 short_gi=0 max_bw=0 rc_init: nss_max=0 mcs_max=255 r_idx_min=0 r_idx_max=11 no_samples=10 WPA: TK 2e13506d30b71ba714cd342aa297384a sta_mgmt_add_key ctrl_port_hdl:1 [01-01 00:05:32 ty D][example_wifi_ap.c:64] send data:hello world ``` -------------------------------- ### Setting up SDL2 on Windows with MinGW Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/integration/ide/pc-simulator.rst Provides steps to set up SDL2 development libraries for MinGW on Windows, including copying files to the MinGW directories and the project's debug folder. ```powershell # Download SDL2 development libraries (e.g., SDL2-devel-2.0.5-mingw.tar.gz) # Decompress the archive. # Assuming MinGW is installed at C:/MinGW # For 64-bit MinGW: # Copy SDL2 folder from SDL2-devel-2.0.5-mingw/x86_64-w64-mingw32/include to C:/MinGW/x86_64-w64-mingw32/include # Copy contents of SDL2-devel-2.0.5-mingw/x86_64-w64-mingw32/lib to C:/MinGW/x86_64-w64-mingw32/lib # Copy SDL2.dll from SDL2-devel-2.0.5-mingw/x86_64-w64-mingw32/bin to {eclipse_workspace}/pc_simulator/Debug/ ``` -------------------------------- ### Pre-commit Installation and Usage Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/CODING_STYLE.rst Instructions for installing and using the pre-commit tool for managing Git hooks. It covers installation, hook setup, running hooks, and skipping specific hooks. ```console pre-commit install ``` ```console SKIP=name-of-the-hook git commit ``` ```console pre-commit run name-of-the-hook ``` -------------------------------- ### Start Animation on Event (C) Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/anim/index.rst Demonstrates how to start an animation when a specific event occurs. This snippet utilizes the LittlevGL (lvgl) library for GUI animations. ```c #include "lv_examples.h" void anim_example_1(void) { lv_obj_t * img = lv_img_create(lv_scr_act()); lv_img_set_src(img, "S:lv_img_builtin_small.png"); lv_obj_align(img, LV_ALIGN_CENTER, 0, -40); lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, img); lv_anim_set_exec_cb(&a, [](void * var, int32_t v) { (*(lv_obj_t**)var) = v; }); lv_anim_set_values(&a, 0, 100); lv_anim_set_time(&a, 1000); lv_anim_set_playback_time(&a, 500); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); } ``` -------------------------------- ### LVGL Demo Initialization and Execution Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/demos/README.md Main function demonstrating LVGL initialization, HAL initialization, creating and running LVGL demos using `lv_demos_create` and `lv_demos_usage`. It includes a main loop for timer handling and display updates. ```c static lv_disp_t* hal_init(void) { lv_disp_t* disp = NULL; ... /* TODO: init display and indev */ ... return disp; } int main(int argc, char ** argv) { lv_init(); lv_disp_t* disp = hal_init(); if (disp == NULL) { LV_LOG_ERROR("lv_demos initialization failure!"); return 1; } if (!lv_demos_create(&argv[1], argc - 1)) { lv_demos_usage(); goto demo_end; } while (1) { uint32_t delay = lv_timer_handler(); if (delay < 1) delay = 1; usleep(delay * 1000); } demo_end: lv_deinit(); return 0; } ``` -------------------------------- ### Install SDL2 and Build Essentials on Debian/Ubuntu Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/integration/ide/pc-simulator.rst Installs the SDL2 library, its development package, and essential build tools on Debian-based Linux distributions. ```bash sudo apt-get update apt-cache search libsdl2 sudo apt-get install libsdl2-2.0-0 sudo apt-get install libsdl2-dev sudo apt-get install build-essential ``` -------------------------------- ### Install Python Dependencies for Mbed TLS Source: https://github.com/tuya/tuyaopen/blob/master/src/libtls/mbedtls-3.1.0/README.md This command installs the necessary Python packages required for Mbed TLS development, specifically for generating library source files, sample programs, and test data. It uses pip to install from the 'scripts/basic.requirements.txt' file. ```shell python -m pip install -r scripts/basic.requirements.txt ``` -------------------------------- ### Micropython LVGL Button Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/get-started/quick-overview.rst A simple Micropython example demonstrating how to initialize LVGL, create a screen, add a button with a label, and display it. ```python # Initialize import display_driver import lvgl as lv # Create a button with a label scr = lv.obj() btn = lv.button(scr) btn.align(lv.ALIGN.CENTER, 0, 0) label = lv.label(btn) label.set_text('Hello World!') lv.screen_load(scr) ``` -------------------------------- ### Hello World Label Example in MicroPython Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/README_zh.rst Shows how to create a 'Hello world' label using MicroPython in LVGL. It covers setting the screen's background color, creating the label, setting its text and color, and aligning it. Includes a link to an online simulator. ```python # Change the active screen's background color scr = lv.screen_active() scr.set_style_bg_color(lv.color_hex(0x003a57), lv.PART.MAIN) # Create a white label, set its text and align it to the center label = lv.label(lv.screen_active()) label.set_text("Hello world") label.set_style_text_color(lv.color_hex(0xffffff), lv.PART.MAIN) label.align(lv.ALIGN.CENTER, 0, 0) ``` -------------------------------- ### Tuya OS Software Timer Example Source: https://github.com/tuya/tuyaopen/blob/master/examples/system/os_sw_timer/README_CN.md Demonstrates creating, starting, and stopping a software timer using Tuya OS interfaces. The timer is configured to trigger a callback function multiple times before self-termination. ```c /* * Copyright (c) 2023 Tuya Inc. * All rights reserved. */ #include #include #include #include "tuya_os_utils.h" #include "tuya_os_timer.h" #define TAL_SW_TIMER_DELAY_MS (3000) #define TAL_SW_TIMER_MAX_CNT (5) static int tal_sw_timer_cnt = 0; static VOID_T tal_sw_timer_callback(PVOID_T pArg) { tal_sw_timer_cnt++; if (tal_sw_timer_cnt <= TAL_SW_TIMER_MAX_CNT) { tuya_print("--- tal sw timer callback\n"); } else { tuya_print("stop and delete software timer\n"); tuya_os_timer_delete(pArg); } } int main(int argc, char **argv) { TUYA_OS_TIMER_T *timer = NULL; timer = tuya_os_timer_create("sw_timer", tal_sw_timer_callback, timer); if (timer == NULL) { tuya_print("create software timer failed\n"); return -1; } tuya_print("sw timer start\n"); tuya_os_timer_start(timer, TAL_SW_TIMER_DELAY_MS, TIMER_CYCLE); while(1) { tuya_os_thread_sleep(1000); tuya_print("feed watchdog\n"); } return 0; } ``` -------------------------------- ### Tuya Open HTTPS Client - HTTP GET Request to httpbin.org Source: https://github.com/tuya/tuyaopen/blob/master/examples/protocols/https_client/README_CN.md This snippet details the second part of the HTTPS client's operation, focusing on a GET request to httpbin.org. It shows the process of establishing a new TLS connection, sending the GET request with appropriate headers, and receiving a JSON response containing request details. ```c [01-03 06:10:17 ty D][example_https_client.c:90] http request send! [01-03 06:10:17 ty D][tcp_transporter.c:102] bind ip:00000000 port:0 ok [01-03 06:10:17 ty D][tuya_tls.c:570] TUYA_TLS Begin Connect httpbin.org:443 [01-03 06:10:17 ty D][tuya_tls.c:338] mbedtls authmode: MBEDTLS_SSL_VERIFY_REQUIRED [01-03 06:10:17 ty D][tuya_tls.c:351] load root ca cert. [01-03 06:10:17 ty D][tuya_tls.c:641] socket fd is set. set to inner send/recv to handshake [01-03 06:10:18 ty D][tuya_tls.c:320] mbedtls_cert_pkey_free. [01-03 06:10:18 ty D][tuya_tls.c:682] handshake finish for httpbin.org. set send/recv to user set [01-03 06:10:18 ty D][tuya_tls.c:688] TUYA_TLS Success Connect httpbin.org:443 Suit:TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256 [01-03 06:10:18 ty D][http_client_wrapper.c:114] tls connencted! [01-03 06:10:18 ty D][http_client_wrapper.c:142] http request send! [01-03 06:10:18 ty D][http_client_wrapper.c:40] HTTP header add key:value key=Content-Type : value=application/json [01-03 06:10:18 ty D][http_client_wrapper.c:51] Sending HTTP GET request to httpbin.org/get [01-03 06:10:19 ty D][http_client_wrapper.c:68] Response Headers: Date: Wed, 12 Feb 2025 07:57:16 GMT Content-Type: application/json Content-Length: 276 Connection: keep-alive Server: gunicorn/19.9.0 Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Response Status: 200 Response Body: { "args": {}, "headers": { "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "TUYA_IOT_SDK", "X-Amzn-Trace-Id": "Root=1-67ac545c-6b40081161add1ce1d14361d" }, "origin": "115.236.167.98", "url": "https://httpbin.org/get" } [01-03 06:10:19 ty D][tls_transporter.c:122] tls transporter close socket fd:4 [01-03 06:10:19 ty D][tcp_transporter.c:194] tcp transporter close socket fd:4 [01-03 06:10:19 ty D][tls_transporter.c:130] tls transporter close tls handler:0x7815bb1fb6f0 [01-03 06:10:19 ty D][tuya_tls.c:799] TUYA_TLS Disconnect ENTER [01-03 06:10:19 ty D][tuya_tls.c:824] TUYA_TLS Disconnect Success [01-03 06:10:19 ty D][tuya_tls.c:496] tuya_tls_connect_destroy. ``` -------------------------------- ### Running the Software Timer Example Source: https://github.com/tuya/tuyaopen/blob/master/examples/system/os_sw_timer/README_CN.md Instructions on how to execute the software timer example. This typically involves compiling the C code and running the resulting executable. ```bash # Compile the C code (assuming you have the Tuya OS SDK set up) # make # Run the executable # ./your_executable_name ``` -------------------------------- ### PikaScript Installation and Compilation Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/docs/integration/bindings/pikascript.rst Shows the output of the pikascript command-line tool, including installed packages and the precompiler's scanning and binding process for the pika_lvgl.pyi file. ```bash $ ./rust-msc-latest-win10.exe (pikascript) packages installed: pikascript-core==v1.10.0 PikaStdLib==v1.10.0 PikaStdDevice==v1.10.0 (pikascript) pika compiler: scanning main.py... binding pika_lvgl.pyi... ``` -------------------------------- ### TuyaOS Timer Example Output Source: https://github.com/tuya/tuyaopen/blob/master/examples/peripherals/timer/README_CN.md This C code snippet demonstrates the output of a TuyaOS timer. It shows the timer starting, triggering multiple callbacks, and finally stopping after the specified conditions are met. The log messages indicate the timer's state and callback events. ```c [01-01 00:00:08 TUYA N][lr:0x70ab9] timer 0 is start [01-01 00:00:08 TUYA D][lr:0x70ad5] -------------Timer Callbcak-------------- [01-01 00:00:09 TUYA D][lr:0x70ad5] -------------Timer Callbcak-------------- [01-01 00:00:09 TUYA D][lr:0x70ad5] -------------Timer Callbcak-------------- [01-01 00:00:10 TUYA D][lr:0x70ad5] -------------Timer Callbcak-------------- [01-01 00:00:10 TUYA D][lr:0x70ad5] -------------Timer Callbcak-------------- [01-01 00:00:10 TUYA N][lr:0x70af7] timer 0 is stop ``` -------------------------------- ### TuyaOpen Project Structure Overview Source: https://github.com/tuya/tuyaopen/blob/master/boards/add_new_board.md Explains the directory structure of the TuyaOpen project, including platform, src, app, and board layers, and their interdependencies. ```markdown + platform 中是芯片原厂的 SDK,还有tuyaopen 的适配层 tkl + src 中是 tuyaopen 的源代码 + app 是应用代码 + board 是开发板相关的代码 这里需要注意的是,tkl 可以调用原厂的代码;src 可以调用 tkl 的代码,不能调用原厂的代码;app 可以调用 tkl,src 的代码,不能调用原厂的代码。 boards/ESP32/common 只能调用tkl、原厂的代码;boards/ESP32 下除了 common 之外的文件夹存放的是开发板的内容,这里只能调用,tkl,src,boards/common 中的代码。之所以在 boards 中新增 common 是为了满足在 tkl 接口能力满足不了的情况下,便于使用原厂的一些功能。 ``` -------------------------------- ### Canvas Drawing: Line Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/widgets/canvas/index.rst Shows how to draw a line on the canvas. This requires defining the start and end points of the line. ```c #include "lv_examples.h" void lv_example_canvas_7(void) { lv_obj_t *canvas = lv_canvas_create_new(lv_scr_act()); lv_canvas_set_buffer_format(canvas, LV_COLOR_FORMAT_ARGB8888); lv_canvas_set_size(canvas, 200, 100); lv_obj_center(canvas); lv_draw_line_dsc_t line_dsc; lv_draw_line_dsc_init(&line_dsc); line_dsc.color = lv_color_make(255, 255, 0); line_dsc.width = 3; lv_canvas_draw_line(canvas, 10, 10, 180, 80, &line_dsc); lv_canvas_finish(canvas, LV_CANVAS_DRAW_FINISH_SWAP); } ``` -------------------------------- ### Shadow Styles Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/styles/index.rst Provides examples of applying shadow styles. ```c #include "styles/lv_example_style_5.h" ``` -------------------------------- ### HTTP Connection Example in C Source: https://github.com/tuya/tuyaopen/blob/master/examples/protocols/http_client/README_CN.md This C code snippet demonstrates establishing an HTTP connection to httpbin.org using the Tuya IoT SDK. It logs connection details, DNS resolution, IP binding, and the response headers and arguments from the server. The output is truncated to the first 1KB of data. ```c [01-01 14:58:54 ty D][lr:0xadbd3] Connect: httpbin.org Port: 80 -->> [01-01 14:58:54 ty D][lr:0x7a689] unw_gethostbyname httpbin.org, prio 1 [01-01 14:58:54 ty D][lr:0x7a7b5] use dynamic dns ip:44.194.147.17 for domain:httpbin.org [01-01 14:58:54 ty D][lr:0xbc05d] bind ip:c0a81cc2 port:0 ok [01-01 14:58:54 ty D][lr:0xadbed] Connect: httpbin.org Port: 80 --<< ,r:0 [01-01 14:58:54 ty I][example_http.c:126] rsp:{ "args": {}, "headers": { "Host": "httpbin.org", "User-Agent": "TUYA_IOT_SDK", "X-Amzn-Trace-Id": "Root=1-65308a26-2d1b68cd71ac3ac235a5020a" }, "origin": "124.90.34.126", "url": "h[01-01 14:58:54 ty D][lr:0xbc0fd] tcp transporter close socket fd:4 ``` -------------------------------- ### Canvas Drawing: Arc Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/widgets/canvas/index.rst Illustrates drawing an arc on the canvas. This requires specifying the arc's start and end angles. ```c #include "lv_examples.h" void lv_example_canvas_5(void) { lv_obj_t *canvas = lv_canvas_create_new(lv_scr_act()); lv_canvas_set_buffer_format(canvas, LV_COLOR_FORMAT_ARGB8888); lv_canvas_set_size(canvas, 200, 100); lv_obj_center(canvas); lv_draw_arc_dsc_t arc_dsc; lv_draw_arc_dsc_init(&arc_dsc); arc_dsc.bg_color = lv_color_make(0, 255, 0); arc_dsc.border_color = lv_color_make(0, 0, 0); arc_dsc.border_width = 2; arc_dsc.start_angle = 0; arc_dsc.end_angle = 1800; // 180 degrees lv_canvas_draw_arc(canvas, 100, 50, 50, &arc_dsc); lv_canvas_finish(canvas, LV_CANVAS_DRAW_FINISH_SWAP); } ``` -------------------------------- ### TuyaOS Software Timer Example Source: https://github.com/tuya/tuyaopen/blob/master/examples/system/os_sw_timer/README.md This C code snippet demonstrates the basic usage of the TuyaOS system software timer. It shows how to start a timer, the callback function that is executed when the timer elapses, and how to stop and release the timer. The timer is configured to trigger multiple times before being stopped. ```c [01-01 00:00:07 ty D][example_sw_timer.c:59] sw timer start [01-01 00:00:10 ty N][example_sw_timer.c:43] --- tal sw timer callback [01-01 00:00:13 ty N][example_sw_timer.c:43] --- tal sw timer callback [01-01 00:00:15 ty D][lr:0x8a455] feed watchdog [01-01 00:00:16 ty N][example_sw_timer.c:43] --- tal sw timer callback [01-01 00:00:19 ty N][example_sw_timer.c:43] --- tal sw timer callback [01-01 00:00:22 ty N][example_sw_timer.c:43] --- tal sw timer callback [01-01 00:00:22 ty N][example_sw_timer.c:46] stop and delete software timer ``` -------------------------------- ### Initialize and Execute http-parser Source: https://github.com/tuya/tuyaopen/blob/master/src/libhttp/coreHTTP/source/dependency/3rdparty/http_parser/README.md Demonstrates initializing the http_parser struct, setting callbacks, and executing the parser with received data. It also shows how to handle errors and check for protocol upgrades. ```c http_parser_settings settings; settings.on_url = my_url_callback; settings.on_header_field = my_header_field_callback; /* ... other callbacks */ http_parser *parser = malloc(sizeof(http_parser)); http_parser_init(parser, HTTP_REQUEST); parser->data = my_socket; /* User data */ size_t len = 80*1024, nparsed; char buf[len]; ssize_t recved; recved = recv(fd, buf, len, 0); if (recved < 0) { /* Handle error. */ } nparsed = http_parser_execute(parser, &settings, buf, recved); if (parser->upgrade) { /* handle new protocol */ } else if (nparsed != recved) { /* Handle error. Usually just close the connection. */ } ``` -------------------------------- ### Image Styles Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/styles/index.rst Demonstrates how to style images. ```c #include "styles/lv_example_style_6.h" ``` -------------------------------- ### BLE Disconnection Event Source: https://github.com/tuya/tuyaopen/blob/master/examples/ble/ble_peripher/README_CN.md Handles the event when the central device disconnects from the BLE peripheral. It logs the disconnection and indicates that the peripheral will start advertising again. ```c [06-10 15:34:57 TUYA D][lr:0x4bb03] ----------bluetooth event callback------- [06-10 15:34:57 TUYA D][lr:0x4bb0b]bluetooth event is : 4 [06-10 15:34:57 TUYA D][lr:0x4bb9f] Bluetooth disconnect. [06-10 15:34:57 TUYA N][lr:0xb32d3] Start Adv ``` -------------------------------- ### Stack Navigation Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/others/fragment/index.rst Illustrates how to implement stack navigation, a pattern for managing a sequence of screens or views. This example is in C. ```c #include // Placeholder for stack navigation implementation void lv_example_fragment_2() { printf("Executing stack navigation example.\n"); } int main() { lv_example_fragment_2(); return 0; } ``` -------------------------------- ### BLE Initialization and Advertising Source: https://github.com/tuya/tuyaopen/blob/master/examples/ble/ble_peripher/README.md Logs indicating the Bluetooth stack initialization and the start of advertising, waiting for a host connection. This is the initial state after BLE is powered on or reset. ```c [01-01 00:00:00 TUYA D][lr:0x84aa3] ----------bluetooth event callback------- [01-01 00:00:00 TUYA D][lr:0x84aa3] bluetooth event is : 1 [01-01 00:00:00 TUYA D][lr:0x84aa3] init Ble/Bt stack and start advertising ``` -------------------------------- ### BLE Connection Event Source: https://github.com/tuya/tuyaopen/blob/master/examples/ble/ble_peripher/README_CN.md Handles the event when a central device successfully connects to the BLE peripheral. It logs the connection event and indicates the start of the connection process. ```c [01-01 00:07:12 TUYA D][lr:0x4aa47] ----------bluetooth event callback------- [01-01 00:07:12 TUYA D][lr:0x4aa4f]bluetooth event is : 2 [01-01 00:07:12 TUYA D][lr:0x4aaa7] Bluetooth starts to connect... [01-01 00:07:12 TUYA I][lr:0x820b3] char handle = 0x00 ``` -------------------------------- ### Size Styles Example Source: https://github.com/tuya/tuyaopen/blob/master/src/liblvgl/lvgl/examples/styles/index.rst Demonstrates how to apply size styles to elements. ```c #include "styles/lv_example_style_1.h" ```