2173 views|0 replies

20

Posts

73

Resources
The OP
 

How to realize the timing and timer operation functions of the Dacai serial port screen [Copy link]

1. Overview
This article mainly describes how to use Lua scripts to implement the timing and timer functions of Guangzhou Dacai UART screen. At present, these two applications are widely used in industry or life. The timing function of the large color screen is to set a specific time, and then when the time reaches the time set by the user, the device will be notified by message, and the device can act according to the specific execution method; the timing function of the large color screen is to set a time range for timing. After the corresponding timing is started, the time will be counted down. After the time reaches 0, the device will be notified by message, and the device can act according to the specific execution method.
2. Scope of application
This article is applicable to Guangzhou Dacai UART screen M series, F series, IoT type and other models that support Lua scripts.
3. Timing function
3.1 Interface configuration
The timing function of Guangzhou Dacai UART screen is mainly: the user sets the timing time on the interface and clicks the "Start" button to trigger. When the timing time is reached, the screen will send a notification command to the device through the serial port. The
interface configuration of this example is mainly realized through text controls and button controls. The text control inputs the timing parameters through the system keyboard, and the button control realizes the trigger action confirmation. The interface settings are shown in Figure 3-1.
Figure 3-1 Timing interface configuration

3.1.1 Control Settings
The controls used in this example are text controls and button controls.
(1) The text control is mainly used for parameter input, and the corresponding input method is set to system keyboard input. The corresponding property settings are shown in Figure 3-2.
Figure 3-2 Text Control Properties
(2) The button control is mainly used to trigger actions. The button control has two states: pop-up/pressed. The operation style is set to switch. The pop-up state is start, and the pressed state is stop; the corresponding property settings are shown in Figure 3-3.
Figure 3-3 Button Control Properties

3.2 Script Writing
Functions implemented by the script: The user sets the timing time on the interface, and then clicks the start button to trigger the timing. When the timing time is reached, the screen will send instructions to the device through the serial port, and the button display on the interface will change from stop to start; at the same time, the user can also click the button to stop the current operation and reset the timing time. Clicking start will start the timing at the newly set time.
Ideas for script implementation: Use the control notification function on_control_notify(screen,control,value) to execute the button press or pop-up operation, corresponding to the start timer start_timer(timer_id,timeout,countdown,repeat) to enter the on_timer(timer_id) function, and perform operations according to the corresponding timer_id. Get the time set by the user through get_value(screen,value), and then get_data_time() to obtain the current RTC time. Finally, determine whether the time set by the user is consistent with the current RTC time. If it is consistent, it will trigger uart_send_data(packet) to send the serial port command AA 01. The corresponding variable functions are shown in Figures 3-4 and 3-5.

Figure 3-4 Timer button control trigger function
Figure 3-5 Timing function
4. Timing function
4.1 Interface configuration
The timing function of Guangzhou Dacai serial screen is mainly: the user sets the timing time on the interface, clicks the "Start" button to trigger, and the time will enter the countdown. When the timing time is up, the screen will send a notification command to the device through the serial port. The
interface configuration of this example is mainly realized through text controls and button controls. The text control uses the system keyboard to input the timing parameters, and the button control realizes the trigger action confirmation. The interface settings are shown in Figure 4-1.
Figure 4-1 Timing interface configuration

4.1.1 Control Configuration
The control configuration of the timing interface of the Dacai serial port screen is the same as that of the timing interface. For details, please refer to the control configuration of the timing interface.
4.2 Script Writing
Functions implemented by the script: The user sets the timing time on the interface, and then clicks the start button to trigger the countdown. When the timing time is reached, the screen will send instructions to the device through the serial port, and the button display on the interface will change from stop to start; at the same time, the user can also click the button to stop the current operation and reset the timing time. Clicking start will count at the newly set time.
The idea of script implementation: Use the control notification function on_control_notify(screen,control,value) to execute the button press or pop-up operation, and at the same time convert the set time value into the second variable count, and then start the timer start_timer(timer_id,timeout,countdown,repeat) to enter the on_timer(timer_id) function, and perform operations according to the corresponding timer_id. Enter on_timer(timer_id) once a second through timing. Each entry will trigger the value of count to decrease by 1. When count is equal to 0, it means that the timing time has been reached, and uart_send_data(packet) will be triggered to send the serial port command AB 01. The corresponding variable functions are shown in Figure 4-2 and Figure 4-3.
Figure 4-2 Timing button control trigger function
Figure 4-3 Timing function
V. Implementation Debugging
5.1 Timing Function Debugging After
the project is set up, you can debug the written Lua script through the virtual screen. After the user sets the corresponding timing time, when the time is reached, the virtual screen serial port will issue the AA 01 command, as shown in Figure 5-1. 5.2 Timing Function Debugging After the project is set up, you can debug the written Lua script through the virtual screen. After the user sets the corresponding timing time, when the timing time is 0, the virtual screen serial port will issue the AB 01 command, as shown in Figure 5-2. VI. Summary The above introduces how the Dacai serial port screen realizes the timing and timing operation functions. These two functions are widely used in life, and the corresponding Lua script implementation relies on the timer function to achieve. The use of the timer function is relatively simple. When the timer is turned on, the function inside the timer will be executed according to the set timing. The corresponding execution function can be written by the user according to needs.
Figure 5-1 Timing function debugging


Figure 5-2 Timing function debugging

This post is from MCU
Personal signature

专业提供TFT彩色串口显示屏、

 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list