Key-based interaction method, electronic device and computer-readable storage medium

文档序号:687336 发布日期:2021-04-30 浏览:7次 中文

阅读说明:本技术 基于按键的交互方法、电子设备以及计算机可读存储介质 (Key-based interaction method, electronic device and computer-readable storage medium ) 是由 张洪治 于 2020-12-28 设计创作,主要内容包括:本发明公开了一种基于按键的交互方法、电子设备以及计算机可读存储介质,该方法包括定时监测各个按键的电平状态,将各所述电平状态对应的状态值赋值至电平变量中与各所述按键对应的电平数据位中;若至少一个电平数据位的状态值为有效电平的状态值,则开始计时;根据计时时长确定按键结果值;将按键结果值赋值至结果变量中状态值为有效电平的状态值的电平数据位对应的结果数据位中,以根据所述结果数据位中的所述按键结果值确定交互参数。本发明提高了多按键的检测和处理效率。(The invention discloses a key-based interaction method, electronic equipment and a computer-readable storage medium, wherein the method comprises the steps of regularly monitoring the level state of each key, and assigning a state value corresponding to each level state to a level data bit corresponding to each key in a level variable; if the state value of at least one level data bit is the state value of the effective level, timing is started; determining a key result value according to the timing duration; and assigning the key result value to a result data bit corresponding to a level data bit of which the state value is the state value of the effective level in the result variable, so as to determine an interactive parameter according to the key result value in the result data bit. The invention improves the detection and processing efficiency of the multiple keys.)

1. A key-based interaction method is characterized in that the key-based interaction method comprises the following steps:

monitoring the level state of each key at regular time, and assigning a state value corresponding to each level state to a level data bit corresponding to each key in a level variable;

if the state value of at least one level data bit is the state value of the effective level, timing is started;

determining a key result value according to the timing duration;

and assigning the key result value to a result data bit corresponding to a level data bit of which the state value is the state value of the effective level in the result variable, so as to determine an interactive parameter according to the key result value in the result data bit.

2. The key-based interaction method of claim 1, wherein after the step of starting timing, further comprising:

and if the state values of all the level data bits are changed into the state values of the invalid level, stopping timing.

3. The key-based interaction method of claim 1, wherein the step of starting timing is followed by:

if the timing duration is longer than the jitter elimination duration, executing the step of determining the key result value according to the timing duration;

if the timing duration is equal to the jitter elimination duration, judging whether the state value of at least one level data bit in the level data bits is the state value of the effective level;

and if the state value of at least one level data bit is not the state value of the effective level, clearing the timing duration.

4. The key-based interaction method of claim 1, wherein the step of determining the key result value according to the timing length comprises:

comparing the timing duration with a preset duration, wherein the preset duration is greater than the jitter elimination duration;

if the timing duration is greater than or equal to the preset duration, assigning a result value corresponding to the long press to the key result value;

and if the timing duration is less than the preset duration, assigning a result value corresponding to the short press to the key result value.

5. The method of claim 4, wherein after the step of comparing the timing duration with a preset duration, the step of determining the key result value according to the timing duration further comprises:

if the timing duration is greater than or equal to the preset duration, acquiring the number of level data bits of the state value of the effective level corresponding to the state value;

if the number is one, the step of assigning the result value corresponding to the long press to the key result value is executed;

and if the number is at least two, assigning the combination to the key result value according to the corresponding result value.

6. The method according to claim 4, wherein after the step of comparing the timing duration with a preset duration, the step of determining the key result value according to the timing duration comprises:

if the timing duration is less than the preset duration, acquiring the number of keys corresponding to the level data bit of the effective level corresponding to the state value;

if the number is one, the step of assigning the result value corresponding to the short press to the key result value is executed;

and if the number is at least two, assigning a result value corresponding to the invalid key to the key result value, and clearing the timing duration.

7. The key-based interaction method of claim 1, wherein the step of determining the key result value according to the timing length comprises:

and when the timing duration of the key is less than the jitter elimination duration, clearing the timing duration, and assigning a result value corresponding to the invalid key to the key result value.

8. A key-based interaction method according to any one of claims 1-7, wherein the key-based interaction method further comprises:

after detecting the newly added key, adding a level data bit corresponding to the newly added key in the level variable;

and adding a result data bit corresponding to the newly added key in the result variable.

9. An electronic device, comprising a memory, a processor, and a key-based interaction program stored in the memory and executable on the processor, the key-based interaction program, when executed by the processor, implementing the steps of the key-based interaction method according to any one of claims 1-8.

10. A computer-readable storage medium, wherein the computer-readable storage medium stores a key-based interaction program, and wherein the key-based interaction program, when executed by a processor, implements the steps of the key-based interaction method of any one of claims 1-8.

Technical Field

The present invention relates to the field of computer technologies, and in particular, to a key-based interaction method, an electronic device, and a computer-readable storage medium.

Background

In an embedded system, a key is a commonly used man-machine interaction device. When the key is pressed and released, the processor executes corresponding codes. However, in many electronic devices, there are often multiple keys, for example, multiple keys may be provided on a smart watch, and the electronic device is controlled by long pressing, short pressing and a combination thereof.

The existing independent keys generally use a mechanical elastic switch, one end of the existing independent key is connected with a pin of a processor, the other end of the existing independent key is connected with the ground or high level of a system, an embedded system judges the on-off state of the key by detecting the level state of the pin connected with the key, the current state of the independent key is recorded by corresponding timing variable and state variable existing in each independent key based on an interactive method of the independent key, and whether the independent key is pressed for a long time or for a short time or is pressed in a combined mode is further judged according to the state of the independent key. When a plurality of independent keys are processed, the program operation period is increased, and the detection and processing efficiency of the plurality of independent keys is low.

Disclosure of Invention

The invention mainly aims to provide a key-based interaction method, electronic equipment and a computer-readable storage medium, and aims to solve the problem of low detection and processing efficiency of multiple keys.

In order to achieve the above object, the present invention provides a key-based interaction method, which includes the following steps:

monitoring the level state of each key at regular time, and assigning a state value corresponding to each level state to a level data bit corresponding to each key in a level variable;

if the state value of at least one level data bit is the state value of the effective level, timing is started;

determining a key result value according to the timing duration;

and assigning the key result value to a result data bit corresponding to a level data bit of which the state value is the state value of the effective level in the result variable, so as to determine an interactive parameter according to the key result value in the result data bit.

In an embodiment, after the step of starting the timing, the method further includes: and if the state values of all the level data bits are changed into the state values of the invalid level, stopping timing.

In one embodiment, the step of starting timing is followed by: if the timing duration is longer than the jitter elimination duration, executing the step of determining the key result value according to the timing duration; if the timing duration is equal to the jitter elimination duration, judging whether the state value of at least one level data bit in the level data bits is the state value of the effective level; and if the state value of at least one level data bit is not the state value of the effective level, clearing the timing duration.

In an embodiment, the step of determining the key result value according to the timing length includes: comparing the timing duration with a preset duration, wherein the preset duration is greater than the jitter elimination duration; if the timing duration is greater than or equal to the preset duration, assigning a result value corresponding to the long press to the key result value; and if the timing duration is less than the preset duration, assigning a result value corresponding to the short press to the key result value.

In an embodiment, after the step of comparing the timing duration with a preset duration, the step of determining the key result value according to the timing duration further includes: if the timing duration is greater than or equal to the preset duration, acquiring the number of level data bits of the state value of the effective level corresponding to the state value; if the number is one, the step of assigning the result value corresponding to the long press to the key result value is executed; and if the number is at least two, assigning the combination to the key result value according to the corresponding result value.

In an embodiment, after the step of comparing the timing duration with a preset duration, the step of determining the key result value according to the timing duration includes: if the timing duration is less than the preset duration, acquiring the number of keys corresponding to the level data bit of the effective level corresponding to the state value; if the number is one, the step of assigning the result value corresponding to the short press to the key result value is executed; and if the number is at least two, assigning a result value corresponding to the invalid key to the key result value, and clearing the timing duration.

In an embodiment, the step of determining the key result value according to the timing length includes: and when the timing duration of the key is less than the jitter elimination duration, clearing the timing duration, and assigning a result value corresponding to the invalid key to the key result value.

In one embodiment, the key-based interaction method further includes: after detecting the newly added key, adding a level data bit corresponding to the newly added key in the level variable; and adding a result data bit corresponding to the newly added key in the result variable.

In order to achieve the above object, the present invention further provides an electronic device, which includes a memory, a processor, and a key-based interaction program stored in the memory and executable on the processor, wherein the key-based interaction program, when executed by the processor, implements the steps of the key-based interaction method as described above.

To achieve the above object, the present invention further provides a computer readable storage medium storing a key-based interaction program, which when executed by a processor implements the steps of the key-based interaction method as described above.

The invention provides a key-based interaction method, electronic equipment and a computer-readable storage medium, which are characterized in that the level state of each key is monitored at regular time, and the state value corresponding to each level state is assigned to the level data bit corresponding to each key in a level variable; if the state value of at least one level data bit is the state value of the effective level, timing is started; determining a key result value according to the timing duration; and assigning the key result value to a result data bit corresponding to a level data bit of which the state value is the state value of the effective level in the result variable, and determining the interactive parameter according to the key result value in the result data bit. Because the state value of the level state of the key is added to the level data bit, the key result value is added to the result data bit, and the plurality of keys are uniformly detected and processed, the condition that the detection period is long due to the fact that the plurality of keys correspond to independent detection programs is avoided, and the detection and processing efficiency of the plurality of keys is improved.

Drawings

Fig. 1 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention;

FIG. 2 is a flowchart illustrating a first exemplary embodiment of a button-based interaction method according to the present invention;

FIG. 3 is a flowchart illustrating a second exemplary embodiment of a button-based interaction method according to the present invention;

FIG. 4 is a flowchart illustrating a detailed process of step S30 of the third embodiment of the key-based interaction method according to the present invention;

FIG. 5 is a flowchart illustrating a detailed process of step S30 of the fourth embodiment of the key-based interaction method according to the present invention;

fig. 6 is a detailed flowchart of step S30 of the fifth embodiment of the key-based interaction method of the present invention.

The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.

Detailed Description

It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

The main solution of the embodiment of the invention is as follows: monitoring the level state of each key at regular time, and assigning a state value corresponding to each level state to a level data bit corresponding to each key in a level variable; if the state value of at least one level data bit is the state value of the effective level, timing is started; determining a key result value according to the timing duration; and assigning the key result value to a result data bit corresponding to a level data bit of which the state value is the state value of the effective level in the result variable, and determining the interactive parameter according to the key result value in the result data bit.

Because the state value of the level state of the key is added to the level data bit, the key result value is added to the result data bit, and the plurality of keys are uniformly detected and processed, the condition that the detection period is long due to the fact that the plurality of keys correspond to independent detection programs is avoided, and the detection and processing efficiency of the plurality of keys is improved.

As an implementation, the electronic device may be as shown in fig. 1.

An embodiment of the present invention relates to an electronic device, including: a processor 101, e.g. an MCU, a memory 102, a communication bus 103. Wherein a communication bus 103 is used for enabling the connection communication between these components. The electronic device may be a wearable device such as a smart watch, a smart bracelet, a VR (Virtual Reality) device, an AR (Augmented Reality) device, or an intelligent speaker, a projector, or a navigation device.

The memory 102 may be a high-speed RAM memory or a non-volatile memory (e.g., a disk memory). As shown in fig. 1, a key-based interactive program may be included in a memory 102, which is a computer-readable storage medium; and the processor 101 may be configured to invoke a key-based interactive program stored in the memory 102 and perform the following operations:

monitoring the level state of each key at regular time, and assigning a state value corresponding to each level state to a level data bit corresponding to each key in a level variable;

if the state value of at least one level data bit is the state value of the effective level, timing is started;

determining a key result value according to the timing duration;

and assigning the key result value to a result data bit corresponding to a level data bit of which the state value is the state value of the effective level in the result variable, so as to determine an interactive parameter according to the key result value in the result data bit.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

and if the state values of all the level data bits are changed into the state values of the invalid level, stopping timing.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

if the timing duration is longer than the jitter elimination duration, executing the step of determining the key result value according to the timing duration;

if the timing duration is equal to the jitter elimination duration, judging whether the state value of at least one level data bit in the level data bits is the state value of the effective level;

and if the state value of at least one level data bit is not the state value of the effective level, clearing the timing duration.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

comparing the timing duration with a preset duration, wherein the preset duration is greater than the jitter elimination duration;

if the timing duration is greater than or equal to the preset duration, assigning a result value corresponding to the long press to the key result value;

and if the timing duration is less than the preset duration, assigning a result value corresponding to the short press to the key result value.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

if the timing duration is greater than or equal to the preset duration, acquiring the number of level data bits of the state value of the effective level corresponding to the state value;

if the number is one, the step of assigning the result value corresponding to the long press to the key result value is executed;

and if the number is at least two, assigning the combination to the key result value according to the corresponding result value.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

if the timing duration is less than the preset duration, acquiring the number of keys corresponding to the level data bit of the effective level corresponding to the state value;

if the number is one, the step of assigning the result value corresponding to the short press to the key result value is executed;

and if the number is at least two, assigning a result value corresponding to the invalid key to the key result value, and clearing the timing duration.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

and when the timing duration of the key is less than the jitter elimination duration, clearing the timing duration, and assigning a result value corresponding to the invalid key to the key result value.

In one embodiment, the processor 101 may be configured to invoke a key-based interaction program stored in the memory 102 and perform the following operations:

after detecting the newly added key, adding a level data bit corresponding to the newly added key in the level variable;

and adding a result data bit corresponding to the newly added key in the result variable.

Based on the hardware architecture of the electronic equipment, the embodiment of the interaction method based on the keys is provided.

Referring to fig. 2, fig. 2 is a first embodiment of a key-based interaction method according to the present invention, where the key-based interaction method includes the following steps:

step S10, periodically monitoring the level states of the keys, and assigning the state values corresponding to the level states to the level data bits corresponding to the keys in the level variables.

Specifically, the level state of each key is monitored in real time according to a preset time interval, and the level state can be an active level and an inactive level. Wherein the active level may be a high level and the inactive level may be a low level; or the active level may be low and the inactive level may be high. The state value corresponding to the level state of the key may be a numerical value, and for example, the state value corresponding to the active level may be 1, and the state value corresponding to the active level may be 0. The level variable is a variable for recording the level state of the key, the level data bit is used for storing a state value corresponding to the level state, and the state value corresponding to the level state is assigned to the level data bit corresponding to the key in the level variable.

In step S20, if the state value of at least one level data bit is the state value of the active level, timing is started.

Specifically, when the state value corresponding to the level data bit corresponds to the state value of the active level, it indicates that the key is pressed, and in order to determine the key pressing result, the time length of the key at the active level needs to be counted. When the state values of the level data bits all become the state values corresponding to the invalid level, the timing is stopped.

Step S30, determining a key result value according to the timing duration;

specifically, the key result value is determined according to the time length corresponding to the key of the active level. The key result value may be represented in binary, and illustratively, the invalid key result value is 00, the short-pressed key result value is 01, the long-pressed key result value is 10, and the combined-pressed key result value is 11.

Step S40, assigning the key result value to a result data bit corresponding to a level data bit of a state value of which the state value is an active level in the result variable, so as to determine an interaction parameter according to the key result value in the result data bit.

Specifically, the key result value is assigned to a corresponding result data bit in a result variable, wherein the level variables of the level data bit of the key correspond to the result variables in the result data bit one to one. And determining an interaction parameter according to the key result value in the result data bit, and calling the terminal equipment according to the interaction parameter.

The preset number of keys, level data bits and result data bits may be preset in the program, and the newly added keys may be assigned to the preset keys upon detection of the newly added keys. If the preset number of keys is not preset, after the newly added keys are detected, level data bits corresponding to the newly added keys can be added to the level variable; and adding a result data bit corresponding to the newly added key in the result variable, and determining a result value of the key according to the level variable of the key. The problem that due to the fact that a plurality of keys correspond to independent detection programs, new detection programs need to be added, resource expenditure of a processor is increased in a multiple mode, the program operation period is obviously increased, and the real-time performance of the system is reduced is solved. And the application does not need to add a new detection program or repeatedly execute programs with similar functions, thereby facilitating the extension of the keys.

In the technical scheme of the embodiment, the level state of each key is monitored at regular time, timing is started when the level state is an effective level, and a key result value is determined according to the level state and timing duration. Because the state value of the level state of the key is assigned to the level data bit, the key result value is assigned to the result data bit, and the plurality of keys are uniformly detected and processed, the condition that the detection period is longer because the plurality of keys correspond to independent detection programs is avoided, and the detection and processing efficiency of the plurality of keys is improved.

Referring to fig. 3, fig. 3 is a second embodiment of the key-based interaction method of the present invention, and based on the first embodiment, after step S20, the method further includes:

step S50, if the timing duration is longer than the jitter elimination duration, executing the step of determining the key result value according to the timing duration;

step S60, if the timing duration is equal to the jitter elimination duration, determining whether the state value of at least one level data bit in the level data bits is the state value of the effective level;

in step S70, if there is no state value of at least one level data bit as the state value of the active level, the timing duration is cleared.

Specifically, the switch used for the key is usually a mechanical elastic switch, and when the mechanical contact is opened and closed, the key switch is not immediately and stably turned on when the mechanical contact is closed, and is not turned off at a moment when the mechanical contact is opened, so that the key is subjected to a series of shakes at the moment of closing and opening. The shake elimination duration is used for judging whether the key shakes, and the shake elimination duration is determined by the mechanical characteristics of the key and is generally 5 ms-10 ms. When the timing duration of the key is longer than the jitter elimination duration, the key result and the key result value need to be determined according to the timing duration, the key result may be invalid, long pressed, short pressed, or combined pressed, and the corresponding key result value may be 00, 01, 10, and 11. And when the timing duration of the key is less than the jitter elimination duration, clearing the timing duration and determining that the key result is invalid. And when the timing duration is equal to the jitter elimination duration, judging whether at least one of the key level variables is an effective level, if not, determining that the key result is invalid, clearing the key timing duration, and if so, determining whether at least two keys are combined according to the duration of the other key. The combined press is a press result including at least two press key combinations, and for example, in the a key, the b key and the c key, when the a key and the b key correspond to state values corresponding to an active level and a corresponding timing duration is longer than a jitter elimination duration, the press result values of the a key and the b key are the combined press. When the timing duration of the key is longer than the jitter elimination duration, the key result can be long press, short press or combined press. And after the key result value is determined, the timing duration is cleared, so that the detection of the next key result value is facilitated.

In the technical scheme of the embodiment, the key result value is determined by the timing duration, whether the key is effective or not can be determined, the key result of the key can be determined under the effective condition, different interaction parameters are determined according to the key result, and the interaction function is realized.

Referring to fig. 4, fig. 4 is a third embodiment of the interaction method based on keys according to the present invention, and based on the second embodiment, the step S30 includes:

step S31, comparing the timing duration with a preset duration, wherein the preset duration is greater than the jitter elimination duration;

step S32, if the timing duration is greater than or equal to the preset duration, assigning a result value corresponding to the long press to the key result value;

and step S33, if the timing duration is less than the preset duration, assigning a result value corresponding to the short press to the key result value.

Specifically, the timing duration and the preset duration are compared, the preset duration is used for judging whether the key is pressed for a long time or a short time, and the preset duration is greater than the shake elimination duration. When the timing duration is longer than or equal to the preset duration, the pressing time of the key is effective and longer, and the key result value of the key corresponds to the key result of long pressing. And when the timing duration is shorter than the preset duration, the pressing time of the key is effective but shorter, and the key result value of the key corresponds to the key result of the short press.

In the technical scheme of the embodiment, the key result value of the key is determined according to the timing duration of the key, and the key result value of long pressing or short pressing of the key can be effectively distinguished. More interaction parameters can be determined according to different result values, and different interaction functions are realized.

Referring to fig. 5, fig. 5 is a second embodiment of the key-based interaction method of the present invention, based on the first embodiment, after the step S31, the step S30 further includes:

step S34, if the timing duration is greater than or equal to the preset duration, acquiring the number of level data bits of the state value of the effective level corresponding to the state value;

step S35, if the number is one, performing the step of assigning the result value corresponding to the long press to the key result value;

and step S36, if the number is at least two, assigning the corresponding result value of the combination to the key result value.

Specifically, when the timing duration is greater than or equal to the preset timing duration, the key corresponding to the timing duration is pressed for a long time, and the number of keys whose state values correspond to the effective level in the level data bit needs to be obtained. When the number of the keys is one, the corresponding key result is long pressing. When the key result is multiple, the key result is a combined press, which indicates that other keys are pressed within the timed time length. After determining the result, the timer period needs to be cleared.

In the technical solution of this embodiment, the key result value of the key is determined according to the number of keys of the active level, and the key result values of long pressing or combined pressing of the keys can be effectively distinguished. More interaction parameters can be determined according to different result values, and different interaction functions are realized.

Referring to fig. 6, fig. 6 is a second embodiment of the key-based interaction method of the present invention, based on the first embodiment, after the step S31, the step S30 further includes:

step S37, if the timing duration is less than the preset duration, acquiring the number of keys corresponding to the level data bit of the effective level corresponding to the state value;

step S38, if the number is one, performing the step of assigning the result value corresponding to the short press to the key result value;

and step S39, if the number is at least two, assigning a result value corresponding to the invalid key to the key result value, and clearing the timing duration.

Specifically, when the timing duration is shorter than the preset duration, the number of keys with the middle state value corresponding to the effective level is obtained, and if the number of the keys is one, the key result is determined to be a short key. And when the number of the keys is at least two, determining that the keys are invalid keys, assigning a result value corresponding to the invalid key to a key result value, and clearing the timing duration.

In the technical solution of this embodiment, the key result value of the key is determined according to the number of keys of the active level, and the short pressing of the key or the invalid key result value can be effectively distinguished. Different interaction parameters may be determined based on different result values.

The present invention also provides an electronic device, which includes a memory, a processor, and a key-based interaction program stored in the memory and executable on the processor, wherein the key-based interaction program, when executed by the processor, implements the steps of the key-based interaction method according to the above embodiments.

The present invention also provides a computer readable storage medium, which stores a key-based interaction program, and when the key-based interaction program is executed by a processor, the key-based interaction program implements the steps of the key-based interaction method according to the above embodiments.

The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.

It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a computer-readable storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above, and includes several instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.

The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

13页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种用于电子产品的多功能按键开关电路

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类