Ú¸€´# ====================== Version Information ====================== # HF-LPT262-LCD V1.0.0 # Script Example # ==================== Global Variable Definitions ==================== g_str_real_time = "" g_wifi_status = 0 g_wifi_flashing = 0 g_wifi_rssi = 0 g_ble_status = 0 g_startstop = 0 g_time_countdown = 0 g_str_countdown = "00:00:00" countdown = "00:00" hidata_prefix = HIDATAPREFIX hidata_ok = "ok" info = "" reply = "" key = "" value = "" # ==================== Functions ==================== FUNCTION _format_countdown() IF(g_startstop > 0 && g_time_countdown > 0) g_time_countdown = g_time_countdown - 1 g_str_countdown = GETCOUNTDOWN(g_time_countdown) # Format: HH:MM:SS # Extract MM:SS countdown = g_str_countdown.subString(3, 8) SEND(L, key_countdown, countdown) END END FUNCTION _send_uart_response() reply = hidata_prefix + info SEND(UART, uart0, reply) reply = "" info = "" END # ==================== Update Screen ==================== FUNCTION _update_show() is_keydata = 1 info = hidata_ok # Keyword processing IF(key == "SCENE") LCDSCENEUPDATE(value) is_keydata = 0 END IF(key == "LCDBACKLIGHT") LCDBACKLIGHT(value) is_keydata = 0 END IF(key == "SCREENSAVE") LCDSCREENSAVE(value) is_keydata = 0 END IF(key == "WIFISTATUS") info = key + "=" + g_wifi_status.prtString() is_keydata = 0 END IF(key == "BLESTATUS") info = key + "=" + g_ble_status.prtString() is_keydata = 0 END IF(key == "GETUTCTIME") info = key + "=" + g_str_real_time is_keydata = 0 END IF(key == "STARTSTOP") IF(value == "0") # Stop countdown g_startstop = 0 g_time_countdown = 0 g_str_countdown = "00:00:00" countdown = "00:00" SEND(L, key_countdown, countdown) ELSE # Start countdown (value unit: minutes) g_time_countdown = GETVALUEINT(value) IF(g_time_countdown > 0) g_time_countdown = g_time_countdown * 60 g_startstop = 1 END END is_keydata = 0 END # Handle unmatched keywords (passthrough) IF(is_keydata == 1) SEND(L, key, value) END _send_uart_response() END FUNCTION _update_device_status() # WiFi status handling g_wifi_status = WIFISTATE IF(g_wifi_status == 1) SEND(L, wifi_status, g_wifi_status) ELSE g_wifi_flashing = 1 - g_wifi_flashing SEND(L, wifi_status, g_wifi_flashing) END # WiFi signal strength g_wifi_rssi = WIFIRSSI SEND(L, wifi_rssi, g_wifi_rssi) # BLE status g_ble_status = BLESTATE SEND(L, ble_status, g_ble_status) END FUNCTION _update_time() IF(g_wifi_status == 1) g_str_real_time = GETREALTIME # Format: YYYY-MM-DD HH:MM:SS # Extract HH:MM utc_time = g_str_real_time.subString(11, 16) SEND(L, real_time, utc_time) END END # ==================== Event Handling ==================== RECV UART uart0 head = 0 IF(hidata_prefix.length() > 0) head = INPUT.indexOf(hidata_prefix) END sign = INPUT.indexOf("=") # Has prefix and has equals sign: set parameter (key=value) IF(head >= 0 && sign > 0 && sign > head) head = head + hidata_prefix.length() key = INPUT.subString(head, sign) value = INPUT.subString(sign + 1, INPUT.length()) _update_show() END # Has prefix but no equals sign: query parameter (key only) IF(head >= 0 && sign < 0) head = head + hidata_prefix.length() key = INPUT.subString(head, INPUT.length()) value = "" _update_show() END # Clear variables key = "" value = "" END # ==================== Scheduled Task ==================== TIMER HeartBeat 1000 _update_device_status() _update_time() _format_countdown() END ÿÿÿÿÿÿÿÿÿÿ