Matrix key detection method and device, electrical equipment and storage medium
By creating a two-dimensional array to store multiple scan results in matrix key scanning and combining it with a counter to analyze interference, the problem of matrix key scanning being susceptible to interference is solved, thus improving the reliability and accuracy of key response.
Patent Information
- Application Number
- CN202511671230.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-14
- Publication Date
- 2026-03-17
AI Technical Summary
Matrix key scanning is easily interfered with in electrical appliances such as microwave ovens, which leads to a decrease in the reliability of key response. Traditional methods have weak anti-interference capabilities.
By creating a first two-dimensional array to store the state sample values of multiple scans, scanning is performed at a preset time interval, and the sample values are stored in chronological order. The key state is determined by combining a counter and the results of multiple scans. The interference intensity is dynamically analyzed, and a multiple scan and full consistency judgment method is used to filter out instantaneous interference.
It improves the accuracy and reliability of key press detection, reduces the false judgment rate, dynamically enhances anti-interference capabilities, and balances resource consumption and anti-interference requirements.
Smart Images

Figure CN121690225A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of key scanning technology, and specifically to a method, apparatus, electrical device, and storage medium for detecting matrix keys. Background Technology
[0002] Matrix buttons are one of the important ways for users to interact with home appliances. Compared with independent buttons, matrix buttons consume less microcontroller I / O (Input / Output, I / O) resources, greatly saving resources and simplifying circuit layout. The traditional method of determining valid buttons is to directly determine the valid buttons based on the current matrix button scanning results. However, in practical applications, matrix button scanning is subject to various interferences, such as microwave interference in microwave ovens and power interference after filter board failure. This results in weak anti-interference ability and a sharp decline in reliability of traditional matrix button scanning solutions. In severe cases of interference, it can even cause serious problems such as buttons becoming unresponsive. Summary of the Invention
[0003] This invention provides a method, apparatus, electrical device, and storage medium for detecting matrix keys, in order to solve the problem of excessive key scanning interference affecting the reliability of key response.
[0004] In a first aspect, the present invention provides a method for detecting matrix buttons, the method comprising: creating a first two-dimensional array, wherein a first dimension of the first two-dimensional array represents all buttons to be scanned in the matrix buttons, and a second dimension is used to store a set of state sample values determined after multiple consecutive scans of each button, the state sample values including a first value indicating that the button is valid and a second value indicating that the button is invalid; scanning the matrix buttons based on a preset time interval, and storing the state sample values of each button obtained in each scan in the first two-dimensional array in the order of scanning time; and determining the pressed state of the button based on the set of state sample values of each button stored in the first two-dimensional array.
[0005] The matrix key detection method provided by this invention creates a first two-dimensional array. The first dimension of the first two-dimensional array represents all keys to be scanned in the matrix key array, and the second dimension stores the set of state sample values determined after multiple consecutive scans of each key. Then, the matrix key array is scanned based on a preset time interval, and the state sample values of each key obtained in each scan are stored in the first two-dimensional array according to the scanning time sequence. Finally, the pressed state of each key can be determined based on the set of state sample values stored in the first two-dimensional array. This avoids the influence of instantaneous interference on the results of a single scan. By statistically analyzing the sample values obtained from multiple scans, the false judgment rate is significantly reduced, and the accuracy and reliability of key judgment are improved.
[0006] In one optional implementation, the second dimension is provided with a corresponding storage capacity. The step of storing the state sample values of each button obtained in each scan into the first two-dimensional array includes: when the number of state sample values of each button stored in the second dimension reaches the storage capacity, removing the state sample values of each button with the earliest scan time, and writing the state sample values of each button obtained in the current scan into the first two-dimensional array in the order of scan time.
[0007] This invention ensures the timeliness of sampled data by storing it in chronological order and removing the oldest data when the capacity is full, and it also achieves a balance between resource consumption and anti-interference requirements by designing a fixed memory footprint.
[0008] In one optional implementation, determining the pressed state of a button based on the set of state sample values of each button stored in the first two-dimensional array includes: if all state sample values of the current button stored in the first two-dimensional array are the first value, then the current button is determined to be in a valid pressed state.
[0009] This invention employs a method of multiple scanning and sampling with full consistency determination to avoid misjudgment that may be caused by momentary interference during a single scanning and sampling, filter out occasional outliers, and improve the reliability of button status determination.
[0010] In one optional implementation, the method further includes: setting a corresponding counter for the current button; if all state sample values of the current button stored in the first two-dimensional array are the second value, performing a zeroing operation on the counter.
[0011] In one optional implementation, the second dimension is provided with a corresponding storage capacity, which represents the number of state sample values that the current button can store. In the process of determining the pressed state of the button, the method further includes: incrementing a counter when the current state sample value of the button is detected to be a first value; controlling the counter to pause counting when it is determined that the current button is in a valid pressed state; and determining the first interference intensity of the matrix button based on the comparison result between the value currently recorded by the counter and the number of state sample values that can be stored in the second dimension of the first two-dimensional array.
[0012] This invention compares the counter value with the second-dimensional storage capacity to convert it into a quantifiable indicator, dynamically analyzing the changes in button status. This not only determines whether a button is effective but also the degree of interference, improving the precision of status analysis and enhancing overall reliability.
[0013] In an optional implementation, the method further includes: if the first interference intensity of the matrix keys is determined to reach the abnormal interference standard, creating a second two-dimensional array, wherein the first dimension of the second two-dimensional array is the same as the first dimension of the first two-dimensional array, and the second dimension is used to store the set of state sample values determined by each key after multiple consecutive scans; combining the second two-dimensional array with the first two-dimensional array to obtain a third two-dimensional array, wherein the number of state sample values that the third two-dimensional array can store is the sum of the number of state sample values that the first two-dimensional array and the second two-dimensional array can store; storing the state sample values of each key obtained in each scan into the third two-dimensional array; incrementing a counter when the state sample value of the current key is detected to be the first value; determining that the current key is valid and controlling the counter to pause counting when all state sample values of the current key in the third two-dimensional array are the first value; and determining the second interference intensity of the matrix keys based on the comparison result between the value currently recorded by the counter and the number of state sample values that the third two-dimensional array can store.
[0014] When the first interference intensity is determined to reach the abnormal interference standard, the present invention can create a second two-dimensional array and combine it into a third two-dimensional array, which is equivalent to increasing the number of samplings and the number of samples for determining the valid state. This can more effectively reduce misjudgments caused by accidental continuous valid sampling and dynamically enhance the anti-interference capability.
[0015] In an optional implementation, the method further includes: if the second interference intensity of the matrix keys meets the normal interference standard, during the next matrix key scan, returning to the step of storing the state sample values of each key obtained in each scan into the third two-dimensional array, until the second interference intensity of the matrix keys determined for a consecutive number of times meets the normal interference standard, restoring the first two-dimensional array as an array for key state detection, and returning to the step of scanning the matrix keys based on a preset time interval and storing the state sample values of each key obtained in each scan into the first two-dimensional array.
[0016] When the second interference intensity is determined to have returned to normal and remained stable, the present invention can restore the judgment using only the first two-dimensional array, which takes into account both anti-interference capability and avoids resource occupation caused by long-term use of large-capacity sampling.
[0017] Secondly, the present invention provides a detection device for matrix buttons, the device comprising: an array creation module for creating a first two-dimensional array, wherein a first dimension of the first two-dimensional array represents all buttons to be scanned in the matrix buttons, and a second dimension is used to store a set of state sample values determined after multiple consecutive scans of each button, the state sample values including a first value indicating that the button is valid and a second value indicating that the button is invalid; a state sample storage module for scanning the matrix buttons based on a preset time interval, and storing the state sample values of each button obtained in each scan into the first two-dimensional array in the order of scanning time; and a button state determination module for determining the pressed state of the button based on the set of state sample values of each button stored in the first two-dimensional array.
[0018] Thirdly, the present invention provides an electrical device, the electrical device including a matrix keypad and a controller, the controller including a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the matrix keypad detection method of the first aspect or any corresponding embodiment described above.
[0019] Fourthly, the present invention provides a computer-readable storage medium storing computer instructions for causing a computer to execute the matrix key detection method of the first aspect or any corresponding embodiment thereof. Attached Figure Description
[0020] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of the structure of an electrical device according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the first process of a matrix key detection method according to an embodiment of the present invention; Figure 3 This is a structural example diagram of a two-dimensional array according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the third process of a matrix key detection method according to an embodiment of the present invention; Figure 5 This is an example diagram of a two-dimensional array update process according to an embodiment of the present invention; Figure 6This is an example diagram of the updated two-dimensional array according to an embodiment of the present invention; Figure 7 This is an example diagram illustrating the valid key press determination according to an embodiment of the present invention; Figure 8 This is a structural example diagram of a third two-dimensional array according to an embodiment of the present invention; Figure 9 This is a flowchart illustrating a method for detecting matrix keys according to an embodiment of the present invention. Figure 10 This is a structural block diagram of a matrix key detection device according to an embodiment of the present invention; Figure 11 This is a schematic diagram of the hardware structure of the controller according to an embodiment of the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0023] It is understood that before using the technical solutions disclosed in the various embodiments of the present invention, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in the present invention and their authorization should be obtained in accordance with relevant laws and regulations through appropriate means.
[0024] like Figure 1 As shown, the electrical device designed in this embodiment of the invention includes a matrix keypad 11 and a controller 12. The controller 12 includes a memory and a processor, which are interconnected. The memory stores computer instructions, and the processor executes the computer instructions to perform the matrix keypad detection method described below. The type of electrical device is not limited, as long as it includes a matrix keypad and a controller. For example, kitchen appliances (microwave ovens, rice cookers, etc.), air conditioners, washing machines, etc. can all be used with the matrix keypad detection method described below. This is just an example.
[0025] According to an embodiment of the present invention, a method for detecting matrix keys is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0026] This embodiment provides a method for detecting matrix buttons, which can be used in the controller of electrical equipment. Figure 2 This is a flowchart of a matrix key detection method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps: Step S201: Create the first two-dimensional array.
[0027] In the first two-dimensional array, the first dimension represents all the keys to be scanned in the matrix keypad, and the second dimension is used to store the set of state sample values determined after multiple consecutive scans of each key. The state sample values include a first value indicating that the key is valid and a second value indicating that the key is invalid.
[0028] In this embodiment of the invention, a first two-dimensional array can be created, where the first dimension of the first two-dimensional array represents all key elements to be scanned in the matrix keypad, such as... Figure 3 As shown, the first dimension is represented by rows, with each row corresponding to the button state of an independent button element. The number of rows can be set according to the number of buttons in the matrix. For example, if a microcontroller has 10 buttons, then it corresponds to gucFilterBuf[0]~gucFilterBuf[9]. The second dimension is represented by columns, which are used to store the set of state sample values determined after multiple consecutive scans of each button. Each column represents the state sample value of each button obtained in the current scan. The number of columns set represents the number of button state sample values that can be stored in the first two-dimensional array. The more columns there are, the stronger the anti-interference ability, but the higher the consumption. The more memory and runtime a microcontroller has, the more effective it can be. Therefore, the number of columns can be adjusted according to project requirements to achieve better anti-interference capabilities and conserve resources. In a specific embodiment, the first two-dimensional array is an anti-interference buffer char type array. When the system is powered on or initialized, the key state sampling content stored in the columns of the first two-dimensional array can be blank to fill the results of subsequent scans into the first two-dimensional array. Alternatively, other elements in the first two-dimensional array except for the key elements can be initialized to 0x3FF, indicating that all keys are at an invalid level in the initial state of the array, so as to update the array in real time using the results of subsequent scans. This is just an example.
[0029] Step S202: Scan the matrix keys based on a preset time interval, and store the state sample values of each key obtained in each scan into the first two-dimensional array in the order of scanning time.
[0030] This invention can scan the matrix keys based on a preset time interval. The preset time interval can be set according to resource consumption and accurate determination of key validity. Taking 2ms as an example, the matrix keys are scanned every 2ms to obtain the state sampling results of all keys. The state sampling value includes a first value indicating that the key is valid and a second value indicating that the key is invalid. Taking the valid level as zero and the invalid level as 1 as an example, the first and second values can also be the level states obtained after debouncing processing. The state sampling values of all keys obtained in each scan can be stored in the first two-dimensional array according to the scan time order. For example, the state sampling values of all keys obtained in the first scan (14ms ago) are stored in the first column (highest bit), and the state sampling values of all keys obtained in the current scan are stored in the current last column (lowest bit). This is just an example.
[0031] Step S203: Determine the pressed state of the button based on the set of state sample values of each button stored in the first two-dimensional array.
[0032] In this embodiment of the invention, the number of sample values that the two-dimensional array can store for each state is taken as 8. When determining the key state for the first time, the current key press state can be determined based on the set of state sample values corresponding to the current key obtained after 8 consecutive scans stored in the two-dimensional array. Subsequently, the current key press state is determined synchronously with the key scanning frequency. For example, the key state determination step can be performed once every 2ms. The method of determining the current key press state based on the set of state sample values of the current key is not limited. For example, when all the state sample values obtained after 8 scans of the current key stored in the two-dimensional array are zero, it is determined that the current key is validly pressed. If any state sample value in the 8 bits is 1, it is determined that the current key is invalid. Alternatively, a preset number of state sample values of 0 can be selected from all the state sample values after 8 scans of the current key in the two-dimensional array to determine that the current key is validly pressed. For example, 5 to 6 state sample values of 0 can determine that the current key is validly pressed. This is just an example.
[0033] The matrix key detection method provided by this invention creates a first two-dimensional array. The first dimension of the first two-dimensional array represents all keys to be scanned in the matrix key array, and the second dimension stores the set of state sample values determined after multiple consecutive scans of each key. Then, the matrix key array is scanned based on a preset time interval, and the state sample values of each key obtained in each scan are stored in the first two-dimensional array according to the scanning time sequence. Finally, the pressed state of each key can be determined based on the set of state sample values stored in the first two-dimensional array. This avoids the influence of instantaneous interference on the results of a single scan. By statistically analyzing the sample values obtained from multiple scans, the false judgment rate is significantly reduced, and the accuracy and reliability of key judgment are improved.
[0034] This embodiment provides a method for detecting matrix buttons, which can be used in the controller of electrical equipment. Figure 4 This is a flowchart of a matrix key detection method according to an embodiment of the present invention, such as... Figure 4 As shown, the process includes the following steps: Step S401: Create the first two-dimensional array.
[0035] In the first two-dimensional array, the first dimension represents all the keys to be scanned in the matrix keypad, and the second dimension is used to store the set of state sample values determined after multiple consecutive scans of each key. The state sample values include a first value indicating that the key is valid and a second value indicating that the key is invalid.
[0036] Step S402: Scan the matrix keys based on a preset time interval, and store the state sample values of each key obtained in each scan into the first two-dimensional array in the order of scanning time.
[0037] Specifically, the second dimension has a corresponding storage capacity, and step S402 above includes: Step S4021: When the number of state sample values of each button stored in the second dimension reaches the storage capacity, remove the state sample values of each button with the earliest scan time, and write the state sample values of each button obtained by the current scan into the first two-dimensional array in the order of scan time.
[0038] In this embodiment of the invention, a corresponding storage capacity is set for the first two-dimensional array. Taking 8 columns of stored state sample values as an example, this ensures the microcontroller's memory and operating consumption as well as its anti-interference capability. If the number of state sample values of each button stored in the second dimension reaches the storage capacity corresponding to the second dimension, and after scanning to obtain the latest state sample values of each button, the state sample values of each button with the earliest scanning time can be extracted, i.e. Figure 5 As shown, the bits can be shifted uniformly to the left. After each left shift, the oldest state sample data is removed. For example, the state sample value collected 16ms ago is removed, and the latest scanned button state sample value is stored in the least significant bit. Figure 6 As shown, after the new scan result is written into the first two-dimensional array, the set of state sample values in the first two-dimensional array is updated. This is just an example.
[0039] This invention ensures the timeliness of sampled data by storing it in chronological order and removing the oldest data when the capacity is full, and it also achieves a balance between resource consumption and anti-interference requirements by designing a fixed memory footprint.
[0040] Step S403: Determine the pressed state of the button based on the set of state sample values of each button stored in the first two-dimensional array.
[0041] Specifically, step S403 includes: Step S4031: If all the state sample values of the current button stored in the first two-dimensional array are the first value, determine that the current button is in a valid pressed state.
[0042] In this embodiment of the invention, after each update of the first two-dimensional array, the validity of a button can be determined based on the two-dimensional array, such as... Figure 7 As shown, when all the state sample values of the current key stored in the first two-dimensional array are zero, it can be determined that the current key is validly pressed. If the 8-bit state sample value of a certain key contains 1, it can be determined that the key is invalid. This is just an example.
[0043] This invention employs a method of multiple scanning and sampling with full consistency determination to avoid misjudgment that may be caused by momentary interference during a single scanning and sampling, filter out occasional outliers, and improve the reliability of button status determination.
[0044] In one optional implementation, the present invention can set a corresponding counter for the current button. If all the state sample values of the current button stored in the first two-dimensional array are the second value, the counter can be cleared.
[0045] This invention includes a counter that counts the scanning state sampling results of the current button to determine the interference intensity of the button. When the first two-dimensional array is initialized, all state sampling values are 0x3FF. When the current button is not pressed, the corresponding 8-bit state sampling values are all 1, indicating that all data are invalid. In this case, the counter can be cleared, i.e., t_cnt = 0.
[0046] Furthermore, the second dimension is equipped with a corresponding storage capacity, which represents the number of state sample values that can be stored for the current button. In the process of determining the button's pressed state, when the current button's state sample value is detected as the first value, the counter can be incremented; when the current button is determined to be in a valid pressed state, the counter is controlled to pause counting; based on the comparison result between the value currently recorded by the counter and the number of state sample values that can be stored in the second dimension of the first two-dimensional array, the first interference intensity of the matrix button is determined.
[0047] This invention performs matrix key scanning at 2ms intervals and stores the state sample values of each key obtained after each scan in a first two-dimensional array. After each scan, if the current key's state sample value is zero, a counter can be incremented, for example, t_cnt is incremented by 1 every 2ms, recording the cumulative number of times the current key's level is zero. Then, after each update of the first two-dimensional array, it can be checked whether all 8 bits of the current key's state sample value are zero. If not all are zero, it is determined that the current key is invalidally pressed, and the counter continues to increment with each occurrence of a state sample value of zero until all 8 bits of the current key's state sample value are zero, indicating that the current key is validly pressed, at which point the counter can be paused. Then, based on the current value recorded by the counter and the data in the first two-dimensional array... The comparison result of the number of state sample values that can be stored in the second dimension (e.g., 8 bits) determines the first interference intensity of the matrix key. Specifically, if the value currently recorded by the counter is equal to 8, or a certain margin value is set, such as not exceeding 10 times, it means that the first value of the current key is continuous and stable, with no interference or little interference, indicating that the first interference intensity is low. The key press state can still be judged according to the 8-bit state sample value, or the number of judgments can be reduced, such as judging the key press state according to the latest 6-bit state sample value. This is just an example. If the value currently recorded by the counter is greater than 8, or a certain margin value is set, such as exceeding 10 times, it means that non-zero interference signals frequently appear in the sample value before reaching the effective press state, indicating that the first interference intensity is high. Subsequently, when all sampled values are detected to be the second value (e.g., 1, invalid level), the counter can be cleared to prepare for the next valid state monitoring cycle. The intensity of the first interference received by the matrix key can also be determined by the judgment time. For example, the counter increments by one every 2ms, so after the counter pauses counting, the judgment time Time = t_cnt 11 2 ms can be calculated. Ideally, the Time value should be 16ms, or a certain margin value can be set. The maximum Time value should not exceed 20ms, indicating that the external interference capability is weak. When Time exceeds 16ms, or when a certain margin value is set and Time exceeds 20ms, it indicates that the key scanning is subject to external interference or the external interference is strong.
[0048] This invention compares the counter value with the second-dimensional storage capacity to convert it into a quantifiable indicator, dynamically analyzing the changes in button status. This not only determines whether a button is effective but also the degree of interference, improving the precision of status analysis and enhancing overall reliability.
[0049] In one optional implementation, if the first interference intensity is determined to reach the abnormal interference standard (e.g., the counter records more than 8 or 10 times), a second two-dimensional array can be created. The second two-dimensional array is combined with the first two-dimensional array to obtain a third two-dimensional array. The number of state sample values that the third two-dimensional array can store is the sum of the number of state sample values that the first two-dimensional array and the second two-dimensional array can store. The state sample values of each key obtained in each scan are stored in the third two-dimensional array. When the state sample value of the current key is detected to be the first value, the counter is incremented. If all state sample values of the current key in the third two-dimensional array are the first value, the current key is determined to be valid, and the counter is controlled to pause counting. Based on the comparison result between the value currently recorded by the counter and the number of state sample values that the third two-dimensional array can store, the second interference intensity of the matrix key is determined.
[0050] In this array, the first dimension of the second two-dimensional array is the same as the first dimension of the first two-dimensional array, and the second dimension is used to store the set of state sample values determined by each button after multiple consecutive scans.
[0051] In this embodiment of the invention, when it is determined that the first interference intensity received by the button is relatively strong, a second two-dimensional array gucFilterBuf2 can be created, such as... Figure 8 As shown, the second two-dimensional array is placed before the first two-dimensional array to combine the two arrays, resulting in a third two-dimensional array. The number of state sample values that the third two-dimensional array can store is the sum of the number of state sample values that the first and second two-dimensional arrays can store. Taking 16 bits as an example, the state sample values of each scanned button can then be stored in the third two-dimensional array. This also includes updating the array by left-shifting as mentioned above. After each subsequent scan and sampling, if the current button's state sample value is 0, a counter can be incremented to record the cumulative number of times the current button's level is zero. Then, after each update of the third two-dimensional array, it can be checked whether the 16-bit state sample value of the current button is all zero. If it is not all zero, it is determined that the current button is invalid. The counter continues to increment as the state sample value becomes zero, until the 16-bit state sample value of the current button is all zero, indicating that the current button is valid. Then the counter can be paused. Then the number currently recorded by the counter is compared with the number of state sample values (16 bits) that can be stored in the third two-dimensional array, or the number currently recorded by the counter is multiplied by 2ms to get Time, and then compared with 32ms. This is just an example.
[0052] In this embodiment of the invention, if it is determined that the number currently recorded by the counter exceeds 16 times, or the calculated Time is greater than 32ms, it indicates that the current matrix key is still subject to relatively high interference. In this case, the state sampling value stored in the third two-dimensional array can still be used to determine the valid key press status. Alternatively, a fourth two-dimensional array can be created and combined with the third two-dimensional array to obtain a fourth two-dimensional array for subsequent key press determination. This is just an example. If it is determined that the number currently recorded by the counter is equal to 16 bits, or the calculated Time is equal to 32ms, it indicates that the current matrix key is subject to relatively low interference.
[0053] When the first interference intensity is determined to reach the abnormal interference standard, the present invention can create a second two-dimensional array and combine it into a third two-dimensional array, which is equivalent to increasing the number of samplings and the number of samples for determining the valid state. This can more effectively reduce misjudgments caused by accidental continuous valid sampling and dynamically enhance the anti-interference capability.
[0054] In one optional implementation, if the second interference intensity of the matrix keys meets the normal interference standard, during the next matrix key scan, the process returns to the step of storing the state sample values of each key obtained in each scan into the third two-dimensional array, until the second interference intensity of the matrix keys is determined for a consecutive number of times and meets the normal interference standard. Then, the first two-dimensional array is restored to the array used for key state detection, and the process returns to the step of scanning the matrix keys based on a preset time interval and storing the state sample values of each key obtained in each scan into the first two-dimensional array.
[0055] like Figure 9 As shown in the embodiment of the present invention, when it is determined that the current matrix key is subjected to low interference intensity, the first two-dimensional array can be not restored for judgment, that is, the method of using the third two-dimensional array to judge the valid press state can still be maintained. After the third two-dimensional array is used to judge the valid press state again, the number of times the state with low interference intensity can be recorded until the state with low anti-interference intensity occurs consecutively a certain number of times (for example, it occurs 3 times). This indicates that the matrix key is subjected to less external interference, and the use of the second two-dimensional array can be paused. The method of using the first two-dimensional array to detect the key press state can be restored, that is, the 8-bit key press can be used to detect the key press. If a state with high interference intensity occurs in the middle, it is necessary to continue to use the 16-bit array to judge the key press and recalculate the number of times the low interference intensity occurs. This is only an example.
[0056] When the second interference intensity is determined to have returned to normal and remained stable, the present invention can restore the judgment using only the first two-dimensional array, which takes into account both anti-interference capability and avoids resource occupation caused by long-term use of large-capacity sampling.
[0057] This embodiment also provides a matrix key detection device, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0058] This embodiment provides a detection device for matrix keypads, such as... Figure 10 As shown, the system includes: an array creation module 1001, used to create a first two-dimensional array, wherein the first dimension of the first two-dimensional array represents all keys to be scanned in the matrix keypad, and the second dimension is used to store the set of state sample values determined after multiple consecutive scans of each keypad, the state sample values including a first value indicating that the keypad is valid and a second value indicating that the keypad is invalid; a state sample storage module 1002, used to scan the matrix keypad based on a preset time interval, and store the state sample values of each keypad obtained in each scan into the first two-dimensional array in the order of the scan time; and a key state determination module 1003, used to determine the pressed state of the keypad based on the set of state sample values of each keypad stored in the first two-dimensional array.
[0059] In some optional implementations, the second dimension is provided with a corresponding storage capacity. The state sampling storage module 1002 includes an array update unit, which is used to remove the state sampling values of each key with the earliest scanning time when the number of state sampling values of each key stored in the second dimension reaches the storage capacity, and write the state sampling values of each key obtained by the current scan into the first two-dimensional array in the order of scanning time.
[0060] In some optional implementations, the button state determination module 1003 includes: a state determination unit, used to determine that the current button is in a valid pressed state if all the state sample values of the current button stored in the first two-dimensional array are the first value.
[0061] In some optional implementations, the matrix key detection device further includes: a counter setting module for setting a corresponding counter for the current key; and a counter clearing module for clearing the counter if all state sample values of the current key stored in the first two-dimensional array are the second value.
[0062] In some optional implementations, the second dimension is provided with a corresponding storage capacity, which represents the number of state sample values that can be stored by the current button. In the process of determining the pressed state of the button, the matrix button detection device further includes: a counter counting module, used to increment the counter when the detected state sample value of the current button is the first value; a counter pausing module, used to control the counter to pause counting when it is determined that the current button is in a valid pressed state; and an interference intensity judgment module, used to determine the first interference intensity of the matrix button based on the comparison result between the value currently recorded by the counter and the number of state sample values that can be stored in the second dimension of the first two-dimensional array.
[0063] In some optional implementations, the matrix key detection device further includes: a second array creation module, used to create a second two-dimensional array if the first interference intensity of the matrix key reaches the abnormal interference standard, wherein the first dimension of the second two-dimensional array is the same as the first dimension of the first two-dimensional array, and the second dimension is used to store the set of state sample values determined by each key after multiple consecutive scans; an array combination module, used to combine the second two-dimensional array with the first two-dimensional array to obtain a third two-dimensional array, wherein the number of state sample values that the third two-dimensional array can store is the sum of the number of state sample values that the first two-dimensional array and the second two-dimensional array can store; a data storage module, used to store the state sample values of each key obtained in each scan into the third two-dimensional array; a counter increment module, used to increment the counter when the current key's state sample value is detected to be the first value; a counter pause module, used to determine that the current key is valid and control the counter to pause counting if all state sample values of the current key in the third two-dimensional array are the first value; and an interference intensity judgment module, used to determine the second interference intensity of the matrix key based on the comparison result between the value currently recorded by the counter and the number of state sample values that the third two-dimensional array can store.
[0064] In some optional embodiments, the matrix key detection device further includes: an array recovery module, used to, if the second interference intensity of the matrix key meets the normal interference standard, return to the step of storing the state sample value of each key obtained in each scan into a third two-dimensional array during the next matrix key scan, until the second interference intensity of the matrix key determined for a consecutive number of times meets the normal interference standard, restore the first two-dimensional array as an array for key state detection, and return to the step of scanning the matrix key based on a preset time interval and storing the state sample value of each key obtained in each scan into the first two-dimensional array.
[0065] The matrix key detection device provided in this embodiment of the invention can execute the matrix key detection method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects for executing the method. Further functional descriptions of the various modules and units described above are the same as in the corresponding embodiments described above, and will not be repeated here.
[0066] Figure 11 This is a schematic diagram of the structure of a controller in an electrical device provided in an embodiment of the present invention.
[0067] The following is a detailed reference. Figure 11 The diagram illustrates a structural schematic suitable for implementing a controller in an embodiment of the present invention. The controller may include a processor (e.g., a central processing unit, graphics processing unit, etc.) 1101, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1102 or a program loaded from memory 1108 into random access memory (RAM) 1103. The RAM 1103 also stores various programs and data required for controller operation. The processor 1101, ROM 1102, and RAM 1103 are interconnected via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0068] Typically, the following devices can be connected to I / O interface 1105: input devices 1106 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 1107 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; memory 1108 including, for example, magnetic tape, hard disk, etc.; and communication devices 1109. Communication device 1109 allows the controller to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 11 A controller with various devices is shown, but it should be understood that it is not required to implement or have all of the devices shown, and may alternatively implement or have more or fewer devices.
[0069] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 1109, or installed from a memory 1108, or installed from a ROM 1102. When the computer program is executed by the processor 1101, it performs the functions defined in the matrix key detection method of the embodiments of the present invention.
[0070] Figure 11The controller shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0071] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the matrix key detection method shown in the above embodiments is implemented.
[0072] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0073] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for detecting a matrix key, characterized in that, The method comprises: creating a first two-dimensional array, wherein a first dimension in the first two-dimensional array represents all keys to be scanned in a matrix key, and a second dimension is used for storing a set of state sampling values of each key determined after multiple continuous scans, the state sampling values comprising a first value representing a valid key and a second value representing an invalid key; scanning the matrix key based on a preset time interval, and storing the state sampling values of each key obtained in each scan in the first two-dimensional array in a scan time sequence; determining the pressed state of the key based on the set of state sampling values of each key stored in the first two-dimensional array.
2. The method of claim 1, wherein, The second dimension is provided with a corresponding storage capacity, and the storing of the state sampling values of each key obtained in each scan in the first two-dimensional array comprises: when the number of state sampling values of each key stored on the second dimension reaches the storage capacity, the state sampling values of each key with the earliest scan time are removed, and the state sampling values of each key obtained in the current scan are written into the first two-dimensional array in a scan time sequence.
3. The method of claim 1, wherein, The determination of the pressed state of the key based on the set of state sampling values of each key stored in the first two-dimensional array comprises: if all the state sampling values of the current key stored in the first two-dimensional array are the first value, it is determined that the current key is in a valid pressed state.
4. The method of claim 3, wherein, The method further comprises: setting a corresponding counter for the current key; if all the state sampling values of the current key stored in the first two-dimensional array are the second value, performing a zero operation on the counter.
5. The method of claim 4, wherein, The second dimension is provided with a corresponding storage capacity, and the storage capacity represents the number of state sampling values that can be stored by the current key, and in the process of determining the pressed state of the key, the method further comprises: when the state sampling value of the current key is detected to be the first value, incrementing the counter; when it is determined that the current key is in a valid pressed state, controlling the counter to pause counting; determining the first interference intensity of the matrix key based on the comparison result of the value currently recorded by the counter and the number of state sampling values that can be stored in the second dimension of the first two-dimensional array.
6. The method of claim 5, wherein, The method further comprises: if it is determined that the first interference intensity of the matrix key reaches an abnormal interference standard, creating a second two-dimensional array, wherein a first dimension in the second two-dimensional array is the same as the first dimension in the first two-dimensional array, and a second dimension is used for storing a set of state sampling values of each key determined after multiple continuous scans; combining the second two-dimensional array and the first two-dimensional array to obtain a third two-dimensional array, wherein the number of state sampling values that can be stored in the third two-dimensional array is the sum of the number of state sampling values that can be stored in the first two-dimensional array and the number of state sampling values that can be stored in the second two-dimensional array; storing the state sampling values of each key obtained in each scan in the third two-dimensional array; when the state sampling value of the current key is detected to be the first value, incrementing the counter; if all the state sampling values of the current key in the third two-dimensional array are the first value, it is determined that the current key is valid, and the counter is controlled to pause counting; Determine the second interference intensity on the matrix key based on a comparison result of a current record value of the counter and a number of state sample values that can be stored in the third two-dimensional array.
7. The method of claim 6, wherein, The method further includes: If the second interference intensity on the matrix key meets the normal interference standard, return to perform the step of storing the state sample value of each key obtained in each scan into the third two-dimensional array in the next matrix key scan, and until the second interference intensity on the matrix key determined for a continuous number of times meets the normal interference standard, restore the first two-dimensional array to an array for key state detection, and return to perform the step of scanning the matrix key based on the preset time interval and storing the state sample value of each key obtained in each scan into the first two-dimensional array.
8. A detection device for matrix keypads, characterized in that, The device includes: An array creation module configured to create a first two-dimensional array, wherein a first dimension of the first two-dimensional array represents all keys in the matrix key to be scanned, and a second dimension is configured to store a set of state sample values of each key determined after a plurality of continuous scans, the state sample values including a first value representing a valid key and a second value representing an invalid key; A state sample storage module configured to scan the matrix key based on a preset time interval, and store the state sample value of each key obtained in each scan into the first two-dimensional array in a scan time sequence; A key state determination module configured to determine the pressed state of the key based on the set of state sample values of each key stored in the first two-dimensional array.
9. An electrical appliance, characterized in that The electrical appliance device includes a matrix key and a controller, the controller includes a memory and a processor, the memory and the processor are communicatively connected with each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the detection method of the matrix key according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, and the computer instructions are used to make the computer execute the detection method of the matrix key according to any one of claims 1 to 7.
