WO2019037240A1 - 按键配置方法、按键运行方法、装置及电子设备 - Google Patents
按键配置方法、按键运行方法、装置及电子设备 Download PDFInfo
- Publication number
- WO2019037240A1 WO2019037240A1 PCT/CN2017/108085 CN2017108085W WO2019037240A1 WO 2019037240 A1 WO2019037240 A1 WO 2019037240A1 CN 2017108085 W CN2017108085 W CN 2017108085W WO 2019037240 A1 WO2019037240 A1 WO 2019037240A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- button
- function
- triggered
- state
- buttons
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
Definitions
- the present invention relates to the field of electronic technologies, and in particular, to a button configuration method, a button operation method, an apparatus, and an electronic device.
- buttons set on an electronic device are configured with only one button function for each button.
- the button can be directly connected to the pin of the MCU (Micro Control Unit) through I/O (input/output, input/output port), but when the number of buttons is large, it cannot be guaranteed.
- MCU Micro Control Unit
- I/O input/output, input/output port
- Each button can be directly connected to the MCU's pins, so additional hardware circuitry needs to be designed to connect each button to the MCU.
- such a button configuration method has complicated hardware circuit design, resulting in an increase in hardware circuit design cost and a long development cycle.
- the present invention provides a button configuration method, a button operation method, a device, and an electronic device, which are used to solve the technical problem that the hardware configuration of the button configuration method in the prior art is complicated, resulting in high development cost and long development cycle. It greatly simplifies the hardware circuit, does not require the design cost of the hardware circuit, and shortens the development cycle.
- the present invention provides a button configuration method, wherein the button is connected to a pin of a control component in an electronic device in a one-to-one correspondence, and the method includes:
- buttons are generated based on the pin information corresponding to each of the buttons and the button function function corresponding to the different triggered states of each of the buttons; the button execution program of each button is used to be executed to implement a corresponding button function when any of the triggered states of each button is generated; any triggered state of each of the buttons is determined based on a change state of a level of a pin of each of the button connections and the correspondence relationship .
- the generating a button execution program includes: based on the pin information corresponding to each of the buttons and the button function function corresponding to the different triggered states of each of the buttons:
- the structure body includes at least pin information and a plurality of triggered states
- the button execution program is generated according to the button execution code of at least one button.
- the pin function according to each button connection and the button function function corresponding to the different triggered state of each button, after constructing the button execution code of each button based on the structure further includes :
- the invention also provides a button operation method, which is applied to an electronic device, and the button is connected to the pins of the control component in the electronic device one-to-one;
- the method includes:
- the triggered state includes a click state, a double click state, or a long press state
- Determining, according to the corresponding relationship between the different triggered states and the different changed states of the one of the buttons, determining the currently triggered state corresponding to the current change state includes:
- the currently triggered state is a click state.
- the determining, according to the corresponding relationship between the different triggered states and the different changed states of the one of the buttons, determining the currently triggered state corresponding to the current change state includes:
- the invention provides a button configuration device, wherein the button is connected in one-to-one correspondence with a pin of a control component in an electronic device, and the device comprises:
- a first determining module configured to determine pin information corresponding to each button
- a matching module configured to establish a correspondence between different triggered states of each of the buttons and different change states of levels of the corresponding pins
- a second determining module configured to determine a button function function corresponding to each of the different triggered states of each of the buttons
- a generating module configured to generate a button execution program based on pin information corresponding to each of the buttons and a button function function corresponding to each of the different triggered states of the button; the button execution program of each button is used for Executing to implement a corresponding button function when any of the triggered states of each of the buttons occurs; any of the triggered states of each of the buttons is based on a change state of a level of a pin connected to each of the buttons and The correspondence is determined.
- the invention also provides a button operation device, wherein the button is connected to the pins of the control component in the electronic device one-to-one;
- the device includes:
- a first detecting module configured to detect a current change state of a level of a pin corresponding to any one of the buttons
- a third determining module configured to determine a current triggered state corresponding to the current change state, based on a corresponding relationship between different triggered states and different changed states of the one of the buttons;
- a first searching module configured to search for a key function function corresponding to the currently triggered state based on the key execution code
- the first execution module is configured to execute the button function function.
- the present invention provides an electronic device including a memory and a processing component
- the memory stores one or more computer program instructions
- the processing component invokes and executes the one or more computer program instructions to:
- the present invention can obtain the following technical effects:
- the invention provides a button configuration method, a button operation method, a device and an electronic device.
- the method is applied to an electronic device, and the buttons of the electronic device are connected to the pins of the control component one-to-one.
- determining the pin information corresponding to each button a correspondence relationship between different triggered states of each button and different changes states of the levels of the corresponding pins is established.
- Determining a key function function corresponding to each of the different triggered states of each of the keys generating a button execution based on the pin information corresponding to each of the keys and the key function function corresponding to each of the different triggered states of each of the keys program.
- the invention implements a program by modular designing a key, so that the key execution program has high portability, reduces the complexity of the hardware circuit design, reduces the development cost, and shortens the development cycle.
- FIG. 1 is a flow chart of an embodiment of a button configuration method according to an embodiment of the present invention
- FIG. 2 is a flow chart of an embodiment of a method for operating a button according to an embodiment of the present invention
- FIG. 3 is a schematic structural diagram of an embodiment of a button configuration apparatus according to an embodiment of the present invention.
- FIG. 4 is a schematic structural diagram of an embodiment of a button operating device according to an embodiment of the present invention.
- FIG. 5 is a schematic structural diagram of another embodiment of an electronic device according to an embodiment of the present invention.
- buttons With the maturity of electronic technology, electronic devices have more and more functions, and the interaction between users and electronic devices is usually achieved by pressing buttons.
- a button set on an electronic device such as a smart speaker or a smart wristband is provided with only one button function for each button.
- Key detection usually requires synchronization of hardware circuits and software programs to ensure button reliability and detection efficiency.
- the design of the hardware circuit needs to be determined according to the actual number of buttons and the number of pins of the corresponding MCU (Micro Control Unit). When the number of buttons is small, the button can be directly connected to the MCU through the I/O (input/output, input/output port), but when the number of buttons is large, there is no guarantee that each button can be directly connected to the MCU. On the pin, this requires the design of additional hardware circuitry to connect each button to the MCU. Since the designed hardware circuit is only for specific functional requirements, software design must be performed for the designed hardware circuit during software development to ensure the reliability and detection efficiency of the button.
- the invention provides a button configuration method, a button operation method, device and device.
- the method is applied to an electronic device, and the buttons of the electronic device are connected with the pins of the control component one by one, and no additional design is needed.
- Complex hardware circuits By determining the pin information corresponding to each button, a correspondence relationship between different triggered states of each button and different changes states of the levels of the corresponding pins is established.
- the invention implements a program by modular designing a key, so that the key execution program has high portability, reduces the complexity of the hardware circuit design, reduces the development cost, and shortens the development cycle.
- FIG. 1 is a flowchart of an embodiment of a method for configuring a button according to an embodiment of the present invention, where the electronic device is The buttons are connected one-to-one with the pins of the control unit.
- the method can include:
- each button is connected to the pins in the control component one by one through a hardware circuit.
- the pin information includes a port type and a pin number corresponding to the pins in the button connection control component.
- the control component may be an MCU (Micro Control Unit) or a processor. Therefore, the hardware circuit connection is simple, and no complicated design hardware circuit is required to realize the connection between each button and the processing component, thereby greatly reducing the design cost of the hardware circuit.
- MCU Micro Control Unit
- the triggered state of the button may include a click state, a double click state, or a long press state.
- any button When any button is pressed, it will cause the level state of the corresponding pin to change, and the level of change caused by different triggered states is different.
- buttons 104 Generate a button execution program based on the pin information corresponding to each of the buttons and the button function function corresponding to each of the different triggered states of the buttons.
- the button function function is pre-established in and stored in a memory connected to the control component, and the button function function of each button is executed by determining a button function function corresponding to each of the different triggered states of each button. a program for being executed to implement a corresponding button function when any of the triggered states of each of the buttons occurs; any of the triggered states of each of the buttons is based on a level of a pin of each of the buttons The change state and the correspondence relationship are determined.
- the generating a key execution function based on the pin information corresponding to each of the keys and the key function of each of the different triggered states of each of the keys includes:
- the structure body includes at least pin information and a plurality of triggered states
- the button execution program is generated according to the button execution code of at least one button.
- the present invention constructs the button execution program using modular design requirements.
- the structure of the program is first executed by defining a key.
- the structure defines the structure and meaning of the key execution program.
- the execution code of the any button is constructed based on the structure according to the pin information of the button to be tested and the button function function corresponding to the different triggered state of the button to be tested. And generating a button execution program according to the execution code of at least one button.
- an electronic device corresponds to four buttons, including: a mute button, a previous button, a next button, and a power button.
- the mute button when the mute button is clicked, the device mute function can be realized.
- the button When the button is pressed for a long time, the device can be connected to the network; when the previous button is clicked, click to implement the play-pause function, and when the button is pressed, the function of playing the previous song is realized;
- the function of playing the next song is realized when the first button is clicked or long pressed; the voice wake-up function is realized when the power button is clicked, and the long press is to implement the power-on or power-off function.
- the key execution procedure for generating four buttons is as follows:
- each of the four buttons defined by the button execution program respectively corresponds to a function function according to the triggered state.
- the set function function is relatively small, the triggered state corresponding to any one of the buttons can be set.
- the function is empty.
- the pin information according to each button connection and the button function function corresponding to different triggered states of each button are used to construct each button based on the structure.
- the button executes the code it also includes:
- the updating the execution code of the button to be updated in the button execution program according to the update request may include:
- the update request is a delete request, and the key execution code of any one of the buttons corresponding to the delete request is deleted;
- the update request is a modification request, and the pin information and/or any button function function in the execution code of the button to be updated in the button execution program is modified;
- the button to be updated is constructed based on the structure Key execution code.
- the modular button execution program does not need to be modified, and only the button execution program needs to be modified according to the needs of the button design.
- the initialization code corresponding to the button may be deleted directly from the button execution program; when the button function corresponding to the triggered state of any button is changed, only the button corresponding to the button execution program needs to be updated.
- the initial code can replace the updated function function with the original function function; when it is necessary to add a new button, it only needs to be based on the pin information of the button to be added in the increase request and the different triggered state of the button to be updated.
- Corresponding button function function based on the structure, constructing a button execution code of the button to be updated, and adding the button execution code to the button execution program.
- buttons to be updated when the hardware circuit needs to add a button to be updated, when the button to be updated clicks, the system of the electronic device is updated, and when the button is pressed, the updated system is verified to verify whether the update is completed. At this point, the button is increased to 5, and the button execution program is updated as follows:
- buttons corresponding to the triggered state of each button for example, to update the function implemented when the mute button and the previous button are clicked, and only need to modify the called function function, and have 4 buttons.
- the button execution program update (the button function changes) is as follows:
- buttons by performing a program based on the button structure configured by the button structure, a plurality of button functions of a single physical button are clicked, double-clicked, long-pressed, or continuously pressed according to different triggered states, and the device may be updated according to the device update requirement.
- the button execution program is updated or modified to realize different requirements of adding, deleting, and modifying functions of the button, so that the button execution program can be applied to different hardware circuits, the portability is high, and multiple button functions can be realized by one button. Therefore, the number of buttons is greatly reduced, thereby reducing the complexity of the hardware circuit design, which can greatly reduce the development cost and shorten the development cycle.
- FIG. 2 is a flowchart of an embodiment of a method for operating a button according to an embodiment of the present invention.
- the buttons of the electronic device are connected to the pins of the control component in a one-to-one correspondence.
- the method can include:
- each of the buttons passes through an I/O (input/output) line and a pin of the processing component.
- a corresponding connection when any button is triggered, causes a change in the corresponding pin level of the processing component.
- the button is pressed, the level of the corresponding pin changes from A (high level) to B ( Low level);
- B low level
- A high level
- the level change state of the corresponding pin of each button can be polled by the timing of 20 ms.
- the triggered state of any one of the buttons can be determined based on the state of change of the level of the corresponding pin of any one of the buttons.
- the triggered state of the button may include: clicking, double clicking, long pressing, or continuous pressing according to the trigger condition of the user.
- the function of searching for a button function corresponding to the currently triggered state based on a button execution program, and executing the function function of the button includes:
- the button execution program is called to find a key function function corresponding to the triggered state, and the key function function is executed.
- the button execution program defines a pin connected to each button and a different triggered state corresponding to each button function function.
- the success rate of detecting the level change state of the button is increased, and the button needs to be “debounced” in advance.
- the button “jitter” caused by the external interference may be a button “jitter” caused by the movement of the device, or a button “jitter” caused by the user accidentally triggering the button.
- the determining, according to the corresponding relationship between the different triggered states of the any one of the buttons and the different changed states, determining the currently triggered state corresponding to the current change state includes:
- the determining whether the changed state is an effective change state may be performed by detecting a change state of a corresponding pin of the button by using a timing of 20 ms.
- the duration of the change of the corresponding pin level state caused by the button "jitter" is short.
- After 20ms polling detection it is necessary to pass the 3 times 20ms timing wheel when the level of the pin is detected to change from A to B.
- the change state is the effective change state; if after 3 times 20ms timing polling, it is detected that the pin level state has changed from B to A. Then, it is judged that the change state is an invalid change state, and the button is a state change caused by a false trigger, so that it is not necessary to perform a corresponding button function.
- the triggered state includes a click state, a double click state, or a long press state
- Determining, according to the corresponding relationship between the different triggered states and the different changed states of the one of the buttons, determining the currently triggered state corresponding to the current change state includes:
- the triggered state is a click state.
- the most important function of the button detection program is to detect the triggered state of the button.
- the duration of the change state can be judged by timing polling of 20 ms.
- the level state of the corresponding pin changes from A to B, and the time of the B state is judged by the 20ms timing task.
- the specific duration can be counted by the counter for each poll, when polling
- the counter is incremented by one. Both long press and continuous press are judged by detecting the duration of the B state. If the B state duration reaches 300ms, it can be judged that the triggered state of the button is long press or continuous press.
- Pressing continuously means that when the button is pressed for a long time, the button function corresponding to the button can be triggered repeatedly, such as the volume increase or volume down button, that is, the button can be continuously triggered by a long press to increase or decrease the volume of the device.
- the button does not meet the long press condition, continue to determine whether the button is triggered or clicked. Among them, clicking or double-clicking needs to be detected after the button is raised. After any button is triggered to generate a valid change state, the button is raised. If it is pressed again within 50ms, it is determined to be double-clicked. If the button is pressed within 50ms, Press again to judge click. Specifically, the level change state of the pin corresponding to the button is changed from A to B, and then changed from B to A. At this time, it is judged whether the interval from B to A is less than or equal to 50 ms, if it is satisfied. Then, it is judged that the triggered state of the button is a double click, and if it is not satisfied, it is determined that the triggered state of the button is a click.
- the detection result is notified to the processing component to call the button execution program, and the function function corresponding to the triggered state of the button is searched based on the button execution program. And through the processing component call and execute the corresponding function function to determine the function corresponding to the button. And after executing the button function function, the button execution program is initialized, and the triggered state of the button is detected after waiting for the button to be triggered again.
- the method of this embodiment can be applied to implement a button function of an electronic device.
- the electronic device may be a sports watch or speaker provided with physical buttons.
- the electronic device is configured to store the button execution process described in the embodiment of FIG.
- each button in the electronic device is connected to the pins of the processing component through the I/O line one by one.
- any button When any button is triggered, it causes a change in the level of the corresponding pin of the processing component.
- the current change state of the level of the pin corresponding to any one of the buttons is detected in real time by the set 20 ms timing.
- the currently triggered state corresponding to the current change state is determined based on a corresponding relationship between different triggered states and different changed states of the one of the buttons.
- calling, by the processing component, the button execution program to search for a key function function corresponding to the currently triggered state, and executing the button function function, thereby implementing a corresponding button function corresponding to the button.
- a click of a button in the device is a mute function.
- the button is determined according to a change state of the level of the pin.
- the triggered state is a click
- the function function corresponding to the button click state is found to be a mute function function based on the button execution program, and the processing component executes the mute function function, thereby implementing the mute function of the button in the electronic device.
- the “jitter” of the button caused by the button false trigger or the external interference can be removed, and the detection of the triggered state of the button is greatly improved. Success rate.
- the triggered state of the button can be accurately detected, and the function is executed by calling the button to execute the program, and the function function corresponding to the triggered state of the button is searched for and executed to realize the button.
- the corresponding button function greatly improves the efficiency and accuracy of button detection.
- the button configuration method described in the embodiment of FIG. 1 can also be used for detecting the button function of the electronic device.
- the method further includes a button component detecting method, wherein the buttons of the electronic device are connected to the pins of the control component in a one-to-one correspondence.
- the method includes:
- each of the buttons is connected to the pins of the processing component through an I/O (input/output, input/output port) line, and when any button is triggered, the corresponding component of the processing component is electrically generated.
- I/O input/output, input/output port
- Flat change when the button is pressed, the level of the corresponding pin changes from A (high level) to B (low level); when the button is raised, the level of the corresponding pin From B (low level) to A (high level).
- the level change state of the corresponding pin of each button can be polled by the timing of 20 ms.
- the triggered state of any one of the buttons can be determined based on the state of change of the level of the corresponding pin of any one of the buttons.
- the triggered state of the button may include: clicking, double clicking, long pressing, or continuous pressing according to the trigger condition of the user.
- the key execution program in order to detect whether the hardware circuit and the key execution program are mismatched, the detection of the key function is required.
- the function of executing the function function after the triggered state of each of the keys is triggered by the triggering of each of the different triggered state detection control components is the same as the function of the trigger state setting of each of the keys. If they are the same, the function of the button corresponding to the triggered state of any of the buttons is correct. If different, the button execution program can be modified based on the method described in the embodiment of FIG. 1 to complete the detection of the button function.
- FIG. 3 is a schematic structural diagram of an embodiment of a button configuration apparatus according to an embodiment of the present invention.
- the keys of the electronic device are connected to the pins of the control component one-to-one;
- the device can include:
- the first determining module 301 is configured to determine pin information corresponding to each button.
- each button is connected to the pins in the control component one by one through a hardware circuit.
- the pin information includes a port type and a pin number corresponding to the pins in the button connection control component.
- the control component may be an MCU (Micro Control Unit) or a processor. Therefore, the hardware circuit connection is simple, and no complicated design hardware circuit is required to realize the connection between each button and the processing component, thereby greatly reducing the design cost of the hardware circuit.
- MCU Micro Control Unit
- the matching module 302 is configured to establish a correspondence between different triggered states of the respective buttons and different changing states of the levels of the corresponding pins.
- the triggered state of the button may include a click state, a double click state, or a long press state.
- any button When any button is pressed, it will cause the level state of the corresponding pin to change, and the level of change caused by different triggered states is different.
- a second determining module 303 configured to determine a button function function corresponding to each of the different triggered states of each button number.
- the generating module 304 is configured to generate a button execution program based on the pin information corresponding to each of the buttons and the button function function corresponding to each of the different triggered states of the buttons.
- the key execution program of each of the keys is configured to be implemented to implement a corresponding button function when any of the triggered states of the each button occurs; any of the triggered states of each of the buttons is based on each of the buttons The state of change of the level of the connected pin and the correspondence relationship are determined.
- the button function function is pre-established in and stored in a memory connected to the control component, and the button function function of each button is executed by determining a button function function corresponding to each of the different triggered states of each button. a program for being executed to implement a corresponding button function when any of the triggered states of each of the buttons occurs; any of the triggered states of each of the buttons is based on a level of a pin of each of the buttons The change state and the correspondence relationship are determined.
- the generating module 304 can include:
- a definition unit for defining a structure of the key execution program is a definition unit for defining a structure of the key execution program.
- the structure includes at least pin information and a plurality of triggered states.
- the code construction unit is configured to construct a key execution code of each of the keys based on the structure according to the pin information of each button connection and the key function function corresponding to the different triggered state of each of the buttons.
- the program generating unit is configured to generate a button execution program according to the button execution code of the at least one button.
- the present invention constructs the button execution program using modular design requirements.
- the structure of the program is first executed by defining a key.
- the structure defines the structure and meaning of the key execution program.
- the execution code of the any button is constructed based on the structure according to the pin information of the button to be tested and the button function function corresponding to the different triggered state of the button to be tested. And generating a button execution program according to the execution code of at least one button.
- an electronic device corresponds to four buttons, including: a mute button, a previous button, a next button, and a power button.
- the mute button when the mute button is clicked, the device mute function can be realized.
- the button When the button is pressed for a long time, the device can be connected to the network; when the previous button is clicked, click to implement the play-pause function, and when the button is pressed, the function of playing the previous song is realized;
- the function of playing the next song is realized when the first button is clicked or long pressed; the voice wake-up function is realized when the power button is clicked, and the long press is to implement the power-on or power-off function.
- the key execution procedure for generating four buttons is as follows:
- each of the four buttons defined by the button execution program respectively corresponds to a function function according to the triggered state.
- the set function function is relatively small, the triggered state corresponding to any one of the buttons can be set.
- the function is empty.
- the method may further include:
- a receiving unit configured to receive an update request
- an update unit configured to update a button execution code to be updated in the button execution program according to the update request.
- the update unit may be specifically configured to:
- the update request is a delete request, and the key execution code of any one of the buttons corresponding to the delete request is deleted;
- the update request is a modification request, and the pin information and/or any button function function in the execution code of the button to be updated in the button execution program is modified;
- the update request is an increase request
- a button function function corresponding to a different triggered state of the button, and a button execution code of the button to be updated is constructed based on the structure.
- the modular button execution program does not need to be modified, and only the button execution program needs to be modified according to the needs of the button design.
- the initialization code corresponding to the button may be deleted directly from the button execution program; when the button function corresponding to the triggered state of any button is changed, only the button corresponding to the button execution program needs to be updated.
- the initial code can replace the updated function function with the original function function; when it is necessary to add a new button, it only needs to be based on the pin information of the button to be added in the increase request and the different triggered state of the button to be updated.
- Corresponding button function function based on the structure, constructing a button execution code of the button to be updated, and adding the button execution code to the button execution program.
- buttons to be updated when the hardware circuit needs to add a button to be updated, when the button to be updated clicks, the system of the electronic device is updated, and when the button is pressed, the updated system is verified to verify whether the update is completed. At this point, the button is increased to 5, and the button execution program is updated as follows:
- buttons corresponding to the triggered state of each button for example, to update the function implemented when the mute button and the previous button are clicked, and only need to modify the called function function, and have 4 buttons.
- the button execution program update (the button function changes) is as follows:
- buttons by performing a program based on the button structure configured by the button structure, a plurality of button functions of a single physical button are clicked, double-clicked, long-pressed, or continuously pressed according to different triggered states, and the device may be updated according to the device update requirement.
- the button execution program is updated or modified to realize different requirements of adding, deleting, and modifying functions of the button, so that the button execution program can be applied to different hardware circuits, the portability is high, and multiple button functions can be realized by one button. Therefore, the number of buttons is greatly reduced, thereby reducing the complexity of the hardware circuit design, which can greatly reduce the development cost and shorten the development cycle.
- FIG. 4 is a schematic structural diagram of an embodiment of a button operation device according to an embodiment of the present invention, wherein a button of the electronic device is connected to a pin of a control component in a one-to-one correspondence;
- the device can include:
- the first detecting module 401 is configured to detect a current change state of a level of a pin corresponding to any one of the buttons.
- each of the buttons is connected to the pins of the processing component through an I/O (input/output, input/output port) line, and when any button is triggered, the corresponding component of the processing component is electrically generated.
- I/O input/output, input/output port
- Flat change when the button is pressed, the level of the corresponding pin changes from A (high level) to B (low level); when the button is raised, the level of the corresponding pin From B (low level) to A (high level).
- the level change state of the corresponding pin of each button can be polled by the timing of 20 ms.
- the third determining module 402 is configured to determine a current triggered state corresponding to the current change state based on a correspondence between different triggered states and different changed states of the any one of the buttons.
- the triggered state of any one of the buttons can be determined based on the state of change of the level of the corresponding pin of any one of the buttons.
- the triggered state of the button may include: clicking, double clicking, long pressing, or continuous pressing according to the trigger condition of the user.
- the first search module 403 is configured to search for a key function function corresponding to the currently triggered state based on the key execution code.
- the first execution module 404 is configured to execute the key function.
- the searching module 403 is specifically configured to:
- the button execution program is called to find a key function function corresponding to the triggered state, and the key function function is executed.
- the button execution program defines a pin for each button connection and a corresponding button for each triggered state of each button Function function.
- the success rate of detecting the level change state of the button is increased, and the button needs to be “debounced” in advance.
- the button “jitter” caused by the external interference may be a button “jitter” caused by the movement of the device, or a button “jitter” caused by the user accidentally triggering the button.
- the third determining module 402 is specifically configured to:
- the determining whether the changed state is an effective change state may be performed by detecting a change state of a corresponding pin of the button by using a timing of 20 ms.
- the duration of the change of the corresponding pin level state caused by the button "jitter" is short.
- After 20ms polling detection it is necessary to pass the 3 times 20ms timing wheel when the level of the pin is detected to change from A to B.
- the change state is the effective change state; if after 3 times 20ms timing polling, it is detected that the pin level state has changed from B to A. Then, it is judged that the change state is an invalid change state, and the button is a state change caused by a false trigger, so that it is not necessary to perform a corresponding button function.
- the triggered state includes a click state, a double click state, or a long press state
- the third determining module 402 can be specifically configured to:
- the triggered state is a click state.
- the most important function of the button detection program is to detect the triggered state of the button.
- the duration of the change state can be judged by timing polling of 20 ms.
- the level state of the corresponding pin changes from A to B, and the time of the B state is judged by the 20ms timing task.
- the specific duration can be counted by the counter for each poll, when polling
- the counter is incremented by one. Both long press and continuous press are judged by detecting the duration of the B state. If the B state duration reaches 300ms, it can be judged that the triggered state of the button is long press or continuous press.
- Pressing continuously means that when the button is pressed for a long time, the button function corresponding to the button can be triggered multiple times continuously, for example, the volume is increased. Or the volume down button, which can be triggered by a long press to increase or decrease the volume of the device.
- the button does not meet the long press condition, continue to determine whether the button is triggered or clicked. Among them, clicking or double-clicking needs to be detected after the button is raised. After any button is triggered to generate a valid change state, the button is raised. If it is pressed again within 50ms, it is determined to be double-clicked. If the button is pressed within 50ms, Press again to judge click. Specifically, the level change state of the pin corresponding to the button is changed from A to B, and then changed from B to A. At this time, it is judged whether the interval from B to A is less than or equal to 50 ms, if it is satisfied. Then, it is judged that the triggered state of the button is a double click, and if it is not satisfied, it is determined that the triggered state of the button is a click.
- the detection result is notified to the processing component to call the button execution program, and the function function corresponding to the triggered state of the button is searched based on the button execution program. And through the processing component call and execute the corresponding function function to determine the function corresponding to the button. And after executing the button function function, the button execution program is initialized, and the triggered state of the button is detected after waiting for the button to be triggered again.
- the method of this embodiment can be applied to the implementation of a button function in an electronic device, wherein the electronic device can be a sports watch or a speaker provided with physical buttons.
- the electronic device is configured to store a button execution program according to the embodiment of FIG. 1.
- Each of the electronic devices passes through an I/O line and a pin of the processing component.
- a corresponding connection when any button is triggered, causes a change in the level of the corresponding pin of the processing component.
- the current change state of the level of the pin corresponding to any one of the buttons is detected in real time by the set 20 ms timing.
- the currently triggered state corresponding to the current change state is determined based on a corresponding relationship between different triggered states and different changed states of the one of the buttons.
- calling, by the processing component, the button execution program to search for a key function function corresponding to the currently triggered state, and executing the button function function, thereby implementing a corresponding button function corresponding to the button.
- a click of a button in the device is a mute function.
- the button is determined according to a change state of the level of the pin.
- the triggered state is a click
- the function function corresponding to the button click state is found to be a mute function function based on the button execution program, and the processing component executes the mute function function, thereby implementing the mute function of the button in the electronic device.
- the “jitter” of the button caused by the button false trigger or the external interference can be removed, and the detection of the triggered state of the button is greatly improved.
- Accuracy by periodically polling and detecting the change state of the corresponding pin of the button, the triggered state of the button can be accurately detected, and the function is executed by calling the button to execute the program, and the function function corresponding to the triggered state of the button is searched for and executed to realize the button.
- the corresponding button function greatly improves the efficiency and accuracy of button detection.
- the button configuration method described in the embodiment of FIG. 1 can also be used for detecting the button function of the electronic device.
- the method further includes: a button detecting device, wherein the buttons of the electronic device are connected to the pins of the control component in a one-to-one correspondence.
- the device can include:
- the second detecting module is configured to detect a current change state of a level of a pin corresponding to any one of the buttons.
- each of the buttons is connected to the pins of the processing component through an I/O (input/output, input/output port) line, and when any button is triggered, the corresponding component of the processing component is electrically generated.
- I/O input/output, input/output port
- Flat change when the button is pressed, the level of the corresponding pin changes from A (high level) to B (low level); when the button is raised, the level of the corresponding pin From B (low level) to A (high level).
- the level change state of the corresponding pin of each button can be polled by the timing of 20 ms.
- the fourth determining module is configured to determine a current triggered state corresponding to the current change state based on a correspondence between different triggered states and different changed states of the one of the buttons.
- the triggered state of any one of the buttons can be determined based on the state of change of the level of the corresponding pin of any one of the buttons.
- the triggered state of the button may include: clicking, double clicking, long pressing, or continuous pressing according to the trigger condition of the user.
- the second search module is configured to search for a key function function corresponding to the currently triggered state based on the key execution program.
- a second execution module configured to execute the button function function.
- the third detecting module is configured to detect, according to the execution result of the button function function, whether the button function corresponding to the triggered state of the any button is correct.
- the key execution program in order to detect whether the hardware circuit and the key execution program are mismatched, the detection of the key function is required.
- the function of executing the function function after the triggered state of each of the keys is triggered by the triggering of each of the different triggered state detection control components is the same as the function of the trigger state setting of each of the keys. If they are the same, the function of the button corresponding to the triggered state of any of the buttons is correct. If different, the button execution program can be modified based on the method described in the embodiment of FIG. 1 to complete the detection of the button function.
- the button detecting device described in each of the above embodiments may be configured in an electronic device, and the electronic device may be any electronic device having physical buttons in practical applications.
- an embodiment of the present invention further provides an electronic device, as shown in FIG. 5, the device includes a memory 501 and a processing component 502;
- the memory 501 stores one or more computer program instructions
- the processing component 502 invokes and executes the one or more computer program instructions to:
- processing component 502 is further configured to perform all or part of the foregoing method steps.
- the processing component 502 can include one or more processors to execute computer instructions.
- the second processing component can also be one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays ( An FPGA, controller, microcontroller, microprocessor or other electronic component implementation for performing the above method.
- ASICs application specific integrated circuits
- DSPs digital signal processors
- DSPDs digital signal processing devices
- PLDs programmable logic devices
- FPGA field programmable gate arrays
- the memory 501 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable.
- SRAM static random access memory
- EEPROM electrically erasable programmable read only memory
- EPROM Programmable Read Only Memory
- PROM Programmable Read Only Memory
- ROM Read Only Memory
- Magnetic Memory Flash Memory
- Disk Disk or Optical Disk.
- the electronic device may also include other components such as an input/output interface, a communication component, and the like.
- the input/output interface provides an interface between the processing component and the peripheral interface module, and the peripheral interface module may be an output device, an input device, or the like.
- the communication component is configured to facilitate wired or wireless communication between the mobile device and other devices, such as communication with the control device, and the like.
- An embodiment of the present invention provides a computer program product, including a computer readable storage medium, for storing computer instructions for use in a key detecting apparatus according to an embodiment of the present invention, which includes a method for detecting a key in any of the above embodiments. The procedures involved.
- a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
- processors CPUs
- input/output interfaces network interfaces
- memory volatile and non-volatile memory
- the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
- RAM random access memory
- ROM read only memory
- Memory is an example of a computer readable medium.
- Computer readable media includes both permanent and non-persistent, removable and non-removable media.
- Information storage can be implemented by any method or technology.
- the information can be computer readable instructions, data structures, modules of programs, or other data.
- Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, read-only optical ROM (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape storage or other magnetic storage device or any other non-transportable medium that can be used to store information that can be accessed by a computing device.
- computer readable media does not include non-transitory computer readable media, such as modulated data signals and carrier waves.
- first device if a first device is coupled to a second device, the first device can be directly electrically coupled to the second device, or electrically coupled indirectly through other devices or coupling means. Connected to the second device.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Input From Keyboards Or The Like (AREA)
Abstract
一种按键配置方法、一种按键运行方法、装置及电子设备,所述按键与控制组件的引脚一一对应连接。通过确定每一个按键对应的引脚信息(101),建立每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系(102)。确定每一个按键的不同被触发状态分别对应的按键功能函数(103),基于每一个按键对应的引脚信息以及不同被触发状态分别对应的按键功能函数,生成按键执行程序(104)。并通过检测任一个按键对应的引脚的电平的当前变化状态(201),确定当前被触发状态(202)。基于按键执行程序查找当前被触发状态对应的按键功能函数(203),并执行按键功能函数从而实现对应的按键功能。通过模块化设计按键执行程序,降低硬件电路设计的复杂度,缩短了开发周期。
Description
本发明涉及电子技术领域,具体地说,涉及一种按键配置方法、一种按键运行方法、装置及电子设备。
随着电子技术的日趋成熟,电子设备具有的功能越来越多,用户与电子设备的交互通常是通过按键来实现的。
现有技术中,在电子设备设置的按键例如智能音箱或智能手环设置的按键,针对每一个按键仅配置一个按键功能。当按键数量较少时可以将按键通过I/O(input/output,输入输出端口)直接连接到MCU(Micro Control Unit,微控制单元)的引脚上,但当按键数量较多时,由于无法保证每一个按键能够直接连接到MCU的引脚上,因此需要设计额外的硬件电路,实现每一个按键与MCU的连接。但这种按键配置方法,硬件电路设计复杂,导致硬件电路设计成本增加,且开发周期较长。
另外,由于复杂的硬件电路设计,需要针对该硬件电路设计复杂的软件程序进行按键检测,大大增加了按键检测的复杂度,从而无法及时、准确地检测该按键是否被有效触发,影响了按键的检测效率和准确度。
发明内容
有鉴于此,本发明提供了一种按键配置方法、一种按键运行方法、装置及电子设备,用以解决现有技术中按键配置方法硬件电路设计复杂导致开发成本高,开发周期长的技术问题,大大简化了硬件电路,不需要硬件电路的设计成本,缩短了开发周期。
为了解决上述技术问题,本发明提供了一种按键配置方法,所述按键与电子设备中控制组件的引脚一一对应连接,所述方法包括:
确定每一个按键对应的引脚信息;
建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系;
确定所述每一个按键的不同被触发状态分别对应的按键功能函数;
基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序;所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
优选地,所述基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序包括:
定义所述按键执行程序的结构体;所述结构体至少包括引脚信息以及多个被触发状态;
按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码;
根据至少一个按键的按键执行代码,生成按键执行程序。
优选地,所述按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码之后,还包括:
接收更新请求;
根据所述更新请求,更新所述按键执行程序中待更新按键执行代码。
本发明还提供了一种按键运行方法,应用于电子设备中,所述按键与电子设备中控制组件的引脚一一对应连接;
所述方法包括:
检测任一个按键对应的引脚的电平的当前变化状态;
基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;
基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数。
优选地,所述被触发状态包括单击状态、双击状态或长按状态;
所述基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态包括:
如果基于所述当前变化状态判定所述任一个按键被触发后的持续时间达到第一预设时间,确定所述当前被触发状态为长按状态;
如果基于所述当前变化状态判定所述任一个按键被抬起后第二预设时间内再次被触发,确定所述当前被触发状态为双击状态;
如果基于所述当前变化状态判定所述任一个按键被触发后的持续时间未达到第一预设时长且在所述任一个按键被抬起后的第二预设时间内未被再次触发,确定所述当前被触发状态为单击状态。
优选地,所述基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态包括:
判断所述当前变化状态是否是有效变化状态;
如果是,基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;
如果否,重新检测任一个按键对应的引脚的电平的当前变化状态。
本发明提供了一种按键配置装置,所述按键与电子设备中控制组件的引脚一一对应连接,所述装置包括:
第一确定模块,用于确定每一个按键对应的引脚信息;
匹配模块,用于建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系;
第二确定模块,用于确定所述每一个按键的不同被触发状态分别对应的按键功能函数;
生成模块,用于基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序;所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
本发明还提供了一种按键运行装置,所述按键与电子设备中控制组件的引脚一一对应连接;
所述装置包括:
第一检测模块,用于检测任一个按键对应的引脚的电平的当前变化状态;
第三确定模块,用于基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;
第一查找模块,用于基于按键执行代码查找所述当前被触发状态对应的按键功能函数;
第一执行模块,用于执行所述按键功能函数。
本发明提供了一种电子设备,包括存储器以及处理组件;
所述存储器存储一条或多条计算机程序指令;
所述处理组件调用并执行所述一条或多条计算机程序指令,实现如下操作:
检测任一个按键对应的引脚的电平的当前变化状态;
基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的被触发状态;
基于按键执行程序查找所述被触发状态对应的按键功能函数,并执行所述按键功能函数。
与现有技术相比,本发明可以获得包括以下技术效果:
本发明给出了一种按键配置方法、一种按键运行方法、装置及电子设备,所述方法应用于电子设备中,所述电子设备的按键与控制组件的引脚一一对应连接。通过确定每一个按键对应的引脚信息,建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系。确定所述每一个按键的不同被触发状态分别对应的按键功能函数,基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序。并通过检测任一个按键对应的引脚的电平的当前变化状态,确定当前变化状态对应的当前被触发状态。基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数,从而实现该按键对应的按键功能。本发明通过模块化设计按键执行程序,使得按键执行程序可移植性高,降低硬件电路设计的复杂度,降低了开发成本,缩短了开发周期。
图1是本发明实施例的一种按键配置方法的一个实施例的流程图;
图2是本发明实施例的一种按键运行方法的一个实施例的流程图;
图3是本发明实施例的一种按键配置装置的一个实施例的结构示意图;
图4是本发明实施例的一种按键运行装置的一个实施例的结构示意图;
图5是本发明实施例的一种电子设备的另一个实施例的结构示意图。
以下将配合附图及实施例来详细说明本发明的实施方式,藉此对本发明如何应用技术手段来解决技术问题并达成技术功效的实现过程能充分理解并据以实施。
随着电子技术的日趋成熟,电子设备具有的功能越来越多,用户与电子设备的交互通常是通过按键来实现的。现有技术中,在电子设备设置的按键例如智能音箱或智能手环设置的按键,针对每一个按键仅设置一个按键功能。按键检测通常需要硬件电路与软件程序同步来保证按键的可靠性及检测效率。硬件电路的设计需要根据实际的按键数量以及对应的MCU(Micro Control Unit,微处理器)的引脚数量确定的。当按键数量较少时可以将按键通过I/O(input/output,输入输出端口)直接连接到MCU的引脚上,但当按键数量较多时,就无法保证每一个按键能够直接连接到MCU的引脚上,这就需要设计额外的硬件电路,实现每一个按键与MCU的连接。由于设计的硬件电路仅针对特定的功能需求,在进行软件研发时也必须针对设计的硬件电路进行软件设计,才能保证按键的可靠性及检测效率。
但这种按键检测方法,硬件电路设计复杂,不仅导致硬件电路设计成本增加,由于软件程序是针对特定需求的硬件电路设计的,因此一但电子设备按键设计需求发生变更时,原有的按键检测方法就不再适用,需要重新对按键的硬件电路和软件程序针对变更的需求进行设计,这也导致的软件程序的可移植性较差,增加了开发成本,增加了开发时间。
为了解决硬件电路设计复杂,导致硬件电路设计成本增加,且开发周期较长的技术问题,发明人经过一系列研究提出了本发明的技术方案。本发明提供了一种按键配置方法、一种按键运行方法、装置及设备,所述方法应用与电子设备中,所述电子设备的按键与控制组件的引脚一一对应连接,不需要额外设计复杂的硬件电路。通过确定每一个按键对应的引脚信息,建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系。确定所述每一个按键的不同被触发状态分别对应的按键功能函数,基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序。并通过检测任一个按键对应的引脚的电平的当前变化状态,确定当前变化状态对应的当前被触发状态。基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数,从而实现该按键对应的按键功能。本发明通过模块化设计按键执行程序,使得按键执行程序可移植性高,降低硬件电路设计的复杂度,降低了开发成本,缩短了开发周期。
下面将结合附图对本发明技术方案进行详细描述。
图1是本发明实施例提供的一种按键配置方法的一个实施例的流程图,所述电子设备的
按键与控制组件的引脚一一对应连接。
该方法可以包括:
101:确定每一个按键对应的引脚信息。
本发明中,为了简化硬件电路设计,需要根据按键数量及按键功能需求进行配置。首先通过硬件电路将每一个按键与控制组件中的引脚一一对应连接。其中,所述引脚信息包括按键连接控制组件中的引脚对应的端口类型及引脚号。
所述控制组件可以是MCU(Micro Control Unit,微控制单元)或处理器。因此硬件电路连接简单,不需要额外设计复杂的硬件电路实现每一个按键与处理组件的连接,大大降低了硬件电路的设计成本。
102:建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系。
其中,所述按键的被触发状态可以包括单击状态、双击状态或长按状态。当任一个按键被按下时,均会引起对应的引脚的电平状态发生变化,不同的被触发状态引起的电平的变化状态不同。通过建立每一个按键的不同被触发状态对应的引脚的电平的变化状态的对应关系,从而可通过检测每一个按键对应的引脚的电平的变化状态确定每一个按键对应的被触发状态。
103:确定所述每一个按键的不同被触发状态分别对应的按键功能函数。
104:基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序。
其中,所述按键功能函数预先建立在并存储在与所述控制组件连接的存储器中,并通过确定每一个按键的不同被触发状态分别对应的按键功能函数,使得所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
可选地,在某些实施例中,所述基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序包括:
定义所述按键执行程序的结构体;所述结构体至少包括引脚信息以及多个被触发状态;
按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码;
根据至少一个按键的按键执行代码,生成按键执行程序。
可选地,本发明采用模块化设计需求构建所述按键执行程序。
具体是,首先通过定义键执行程序的结构体。所述结构体,定义了键执行程序的结构及含义。
例如,可以定义为:
在该结构体定义的基础上,按照待测试按键连接的引脚信息以及所述待测试按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述任一按键的执行代码,并根据至少一个按键的执行代码,生成按键执行程序。
例如,某一电子设备对应四个按键,包括:静音按键、上一首按键、下一首按键及电源按键。其中,静音按键单击时可以实现设备静音功能,长按时可以实现设备的联网功能;上一首按键单击时单击实现播放-暂停功能,长按时实现播放上一首歌曲的功能;下一首按键单击或长按时实现播放下一首歌曲的功能;电源按键单击时实现语音唤醒功能,长按是实现开机或关机功能。生成四个按键的按键执行程序如下:
#define KEY_NR (4) //按键个数为4的按键执行程序
struct Key keys[KEY_NR]=
{
{KEY_MUTE_GPIO_Port,KEY_MUTE_Pin,mute_hook,dummy_hook,set_up_hook},
//定义了静音按键的端口号,引脚号,单击对应静音功能函数,双击对应为空,长按对应
联网功能函数
{KEY_PRE_GPIO_Port,KEY_PRE_Pin,paly_pause_hook,dummy_hook,previous_hook},
//定义了上一首按键的端口号,引脚号,单击对应播放暂停功能函数,双击对应为空,长
按对应上一首功能函数
{KEY_NEXT_GPIO_Port,KEY_NEXT_Pin,next_hook,dummy_hook,next_hook},
//定义了下一首按键的端口号,引脚号,单击对应下一首功能函数,双击对应为空,长
按对应下一首功能函数
{KEY_POWER_GPIO_Port,KEY_POWER_Pin,hot_word_hook,dummy_hook,power_hook},
//定义了电源按键的端口号,引脚号,单击对应语音唤醒功能函数,双击对应为空,长按
对应开机/关机功能函数
};
可见,按键执行程序定义的4个按键中的每一个函数根据被触发状态,分别对应一个功能函数,当然如果设定的功能函数比较少,可以设定所述任一个按键的被触发状态对应的功能函数为空。
可选地,在某些实施例中,所述按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码之后,还包括:
接收更新请求;
根据所述更新请求,更新所述按键执行程序中待更新按键执行代码。
可选地,在某些实施例中,所述根据所述更新请求,更新所述按键执行程序中待更新按键的执行代码可以包括:
更新请求为删除请求,删除所述删除请求对应的所述任一按键的按键执行代码;
更新请求为修改请求,修改所述按键执行程序中待更新按键的执行代码中的引脚信息和/或任一按键功能函数;
更新请求为增加请求时,按照所述增加请求中的待更新按键的引脚信息以及所述待更新按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述待更新按键的按键执行代码。
因此,当按键的硬件连接设计或按键功能需要进行更新时,不需要修改模块化按键执行程序,仅需要根据按键设计的需求,修改按键执行程序即可。
当电子设备中按键减少时,即可直接从按键执行程序中,删除该按键对应的初始化代码;当任一按键的被触发状态对应的按键功能更改时,只需要更新按键执行程序中该按键对应的初始代码,将更新的功能函数替换原始的功能函数即可;当需要增加新的按键时,只需要根据增加请求中的待增加按键的引脚信息以及所述待更新按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述待更新按键的按键执行代码,将该按键执行代码添加到按键执行程序中即可。
例如,当硬件电路需要新增一个待更新按键,当该待更新按键单击时实现电子设备的系统的更新,长按时实现对更新的系统进行校验,验证是否更新完成。此时按键增加为5个,按键执行程序更新如下:
#define KEY_NR (5) //按键个数为5的按键执行程序
struct Key keys[KEY_NR]=
{
{KEY_UPDATE_GPIO_Port,KEY_UPDATE_Pin,update_hook,dummy_hook,check_hook},
//定义了新增更新按键的端口号,引脚号,单击对应更新功能函数,双击对应为空,长按
对应为校验功能函数
{KEY_MUTE_GPIO_Port,KEY_MUTE_Pin,mute_hook,dummy_hook,set_up_hook},
{KEY_PRE_GPIO_Port,KEY_PRE_Pin,paly_pause_hook,dummy_hook,previous_hook},
{KEY_NEXT_GPIO_Port,KEY_NEXT_Pin,next_hook,dummy_hook,next_hook},
{KEY_POWER_GPIO_Port,KEY_POWER_Pin,hot_word_hook,dummy_hook,power_hook},
};
同样,还可以修改每一按键的被触发状态对应的功能,例如,对静音按键及上一首按键的单击时实现的功能进行更新,只需修改调用的功能函数即可,具有4个按键(按键功能发生变化)的按键执行程序更新如下:
本实施例中,通过基于按键结构体配置的按键执行程序,实现了对单一物理按键的单击、双击、长按或连续按不同被触发状态配置多种按键功能,并可根据设备更新需求对该按键执行程序进行更新或修改,实现按键的添加、删除以及功能修改的不同需求,使按键执行程序可以适用于不同的硬件电路,可移植性高,且由于一个按键可以实现多个按键功能,因此大大减少了按键数量,从而降低硬件电路设计的复杂度,可以大大降低了开发成本,缩短了开发周期。
图2是本发明实施例提供的一种按键运行方法的一个实施例的流程图,所述电子设备的按键与控制组件的引脚一一对应连接。
该方法可以包括:
201:检测任一个按键对应的引脚的电平的当前变化状态。
可选地,所述每一个按键通过I/O(input/output,输入输出端口)线与处理组件的引脚一
一对应连接,当任一按键被触发后,会引起处理组件相应引脚电平的变化,当该按键被按下时,相应的引脚的电平由A(高电平)变为B(低电平);当该按键被抬起时,相应的引脚的电平由B(低电平)变为A(高电平)。
本发明中,可以通过20ms的定时,轮询检测每一个按键对应引脚的电平变化状态。
202:基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态。
因此基于任一个按键对应引脚的电平的变化状态,即可确定所述任一个按键的被触发状态。其中,所述按键的被触发状态根据用户的触发情况可以包括:单击、双击、长按或连续按。
203:基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数。
可选地,在某些实施例中,所述基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数包括:
调用按键执行程序查找被触发状态对应的按键功能函数,并执行所述按键功能函数。
所述按键执行程序定义了每一按键连接的引脚以及每一按键的不同被触发状态对应按键功能函数。
可选地,为了避免按键因外界干扰引起的“抖动”提高按键的电平变化状态的检测的成功率,需要预先对按键进行“去抖动”。所述外界干扰引起的按键“抖动”,可以是由于设备移动过程中引起的按键“抖动”,或者由于用户误触发按键引起的按键“抖动”。
可选地,在某些实施例中,所述基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态包括:
判断所述当前变化状态是否是有效变化状态;
如果是,基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;
如果否,重新检测任一个按键对应的引脚的电平的当前变化状态。
可选地,所述判断所述变化状态是否为有效变化状态,可以通过20ms定时进行按键对应引脚变化状态的检测。通常按键“抖动”引起的相应引脚电平状态的变化的持续时间较短,通过20ms轮询检测,需要当检测到该引脚的电平由A变化到B时,经过3次20ms定时轮询,检测到该引脚的电平状态仍处于B状态,则该次变化状态为有效变化状态;如果经过3次20ms定时轮询后,检测到该引脚电平状态已经由B变化到A,则判断该变化状态为无效变化状态,该按键为误触发引起的状态变化,因此不需要执行相应按键功能。
可选地,在某些实施例中,所述被触发状态包括单击状态、双击状态或长按状态;
所述基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态包括:
如果基于所述变化状态判定所述任一个按键被触发后的持续时间达到第一预设时间,确定所述被触发状态为长按状态;
如果基于所述变换状态判定所述任一个按键被抬起后第二预设时间内是否再次被触发,确定所述被触发状态为双击状态;
如果基于所述变换状态判定所述任一个按键被出发后的持续时间未达到第一预设时长且在所述任一个按键被抬起后的第二预设时间内未被再次触发,确定所述被触发状态为单击状态。
可选地,按键检测程序最重要就是要检测按键的被触发状态,为了保证检测的准确性,可以通过20ms的定时轮询,判断变化状态的持续时间。
当任一个按键被按下后,对应引脚的电平状态由A变化到B,通过20ms定时任务判断B状态持续的时间,具体持续时间可以通过计数器对每次轮询进行计数,当轮询时检测该电平为B状态,则计数器加1。长按和连续按都是通过检测B状态持续时间进行判断。如果B状态持续时间达到300ms时,即可判断该按键的被触发状态为长按或连续按。
连续按为在长按该按键时,可以连续地多次触发该按键对应的按键功能,例如音量增加或音量减少键,即可以通过长按不断触发该按键增加或减少设备的音量。
如果该按键不满足长按条件时,继续判断该按键是否为单击或双击的被触发状态。其中,单击或双击需要在按键抬起后进行检测,当任一个按键触发后产生有效的变化状态之后,按键抬起,如果在50ms内再次按下即判断为双击,如果50ms内按键为被再次按下即判断为单击。具体为,该按键对应的引脚的电平变化状态为,由A变化到B后,再由B变化到A,此时判断由B变化到A时间隔是时间是否小于或等于50ms,如果满足,则判断该按键的被触发状态为双击,如果不满足则判断该按键的被触发状态为单击。
当通过按键的引脚的电平的状态变化检测确定该按键的被触发状态后,将检测结果通知处理组件调用所述按键执行程序,基于按键执行程序查找该按键的被触发状态对应的功能函数,并通过处理组件调用并执行相应的功能函数,以确定按键对应的功能。并在执行该按键功能函数后初始化该按键执行程序,等待该按键再次被触发后检测该按键的被触发状态。
本实施例的方法,可以适用于实现电子设备的按键功能。所述电子设备可以是设置有物理按键的运动手表或音箱。
可选地,在一个实际应用中,所述电子设备中设置了存储有图1实施例所述按键执行程
序,所述电子设备中的每一个按键通过I/O线与处理组件的引脚一一对应连接,当任一按键被触发后,会引起处理组件相应引脚的电平的变化。通过设定的20ms定时实时检测任一个按键对应的引脚的电平的当前变化状态。当该设备的任一按键被按下时,基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态。并通过处理组件调用所述按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数,从而实现该按键对应的相应按键功能。
例如,该设备中的某一按键的单击为静音功能,当检测到该按键被触发并引起该按键对应引脚的电平的变化后,根据该引脚的电平的变化状态确定该按键的被触发状态为单击,然后基于按键执行程序查找到该按键单击状态对应的功能函数为静音功能函数,此时处理组件执行静音功能函数,从而实现该电子设备中该按键的静音功能。
本实施例中,通过检测按键对应引脚的电平的变化状态的是否为有效变化状态,可以去除按键误触发或外界干扰引起的按键的“抖动”,大大提高了按键的被触发状态的检测成功率。且通过定时轮询检测按键对应引脚的变化状态,可以准确地检测出按键的被触发状态,并通过处理组件调用按键执行程序,查找并执行该按键被触发状态对应的功能函数从而实现该按键对应的按键功能,从而大大提高了按键检测的有效率和准确率。
可选地,在生产制造电子设备时,还可以基于图1实施例所述的按键配置方法用于对电子设备的按键功能的检测。
可选地,还可以包括,一种按键件检测方法,所述电子设备的按键与控制组件的引脚一一对应连接。
所述方法包括:
检测任一个按键对应的引脚的电平的当前变化状态。
可选地,所述每一个按键通过I/O(input/output,输入输出端口)线与处理组件的引脚一一对应连接,当任一按键被触发后,会引起处理组件相应引脚电平的变化,当该按键被按下时,相应的引脚的电平由A(高电平)变为B(低电平);当该按键被抬起时,相应的引脚的电平由B(低电平)变为A(高电平)。
本发明中,可以通过20ms的定时,轮询检测每一个按键对应引脚的电平变化状态。
基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态。
因此基于任一个按键对应引脚的电平的变化状态,即可确定所述任一个按键的被触发状态。其中,所述按键的被触发状态根据用户的触发情况可以包括:单击、双击、长按或连续按。
基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数。
根据所述按键功能函数的执行结果,检测所述任一按键的被触发状态对应的按键功能是否正确。
在一个实际应用中,在基于图1实施例构建了按键执行程序之后,为了检测硬件电路与按键执行程序是否匹配有误,需要进行按键功能的检测。通过触发每一个按键的不同的被触发状态检测控制组件响应每一个按键的被触发状态后执行功能函数的执行结果是否与每一个按键不同被触发状态设定的功能相同。如果相同则所述任一按键的被触发状态对应的按键功能正确,如果不同,则可以基于图1实施例中所述的方法,对按键执行程序进行修改,从而完成按键功能的检测。
本实施例中,通过根据所述按键功能函数的执行结果,可以有效地检测每一个按键的不同被触发状态对应的按键功能是否正确,并实现根据按键检测结果修改相应的按键执行程序,大大提高了电子设备中按键功能的检测效率。
图3是本发明实施例的一种按键配置装置的一个实施例的结构示意图。所述电子设备的按键与控制组件的引脚一一对应连接;
所述装置可以包括:
第一确定模块301,用于确定每一个按键对应的引脚信息。
本发明中,为了简化硬件电路设计,需要根据按键数量及按键功能需求进行配置。首先通过硬件电路将每一个按键与控制组件中的引脚一一对应连接。其中,所述引脚信息包括按键连接控制组件中的引脚对应的端口类型及引脚号。
所述控制组件可以是MCU(Micro Control Unit,微控制单元)或处理器。因此硬件电路连接简单,不需要额外设计复杂的硬件电路实现每一个按键与处理组件的连接,大大降低了硬件电路的设计成本。
匹配模块302,用于建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系。
其中,所述按键的被触发状态可以包括单击状态、双击状态或长按状态。当任一个按键被按下时,均会引起对应的引脚的电平状态发生变化,不同的被触发状态引起的电平的变化状态不同。通过建立每一个按键的不同被触发状态对应的引脚的电平的变化状态的对应关系,从而可通过检测每一个按键对应的引脚的电平的变化状态确定每一个按键对应的被触发状态。
第二确定模块303,用于确定所述每一个按键的不同被触发状态分别对应的按键功能函
数。
生成模块304,用于基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序。
所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
其中,所述按键功能函数预先建立在并存储在与所述控制组件连接的存储器中,并通过确定每一个按键的不同被触发状态分别对应的按键功能函数,使得所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
可选地,在某些实施例中,所述生成模块304可以包括:
定义单元,用于定义所述按键执行程序的结构体。
其中,所述结构体至少包括引脚信息以及多个被触发状态。
代码构建单元,用于按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码。
程序生成单元,用于根据至少一个按键的按键执行代码,生成按键执行程序。
可选地,本发明采用模块化设计需求构建所述按键执行程序。
具体是,首先通过定义键执行程序的结构体。所述结构体,定义了键执行程序的结构及含义。
例如,可以定义为:
在该结构体定义的基础上,按照待测试按键连接的引脚信息以及所述待测试按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述任一按键的执行代码,并根据至少一个按键的执行代码,生成按键执行程序。
例如,某一电子设备对应四个按键,包括:静音按键、上一首按键、下一首按键及电源按键。其中,静音按键单击时可以实现设备静音功能,长按时可以实现设备的联网功能;上一首按键单击时单击实现播放-暂停功能,长按时实现播放上一首歌曲的功能;下一首按键单击或长按时实现播放下一首歌曲的功能;电源按键单击时实现语音唤醒功能,长按是实现开机或关机功能。生成四个按键的按键执行程序如下:
#define KEY_NR (4) //按键个数为4的按键执行程序
struct Key keys[KEY_NR]=
{
{KEY_MUTE_GPIO_Port,KEY_MUTE_Pin,mute_hook,dummy_hook,set_up_hook},
//定义了静音按键的端口号,引脚号,单击对应静音功能函数,双击对应为空,长按对应
联网功能函数
{KEY_PRE_GPIO_Port,KEY_PRE_Pin,paly_pause_hook,dummy_hook,previous_hook},
//定义了上一首按键的端口号,引脚号,单击对应播放暂停功能函数,双击对应为空,长
按对应上一首功能函数
{KEY_NEXT_GPIO_Port,KEY_NEXT_Pin,next_hook,dummy_hook,next_hook},
//定义了下一首按键的端口号,引脚号,单击对应下一首功能函数,双击对应为空,长
按对应下一首功能函数
{KEY_POWER_GPIO_Port,KEY_POWER_Pin,hot_word_hook,dummy_hook,power_hook},
//定义了电源按键的端口号,引脚号,单击对应语音唤醒功能函数,双击对应为空,长按
对应开机/关机功能函数
};
可见,按键执行程序定义的4个按键中的每一个函数根据被触发状态,分别对应一个功能函数,当然如果设定的功能函数比较少,可以设定所述任一个按键的被触发状态对应的功能函数为空。
可选地,在某些实施例中,所述代码构建单元之后,还可以包括:
接收单元,用于接收更新请求;
更新单元,用于根据所述更新请求,更新所述按键执行程序中待更新按键执行代码。
可选地,在某些实施例中,所述更新单元具体可以用于:
更新请求为删除请求,删除所述删除请求对应的所述任一按键的按键执行代码;
更新请求为修改请求,修改所述按键执行程序中待更新按键的执行代码中的引脚信息和/或任一按键功能函数;
更新请求为增加请求时,按照所述增加请求中的待更新按键的引脚信息以及所述待更新
按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述待更新按键的按键执行代码。
因此,当按键的硬件连接设计或按键功能需要进行更新时,不需要修改模块化按键执行程序,仅需要根据按键设计的需求,修改按键执行程序即可。
当电子设备中按键减少时,即可直接从按键执行程序中,删除该按键对应的初始化代码;当任一按键的被触发状态对应的按键功能更改时,只需要更新按键执行程序中该按键对应的初始代码,将更新的功能函数替换原始的功能函数即可;当需要增加新的按键时,只需要根据增加请求中的待增加按键的引脚信息以及所述待更新按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述待更新按键的按键执行代码,将该按键执行代码添加到按键执行程序中即可。
例如,当硬件电路需要新增一个待更新按键,当该待更新按键单击时实现电子设备的系统的更新,长按时实现对更新的系统进行校验,验证是否更新完成。此时按键增加为5个,按键执行程序更新如下:
#define KEY_NR (5) //按键个数为5的按键执行程序
struct Key keys[KEY_NR]=
{
{KEY_UPDATE_GPIO_Port,KEY_UPDATE_Pin,update_hook,dummy_hook,check_hook},
//定义了新增更新按键的端口号,引脚号,单击对应更新功能函数,双击对应为空,长按
对应为校验功能函数
{KEY_MUTE_GPIO_Port,KEY_MUTE_Pin,mute_hook,dummy_hook,set_up_hook},
{KEY_PRE_GPIO_Port,KEY_PRE_Pin,paly_pause_hook,dummy_hook,previous_hook},
{KEY_NEXT_GPIO_Port,KEY_NEXT_Pin,next_hook,dummy_hook,next_hook},
{KEY_POWER_GPIO_Port,KEY_POWER_Pin,hot_word_hook,dummy_hook,power_hook},
};
同样,还可以修改每一按键的被触发状态对应的功能,例如,对静音按键及上一首按键的单击时实现的功能进行更新,只需修改调用的功能函数即可,具有4个按键(按键功能发生变化)的按键执行程序更新如下:
本实施例中,通过基于按键结构体配置的按键执行程序,实现了对单一物理按键的单击、双击、长按或连续按不同被触发状态配置多种按键功能,并可根据设备更新需求对该按键执行程序进行更新或修改,实现按键的添加、删除以及功能修改的不同需求,使按键执行程序可以适用于不同的硬件电路,可移植性高,且由于一个按键可以实现多个按键功能,因此大大减少了按键数量,从而降低硬件电路设计的复杂度,可以大大降低了开发成本低,缩短了开发周期。
图4是本发明实施例的一种按键运行装置的一个实施例的结构示意图,所述电子设备的按键与控制组件的引脚一一对应连接;
所述装置可以包括:
第一检测模块401,用于检测任一个按键对应的引脚的电平的当前变化状态。
可选地,所述每一个按键通过I/O(input/output,输入输出端口)线与处理组件的引脚一一对应连接,当任一按键被触发后,会引起处理组件相应引脚电平的变化,当该按键被按下时,相应的引脚的电平由A(高电平)变为B(低电平);当该按键被抬起时,相应的引脚的电平由B(低电平)变为A(高电平)。
本发明中,可以通过20ms的定时,轮询检测每一个按键对应引脚的电平变化状态。
第三确定模块402,用于基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态。
因此基于任一个按键对应引脚的电平的变化状态,即可确定所述任一个按键的被触发状态。其中,所述按键的被触发状态根据用户的触发情况可以包括:单击、双击、长按或连续按。
第一查找模块403,用于基于按键执行代码查找所述当前被触发状态对应的按键功能函数。
第一执行模块404,用于执行所述按键功能函数。
可选地,在某些实施例中,所述查找模块403具体可以用于:
调用按键执行程序查找被触发状态对应的按键功能函数,并执行所述按键功能函数。
所述按键执行程序定义了每一按键连接的引脚以及每一按键的不同被触发状态对应按键
功能函数。
可选地,为了避免按键因外界干扰引起的“抖动”提高按键的电平变化状态的检测的成功率,需要预先对按键进行“去抖动”。所述外界干扰引起的按键“抖动”,可以是由于设备移动过程中引起的按键“抖动”,或者由于用户误触发按键引起的按键“抖动”。
可选地,在某些实施例中,所述第三确定模块402具体可以用于:
判断所述当前变化状态是否是有效变化状态;
如果是,基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;
如果否,重新检测任一个按键对应的引脚的电平的当前变化状态。
可选地,所述判断所述变化状态是否为有效变化状态,可以通过20ms定时进行按键对应引脚变化状态的检测。通常按键“抖动”引起的相应引脚电平状态的变化的持续时间较短,通过20ms轮询检测,需要当检测到该引脚的电平由A变化到B时,经过3次20ms定时轮询,检测到该引脚的电平状态仍处于B状态,则该次变化状态为有效变化状态;如果经过3次20ms定时轮询后,检测到该引脚电平状态已经由B变化到A,则判断该变化状态为无效变化状态,该按键为误触发引起的状态变化,因此不需要执行相应按键功能。
可选地,在某些实施例中,所述被触发状态包括单击状态、双击状态或长按状态;
所述第三确定模块402具体可以用于:
如果基于所述变化状态判定所述任一个按键被触发后的持续时间达到第一预设时间,确定所述被触发状态为长按状态;
如果基于所述变换状态判定所述任一个按键被抬起后第二预设时间内是否再次被触发,确定所述被触发状态为双击状态;
如果基于所述变换状态判定所述任一个按键被出发后的持续时间未达到第一预设时长且在所述任一个按键被抬起后的第二预设时间内未被再次触发,确定所述被触发状态为单击状态。
可选地,按键检测程序最重要就是要检测按键的被触发状态,为了保证检测的准确性,可以通过20ms的定时轮询,判断变化状态的持续时间。
当任一个按键被按下后,对应引脚的电平状态由A变化到B,通过20ms定时任务判断B状态持续的时间,具体持续时间可以通过计数器对每次轮询进行计数,当轮询时检测该电平为B状态,则计数器加1。长按和连续按都是通过检测B状态持续时间进行判断。如果B状态持续时间达到300ms时,即可判断该按键的被触发状态为长按或连续按。
连续按为在长按该按键时,可以连续地多次触发该按键对应的按键功能,例如音量增加
或音量减少键,即可以通过长按不断触发该按键增加或减少设备的音量。
如果该按键不满足长按条件时,继续判断该按键是否为单击或双击的被触发状态。其中,单击或双击需要在按键抬起后进行检测,当任一个按键触发后产生有效的变化状态之后,按键抬起,如果在50ms内再次按下即判断为双击,如果50ms内按键为被再次按下即判断为单击。具体为,该按键对应的引脚的电平变化状态为,由A变化到B后,再由B变化到A,此时判断由B变化到A时间隔是时间是否小于或等于50ms,如果满足,则判断该按键的被触发状态为双击,如果不满足则判断该按键的被触发状态为单击。
当通过按键的引脚的电平的状态变化检测确定该按键的被触发状态后,将检测结果通知处理组件调用所述按键执行程序,基于按键执行程序查找该按键的被触发状态对应的功能函数,并通过处理组件调用并执行相应的功能函数,以确定按键对应的功能。并在执行该按键功能函数后初始化该按键执行程序,等待该按键再次被触发后检测该按键的被触发状态。
本实施例的方法可以适用于电子设备中的按键功能的实现,其中所述电子设备可以是设置有物理按键的运动手表或音箱。
可选地,在一个实际应用中,所述电子设备中设置了存储有图1实施例所述按键执行程序,所述电子设备中的每一个按键通过I/O线与处理组件的引脚一一对应连接,当任一按键被触发后,会引起处理组件相应引脚的电平的变化。通过设定的20ms定时实时检测任一个按键对应的引脚的电平的当前变化状态。当该设备的任一按键被按下时,基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态。并通过处理组件调用所述按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数,从而实现该按键对应的相应按键功能。
例如,该设备中的某一按键的单击为静音功能,当检测到该按键被触发并引起该按键对应引脚的电平的变化后,根据该引脚的电平的变化状态确定该按键的被触发状态为单击,然后基于按键执行程序查找到该按键单击状态对应的功能函数为静音功能函数,此时处理组件执行静音功能函数,从而实现该电子设备中该按键的静音功能。
本实施例中,通过检测按键对应引脚的电平的变化状态的是否为有效变化状态,可以去除按键误触发或外界干扰引起的按键的“抖动”,大大提高了按键的被触发状态的检测准确率。且通过定时轮询检测按键对应引脚的变化状态,可以准确地检测出按键的被触发状态,并通过处理组件调用按键执行程序,查找并执行该按键被触发状态对应的功能函数从而实现该按键对应的按键功能,从而大大提高了按键检测的有效率和准确率。
可选地,在生产制造电子设备时,还可以基于图1实施例所述的按键配置方法用于对电子设备的按键功能的检测。
可选地,还可以包括,一种按键件检测装置,所述电子设备的按键与控制组件的引脚一一对应连接。
所述装置可以包括:
第二检测模块,用于检测任一个按键对应的引脚的电平的当前变化状态。
可选地,所述每一个按键通过I/O(input/output,输入输出端口)线与处理组件的引脚一一对应连接,当任一按键被触发后,会引起处理组件相应引脚电平的变化,当该按键被按下时,相应的引脚的电平由A(高电平)变为B(低电平);当该按键被抬起时,相应的引脚的电平由B(低电平)变为A(高电平)。
本发明中,可以通过20ms的定时,轮询检测每一个按键对应引脚的电平变化状态。
第四确定模块,用于基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态。
因此基于任一个按键对应引脚的电平的变化状态,即可确定所述任一个按键的被触发状态。其中,所述按键的被触发状态根据用户的触发情况可以包括:单击、双击、长按或连续按。
第二查找模块,用于基于按键执行程序查找所述当前被触发状态对应的按键功能函数。
第二执行模块,用于执行所述按键功能函数。
第三检测模块,用于根据所述按键功能函数的执行结果,检测所述任一按键的被触发状态对应的按键功能是否正确。
在一个实际应用中,在基于图1实施例构建了按键执行程序之后,为了检测硬件电路与按键执行程序是否匹配有误,需要进行按键功能的检测。通过触发每一个按键的不同的被触发状态检测控制组件响应每一个按键的被触发状态后执行功能函数的执行结果是否与每一个按键不同被触发状态设定的功能相同。如果相同则所述任一按键的被触发状态对应的按键功能正确,如果不同,则可以基于图1实施例中所述的方法,对按键执行程序进行修改,从而完成按键功能的检测。
本实施例中,通过根据所述按键功能函数的执行结果,可以有效地检测每一个按键的不同被触发状态对应的按键功能是否正确,并实现根据按键检测结果修改相应的按键执行程序,大大提高了电子设备中按键功能的检测效率。
在一个可能的设计中,上述各个实施例所述的按键检测装置可以配置电子设备中,该电子设备在实际应用中可以是任一具有物理按键的电子设备。
因此,本发明实施例还提供了一种电子设备,如图5中所示,该设备包括存储器501以及处理组件502;
所述存储器501存储一条或多条计算机程序指令;
所述处理组件502调用并执行所述一条或多条计算机程序指令,实现如下操作:
检测任一个按键对应引脚的电平的变化状态;
基于所述变化状态,确定所述任一个按键的被触发状态;
查找所述被触发状态对应的按键功能函数,并执行所述按键功能函数;
根据所述按键功能函数的执行结果,确定所述任一按键的被触发状态对应的按键功能。
可选地,该处理组件502还用于执行前述各方法步骤中的全部或部分步骤。
其中,该处理组件502可以包括一个或多个处理器来执行计算机指令。当然第二处理组件也可以为一个或多个应用专用集成电路(ASIC)、数字信号处理器(DSP)、数字信号处理设备(DSPD)、可编程逻辑器件(PLD)、现场可编程门阵列(FPGA)、控制器、微控制器、微处理器或其他电子元件实现,用于执行上述方法。
该存储器501可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。
当然,所述电子设备还可以包括其他部件,例如输入/输出接口、通信组件等。输入/输出接口为处理组件和外围接口模块之间提供接口,上述外围接口模块可以是输出设备、输入设备等。通信组件被配置为便于可移动设备和其他设备之间有线或无线方式的通信,例如和控制设备的通信等等。
本发明实施例提供了一种计算机程序产品,包括计算机可读存储介质,用于储存本发明实施例所述按键检测装置所用的计算机指令,其包含用于执行上述任一实施例中按键检测方法所涉及的程序。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器
(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
如在说明书及权利要求当中使用了某些词汇来指称特定组件。本领域技术人员应可理解,硬件制造商可能会用不同名词来称呼同一个组件。本说明书及权利要求并不以名称的差异来作为区分组件的方式,而是以组件在功能上的差异来作为区分的准则。如在通篇说明书及权利要求当中所提及的“包含”为一开放式用语,故应解释成“包含但不限定于”。“大致”是指在可接收的误差范围内,本领域技术人员能够在一定误差范围内解决所述技术问题,基本达到所述技术效果。此外,“耦接”一词在此包含任何直接及间接的电性耦接手段。因此,若文中描述一第一装置耦接于一第二装置,则代表所述第一装置可直接电性耦接于所述第二装置,或通过其他装置或耦接手段间接地电性耦接至所述第二装置。说明书后续描述为实施本发明的较佳实施方式,然所述描述乃以说明本发明的一般原则为目的,并非用以限定本发明的范围。本发明的保护范围当视所附权利要求所界定者为准。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的商品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种商品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的商品或者系统中还存在另外的相同要素
上述说明示出并描述了本发明的若干优选实施例,但如前所述,应当理解本发明并非局限于本文所披露的形式,不应看作是对其他实施例的排除,而可用于各种其他组合、修改和环境,并能够在本文所述申请构想范围内,通过上述教导或相关领域的技术或知识进行改动。而本领域人员所进行的改动和变化不脱离本发明的精神和范围,则都应在本发明所附权利要求的保护范围内。
Claims (9)
- 一种按键配置方法,其中,所述按键与电子设备中控制组件的引脚一一对应连接,所述方法包括:确定每一个按键对应的引脚信息;建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系;确定所述每一个按键的不同被触发状态分别对应的按键功能函数;基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序;所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
- 根据权利要求1所述的方法,其中,所述基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序包括:定义所述按键执行程序的结构体;所述结构体至少包括引脚信息以及多个被触发状态;按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码;根据至少一个按键的按键执行代码,生成按键执行程序。
- 根据权利要求2所述方法,其中,所述按照每一个按键连接的引脚信息以及所述每一个按键的不同被触发状态对应的按键功能函数,基于所述结构体构建所述每一个按键的按键执行代码之后,还包括:接收更新请求;根据所述更新请求,更新所述按键执行程序中待更新按键执行代码。
- 一种按键运行方法,其中,应用于电子设备中,所述按键与电子设备中控制组件的引脚一一对应连接;所述方法包括:检测任一个按键对应的引脚的电平的当前变化状态;基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;基于按键执行程序查找所述当前被触发状态对应的按键功能函数,并执行所述按键功能函数。
- 根据权利要求4所述的方法,其中,所述被触发状态包括单击状态、双击状态或长按状态;所述基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态包括:如果基于所述当前变化状态判定所述任一个按键被触发后的持续时间达到第一预设时间,确定所述当前被触发状态为长按状态;如果基于所述当前变化状态判定所述任一个按键被抬起后第二预设时间内再次被触发,确定所述当前被触发状态为双击状态;如果基于所述当前变化状态判定所述任一个按键被触发后的持续时间未达到第一预设时长且在所述任一个按键被抬起后的第二预设时间内未被再次触发,确定所述当前被触发状态为单击状态。
- 根据权利要求4所述的方法,其中,所述基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态包括:判断所述当前变化状态是否是有效变化状态;如果是,基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;如果否,重新检测任一个按键对应的引脚的电平的当前变化状态。
- 一种按键配置装置,其中,所述按键与电子设备中控制组件的引脚一一对应连接,所述装置包括:第一确定模块,用于确定每一个按键对应的引脚信息;匹配模块,用于建立所述每一个按键的不同被触发状态与其对应引脚的电平的不同变化状态的对应关系;第二确定模块,用于确定所述每一个按键的不同被触发状态分别对应的按键功能函数;生成模块,用于基于所述每一个按键对应的引脚信息以及所述每一个按键的不同被触发状态分别对应的按键功能函数,生成按键执行程序;所述每一个按键的按键执行程序用于被执行以实现所述每一个按键的任一被触发状态发生时对应的按键功能;所述每一个按键的任一被触发状态基于所述每一个按键连接的引脚的电平的变化状态以及所述对应关系确定。
- 一种按键运行装置,其中,所述按键与电子设备中控制组件的引脚一一对应连接;所述装置包括:第一检测模块,用于检测任一个按键对应的引脚的电平的当前变化状态;第三确定模块,用于基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的当前被触发状态;第一查找模块,用于基于按键执行代码查找所述当前被触发状态对应的按键功能函数;第一执行模块,用于执行所述按键功能函数。
- 一种电子设备,其中,包括存储器以及处理组件;所述存储器存储一条或多条计算机程序指令;所述处理组件调用并执行所述一条或多条计算机程序指令,实现如下操作:检测任一个按键对应的引脚的电平的当前变化状态;基于所述任一个按键的不同被触发状态与不同变化状态的对应关系,确定所述当前变化状态对应的被触发状态;基于按键执行程序查找所述被触发状态对应的按键功能函数,并执行所述按键功能函数。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710734610.8A CN107562456A (zh) | 2017-08-24 | 2017-08-24 | 按键配置方法、按键运行方法、装置及电子设备 |
| CN201710734610.8 | 2017-08-24 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2019037240A1 true WO2019037240A1 (zh) | 2019-02-28 |
Family
ID=60976469
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2017/108085 Ceased WO2019037240A1 (zh) | 2017-08-24 | 2017-10-27 | 按键配置方法、按键运行方法、装置及电子设备 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN107562456A (zh) |
| WO (1) | WO2019037240A1 (zh) |
Families Citing this family (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109922194B (zh) * | 2018-12-21 | 2021-06-29 | 贵州财富之舟科技有限公司 | 按键扩展方法、系统及终端 |
| CN109766014A (zh) * | 2018-12-28 | 2019-05-17 | 惠州市蓝微电子有限公司 | 一种单片机识别按键按击操作的方法 |
| CN110221709B (zh) * | 2019-05-28 | 2023-01-06 | 深圳超酷科技有限公司 | 一种按键检测方法、键盘及按键系统 |
| CN111078118B (zh) * | 2019-12-03 | 2023-07-21 | 北京长峰天通科技有限公司 | 一种用于对按键进行防抖处理的装置及方法 |
| CN111327305A (zh) * | 2020-02-24 | 2020-06-23 | Oppo广东移动通信有限公司 | 电子设备按键控制方法、装置、电子设备和存储介质 |
| CN117898551B (zh) * | 2023-12-15 | 2025-03-25 | 广州星际悦动股份有限公司 | 牙刷的按键配置方法、装置、电子设备及存储介质 |
| CN120233687A (zh) * | 2025-06-03 | 2025-07-01 | 河南科技大学 | 一种硬件自适应智能控制系统、方法、智能按键及键盘 |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1667551A (zh) * | 2004-03-08 | 2005-09-14 | 明基电通股份有限公司 | 可使用多个按键的电子装置 |
| CN101510127A (zh) * | 2009-03-30 | 2009-08-19 | 北京中星微电子有限公司 | 一种实现键盘模块复合键功能的方法、装置和芯片 |
| CN102799279A (zh) * | 2011-05-26 | 2012-11-28 | 联想(北京)有限公司 | 按键识别方法、键盘和电子设备 |
| US20130166955A1 (en) * | 2011-12-22 | 2013-06-27 | Wistron Corporation | Keyboard automatic test method and system using the same |
| CN104965579A (zh) * | 2015-07-24 | 2015-10-07 | 康泰医学系统(秦皇岛)股份有限公司 | 一种设备微处理器的长按键复位电路及其复合功能方法 |
Family Cites Families (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN202841089U (zh) * | 2012-06-08 | 2013-03-27 | 国基电子(上海)有限公司 | 开关机电路及具有该开关机电路的电子装置 |
| CN103677298A (zh) * | 2012-09-07 | 2014-03-26 | 曹伟林 | 一种智能终端及智能终端键盘输入方法 |
| CN104866114B (zh) * | 2014-02-24 | 2017-12-29 | 联想(北京)有限公司 | 一种硬件按键控制方法、装置及电子设备 |
| CN104020694A (zh) * | 2014-06-16 | 2014-09-03 | 法视网络传媒技术(北京)有限公司 | 支持一键触发的节能可穿戴设备、移动终端、触发方法及装置 |
| CN105578344B (zh) * | 2014-10-10 | 2020-07-14 | 深圳富泰宏精密工业有限公司 | 耳机接口状态侦测系统与方法 |
-
2017
- 2017-08-24 CN CN201710734610.8A patent/CN107562456A/zh active Pending
- 2017-10-27 WO PCT/CN2017/108085 patent/WO2019037240A1/zh not_active Ceased
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1667551A (zh) * | 2004-03-08 | 2005-09-14 | 明基电通股份有限公司 | 可使用多个按键的电子装置 |
| CN101510127A (zh) * | 2009-03-30 | 2009-08-19 | 北京中星微电子有限公司 | 一种实现键盘模块复合键功能的方法、装置和芯片 |
| CN102799279A (zh) * | 2011-05-26 | 2012-11-28 | 联想(北京)有限公司 | 按键识别方法、键盘和电子设备 |
| US20130166955A1 (en) * | 2011-12-22 | 2013-06-27 | Wistron Corporation | Keyboard automatic test method and system using the same |
| CN104965579A (zh) * | 2015-07-24 | 2015-10-07 | 康泰医学系统(秦皇岛)股份有限公司 | 一种设备微处理器的长按键复位电路及其复合功能方法 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN107562456A (zh) | 2018-01-09 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2019037240A1 (zh) | 按键配置方法、按键运行方法、装置及电子设备 | |
| US10970269B2 (en) | Intermediate consistency levels for database configuration | |
| CN107193681B (zh) | 数据校验方法及装置 | |
| WO2019085087A1 (zh) | 接口测试及测试数据生成方法、装置、终端和存储介质 | |
| EP3811232A1 (en) | Data processing method, apparatus, and device | |
| WO2018177252A1 (zh) | 一种基于区块链的数据存储以及查询的方法及装置 | |
| CN105740690A (zh) | 一种解锁方法及移动终端 | |
| CN107203465B (zh) | 系统接口测试方法及装置 | |
| CN111464402A (zh) | 一种智能家居设备的控制方法、终端设备及介质 | |
| CN104298551A (zh) | 应用程序调用系统及方法 | |
| KR101334111B1 (ko) | 쿼드 데이터 레이트(qdr) 제어기 및 그의 실현방법 | |
| TW201740684A (zh) | 時序錯誤偵測與修正之裝置及其常態時序設計方法 | |
| CN107515791B (zh) | 通过本地服务器对本地客户机应用进行事件服务的方法 | |
| CN108509541B (zh) | 一种消息读取方法、消息读取装置及移动终端 | |
| WO2019019158A1 (zh) | 一种应用的操作方法和装置 | |
| CN107395872B (zh) | 应用启动方法、装置、存储介质及电子设备 | |
| CN107832224A (zh) | 一种应用程序的测试方法、装置、存储介质及智能终端 | |
| US12443475B2 (en) | Method and apparatus for obtaining information of stack frame in call stack, device, and medium | |
| CN115576602A (zh) | 一种实现实体类转换的方法、存储介质及电子装置 | |
| CN112667255B (zh) | 更新方法、装置、电子设备及存储介质 | |
| CN116450597A (zh) | 一种日志的管理方法以及相关装置 | |
| WO2022105126A1 (zh) | 显示窗口中内容信息的确认方法、装置、设备及存储介质 | |
| CN112615589B (zh) | 环形振荡器频率调整方法、装置、存储介质及设备 | |
| CN112468952B (zh) | 定位方法、装置、存储介质及电子设备 | |
| CN115422117A (zh) | 一种低成本芯片间可靠通讯方法 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 17922804 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 17922804 Country of ref document: EP Kind code of ref document: A1 |




