Disclosure of Invention
In view of the above disadvantages of the prior art, an object of the present invention is to provide a bluetooth search detection method, a detection device, a storage medium, and a mobile terminal, wherein when a user uses a bluetooth function of the mobile terminal, a timer and a counter are used to flexibly detect and output a start or stop state of a bluetooth search, which can greatly improve efficiency of searching for a bluetooth device and avoid wasting terminal power by continuously searching for the bluetooth device.
In order to achieve the purpose, the invention adopts the following technical scheme:
a Bluetooth searching and detecting method comprises the following steps:
detecting the voltage of an interrupt detection pin of the Bluetooth module and judging whether a first interrupt signal or a second interrupt signal is generated, if so, starting a timer with the overtime time as the preset time;
judging whether the timer is overtime, acquiring the voltage of the current interrupt detection pin when the timer is overtime, and controlling the timer to count again;
controlling the count value of a first counter or a second counter to be increased by one according to the current voltage of the interrupt detection pin, judging whether the count value of the current first counter or the current second counter is greater than a preset threshold value, and if so, correspondingly outputting a Bluetooth search detection result according to the count value of the first counter or the second counter; otherwise, whether the timer is overtime or not is continuously judged.
In the bluetooth search detection method, after the step of correspondingly outputting the bluetooth search detection result according to the count value of the first counter or the second counter, the method further includes:
and clearing the first counter and the second counter and closing the timer.
In the bluetooth search detection method, the step of detecting the voltage of the interrupt detection pin of the bluetooth module and judging whether to generate a first interrupt signal or a second interrupt signal, if so, starting a timer with timeout time as preset time includes:
detecting the voltage of an interrupt detection pin of a Bluetooth module, judging that a first interrupt signal is generated currently when the voltage of the interrupt detection pin is greater than a first threshold value, and judging that a second interrupt signal is generated currently when the voltage of the interrupt detection pin is less than a second threshold value;
and starting a timer with the timeout time being preset time when the first interrupt signal or the second interrupt signal is generated.
In the bluetooth search detection method, the step of determining whether the timer is overtime, acquiring the voltage of the interrupt detection pin when the timer is overtime, and controlling the timer to restart includes:
judging whether the timing value of the timer is greater than or equal to a preset time or not;
when the current voltage of the interruption detection pin is greater than or equal to the preset time, acquiring the current voltage of the interruption detection pin, and controlling the timer to count again;
and when the time is less than the preset time, controlling the timer to continue timing.
In the bluetooth search detection method, the count value of the first counter or the second counter is controlled to be increased by one according to the current voltage of the interrupt detection pin, whether the count value of the current first counter or the current second counter is greater than a preset threshold value is judged, and if yes, a bluetooth search detection result is correspondingly output according to the count value of the first counter or the second counter; otherwise, the step of continuously judging whether the timer is overtime comprises the following steps:
if the voltage of the current interrupt detection pin is larger than a first threshold value, controlling a first counter to increase by one, and if the voltage of the current interrupt detection pin is smaller than a second threshold value, controlling a second counter to increase by one;
judging whether the count value of the current first counter or the second counter is larger than a preset threshold value, if so, correspondingly outputting a Bluetooth search detection result according to the count value of the first counter or the second counter; otherwise, whether the timer is overtime or not is continuously judged.
In the bluetooth search detection method, whether the count value of the current first counter or second counter is greater than a preset threshold value is judged, and if yes, a bluetooth search detection result is correspondingly output according to the count value of the first counter or second counter; otherwise, the step of continuously judging whether the timer is overtime comprises the following steps:
judging whether the count value of the current first counter or the second counter is larger than a preset threshold value or not;
if the count value of the current first counter is greater than the preset threshold value, judging that the Bluetooth search is started, and if the count value of the current second counter is greater than the preset threshold value, judging that the Bluetooth search is stopped; otherwise, whether the timer is overtime or not is continuously judged.
In the bluetooth search detection method, the preset time range is 10 ms to 25 ms.
A bluetooth search detection apparatus comprising a processor, a memory communicatively coupled to the processor, the memory storing a computer program for execution by the processor to implement the steps in the bluetooth search detection method as described above; the processor is configured to invoke a computer program in the memory to perform the steps in the bluetooth search detection method as described above.
A computer readable storage medium storing one or more programs, the one or more programs being executable by one or more processors to implement the steps in the bluetooth search detection method as described above.
A mobile terminal comprising a bluetooth detection apparatus as described above.
Compared with the prior art, in the bluetooth search detection method, the detection device, the storage medium and the mobile terminal, the bluetooth search detection method detects the voltage of the interrupt detection pin of the bluetooth module and judges whether the first interrupt signal or the second interrupt signal is generated, and if so, a timer with the timeout time being the preset time is started; then judging whether the timer is overtime, acquiring the voltage of the current interrupt detection pin when the timer is overtime, and controlling the timer to count again; then controlling the count value of the first counter or the second counter to be increased by one according to the current voltage of the interruption detection pin, judging whether the count value of the current first counter or the current second counter is greater than a preset threshold value, and if so, correspondingly outputting a Bluetooth search detection result according to the count value of the first counter or the second counter; otherwise, whether the timer is overtime or not is continuously judged. When a user uses the Bluetooth function of the mobile terminal, the starting or stopping state of the Bluetooth search is flexibly detected and output by using the timer and the counter, so that the efficiency of searching the Bluetooth equipment can be greatly improved, and the waste of the electric quantity of the terminal due to continuous searching is avoided.
Detailed Description
In view of the disadvantages that the searching efficiency is affected by the continuous searching of the mobile terminal bluetooth in the prior art, the invention aims to provide a bluetooth searching detection method, a detection device, a storage medium and a mobile terminal.
In order to make the objects, technical solutions and effects of the present invention clearer and clearer, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, the bluetooth search detection method provided by the present invention includes the following steps:
s100, detecting the voltage of an interrupt detection pin of the Bluetooth module and judging whether a first interrupt signal or a second interrupt signal is generated, if so, starting a timer with the overtime time as the preset time;
s200, judging whether the timer is overtime, acquiring the voltage of the current interrupt detection pin when the timer is overtime, and controlling the timer to count again;
s300, controlling the count value of a first counter or a second counter to be increased by one according to the current voltage of the interrupt detection pin, judging whether the count value of the current first counter or the current second counter is larger than a preset threshold value, and if yes, correspondingly outputting a Bluetooth search detection result according to the count value of the first counter or the second counter; otherwise, whether the timer is overtime or not is continuously judged.
In the Bluetooth searching and detecting method provided by the invention, a mobile terminal Bluetooth module is provided with two pins which are used for being connected with a main controller and are respectively a VIN pin and a grounding pin, wherein the VIN pin is an interruption detection pin, when the Bluetooth searching is started or stopped, the voltage of the interruption detection pin changes, therefore, the invention judges whether a first interruption signal or a second interruption signal is generated by detecting the voltage of the interruption detection pin of the Bluetooth module, when the first interruption signal or the second interruption signal is generated, a timer with the overtime of the preset time is started, then the timer is judged whether the timer is overtime, if the timer is overtime, the current voltage of the interruption detection pin is triggered and obtained, and the timer is controlled to count again, namely, the timer triggers and obtains the voltage of the current interruption detection pin every preset time, then the count value of a first counter or a second counter is controlled to add one according to the voltage of the current interruption detection pin, and judging whether the count value of the current first counter or the second counter is greater than a preset threshold value, if the count value of one of the first counter or the second counter is greater than the preset threshold value, correspondingly outputting a Bluetooth search detection result, and if the count values of the first counter and the second counter are both less than the preset threshold value, continuously judging whether the timer is overtime and triggering to acquire the voltage of the current interrupt detection pin, further controlling the count value of the first counter or the second counter, and outputting the Bluetooth search detection result until the count value of one of the first counter and the second counter reaches the preset threshold value. In the invention, when the user uses the Bluetooth function of the mobile terminal, the working state of the current Bluetooth module is judged by using the timer and the counter, and the starting or stopping state of the Bluetooth search is flexibly detected and output according to the timing time and the count value, so that the efficiency of searching the Bluetooth equipment can be greatly improved, and the waste of the electric quantity of the terminal due to continuous searching is avoided.
Preferably, the step S300 is followed by the step of:
s400, clearing the first counter and the second counter and closing the timer.
In this embodiment, after the bluetooth search detection result is output, it represents that the detection and determination of the bluetooth search state has been completed in the current period, so that the first counter and the second counter are cleared and the timer is turned off for timing and counting when the next user uses the bluetooth function, thereby ensuring the accuracy of detecting the start and stop of the bluetooth search each time the user uses the bluetooth function.
Specifically, the step S100 includes the steps of:
s101, detecting the voltage of an interrupt detection pin of a Bluetooth module, judging that a first interrupt signal is generated currently when the voltage of the interrupt detection pin is larger than a first threshold value, and judging that a second interrupt signal is generated currently when the voltage of the interrupt detection pin is smaller than a second threshold value;
s102, starting a timer with the timeout time being preset time when the first interrupt signal or the second interrupt signal is generated.
In this embodiment, after detecting the voltage of the interrupt detection pin of the bluetooth module and determining whether to generate a first interrupt signal or a second interrupt signal, specifically, after detecting the voltage of the interrupt detection pin, if the voltage of the interrupt detection pin is greater than a first threshold, it is determined that the first interrupt signal is currently generated, if the voltage of the interrupt detection pin is less than a second threshold, it is determined that the second interrupt signal is currently generated, since the voltage of the interrupt detection pin changes when the bluetooth starts a search and stops the search, specifically, the voltage of the pin is greater than the first threshold VH when the search is started, and the voltage of the pin is less than the second threshold VL when the search is stopped, it is determined that the current bluetooth search state changes by detecting the voltage of the pin and generating a corresponding interrupt signal, and when the first interrupt signal or the second interrupt signal is generated, a timer whose timeout time is a preset time is started, and then accurately detecting the starting and closing states of the Bluetooth search according to subsequent timing and counting, and improving the detection efficiency of the Bluetooth search.
Further, the step S200 includes the steps of:
s201, judging whether the timing value of the timer is more than or equal to a preset time or not;
s202, when the current voltage of the interruption detection pin is greater than or equal to the preset time, acquiring the current voltage of the interruption detection pin, and controlling the timer to count again;
and S203, controlling the timer to keep timing when the time is less than the preset time.
In this embodiment, after detecting that the interrupt signal is generated by the interrupt detection pin, a timer with a timeout time being a preset time is started, and then whether a timing value of the timer is greater than or equal to the preset time is determined, namely, judging whether the current timer is overtime or not, acquiring the current voltage of the interrupt detection pin when the current timer is more than or equal to the preset time, and controls the timer to count again, when the time is less than the preset time, controls the timer to count continuously, namely, the invention triggers the action of acquiring the voltage of the interrupt detection pin through the timer and triggers the action once every preset time, when the timer is overtime and triggered, the timer is restarted to realize the repeated operation of acquiring the voltage, the preset time is preferably 10 ms-25 ms, and may be selected according to actual needs, which is not limited in the present invention.
Specifically, the step S300 includes the steps of:
s301, if the voltage of the current interrupt detection pin is larger than a first threshold value, controlling a first counter to increase by one, and if the voltage of the current interrupt detection pin is smaller than a second threshold value, controlling a second counter to increase by one;
s302, judging whether the count value of the current first counter or second counter is larger than a preset threshold value, if so, correspondingly outputting a Bluetooth search detection result according to the count value of the first counter or second counter; otherwise, whether the timer is overtime or not is continuously judged.
Specifically, the step S302 includes the steps of:
s3021, judging whether the count value of the current first counter or the current second counter is greater than a preset threshold value;
s3022, if the count value of the current first counter is greater than the preset threshold, determining that the Bluetooth search is started, and if the count value of the current second counter is greater than the preset threshold, determining that the Bluetooth search is stopped; otherwise, whether the timer is overtime or not is continuously judged.
In this embodiment, after detecting an interrupt signal and starting a timer to obtain a voltage of an interrupt detection pin, if the currently obtained voltage is greater than a first threshold VH, then a bluetooth search is in an activated state, and the first counter is controlled to increment by one, if the currently obtained voltage is less than a second threshold VL, then the bluetooth search is in a deactivated state, and the second counter is controlled to increment by one, because the timer obtains the pin voltage once every preset time, that is, the value of the first counter or the second counter changes every preset time, it is determined whether the count value of the first counter or the second counter is greater than the preset threshold after the count value changes, if the count value of the current first counter is greater than the preset threshold, it represents that the current bluetooth search is in the activated state for a period of time (i.e., the preset time is the current count value), then it is determined that the bluetooth search is activated, if the count value of the current second counter is greater than the preset threshold value, the current Bluetooth search is in a stop state for a period of time, the Bluetooth search is judged to be stopped at the moment, namely the working state of the Bluetooth search is detected and judged respectively through the count values of the first counter and the second counter, the problem that the Bluetooth search is continuously started is avoided, the efficiency of searching the mobile terminal cathode Bluetooth device is effectively improved, and the energy consumption of the system is saved.
Based on the bluetooth search detection method, the present invention also provides a computer-readable storage medium storing one or more programs, which are executable by one or more processors to implement the steps in the bluetooth search detection method as described above. Since the bluetooth search detection has been described in detail above, it is not described in detail here, and it is specifically referred to the corresponding embodiment of the above method.
Based on the above bluetooth search detection method, the present invention further provides a bluetooth detection apparatus, as shown in fig. 2, the bluetooth search detection apparatus includes a processor 10, a memory 20 communicatively connected to the processor 10, and a communication interface 30 for signal transmission, where the processor 10, the storage area 20, and the communication interface 30 are all connected through a communication bus 40. Wherein the memory 20 stores a computer program which is executed by the processor 10 to implement the steps in the bluetooth search detection method as described above; the processor 10 is adapted to call a computer program in the memory 20 to perform the steps of the bluetooth search detection method as described above. Since the bluetooth search detection has been described in detail above, it is not described in detail here, and it is specifically referred to the corresponding embodiment of the above method.
The invention also provides a mobile terminal comprising the bluetooth detection device, which is not described in detail since the bluetooth detection device is described in detail above.
In summary, in the bluetooth search detection method, the detection device, the storage medium, and the mobile terminal provided by the present invention, the bluetooth search detection method detects the voltage of the interrupt detection pin of the bluetooth module and determines whether to generate the first interrupt signal or the second interrupt signal, and if so, starts the timer with the timeout period being the preset time; then judging whether the timer is overtime, acquiring the voltage of the current interrupt detection pin when the timer is overtime, and controlling the timer to count again; then controlling the count value of the first counter or the second counter to be increased by one according to the current voltage of the interruption detection pin, judging whether the count value of the current first counter or the current second counter is greater than a preset threshold value, and if so, correspondingly outputting a Bluetooth search detection result according to the count value of the first counter or the second counter; otherwise, whether the timer is overtime or not is continuously judged. When a user uses the Bluetooth function of the mobile terminal, the starting or stopping state of the Bluetooth search is flexibly detected and output by using the timer and the counter, so that the efficiency of searching the Bluetooth equipment can be greatly improved, and the waste of the electric quantity of the terminal due to continuous searching is avoided.
It should be understood that equivalents and modifications of the technical solution and inventive concept thereof may occur to those skilled in the art, and all such modifications and alterations should fall within the scope of the appended claims.