|
SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
|
Functions | |
| void | ui_widget_mgr_init (lv_obj_t *parent) |
| ipc_ui_init() เรียกฟังก์ชันนี้เอง — ห้ามเรียกโดยตรง | |
| void | ui_widget_mgr_set_parent (lv_obj_t *parent) |
| เคลียร์ widget ทั้งหมดแล้วตั้ง parent ใหม่; ถูกเรียกผ่าน ipc_ui_set_container() เท่านั้น | |
| bool | ui_widget_mgr_needs_container (void) |
| คืน true ขณะที่ parent เป็น NULL; ไม่มีผู้เรียกที่ใดเลย | |
| int | ui_widget_mgr_create (const ipc_ui_create_t *cfg) |
| สร้าง widget จาก config; คืน handle 0-31, -1 เมื่อตารางเต็ม, -2 เมื่อชนิดไม่ถูกต้อง | |
| int | ui_widget_mgr_create_sprite (const lv_image_dsc_t *dsc, int16_t x, int16_t y) |
| สร้าง sprite ชนิดภาพลงใน handle table เดียวกัน | |
| void | ui_widget_mgr_set_sprite_image (int handle, const lv_image_dsc_t *dsc) |
| สลับภาพของ sprite; descriptor มาจาก game_sprite_lookup() | |
| void | ui_widget_mgr_delete (int handle) |
| ลบ widget หนึ่งตัวและปล่อย handle ของมันคืน | |
| void | ui_widget_mgr_clear_all (void) |
| ลบ widget ทุกตัวและรีเซ็ต handle table | |
| void | ui_widget_mgr_set_text (int handle, const char *text) |
| ตั้งข้อความของ widget; ส่วน dispatch จะตั้ง fast drain ให้พร้อมทำงานหลังจากนั้น | |
| void | ui_widget_mgr_set_value (int handle, int32_t value) |
| ตั้งค่าตัวเลข; ตั้ง fast drain ให้พร้อมทำงานเพื่อไม่ให้แดชบอร์ดถูกตรึงไว้ที่ 5 FPS | |
| void | ui_widget_mgr_set_position (int handle, int16_t x, int16_t y) |
| ย้ายตำแหน่ง widget; ตั้ง fast drain ให้พร้อมทำงานเพื่ออัตราเฟรมระหว่างเล่นเกม | |
| void | ui_widget_mgr_set_size (int handle, int16_t w, int16_t h) |
| เปลี่ยนขนาดของ widget | |
| void | ui_widget_mgr_set_color (int handle, uint32_t color) |
| ตั้งสีหลัก 0xRRGGBB | |
| void | ui_widget_mgr_set_visible (int handle, bool visible) |
| แสดงหรือซ่อน widget หนึ่งตัว | |
| void | ui_widget_mgr_set_all_visible (bool visible) |
| แสดงหรือซ่อน widget ที่จัดการอยู่ทุกตัว; เป็นตัวสลับมุมมองของการสลับคอนโซลบนหน้า Playground | |
| int32_t | ui_widget_mgr_get_value (int handle) |
| อ่านค่าปัจจุบันของ widget; ค่า 0 หมายถึง handle ไม่ถูกต้องได้ด้วย | |
| void | ui_widget_mgr_set_dotmatrix (int handle, const uint8_t *bitmap, uint8_t len) |
| โหลดบิตแมปเข้าไปใน widget ชนิด DotMatrix | |
| void | ui_widget_mgr_set_image (int handle, uint16_t offset, const uint8_t *data, uint8_t len) |
| การส่ง RGB565 เป็นก้อน ๆ เข้าไปใน canvas ของ widget ชนิด Image | |
| void | ui_widget_mgr_event_push (uint8_t handle, uint8_t event_type, int32_t value) |
| ฝั่งผู้ผลิตข้อมูลของ event ring; เฉพาะ LVGL event callback ภายในเท่านั้น | |
| int | ui_widget_mgr_event_drain (ipc_ui_event_t *out, int max_events) |
| ระบาย event ออกให้ POLL_EVENTS — เป็น backend ของ ui.poll() | |
| int | ui_widget_mgr_count (void) |
| จำนวน handle ที่ยังใช้งานอยู่; ไม่มีผู้เรียกเลยที่ใด | |
| int | ui_widget_mgr_list (ipc_ui_widget_info_t *out, int max_items) |
| handle และชนิดของ widget ที่ทำงานอยู่ทุกตัว — เป็น backend ของ ui.list() | |
| lv_obj_t * | ui_widget_mgr_get_parent (void) |
| parent ปัจจุบันที่เป็น null ได้; ทุก call site ตรวจ null ของค่านี้ | |
| void | ui_widget_mgr_set_screen (int16_t width, int16_t height) |
| ตั้งขนาดหน้าจอและรีเซ็ตกริดของ auto-layout | |
| int | ui_widget_mgr_chart_add_series (int handle, uint32_t color) |
| เพิ่มชุดข้อมูลให้ Chart; คืนดัชนี 0-3 หรือ -1 | |
| void | ui_widget_mgr_chart_set_next (int handle, uint8_t series_idx, int32_t value) |
| ต่อค่าถัดไปเข้าไปในชุดข้อมูลของ chart ชุดหนึ่ง | |
| int | ui_widget_mgr_item_add (const ipc_ui_item_add_t *it) |
| ต่อรายการหนึ่งรายการ; ค่าที่คืนมีหลายความหมาย และมีกฎเรื่องตัวโค้ดที่ทำงานจริง 2 ชุด | |
| void | ui_widget_mgr_item_clear (int handle) |
| ล้าง widget ชนิดคอลเล็กชันให้ว่าง | |
| void | ui_widget_mgr_set_prop (int handle, uint8_t prop_id, int32_t value) |
| ตั้งคุณสมบัติ UI_PROP_* หนึ่งรายการ; เป็นกลไกที่ .listen() ใช้สมัครรับ event | |
| lv_obj_t * | ui_widget_mgr_get_object (int handle) |
| อ็อบเจ็กต์ LVGL ที่อยู่หลัง handle; เป็นเส้นทาง GET_TEXT สำหรับข้อความที่ผู้ใช้พิมพ์ | |
Header: ui_widget_mgr.h ตัวโค้ดที่ทำงานจริงซึ่งอยู่ใน archive (libbento_ipc.a) "Widget handle table and LVGL widget lifecycle manager. Maps handle IDs (0-31) to lv_obj_t* pointers. Creates, modifies, deletes LVGL widgets in GFX task context" (ui_widget_mgr.h)
อ่านย่อหน้านี้ก่อน — ว่าใครเป็นผู้เรียกฟังก์ชันเหล่านี้จริง ๆ ฟังก์ชันพื้นฐานชุดนี้ ไม่ใช่ ส่วนที่แอปพลิเคชันภาษา C เรียกใช้ ภายใน archive ผู้เรียกเพียงรายเดียวของพวกมันคือ switch คำสั่ง IPC_UI (ส่วน dispatch คำสั่ง UI) ซึ่งถูกระบายคิวจาก LVGL timer 50 ms ผู้เรียกจริงคือสคริปต์ MicroPython บน CM33_NS: การเรียก ui.* แต่ละครั้งใน modui.c จะแพ็ก payload ส่งผ่าน pipe แล้ว switch ด้านล่างจึงแกะออกมาและเรียกฟังก์ชันพื้นฐานหนึ่งตัว การเขียนเอกสารว่า "call this from your page code" จะบิดเบือนสถาปัตยกรรม — หน้า (page) ที่เรียก ui_widget_mgr_create() โดยตรงคือการข้ามเจ้าของ handle table ไป และจะเกิด race condition กับ CLEAR_ALL ของสคริปต์ตัวถัดไป
แต่ละรายการจึงให้ข้อมูล 3 อย่าง: คำสั่ง IPC ที่ dispatch มาถึงฟังก์ชันนั้น (ค่าคงที่ใน ipc_ui_protocol.h) ส่วนที่เรียกใช้ได้ฝั่ง MicroPython ui.* ที่เข้าถึงมัน และข้อกำหนดการเรียกใช้ ทุก case อธิบายเป็นข้อความ เพราะตัว switch อยู่ใน archive และไม่ได้ส่งมอบเป็นซอร์ส ฟังก์ชันพื้นฐาน 2 ตัวถูกเรียกจากนอก switch (init โดย ipc_ui_init() และ set_parent โดย ipc_ui_set_container()) อีก 2 ตัวไม่มีผู้เรียกที่ใดเลย (count, needs_container) และอีก 2 ตัวถูกเรียกจากหน้า (page) Playground ของเทมเพลตเอง (clear_all, set_all_visible)
| void ui_widget_mgr_init | ( | lv_obj_t * | parent | ) |
ipc_ui_init() เรียกฟังก์ชันนี้เอง — ห้ามเรียกโดยตรง
Initialize the widget manager.
| parent | The LVGL parent object (UX/UI tab scrollable container). |
ipc_ui_init() เรียกฟังก์ชันนี้เองเป็นคำสั่งแรกของตน — ห้ามเรียกโดยตรง ไม่ได้ถูกเรียกจากส่วน dispatch คำสั่ง UI รับ NULL ของ deferred binding (การผูกแบบเลื่อนเวลา) ตอนบูต ส่วน parent ตัวจริงนั้นหน้า (page) จะจัดหาให้ภายหลังผ่าน ipc_ui_set_container() ipc_ui_init() เท่านั้น ครั้งเดียวตอนเริ่มระบบ | void ui_widget_mgr_set_parent | ( | lv_obj_t * | parent | ) |
เคลียร์ widget ทั้งหมดแล้วตั้ง parent ใหม่; ถูกเรียกผ่าน ipc_ui_set_container() เท่านั้น
Update the parent container (for page-based navigation). Clears all existing widgets and sets new parent.
| parent | New LVGL parent object, or NULL to invalidate. |
ui_widget_mgr.h) ให้ส่ง NULL เข้ามาเพื่อทำให้เป็นโมฆะ ผู้เรียกเพียงรายเดียวคือ ipc_ui_set_container() — เป็นการนำทางตามหน้า (page) ไม่ใช่ส่วน dispatch คำสั่ง UI ผู้ใช้ไลบรารี (consumer) เรียก ipc_ui_set_container() ห้ามเรียกฟังก์ชันนี้ ทำงานใน GFX-task context คืนค่า void ipc_ui_set_container() เท่านั้น ซึ่งเป็น wrapper บาง ๆ ที่ส่งอาร์กิวเมนต์ต่อมายังฟังก์ชันนี้และไม่ได้ทำอย่างอื่น ส่วน call site ของ wrapper ตัวนั้นในเทมเพลตอยู่ที่ container ของ UI | bool ui_widget_mgr_needs_container | ( | void | ) |
คืน true ขณะที่ parent เป็น NULL; ไม่มีผู้เรียกที่ใดเลย
Check if the widget manager has no parent container.
NULL — คือช่วงระหว่าง ipc_ui_set_container(NULL) ตอนทำลายหน้า (page) กับการผูกของหน้าถัดไป กล่าวคือช่วงที่ CREATE จะล้มเหลว ไม่มีผู้เรียกที่ใดเลย ตัวอย่างที่เขียนขึ้นเองโยงฟังก์ชันนี้เข้ากับข้อกำหนดของ deferred binding: หน้า (page) ที่ต้องการทราบว่า widget ของสคริปต์วางลงได้แล้วหรือยัง ให้ถามฟังก์ชันนี้ ใน GFX-task context | int ui_widget_mgr_create | ( | const ipc_ui_create_t * | cfg | ) |
สร้าง widget จาก config; คืน handle 0-31, -1 เมื่อตารางเต็ม, -2 เมื่อชนิดไม่ถูกต้อง
Create a widget from IPC CREATE payload.
| cfg | Parsed CREATE payload. |
-1 เมื่อตารางเต็ม และ -2 เมื่อชนิดไม่ถูกต้อง ส่วน dispatch จับค่าเหล่านั้นให้เป็น UI_STATUS_OK / UI_STATUS_TABLE_FULL / UI_STATUS_INVALID_TYPE ในคำตอบแบบสองทาง ตั้ง fast drain ให้พร้อมทำงาน และเมื่อ CREATE ครั้งแรก จะซ่อน container ไว้จนกว่า POLL_EVENTS หรือการหมดเวลาจะเปิดให้เห็นอีกครั้ง (เพื่อให้การสร้างเป็นชุดรวดปรากฏขึ้นพร้อมกันทีเดียว) ทำงานใน GFX-task context ui.Button(...), ui.Label(...), ui.Slider(...), ui.Chart(...) และตัวอื่นที่เหลือในตารางคลาส ui (modui.c:1226, แบบสองทาง) IPC_CMD_UI_CREATE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | int ui_widget_mgr_create_sprite | ( | const lv_image_dsc_t * | dsc, |
| int16_t | x, | ||
| int16_t | y ) |
สร้าง sprite ชนิดภาพลงใน handle table เดียวกัน
Create an image sprite from a compiled C descriptor. Reuses the widget handle table so position/visibility/delete work through the normal ops.
| dsc | Compiled sprite descriptor (resolved per-project from a SPR id). |
-1 เมื่อตารางเต็ม, -2 เมื่อไม่ถูกต้องหรือไม่มี sprite engine — กรณีหลังคือสิ่งที่ค่าปริยายชนิด weak ของ game_sprite_create ให้ออกมา (ดู Weak hook (ให้นิยามเอง ห้ามเรียก)) ทำงานใน GFX-task context ui.sprite(id, x, y) (modui.c:1731, แบบสองทาง) IPC_CMD_UI_SPRITE_NEW (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task ค้นหา sprite ตาม id ผ่าน hook ชนิด weak game_sprite_lookup() แล้วเรียกฟังก์ชันนี้ด้วยผลลัพธ์ที่ได้ | void ui_widget_mgr_set_sprite_image | ( | int | handle, |
| const lv_image_dsc_t * | dsc ) |
สลับภาพของ sprite; descriptor มาจาก game_sprite_lookup()
Swap a sprite's image (directional head, enemy kind, explosion frame). No-op on invalid handle or NULL descriptor.
NULL ตัว descriptor มาจาก game_sprite_lookup() ที่โปรเจกต์เขียนทับไว้ ซึ่งส่วน dispatch เรียกก่อนเรียกฟังก์ชันนี้ ทำงานใน GFX-task context w.frame(sprite_id) บน handle ของ sprite (modui.c:651) IPC_CMD_UI_SPRITE_FRAME (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task ค้นหาภาพใหม่ตาม id ผ่าน game_sprite_lookup() แล้วเรียกฟังก์ชันนี้ด้วยผลลัพธ์ที่ได้ | void ui_widget_mgr_delete | ( | int | handle | ) |
ลบ widget หนึ่งตัวและปล่อย handle ของมันคืน
Delete a widget by handle.
| handle | Handle ID (0-31). |
w.delete() (modui.c:506) IPC_CMD_UI_DELETE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_clear_all | ( | void | ) |
ลบ widget ทุกตัวและรีเซ็ต handle table
Delete all widgets and reset the handle table.
CLEAR_ALL ของส่วน dispatch (เมื่อมีสคริปต์ใหม่) และหน้า (page) Playground ของเทมเพลต ซึ่งเรียกจาก LVGL callback ชนิด LV_EVENT_CLICKED — ทำงานใน GFX-task context ในหน้านั้น widget ถูกรื้อทิ้ง ก่อนที่คำสั่ง restart ทาง IPC จะถูกส่งออกไป CM33_NS จึงดัน widget ใหม่เข้าไปในตารางที่เคลียร์ไปได้ครึ่งเดียวไม่ได้ คืนค่า void ไม่มีเส้นทางแจ้งข้อผิดพลาด รูปแบบที่ทำลายข้อมูลที่ page_playground.c:105 จะเคลียร์ ส่ง IPC_CMD_DELETE_MAIN_PY แล้วรีเซ็ต MCU ui.clear() (modui.c:1553) และยังถูกสั่งโดย ui.program() กับเส้นทาง deploy ของ IDE ด้วย (:1641, :1975) IPC_CMD_UI_CLEAR_ALL (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ แล้วจึงรีเซ็ตสถานะ auto-navigate สำหรับสคริปต์ถัดไป | void ui_widget_mgr_set_text | ( | int | handle, |
| const char * | text ) |
ตั้งข้อความของ widget; ส่วน dispatch จะตั้ง fast drain ให้พร้อมทำงานหลังจากนั้น
Set text on a widget.
w.text("...") (modui.c:396 และ :527 กับ :1261 สำหรับข้อความตอนสร้าง) ให้สังเกตขีดจำกัดของ payload ที่ 95 ไบต์สำหรับตัวสร้าง และ 126 ไบต์สำหรับ .text() ซึ่งบังคับใช้ที่ฝั่ง CM33_NS IPC_CMD_UI_SET_TEXT (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ แล้วจึงตั้ง fast drain ให้พร้อมทำงาน | void ui_widget_mgr_set_value | ( | int | handle, |
| int32_t | value ) |
ตั้งค่าตัวเลข; ตั้ง fast drain ให้พร้อมทำงานเพื่อไม่ให้แดชบอร์ดถูกตรึงไว้ที่ 5 FPS
Set numeric value on a widget.
w.value(n) (modui.c:424) IPC_CMD_UI_SET_VALUE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ แล้วจึงตั้ง fast drain ให้พร้อมทำงาน | void ui_widget_mgr_set_position | ( | int | handle, |
| int16_t | x, | ||
| int16_t | y ) |
ย้ายตำแหน่ง widget; ตั้ง fast drain ให้พร้อมทำงานเพื่ออัตราเฟรมระหว่างเล่นเกม
Set position of a widget.
w.pos(x, y) (modui.c:442) IPC_CMD_UI_SET_POSITION (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ แล้วจึงตั้ง fast drain ให้พร้อมทำงาน | void ui_widget_mgr_set_size | ( | int | handle, |
| int16_t | w, | ||
| int16_t | h ) |
เปลี่ยนขนาดของ widget
Set size of a widget.
w.size(w, h) (modui.c:460) IPC_CMD_UI_SET_SIZE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_set_color | ( | int | handle, |
| uint32_t | color ) |
ตั้งสีหลัก 0xRRGGBB
Set primary color of a widget.
0xRRGGBB ทำงานใน GFX-task context w.color(0xRRGGBB) (modui.c:476) IPC_CMD_UI_SET_COLOR (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_set_visible | ( | int | handle, |
| bool | visible ) |
แสดงหรือซ่อน widget หนึ่งตัว
Show or hide a widget.
w.show() / w.hide() (modui.c:486, :496) IPC_CMD_UI_SET_VISIBLE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_set_all_visible | ( | bool | visible | ) |
แสดงหรือซ่อน widget ที่จัดการอยู่ทุกตัว; เป็นตัวสลับมุมมองของการสลับคอนโซลบนหน้า Playground
Show or hide ALL managed widgets at once. Used by Console/UI toggle to switch between widget view and console view.
| int32_t ui_widget_mgr_get_value | ( | int | handle | ) |
อ่านค่าปัจจุบันของ widget; ค่า 0 หมายถึง handle ไม่ถูกต้องได้ด้วย
Get current value of a widget.
w.value() ที่ไม่ใส่อาร์กิวเมนต์ (modui.c:409, แบบสองทาง) IPC_CMD_UI_GET_VALUE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_set_dotmatrix | ( | int | handle, |
| const uint8_t * | bitmap, | ||
| uint8_t | len ) |
โหลดบิตแมปเข้าไปใน widget ชนิด DotMatrix
Set dot matrix bitmap data.
DotMatrix โดยข้อมูล len ไบต์ตามหลัง handle อยู่ใน payload ทำงานใน GFX-task context w.set_pixels(bytes) บน ui.DotMatrix (modui.c:589) IPC_CMD_UI_SET_DOTMATRIX (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_set_image | ( | int | handle, |
| uint16_t | offset, | ||
| const uint8_t * | data, | ||
| uint8_t | len ) |
การส่ง RGB565 เป็นก้อน ๆ เข้าไปใน canvas ของ widget ชนิด Image
Set image pixel data (chunked RGB565 transfer).
| handle | Widget handle (must be UI_WIDGET_IMAGE). |
| offset | Byte offset into the canvas pixel buffer. |
| data | Chunk of RGB565 pixel data. |
| len | Chunk length in bytes. |
Image : offset คือระยะเยื้องเป็นไบต์ในบัฟเฟอร์พิกเซล ส่วน len คือความยาวของก้อนข้อมูล handle ต้องเป็น UI_WIDGET_IMAGE ฝั่งสคริปต์วนส่งก้อนข้อมูลที่ใหญ่ไม่เกินงบของ payload ทำงานใน GFX-task context w.set_image(data) บน ui.Image (modui.c:558 หนึ่งข้อความ IPC ต่อหนึ่งก้อนข้อมูล) IPC_CMD_UI_SET_IMAGE (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_event_push | ( | uint8_t | handle, |
| uint8_t | event_type, | ||
| int32_t | value ) |
ฝั่งผู้ผลิตข้อมูลของ event ring; เฉพาะ LVGL event callback ภายในเท่านั้น
Push an event into the ring buffer (called from LVGL event callbacks).
ui_widget_mgr_event_drain() ถูกเรียกจาก LVGL event callback ภายใน widget manager ที่อยู่ใน archive — มี 2 จุด และทั้งสองเป็นจุดภายใน: widget event callback ตัวทั่วไป ซึ่งผลักเฉพาะ event ที่มีชนิดไม่เป็นศูนย์ และ input event callback สำหรับ input event ทั้ง 12 แบบ ซึ่งจะตรวจ mask การสมัครรับประจำ widget (บิต UI_EVENT_MASK(event_type)) ก่อน แล้วคืนกลับโดยไม่ผลักข้อมูลเข้าคิว เมื่อสคริปต์ไม่ได้ .listen() event นั้นไว้ ที่นี่ยังเป็นจุดที่มีการเรียก ipc_ui_input_activity() ด้วย ทำงานใน GFX-task context w.listen("pressed", cb) และ w.bind(...) เป็นตัวตั้ง mask ที่ยอมให้การผลักข้อมูลผ่านเข้ามา ส่วน ui.poll() เป็นตัวระบายคิว libbento_ipc.a ที่สร้างไว้ล่วงหน้า และไม่ได้ส่งมอบมาเป็นซอร์ส | int ui_widget_mgr_event_drain | ( | ipc_ui_event_t * | out, |
| int | max_events ) |
ระบาย event ออกให้ POLL_EVENTS — เป็น backend ของ ui.poll()
Drain events from the ring buffer.
| out | Output array. |
| max_events | Maximum events to drain. |
max_events รายการลงในอาร์เรย์ที่ผู้เรียกเป็นเจ้าของ แล้วคืนค่าเป็นจำนวนที่ระบายได้ ส่วน dispatch ตอบ POLL_EVENTS ด้วยไบต์ชุดนั้นพอดี คำสั่งเดียวกันนี้ยังเปิดให้เห็น container ที่ถูกซ่อนไว้จาก CREATE ครั้งแรกด้วย — ผ่าน ui_widget_mgr_get_parent() ที่ตรวจ null แล้ว — เพื่อให้ widget ของสคริปต์ปรากฏขึ้นพร้อมกันทีเดียว ทำงานใน GFX-task context ui.poll() (modui.c:1324, แบบสองทาง) — เป็นการเรียกที่ทุก event loop ต้องทำ callback ของ .listen() ถูกเรียกจากผลลัพธ์ของมัน IPC_CMD_UI_POLL_EVENTS (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ โดยส่ง UI_MAX_EVENTS_PER_POLL เป็น max_events | int ui_widget_mgr_count | ( | void | ) |
จำนวน handle ที่ยังใช้งานอยู่; ไม่มีผู้เรียกเลยที่ใด
Get current widget count.
ui_widget_mgr.h:142) กับการนิยามอีก 3 แห่ง — ไม่มีผู้เรียกเลย ตัวอย่างที่เขียนขึ้นเองอ่านค่านี้ใน GFX-task context หลัง clear_all() ในฐานะข้อยืนยันตอนรื้อถอน ส่วนการอ่านจำนวนจาก task อื่นจะเกิด race condition กับเส้นทาง dispatch ui.list() ใช้ ui_widget_mgr_list() ไม่ใช่ฟังก์ชันนี้) | int ui_widget_mgr_list | ( | ipc_ui_widget_info_t * | out, |
| int | max_items ) |
handle และชนิดของ widget ที่ทำงานอยู่ทุกตัว — เป็น backend ของ ui.list()
List all active widgets (handle + type).
| out | Output array of ipc_ui_widget_info_t. |
| max_items | Maximum items to fill. |
max_items รายการ (ส่วน dispatch ส่ง UI_MAX_WIDGETS) แล้วคืนค่าเป็นจำนวนที่เขียนได้ ทำงานใน GFX-task context ui.list() (modui.c:1432, แบบสองทาง) และ ui.get(id) (:1519) รวมถึงการ re-sync ภายในที่ modui.c:138-153 และ :291 IPC_CMD_UI_LIST (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | lv_obj_t * ui_widget_mgr_get_parent | ( | void | ) |
parent ปัจจุบันที่เป็น null ได้; ทุก call site ตรวจ null ของค่านี้
Get the current parent container object.
NULL เมื่อใดก็ตามที่ยังไม่มีหน้า (page) ใดผูก container ไว้ คือช่วงระหว่าง ipc_ui_set_container(NULL) ตอนทำลาย กับการผูกของหน้าถัดไป ส่วน dispatch คำสั่ง UI ตรวจ null แบบเดียวกันนี้ทุกครั้งที่ซ่อน container ตอน CREATE ครั้งแรก ที่เปิดให้เห็นตอน POLL_EVENTS หรือ CLEAR_ALL และที่เปิดให้เห็นเมื่อหมดเวลานิรภัยในกรณีที่ POLL_EVENTS ไม่มาเลย ทำงานใน GFX-task context | void ui_widget_mgr_set_screen | ( | int16_t | width, |
| int16_t | height ) |
ตั้งขนาดหน้าจอและรีเซ็ตกริดของ auto-layout
Set screen dimensions and reset auto-layout grid.
| width | Screen width in pixels (auto-layout wraps at width - 100). |
| height | Screen height in pixels (reserved for future use). |
width - 100 ส่วน height สงวนไว้) ทำงานใน GFX-task context ui.screen(w, h) (modui.c:1647) IPC_CMD_UI_SET_SCREEN (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | int ui_widget_mgr_chart_add_series | ( | int | handle, |
| uint32_t | color ) |
เพิ่มชุดข้อมูลให้ Chart; คืนดัชนี 0-3 หรือ -1
Add a series to a chart widget.
| handle | Widget handle (must be UI_WIDGET_CHART). |
| color | Series color (0xRRGGBB). |
Chart แล้วคืนค่าดัชนีของชุดข้อมูลเป็น 0-3 หรือ -1 ตัว handle ต้องเป็น UI_WIDGET_CHART เป็นแบบสองทางเพื่อให้สคริปต์ทราบดัชนี ทำงานใน GFX-task context w.add_series(color) บน ui.Chart (modui.c:605, แบบสองทาง) IPC_CMD_UI_CHART_ADD_SERIES (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_chart_set_next | ( | int | handle, |
| uint8_t | series_idx, | ||
| int32_t | value ) |
ต่อค่าถัดไปเข้าไปในชุดข้อมูลของ chart ชุดหนึ่ง
Set next value for a specific chart series.
| handle | Widget handle (must be UI_WIDGET_CHART). |
| series_idx | Series index (0-3). |
| value | Data value. |
w.set_next(series, value) (modui.c:631) IPC_CMD_UI_CHART_SET_NEXT (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | int ui_widget_mgr_item_add | ( | const ipc_ui_item_add_t * | it | ) |
ต่อรายการหนึ่งรายการ; ค่าที่คืนมีหลายความหมาย และมีกฎเรื่องตัวโค้ดที่ทำงานจริง 2 ชุด
Append one item to a collection or container widget.
| it | Parsed ITEM_ADD payload; the meaning of a/b/flags/text is per widget type and is tabulated beside ui_widget_type_t. |
>= 0 คือ handle ของหน้า (page) ลูกที่ container สร้างขึ้น (Tabview / Tileview / Win); UI_ITEM_ADD_OK_NO_CHILD (-3) หมายความว่ารายการถูกต่อเข้าไปแล้วโดยไม่มีอ็อบเจ็กต์ลูก; -1 คือตารางเต็ม; -2 คือ handle ไม่ถูกต้อง ชนิดผิด หรือเพิ่มรายการนั้นไม่ได้ คอมเมนต์แบบบล็อกใน header มีผลผูกพัน: ฟังก์ชันนี้ "MUST exist, and behave the same way for the same widget type, in BOTH widget-manager implementations — claw's and game's" เพราะชุดคิต Game คอมไพล์ตัว dispatcher ของ UI ของ claw เข้ากับ widget manager ของ game และชนิดที่ฝ่ายหนึ่งรองรับแต่อีกฝ่ายไม่รองรับจะคืนค่า UI_STATUS_INVALID_TYPE บนบอร์ดบางรุ่น โดยไม่มีข้อผิดพลาดตอน build ที่ใดเลย ทำงานใน GFX-task context w.add_item, w.add_row, w.add_option, w.add_button, w.add_point, w.add_tab, w.add_tile, w.add_page, w.add_span, w.row, w.section, w.separator (modui.c:686 แบบ fire-and-forget และ :694 แบบสองทางสำหรับรูปที่เป็น container) IPC_CMD_UI_ITEM_ADD (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_item_clear | ( | int | handle | ) |
ล้าง widget ชนิดคอลเล็กชันให้ว่าง
Empty a collection widget (all rows / options / buttons / list entries). No-op on a bad handle or a widget type with no collection.
item_add ทำงานใน GFX-task context w.clear_items() (modui.c:836) IPC_CMD_UI_ITEM_CLEAR (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | void ui_widget_mgr_set_prop | ( | int | handle, |
| uint8_t | prop_id, | ||
| int32_t | value ) |
ตั้งคุณสมบัติ UI_PROP_* หนึ่งรายการ; เป็นกลไกที่ .listen() ใช้สมัครรับ event
Set one per-widget property.
| handle | Widget handle. |
| prop_id | UI_PROP_*. |
| value | Property value; two props carry a hi16/lo16 pair (see header). |
UI_PROP_*) มีสองคุณสมบัติที่บรรจุคู่ hi16/lo16 ไว้ใน value ใช้กฎเรื่องตัวโค้ดที่ทำงานจริง 2 ชุดเดียวกันกับ item_add คุณสมบัติ UI_PROP_EVENT_MASK คือกลไกที่ .listen() ใช้สมัครให้ widget รับ input event ทำงานใน GFX-task context w.prop(ui.PROP_*, value) และตัวช่วยที่มีชื่อเฉพาะ w.ticks(), w.digits(), w.col_width(), w.listen(), w.opens(), w.pen(), w.month() (modui.c:856) IPC_CMD_UI_SET_PROP (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เมื่อได้รับคำสั่งนี้ | lv_obj_t * ui_widget_mgr_get_object | ( | int | handle | ) |
อ็อบเจ็กต์ LVGL ที่อยู่หลัง handle; เป็นเส้นทาง GET_TEXT สำหรับข้อความที่ผู้ใช้พิมพ์
The LVGL object behind a handle, or NULL if the slot is empty.
The manager IS the handle table, so answering this is its job. Nothing on the device calls it — it exists so a host harness can drive an object the way a finger would (lv_obj_send_event), which is the only way to photograph behaviour that only a tap can start, such as a menu row loading its page.
NULL เมื่อช่องนั้นว่าง มีข้อเท็จจริง 2 ข้อ ทั้งคู่เป็นจริงและต้องอ่านคู่กัน: header ระบุว่า "Nothing on the device calls it — it exists so a host harness can drive an object the way a finger would" และส่วน dispatch คำสั่ง UI ก็เรียกมันเมื่อได้รับ GET_TEXT — ไม่ใช่จาก opcode GET_OBJECT — เพื่อใช้อ็อบเจ็กต์นั้นอ่านข้อความที่ผู้ใช้พิมพ์ลงใน textarea คอมเมนต์ของ IPC_CMD_UI_GET_TEXT ใน ipc_ui_protocol.h บรรยายเส้นทางนั้นว่าเป็น "the only way anything a user TYPES can reach MicroPython" ทำงานใน GFX-task context w.text() ที่ไม่ใส่อาร์กิวเมนต์ (modui.c:366, แบบสองทาง) บน ui.Textarea หรือ widget ที่มีคีย์บอร์ดรองรับ IPC_CMD_UI_GET_TEXT (ipc_ui_protocol.h): ส่วน dispatch คำสั่ง UI ใน GFX task เรียกฟังก์ชันนี้เพื่อเข้าถึงอ็อบเจ็กต์ของ widget แล้วอ่านข้อความกลับ