Event measurement method and electronic device

By using ultrasonic algorithms in electronic devices instead of proximity sensors and combining acceleration data to determine the proximity of objects, the problem of proximity sensor detection delay is solved, and a faster and more accurate automatic screen-opening and extinguishing effect is achieved.

CN119562006BActive Publication Date: 2025-06-06HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510126542.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-27
Publication Date
2025-06-06
Estimated Expiration
2045-01-27

AI Technical Summary

Technical Problem

In existing electronic devices, proximity sensors may have delays when detecting objects approaching, affecting the timeliness of automatic screen lighting and extinguishing and user experience.

Method used

An ultrasonic algorithm is used instead of the proximity sensor, and an ultrasonic signal is emitted through the earpiece and the uplink signal is received by the microphone. Combined with the acceleration data, it is determined whether there is an object approaching, so as to achieve faster and more accurate event detection.

Benefits of technology

It improves the response speed and accuracy of electronic devices when detecting objects approaching, reduces the delay of automatically turning on and extinguishing the screen, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119562006B_ABST
    Figure CN119562006B_ABST
Patent Text Reader

Abstract

The present application provides an event measurement method and an electronic device. In this method, in response to an application's request to call a proximity sensor, the electronic device starts a pre-judgment mode in addition to starting the hardware required to implement the ultrasonic proximity judgment function. The ultrasonic algorithm is started only after the pre-judgment mode is started, and an ultrasonic algorithm startup flag is set to indicate whether the ultrasonic algorithm has been started. The startup completion indicates that the ultrasonic algorithm is fully started and the uplink ultrasonic signal can be successfully acquired. Incomplete startup indicates that the ultrasonic algorithm is not fully started and the uplink ultrasonic signal cannot be acquired. The reasons for not being able to acquire include: the hardware such as the earpiece or microphone has not yet completed startup. If the ultrasonic algorithm startup flag indicates that the ultrasonic algorithm has completed startup, the pre-judgment mode is terminated and the ultrasonic algorithm is executed in the non-pre-judgment mode. In the pre-judgment mode, event detection can be completed based only on acceleration data, without relying on ultrasonic signals.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to a usage event measurement method and an electronic device. Background Art

[0002] Automatically sensing whether an object is approaching is an important function of electronic devices. This function can automatically turn the screen on and off to prevent misoperation. For example, when answering a call, when the user's head is close to the electronic device, the electronic device can detect this action and turn off or lock the screen. This can prevent the ear or facial skin from accidentally touching the buttons on the screen and avoid misoperation during the call.

[0003] At this stage, a proximity sensor (also known as a proximity light sensor) can be installed in an electronic device to detect whether there is an object approaching the electronic device. If there is an object approaching the electronic device, the proximity sensor detects a proximity event; if there is no object approaching the electronic device, the proximity sensor detects a distance event. Here, the object approaching the electronic device can usually be the user's head. For example, when talking on a phone, the user brings the electronic device close to his head, and the proximity sensor can detect the proximity event. If the two events detected are different, and the latter is a proximity event, the electronic device turns off the screen. If the two events detected are different, and the latter is a distance event, the electronic screen turns on. If the two events detected are the same, the electronic device keeps the screen on and off. Summary of the invention

[0004] The present application provides an event measurement method and an electronic device for optimizing a process in which an ultrasonic algorithm replaces a proximity sensor to measure an event (approach event or distance event).

[0005] In a first aspect, the present application provides an event measurement method, which is applied to an electronic device that does not have a proximity sensor, or the proximity sensor is unavailable, the method comprising: in response to a request from an application to call the proximity sensor, starting an earpiece, a microphone and starting a pre-judgment mode; performing a pre-judgment operation in the pre-judgment mode, the pre-judgment operation comprising: judging whether the electronic device is accelerating based on first acceleration data, and acquiring a first uplink ultrasonic signal through an ultrasonic algorithm; when the first uplink ultrasonic signal is successfully acquired, judging whether there is an obstruction in front of the screen of the electronic device based on the first uplink ultrasonic signal and the first downlink ultrasonic signal, and modifying an ultrasonic algorithm start flag from a first value to a second value; when the first uplink ultrasonic signal fails to be acquired, the ultrasonic algorithm start flag remains the first value; the first uplink ultrasonic signal is a first downlink ultrasonic signal emitted by the earpiece collected by the microphone The first uplink ultrasonic signal is obtained and transmitted to the first memory, the first memory is the memory used by the ultrasonic algorithm, and the first downlink ultrasonic signal is provided by the ultrasonic algorithm; the first value indicates that the ultrasonic algorithm is not fully started; the pre-judgment operation also includes: feeding back a first event to the application, the first event is used to indicate whether there is an object approaching the electronic device; in the case where the first uplink ultrasonic signal fails to be obtained, the first event is determined based on whether there is acceleration; in the case where the first uplink ultrasonic signal is successfully obtained, the first event is determined based on whether there is acceleration and whether there is occlusion; after the pre-judgment operation is completed, the value of the ultrasonic algorithm start-up flag is determined; when it is determined that the ultrasonic algorithm start-up flag is the second value, the pre-judgment mode is terminated, and the first event is determined by the ultrasonic algorithm based on the second acceleration data, the second downlink ultrasonic signal and the second uplink ultrasonic signal, and the first event is fed back to the application again.

[0006] In the above embodiment, although the proximity sensor of the lower layer is replaced by the ultrasonic proximity judgment function. However, the application that needs to call the proximity sensor does not need to perceive the changes in the lower layer. When the application needs to use the proximity sensor, it can still be called based on the original call request without modifying the call logic of the application. However, this call request is used by the electronic device to start the hardware and software resources of the ultrasonic proximity judgment function, including starting the earpiece, microphone, ultrasonic algorithm and starting the pre-judgment mode. Since the ultrasonic algorithm can only obtain the uplink ultrasonic signal after opening the path between the ultrasonic algorithm and the earpiece and the microphone, this process is affected by the working state of the electronic device. If the electronic device currently has many tasks, this process may be very slow, affecting the first return event. However, the pre-judgment operation performed in the pre-judgment mode does not depend on the uplink ultrasonic signal. If the uplink ultrasonic signal is not obtained when the pre-judgment operation is performed, there is no need to wait to obtain the uplink ultrasonic signal. The event can be measured based only on the acceleration data, and the first event can be returned quickly, increasing the sensitivity of the ultrasonic proximity function to detect events.

[0007] In combination with the first aspect, in some embodiments, the first event is determined by the ultrasonic algorithm based on the second acceleration data, the second downlink ultrasonic signal and the second uplink ultrasonic signal, specifically including: judging whether there is an occlusion in front of the screen of the electronic device based on the second downlink ultrasonic signal and the second uplink ultrasonic signal by the ultrasonic algorithm; if there is no occlusion, determining a moving away event; if there is an occlusion, judging whether the electronic device is accelerated based on the second acceleration data of the ultrasonic algorithm; if there is acceleration, determining an approach event, or, if there is no acceleration, determining a moving away event.

[0008] In the above embodiment, when determining whether there is an occlusion based only on the ultrasonic algorithm to determine whether there is an object approaching the electronic device, the probability of accurate judgment is greater than probability 1. Probability 1 is the probability of accurate judgment when determining whether there is acceleration based only on acceleration data to determine whether there is an object approaching the electronic device. Therefore, if it is determined based on the ultrasonic algorithm that there is no occlusion, the accuracy of determining the distance event is higher. In order to save computing resources, it is possible to first determine whether there is an occlusion through the uplink ultrasonic signal and the downlink ultrasonic signal, and when there is an occlusion, it is further determined based on the acceleration data whether there is acceleration. The presence of an approaching event is determined only when it is determined that there is occlusion and acceleration. When there is no occlusion, the distance event can be directly returned. It is no longer determined whether there is acceleration based on the acceleration data.

[0009] In combination with the first aspect, in some embodiments, the method further includes: when it is determined that the ultrasonic algorithm start flag is still the first value, performing the pre-judgment operation again in the pre-judgment mode.

[0010] In the above embodiment, after a pre-judgment operation, if the ultrasonic algorithm start flag is still the first value, it means that the ultrasonic algorithm cannot be used to detect events. Otherwise, when the ultrasonic algorithm is executed, the uplink ultrasonic signal will be waited for to be returned because the uplink ultrasonic signal is not obtained, resulting in the measurement event time being prolonged. When an object approaches the electronic device, the proximity event cannot be detected in time, and the screen is turned off to prevent misoperation, affecting the user experience.

[0011] In combination with the first aspect, in some embodiments, performing a pre-judgment operation in the pre-judgment mode specifically includes:

[0012] A first thread is created, where the first thread is used to run a first program, where the first program is used to perform the pre-judgment operation; the first thread and a second thread that runs the ultrasonic algorithm are co-processed.

[0013] In the above embodiment, the first thread is the pre-judgment thread involved in the following embodiment, and the second thread is the thread running the ultrasonic algorithm. The first thread and the second thread are co-processed, which can enable the pre-judgment thread to obtain the uplink ultrasonic signal through the ultrasonic algorithm more quickly.

[0014] In combination with the first aspect, in some embodiments, creating a first thread specifically includes: creating the first thread through an ultrasonic framework module; the ultrasonic framework module is also used to start or end the pre-judgment mode; starting the ultrasonic algorithm specifically includes: starting the ultrasonic algorithm through the ultrasonic framework module.

[0015] In the above embodiment, the pre-judgment mode and the ultrasonic algorithm are managed by the ultrasonic framework module, instead of mixing the pre-judgment operation and the ultrasonic algorithm into a program on the same thread. This allows the ultrasonic algorithm to perform related operations for acquiring uplink ultrasonic signals when the pre-judgment operation is performed in the pre-judgment mode.

[0016] In combination with the first aspect, in some embodiments, in response to the application's request to call the proximity sensor, the earpiece and the microphone are started and the pre-judgment mode is started, specifically including: the proximity sensor hardware abstraction module responds to the application's request to call the proximity sensor, notifying the audio hardware abstraction module to start the software and hardware resources required to judge the first event; the audio hardware abstraction module starts the earpiece and the microphone through the first kernel, and sends a start notification to the ultrasound framework module running on the second kernel through the first kernel, and the start notification is used to notify the ultrasound framework module to start the pre-judgment mode.

[0017] In the above embodiment, the request for calling the proximity sensor is transmitted to the proximity sensor hardware abstraction layer and converted into an instruction for starting the ultrasonic pre-judgment function (an instruction for notifying the audio hardware abstraction module to start the software and hardware resources required for judging the first event). In this way, the sensor hardware abstraction layer is at a lower level in the system architecture, and the modules applied to the proximity sensor hardware abstraction layer do not need to be adapted or modified, thereby reducing the modules that need to adjust the logic.

[0018] In combination with the first aspect, in some embodiments, the first program, the ultrasonic algorithm and the acceleration sensor driver all run on the second core; the acceleration sensor driver is used to obtain acceleration data from the acceleration sensor and transmit it to the first thread where the first program is located and the second thread where the ultrasonic algorithm is located; the acceleration data includes at least the first acceleration data and the second acceleration data.

[0019] In the above embodiment, the first kernel may include the Linux kernel in the following embodiment, and the second kernel may include the SCP kernel involved in the following embodiment. The first program is the pre-judgment program involved in the following embodiment. The ultrasonic algorithm, the pre-judgment program and the acceleration sensor driver are placed in the same kernel, so that it is convenient for the pre-judgment thread and the thread running the ultrasonic algorithm to subscribe to the acceleration data from the acceleration sensor driver. The ultrasonic judgment module and the ultrasonic framework module are also placed in the same kernel, which is convenient for the ultrasonic framework module and the ultrasonic judgment module (including the ultrasonic algorithm and the pre-judgment program) to transmit data, transmit commands and share data. Because after the ultrasonic judgment proximity program is started, the event will be detected according to the frequency cycle, which is relatively power-consuming. The ultrasonic framework module, the ultrasonic judgment module and the acceleration sensor are independent of the Linux kernel of the main processor and placed on the kernel of the auxiliary processor (also called the SCP kernel), which can reduce the burden of the main processor during operation, improve the performance of the electronic device, and also facilitate management.

[0020] In combination with the first aspect, in some embodiments, the startup notification is also used to notify the ultrasonic framework module to create a first buffer area and a second buffer area, and to start the ultrasonic algorithm after the creation. The method also includes: after starting the ultrasonic algorithm, sending the downlink ultrasonic signal to the ultrasonic framework module through the ultrasonic algorithm; the ultrasonic framework module caches the downlink ultrasonic signal to the first buffer area; the ultrasonic framework module transmits the downlink ultrasonic signal in the first buffer area to the audio codec, the audio codec is used to send a downlink audio signal to the earpiece, the downlink audio signal at least includes the downlink ultrasonic signal, the audio codec is also used to receive an uplink audio signal collected by the microphone, the uplink audio signal at least includes the uplink ultrasonic signal; the software and hardware resources include the audio codec, and the audio codec is obtained through the first The kernel is started; the ultrasonic framework module caches the uplink audio signal transmitted by the audio codec to the second buffer area; the ultrasonic framework module transmits the uplink audio signal in the second buffer area to the second thread where the ultrasonic algorithm is located; the uplink audio signal is used to parse the uplink ultrasonic signal through the ultrasonic algorithm; the downlink ultrasonic signal includes the first downlink ultrasonic signal and the second downlink ultrasonic signal, and the uplink audio signal includes at least the first uplink audio signal and the second uplink audio signal; the earpiece transmits the first downlink ultrasonic signal for the microphone to obtain the first uplink audio signal, and the first uplink audio signal is used to parse the first uplink ultrasonic signal, the earpiece transmits the second downlink ultrasonic signal for the microphone to obtain the second uplink audio signal, and the second uplink audio signal is used to parse the second uplink ultrasonic signal.

[0021] In the above embodiment, the first buffer area and the second buffer area can be respectively the downlink buffer area and the uplink buffer area involved in the following embodiment. Setting the buffer area can avoid data loss caused by inconsistent speed when the ultrasonic frame module sends and receives audio signals.

[0022] In combination with the first aspect, in some embodiments, before responding to the request of the application to call the proximity sensor, the method further includes:

[0023] In response to a first operation, the application sends a request to call the proximity sensor; the first operation includes at least one of the following: an operation on a dialing control, an operation on an answering control, and an operation on a voice playing control.

[0024] In the above embodiment, the operation on the dialing control and the operation on the answering control indicate that the use scenario of the ultrasonic proximity judgment function includes the call scenario. The operation on the voice playing control indicates that the use scenario of the ultrasonic proximity judgment function includes the voice playing scenario.

[0025] In combination with the first aspect, in some embodiments, after the first event is fed back to the application, the method further includes: when the fed back first event is an approach event, the electronic device turns off the screen; when the fed back first event is a distance event, the electronic device turns on the screen.

[0026] In the above embodiment, the ultrasonic proximity function detection event can be used to realize the automatic screen on and off of the electronic device. When an object approaches the electronic device, the screen is turned off to avoid accidental touches. When no object approaches the electronic device, it may be that the user needs to use the electronic device, so the screen is turned on.

[0027] In a second aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the electronic device to execute the method implemented in the first aspect.

[0028] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, comprising instructions, which, when executed on an electronic device, enable the electronic device to execute the method implemented in the first aspect.

[0029] In a fourth aspect, an embodiment of the present application provides a chip system, which is applied to an electronic device. The chip system includes one or more processors, and the processor is used to call computer instructions so that the electronic device executes the method implemented in the first aspect.

[0030] In a fifth aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on an electronic device, enables the electronic device to execute the method implemented in the first aspect.

[0031] It is understandable that the electronic device provided in the second aspect, the computer storage medium provided in the third aspect, the chip system provided in the fourth aspect, and the computer program product provided in the fifth aspect are all used to execute the method provided in the embodiment of the present application. Therefore, other beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 An exemplary scenario in which an ultrasonic proximity determination function replaces a proximity sensor is shown;

[0033] Figure 2 An exemplary system architecture diagram involved in implementing an ultrasonic proximity determination function in an embodiment is shown;

[0034] Figure 3 An exemplary module interaction diagram involved in implementing an ultrasonic proximity determination function in an embodiment is shown;

[0035] Figure 4 A schematic diagram comparing the activation of the ultrasonic proximity judgment function and the proximity sensor is shown;

[0036] Figure 5 An exemplary system architecture diagram involved in implementing an ultrasonic proximity determination function in an embodiment is shown;

[0037] Figure 6 An exemplary module interaction diagram involved in implementing the ultrasonic proximity judgment function in another embodiment is shown;

[0038] Figure 7 An exemplary flow chart involved in implementing the pre-judgment mode in another embodiment is shown;

[0039] Figure 8 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0040] In one solution, in order to simplify the hardware design of the electronic device, save internal space, and free up more space for other components, the electronic device may not deploy a proximity sensor, but use an ultrasonic proximity judgment function instead of the proximity sensor to measure approach events or distance events.

[0041] The software and hardware resources involved in implementing the ultrasonic proximity judgment function include but are not limited to: ultrasonic proximity judgment program (software), earpiece (hardware), and microphone (hardware).

[0042] like Figure 1 As shown, in the process of realizing the ultrasonic proximity judgment function, the earpiece is used to transmit an ultrasonic signal (also called a downlink ultrasonic signal), and the microphone is used to receive a returned ultrasonic signal (also called an uplink ultrasonic signal). The ultrasonic proximity judgment program may include an ultrasonic algorithm, and the electronic device can use the ultrasonic algorithm to analyze the downlink ultrasonic signal and the uplink ultrasonic signal to determine the distance between the electronic device and the object. If the distance is less than the preset distance, the ultrasonic algorithm is used to determine that there is an obstruction in front of the electronic device screen. If the distance is greater than or equal to the preset distance, the ultrasonic algorithm is used to determine that there is no obstruction in front of the electronic device screen. If there is an obstruction, the electronic device can determine that there is a proximity event through the ultrasonic algorithm. If there is no obstruction, the electronic device can determine that there is a distance event through the ultrasonic algorithm.

[0043] After the ultrasonic proximity judgment function is activated, if the two detected events are different and the latter is a proximity event, the electronic device turns off the screen. If the two detected events are different and the latter is a distance event, the electronic screen turns on. If the two detected events are the same, the electronic device keeps the screen on and off. After the ultrasonic proximity judgment function is activated, if the first detected event is a proximity event, the electronic device turns off the screen; if the first detected event is a distance event, the electronic device turns on the screen.

[0044] Continue to refer Figure 1 In order to make the measured uplink ultrasonic signal more accurate, the microphone needs to be set on the same side of the electronic device together with the earpiece. For example, both are set on the top of the electronic device. If the electronic device has multiple microphones, the microphone on the same side as the earpiece can also be called a secondary microphone. The secondary microphone is usually not on the same side as the main microphone. For example, the secondary microphone is on the top and the main microphone is on the bottom.

[0045] In order to enable the ultrasonic proximity judgment function to provide a higher accuracy when in use, the hardware resources involved in realizing the ultrasonic proximity judgment function may include an accelerometer in addition to the earpiece and microphone. The accelerometer can be used to provide acceleration data to the ultrasonic algorithm. After the electronic device determines that there is an obstruction in front of the electronic device screen through the ultrasonic algorithm, it can further determine whether the electronic device is accelerated through the acceleration data. If there is an obstruction and acceleration, the electronic device can determine the existence of an approaching event through the ultrasonic algorithm. If there is an obstruction but no acceleration, the electronic device can determine the existence of a moving away event through the ultrasonic algorithm. If there is no obstruction, the electronic device can determine the existence of a moving away event through the ultrasonic algorithm.

[0046] In some possible cases, in order to save power consumption, the electronic device can enable the ultrasonic proximity judgment function in a preset scenario. The preset scenario may include a communication scenario such as a voice playback scenario and a call scenario. In addition, it may also include a scenario where the screen is locked but not turned off. This embodiment of the application is not limited to this.

[0047] In the voice playback scenario or call scenario, if only one earpiece is turned on, in addition to the ultrasonic proximity judgment program, earpiece, microphone, and acceleration sensor, an audio encoder may also be included. The audio encoder is used to mix the downlink communication signal and the downlink ultrasonic signal, and then transmit them to the earpiece for transmission. In this way, the downlink communication signal transmitted by the earpiece can be heard by the user, and at the same time, the downlink ultrasonic signal transmitted by the earpiece can be used by the microphone to collect the uplink ultrasonic signal, thereby realizing the ultrasonic proximity judgment function.

[0048] It should be noted here that after the ultrasonic proximity judgment function is turned on, the conditions for ending the ultrasonic proximity judgment function include but are not limited to: ending the preset scene, when the preset scene is a communication scene, stop using the handset, and use the speaker to play the downlink communication signal. Because when the user uses the speaker to make a call or play voice, the electronic device is usually not attached to the head but kept at a distance. This means that even if there is a proximity event, no false touch will occur, and there is no need to turn on the ultrasonic proximity judgment function.

[0049] Figure 2 An exemplary system architecture involved in implementing the ultrasonic proximity determination function in one embodiment is shown.

[0050] The system architecture is divided into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the system architecture is divided into five layers, from top to bottom, namely, the application layer, the application framework layer, the hardware abstraction layer (HAL), the kernel layer, and the hardware layer.

[0051] like Figure 2 As shown, the application layer may include a series of application packages, such as communication applications, common communication applications may include call applications, social applications, etc.

[0052] The application framework provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. Electronic devices can build rich application functions through these APIs without directly interacting with the underlying architecture of the system.

[0053] The application framework layer may include a proximity sensor framework (referred to as sensor FWK). In addition, other frameworks may also be included, such as an audio framework, Figure 2 Not shown.

[0054] The hardware abstraction layer is an interface layer located between the operating system kernel layer and other layers of the electronic device (such as the application framework layer). Its purpose is to abstract the hardware and provide a virtual hardware platform for the operating system.

[0055] The hardware abstraction layer may include an audio hardware abstraction module (referred to as audio HAL) and a proximity sensor hardware abstraction module (referred to as sensor HAL).

[0056] The kernel layer is the layer between hardware and software, which can serve as a bridge for communication between software and hardware.

[0057] The kernel layer may include at least one kernel, such as a Linux kernel and a single chip package (SCP) kernel (SCP kernel for short). One kernel may communicate with another kernel through an inter-processor interrupt (IPI) mechanism.

[0058] The SCP kernel may include the aforementioned ultrasonic proximity judgment program. In this embodiment, the ultrasonic proximity judgment program may include an ultrasonic framework module and an ultrasonic algorithm. The SCP kernel may also include an acceleration sensor driver.

[0059] The hardware layer may include the aforementioned earpiece, microphone, audio codec, modem, and accelerometer.

[0060] Each level cooperates with each other to complete the ultrasonic proximity judgment function involved in the scheme. The description of this process can refer to the following content.

[0061] See Figure 2 As shown in (1), the communication application subscribes to the proximity sensor and sends a request to call the proximity sensor (referred to as a call request) to the sensor HAL through the sensor FWK.

[0062] See Figure 2 As shown in (2), the sensor FWK calls the proximity sensor start interface to send a call request to the sensor HAL to notify the sensor HAL to start the proximity sensor.

[0063] See Figure 2As shown in (3), in response to the call request, the sensor HAL calls the ultrasonic proximity interface to notify the audio HAL to start the ultrasonic proximity judgment function. It can also be understood as notifying the audio HAL to start the software and hardware resources required to judge the proximity event.

[0064] See Figure 2 As shown in (4), the audio HAL starts the software and hardware resources required for the ultrasonic proximity detection function through the Linux kernel. This process includes: Figure 2 (4a) and Figure 2 At (4b), the audio HAL starts the microphone, earpiece, and audio codec through the Linux kernel. Figure 2 At (5), the audio HAL notifies the ultrasonic framework module through the Linux kernel to start the ultrasonic proximity judgment program. Here, the Linux kernel can notify the ultrasonic framework module to start the ultrasonic proximity judgment program through the IPI mechanism.

[0065] See Figure 2 As shown in (6), after receiving the notification of starting the ultrasonic proximity judgment program, the ultrasonic framework module creates two buffers, including an uplink buffer and a downlink buffer. The uplink buffer can be used to cache the uplink ultrasonic signal collected by the microphone, and the downlink buffer can be used to cache the downlink ultrasonic signal sent to the earpiece.

[0066] See Figure 2 As shown in (7), the ultrasonic framework module starts the ultrasonic algorithm. After the ultrasonic algorithm is started, the following operations can be performed: sending a downlink ultrasonic signal and retrieving an uplink ultrasonic signal (operation 1), obtaining acceleration data (operation 2), judging an event (approaching event or moving away event) based on acceleration data, downlink ultrasonic signals and uplink ultrasonic signals, and feeding back approaching events or moving away events (operation 3). Operations 1 to 3 are executed in a loop. After operation 3 is completed, operation 1 is executed, and then operations 2 and 3 are executed until the ultrasonic approach judgment function is terminated. This means that the ultrasonic algorithm will send downlink ultrasonic signals multiple times and retrieving uplink ultrasonic signals multiple times, and obtain acceleration data multiple times. After each retrieving of the uplink ultrasonic signal and obtaining acceleration data, an event can be determined. For a description of operations 1 to 3, please refer to the following content.

[0067] Among them, operation 1 see Figure 2At (7a), (8) and (9), the ultrasonic algorithm sends the downlink ultrasonic signal to the ultrasonic framework module. The ultrasonic framework module caches the received downlink ultrasonic signal in the downlink buffer area. Then, the downlink ultrasonic signal is obtained from the downlink buffer area and sent to the audio codec, and the audio codec can send the downlink ultrasonic signal to the earpiece. When there is a modem (Modem) transmitting the downlink communication signal to the audio codec, the audio codec can also mix the downlink communication signal and the ultrasonic signal and send it to the earpiece. Therefore, the downlink audio signal sent by the audio codec to the earpiece includes at least the downlink ultrasonic signal. The earpiece receives the downlink audio signal and sends the downlink audio signal. Subsequently, the microphone collects the uplink audio signal, which includes at least the uplink ultrasonic signal and may also include the uplink communication signal. The microphone transmits the uplink audio signal to the audio codec, and the audio codec can transmit the uplink audio signal to the ultrasonic framework module. The ultrasonic framework module caches the uplink audio signal in the uplink buffer area. Subsequently, the uplink audio signal is obtained from the uplink buffer area and transmitted to the ultrasonic algorithm.

[0068] It should be noted that when the audio codec mixes the downlink communication signal and the downlink ultrasonic signal, it needs to perform an anti-clipping operation to ensure the quality of the mixed audio. The anti-clipping operation includes but is not limited to gain adjustment and filtering of the audio signal.

[0069] The purpose of setting the uplink buffer area and the downlink buffer area here is to prevent the audio signal (such as the uplink audio signal or the downlink ultrasonic signal) from being lost due to inconsistent sending and receiving speeds of the ultrasonic frame module, thereby causing errors.

[0070] Operation 2 Figure 2 At (7b), the ultrasonic algorithm subscribes to the acceleration data from the acceleration sensor driver. This means that the ultrasonic algorithm can obtain the acceleration data collected by the acceleration sensor through the acceleration sensor driver.

[0071] Operation 3 Figure 2At (10), the ultrasonic algorithm parses the uplink ultrasonic signal from the uplink audio signal, and then the ultrasonic algorithm determines whether there is an approach event based on the acceleration data and the uplink and downlink ultrasonic signals. If there is an approach event, the approach event is reported, otherwise the distance event is reported. Among them, the uplink ultrasonic signal includes the downlink ultrasonic signal and the uplink ultrasonic signal, and the uplink ultrasonic signal (referred to as the uplink ultrasonic signal a) and the downlink ultrasonic signal (referred to as the downlink ultrasonic signal a) used to determine an event and the acceleration data (recorded as acceleration data a) are corresponding. The correspondence here includes: the uplink ultrasonic signal a used to determine an event is obtained by collecting the downlink ultrasonic signal a emitted by the earpiece through the microphone. The timestamp of the earpiece collecting the uplink ultrasonic signal a (carried in the uplink ultrasonic signal a) and the timestamp of the acceleration sensor collecting the acceleration data a (carried in the acceleration data a) are the same. This means that the uplink ultrasonic signal a and the acceleration data a indicate whether there is an object approaching the electronic device at the same time.

[0072] It should be noted here that it is optional for the audio codec to transmit the uplink audio signal to the ultrasonic framework module. In actual situations, the audio codec can separate the uplink ultrasonic signal from the uplink audio signal and then transmit it to the ultrasonic framework module. Subsequently, the ultrasonic framework module transmits the uplink ultrasonic signal to the ultrasonic algorithm. In a call scenario, Figure 2 The uplink audio signal involved in the above may include an uplink communication signal. The uplink communication signal includes an audible audio signal. For example, human voice, environmental sound, etc. At this time, the audio codec may also separate the uplink communication signal from the uplink audio signal, and then transmit it to the modem, and then transmit it to other electronic devices through the modem. In the voice playback scenario, the uplink audio signal may not be included.

[0073] Above Figure 2 The downlink communication signals involved in the communication may exist in communication scenarios such as call scenarios and voice playback scenarios. The downlink communication signals include audio signals sent by other electronic devices received by the modem.

[0074] It should also be noted that Figure 2 The audio codec involved is optional. In non-communication scenarios, the uplink ultrasonic signal and the downlink ultrasonic signal can be sent and received directly between the ultrasonic framework module and the earpiece and microphone.

[0075] Figure 3 An exemplary module interaction diagram involved in implementing an ultrasonic proximity determination function in one embodiment is shown.

[0076] Figure 3 In this example, an approach event is detected in a communication scenario such as a call scenario or a voice playback scenario. For details about detecting a distance event and detecting an event again, please refer to Figure 3 The process of detecting a proximity event can refer to the following steps S11 to S20.

[0077] S11. The communication application calls the proximity sensor.

[0078] In response to operation 1, the communication application sends a request to call the proximity sensor (the aforementioned Figure 2 The operation 1 includes but is not limited to at least one of the following: an operation on a dialing control, an operation on an answering control, and an operation on a voice playing control.

[0079] The call request is transmitted to the sensor HAL through the sensor FWK. For the specific transmission process, please refer to the above Figure 2 (1) and Figure 2 The content involved in (2)

[0080] S12. The sensor HAL determines that an ultrasonic proximity judgment event is used, and sends a message to the audio HAL to start the ultrasonic proximity judgment function.

[0081] When it is determined that there is no proximity sensor in the electronic device or that the proximity sensor exists but is unavailable (for example, damaged), the sensor HAL determines to use ultrasound to determine the proximity event and sends a message to the audio HAL to start the ultrasound proximity determination function. Figure 2 The content shown in (3) in the figure.

[0082] It should be noted here that if there is an available proximity sensor in the electronic device, after S11, the sensor HAL does not execute S12, but instead notifies the Linux kernel to start the proximity sensor (located at the hardware layer), specifically notifying the proximity sensor driver in the Linux kernel to start the proximity sensor. Subsequently, the proximity sensor starts and detects events (approach events or distance events). Then, the detected events are fed back to the communication application.

[0083] S13. The audio HAL starts the software and hardware resources required for the ultrasonic proximity judgment function through the Linux kernel. The process of starting the hardware resources can refer to the following step S14a, and the process of starting the software resources can refer to the following step S14b.

[0084] S14a. The audio HAL calls the Linux kernel to start the microphone, earpiece, and audio codec.

[0085] The Linux kernel has hardware drivers that can be used to implement the interaction between various hardware and upper-layer software. For example, it includes a microphone driver that can be used to start the microphone, a receiver driver that can be used to start the receiver, and an audio codec driver that is used to start the audio codec.

[0086] S14b. The audio HAL calls the Linux kernel to notify the ultrasonic framework module to start the ultrasonic proximity judgment program.

[0087] After receiving the notification of starting the ultrasound proximity determination program, the ultrasound framework module executes the following steps S15 and S16.

[0088] S15. The ultrasound framework module creates an uplink buffer area and a downlink buffer area.

[0089] The downlink buffer area is used to buffer the downlink ultrasonic signal sent to the ultrasonic framework module by the subsequent ultrasonic algorithm. The uplink buffer area can be used to buffer the uplink audio signal (at least including the uplink ultrasonic signal) collected by the subsequent microphone.

[0090] For more information about the uplink buffer area and the downlink buffer area, please refer to the above Figure 2 The description of the relevant contents shown in (6) will not be repeated here.

[0091] S16. The ultrasound framework module starts the ultrasound algorithm.

[0092] Starting the ultrasound algorithm means that the ultrasound framework module creates a thread for running the ultrasound algorithm, and executes the logical steps in the ultrasound algorithm through the thread to implement event detection (including the aforementioned operations 1 to 3) through the ultrasound algorithm.

[0093] Operations 1 to 3 performed by the ultrasonic algorithm mentioned in the embodiment of the present application are actually performed by the thread where the ultrasonic algorithm is located. Just for the convenience of description, they are referred to as performed by the ultrasonic algorithm.

[0094] After the ultrasound algorithm is started, the following steps S17a and S17b are executed.

[0095] S17a. The ultrasonic algorithm sends a downlink ultrasonic signal to the ultrasonic framework module.

[0096] S17b. The ultrasonic algorithm drives the acceleration sensor to subscribe to acceleration data.

[0097] S17b is the aforementioned operation 2. S17a belongs to the aforementioned operation 1, which is to retrieve the uplink audio signal. Since the execution of operation 1 is more time-consuming than operation 2, in some embodiments, step S17a may be executed first, and then step S17b.

[0098] After S17a, the ultrasound algorithm continues to execute the remaining steps in operation 1. See step S18 described below.

[0099] S18. Obtain an uplink audio signal based on the downlink ultrasonic signal, the audio codec, the earpiece and the microphone, and buffer the uplink audio signal in an uplink buffer area.

[0100] The ultrasonic framework module obtains the downlink ultrasonic signal from the downlink buffer area and sends it to the audio codec, which transmits the downlink ultrasonic signal to the handset. After the handset plays, the microphone collects the sound signal, obtains the uplink audio signal (at least including the uplink ultrasonic signal), and returns it to the audio codec. Then, the audio codec transmits the uplink audio signal to the ultrasonic framework module. The ultrasonic framework module caches the uplink audio signal in the uplink buffer area.

[0101] The contents of step S18 can refer to the above Figure 2 In (8) and Figure 2 The contents shown in (9) will not be repeated here.

[0102] Subsequently, the ultrasonic framework module obtains the uplink audio signal from the uplink buffer area and transmits it to the ultrasonic algorithm, so that the ultrasonic algorithm performs operation 3, see the following step S19.

[0103] S19. The ultrasonic algorithm obtains an uplink ultrasonic signal from the uplink audio signal, and determines whether there is a proximity event based on the acceleration data and the uplink and downlink ultrasonic signals.

[0104] S20. If it is determined that there is a proximity event, return the proximity event to the communication application. If the communication application previously received a distance event, or the proximity event received in step S20 is the first proximity event received after the call request is issued, then in response to the proximity event, the communication application initiates a screen-off operation.

[0105] It should be noted that steps S17a, S17b, S18, S19 and S20 are executed cyclically after the ultrasonic proximity function is activated. Approach events or distance events can be returned to the communication application one by one. There is no order of execution of the aforementioned steps S14a and S14b.

[0106] It should also be noted that the ultrasonic algorithm and the accelerometer driver are placed in the same kernel, so that the ultrasonic algorithm can subscribe to the acceleration data from the accelerometer driver. The ultrasonic algorithm and the ultrasonic framework module should also be placed in the same kernel to facilitate data transmission and sharing between the ultrasonic framework module and the ultrasonic algorithm. Because after the ultrasonic proximity judgment program is started, events will be detected in a frequency cycle, which is relatively power-consuming. Placing the ultrasonic framework module, ultrasonic algorithm, and accelerometer independently from the Linux kernel of the main processor on the kernel of the auxiliary processor (also called the SCP kernel) can reduce the burden of the main processor during operation, improve the performance of the electronic equipment, and also facilitate management.

[0107] Although the above scheme can use the ultrasonic proximity judgment function instead of the proximity sensor to measure approach events or distance events. However, the ultrasonic proximity judgment function needs to start the software and hardware resources to obtain the uplink audio signal before it can start to judge whether there is a proximity event. This results in a longer time (recorded as time 1) from starting the ultrasonic proximity judgment function to the first detection of the event. This means that before the first event is detected, if there is an object close to the electronic device (for example, the user puts the electronic device against the ear), the proximity event may not be detected, resulting in the electronic device not being able to turn off the screen in time when the object approaches to prevent accidental touches.

[0108] like Figure 4 As shown in (1), if there is an available proximity sensor in the electronic device, after the application (such as a communication application) issues a call request, the call request is transmitted through the software layer to the sensor HAL, and then the proximity sensor at the hardware layer can be started. This process is simple and fast, usually less than 40ms. This means that the electronic device starts the proximity sensor very quickly, and there will be no problem of not being able to detect the first proximity event.

[0109] And reference Figure 4 As shown in (2), when the ultrasonic proximity judgment function is used instead of the proximity sensor measurement event, after the application (such as a communication application) issues a call request, the call request is transmitted through the software layer to the sensor HAL, and then becomes the hardware resources (such as microphones and earpieces) and software resources (such as ultrasonic algorithms) involved in starting the ultrasonic judgment function. After the ultrasonic algorithm and the earpiece are both started, the earpiece can obtain the downlink ultrasonic signal and then transmit the downlink ultrasonic signal. Subsequently, the microphone needs to collect the uplink ultrasonic signal and return it to the ultrasonic algorithm. This process requires a lot of hardware and software resources to be enabled and is relatively time-consuming. In addition, it still takes time to determine whether there is a proximity event based on acceleration data and uplink and downlink ultrasonic signals.

[0110] It can be seen that the time required from starting the ultrasonic proximity function to the first detection of an event (recorded as time 1) is greatly affected by the speed at which software and hardware resources are turned on. If the electronic device has other tasks at this time, the speed at which the electronic device turns on resources such as the microphone, earpiece, and ultrasonic algorithm will be slower, which can be as long as 600ms-1200ms. After the ultrasonic proximity function is activated, if an object approaches the electronic device within 600ms-1200ms (for example, the user puts the electronic device against his ear), the event cannot be returned. It will take 600ms-1200ms to detect the proximity event, and then turn off the screen, which will reduce the user experience.

[0111] In order to reduce the aforementioned time 1 (the time required from starting the ultrasonic proximity judgment function to detecting an event for the first time), so that the ultrasonic proximity judgment function can be more sensitive, an event detection method is proposed here. In this method, compared with the aforementioned solution, a pre-judgment program is added to the software resources for realizing the ultrasonic proximity judgment function. The pre-judgment program is executed in the pre-judgment mode, and the aforementioned ultrasonic algorithm is executed in the non-pre-judgment mode.

[0112] In response to an application (such as the aforementioned communication application) calling a proximity sensor request, the electronic device will start the pre-judgment mode in addition to starting the hardware required to implement the ultrasonic proximity judgment function (including at least the earpiece and the microphone). The ultrasonic algorithm is started only after the pre-judgment mode is started, and an ultrasonic algorithm startup flag is set to indicate whether the ultrasonic algorithm has been started. The startup completion indicates that the ultrasonic algorithm is fully started and the uplink ultrasonic signal can be successfully acquired. Incomplete startup indicates that the ultrasonic algorithm is not fully started and the uplink ultrasonic signal cannot be acquired. The reasons for not being able to acquire include: the hardware such as the earpiece or the microphone has not yet completed startup. If the ultrasonic algorithm startup flag indicates that the ultrasonic algorithm has completed startup, the pre-judgment mode is terminated and the ultrasonic algorithm is executed in the non-pre-judgment mode.

[0113] In the pre-judgment mode, the electronic device can perform a pre-judgment operation, which includes: judging whether the electronic device is accelerated based on the acceleration data 1, and obtaining the uplink ultrasonic signal 1 through the ultrasonic algorithm. In the case where the uplink ultrasonic signal 1 is successfully obtained, it is judged whether there is an obstruction in front of the electronic device screen based on the uplink ultrasonic signal 1 and the downlink ultrasonic signal 1, and the ultrasonic algorithm start flag is changed from 0 to 1; in the case where the uplink ultrasonic signal 1 fails to be obtained, the ultrasonic algorithm start flag is still 0. The uplink ultrasonic signal is obtained by collecting the downlink ultrasonic signal 1 emitted by the earpiece through the microphone and transmitted to the memory 1. The memory 1 is the memory used by the ultrasonic algorithm, and the downlink ultrasonic signal 1 is provided by the ultrasonic algorithm. The ultrasonic algorithm start flag is 0, indicating that the ultrasonic algorithm is not fully started. The ultrasonic algorithm start flag is 1, indicating that the ultrasonic algorithm has been started. The value of the ultrasonic algorithm start flag is indicated by 0 and 1 for example. In fact, other values ​​can also be used, for example, false (the same effect as 0) and true (the same effect as 1). The embodiment of the present application is not limited to this.

[0114] The pre-judgment operation also includes: feeding back an event (a moving away event or a moving approach event) to the application, where the event is used to indicate whether an object is approaching the electronic device. In the case where the uplink ultrasonic signal 1 fails to be acquired, the event is determined based on whether there is acceleration. In the case where the uplink ultrasonic signal 1 is successfully acquired, the event is determined based on whether there is acceleration and whether there is occlusion.

[0115] After the pre-judgment operation is completed, the value of the ultrasonic algorithm start flag is determined.

[0116] When it is determined that the ultrasonic algorithm startup flag is 1, the pre-judgment mode is terminated, and an event is determined by the ultrasonic algorithm based on the acceleration data 2, the downlink ultrasonic signal 2, and the uplink ultrasonic signal 2, and the event is fed back to the application again. When it is determined that the ultrasonic algorithm startup flag is still 0, the pre-judgment operation is performed again in the pre-judgment mode.

[0117] In this way, for the case where the uplink ultrasonic signal is acquired slowly for the first time, by performing a pre-judgment operation, the electronic device can determine whether there is a proximity event based only on the acceleration data, and then return to the first detected event after the ultrasonic proximity judgment function is turned on. For the case where the uplink ultrasonic signal is acquired quickly for the first time, by performing a pre-judgment operation, the electronic device can still determine whether there is a proximity event based on the acceleration data and the uplink and downlink audio signals.

[0118] Since the acceleration sensor is usually in the start-up state after the electronic device is turned on, the acceleration data can be obtained quickly. Therefore, even if the uplink ultrasonic signal is not obtained, it is possible to quickly measure whether there is a proximity event based on the acceleration data in the pre-judgment mode, which can effectively shorten the time 1 involved above (the time required from starting the ultrasonic proximity judgment function to the first detection of the event).

[0119] It should be noted that starting the ultrasonic algorithm means creating a thread for executing the ultrasonic algorithm. The ultrasonic algorithm can run and transmit the downlink ultrasonic signal to the receiver, but it does not mean that the ultrasonic algorithm can successfully obtain the uplink ultrasonic signal. Because successfully obtaining the uplink ultrasonic signal requires not only starting the ultrasonic algorithm, but also considering whether the resources used to obtain the uplink ultrasonic signal, such as the microphone and receiver, can normally return the uplink ultrasonic signal to the ultrasonic algorithm.

[0120] Figure 5 An exemplary system architecture involved in implementing the ultrasonic proximity determination function involved in the event detection method is shown.

[0121] Figure 5 The system architecture described in Figure 2 The system architecture involved is similar to that of Figure 5 The SCP core shown includes not only an ultrasonic framework module, an ultrasonic algorithm, and an acceleration sensor driver, but also a pre-judgment program. The pre-judgment program and the ultrasonic algorithm are collectively referred to as an ultrasonic judgment module.

[0122] Figure 5 The functions and positions of the various levels shown in Figure 2 Similarly, please refer to the above Figure 2 The description of the relevant contents will not be repeated here.

[0123] Each level cooperates with each other to complete the event measurement method involved in the embodiment of the present application and realize the ultrasonic proximity judgment function. The description of this process can refer to the following content.

[0124] See Figure 5 Middle (1) - Figure 5 Medium (5) Figure 5 Medium (4a) and Figure 5 As shown in (4b), the communication application sends a request (call request) to call the proximity sensor to the sensor HAL through the sensor FWK to subscribe to the proximity sensor. In response to the call request, the sensor HAL notifies the audio HAL to start the software and hardware resources required to determine the event. After receiving the notification, the audio HAL starts the earpiece and microphone through the Linux kernel, and starts the audio codec, and sends a startup notification to the ultrasound framework module running on the SCP kernel through the Linux kernel to notify the ultrasound framework module to start the ultrasound proximity determination program.

[0125] Figure 5 Middle (1) - Figure 5 Medium (5) Figure 5 Medium (4a) and Figure 5 The contents shown in (4b) are respectively the same as those in the above Figure 2 Middle (1) - Figure 2 Medium (5) Figure 2 Medium (4a) and Figure 2 The content shown in (4b) is the same as that shown in (4b), and you can refer to the aforementioned related content, which will not be repeated here.

[0126] The ultrasonic framework module starts the ultrasonic approach judgment procedure, including: Figure 5 In (6), after receiving the start notification, the ultrasound framework module starts the pre-judgment mode, and see Figure 5 (7) and Figure 5 As shown in (8), after receiving the start notification, the ultrasound framework module also creates an uplink buffer area and a downlink buffer area, and then the ultrasound framework module also starts the ultrasound algorithm. Figure 5 (6) and Figure 5 The execution order of the steps shown in (7) takes precedence over Figure 5 The steps shown in (8) in . Figure 5 (6) and Figure 5 There is no particular order in which the steps (7) are executed. Figure 5 Step (6) in the above code, and then execute Figure 5 By following the steps shown in step (7) in the figure, you can enter the pre-judgment mode as quickly as possible and return the event.

[0127] See Figure 5At (6), after receiving the start notification, the ultrasound framework module starts the pre-judgment mode. The process includes: the ultrasound framework module creates a pre-judgment thread and executes a pre-judgment program. The pre-judgment program is used to implement the pre-judgment operation involved in the above. After the pre-judgment thread is created, Figure 5 At (6a), the pre-judgment thread subscribes to the acceleration data through the acceleration sensor to obtain the acceleration data. After obtaining the acceleration data, see Figure 5 At (6b), the pre-judgment thread determines whether there is a proximity event based on the acceleration data. The pre-judgment thread also obtains an uplink ultrasonic signal from the ultrasonic algorithm. If an uplink ultrasonic signal is obtained, it determines whether there is a proximity event based on the acceleration data, including: determining whether there is a proximity event based on the acceleration data combined with the uplink ultrasonic signal. If the uplink ultrasonic signal is not obtained, it determines whether there is a proximity event based on the acceleration data, including: determining whether there is a proximity event based only on the acceleration data. After determining the event, the pre-judgment thread returns the event to the communication application. After returning the event, the pre-judgment thread ends.

[0128] It should be noted here that the aforementioned Figure 5 (6a) and Figure 5 The steps shown in (6b) and Figure 5 Middle (7) - Figure 5 In (10), including Figure 5 The execution order of the steps in (8a) is not fixed and is affected by the operating status of the electronic device.

[0129] See Figure 5 Middle (7) - Figure 5 (5) and Figure 5 At (8a), the ultrasonic framework module creates an uplink buffer area and a downlink buffer area. After the buffer area is created, the ultrasonic algorithm is started, including: creating a thread for running the ultrasonic algorithm, and executing the logic in the ultrasonic algorithm (including the aforementioned operations 1-3) through the thread. After starting the ultrasonic algorithm, the ultrasonic algorithm can send a downlink ultrasonic signal to the ultrasonic framework module (cached in the downlink buffer area). Subsequently, the downlink ultrasonic signal is processed by the audio codec (which may include mixing with the downlink communication signal) to obtain a downlink audio signal (at least including the downlink ultrasonic signal). The downlink audio signal is then transmitted to the earpiece. After the earpiece transmits the downlink audio signal, the microphone can collect the uplink audio signal (at least including the uplink ultrasonic signal, and may also include the uplink communication signal). The uplink audio signal is returned to the ultrasonic framework module and cached in the uplink buffer area. Subsequently, the ultrasonic framework module transmits the uplink audio signal to the ultrasonic algorithm.

[0130] The ultrasonic framework module determines the value of the ultrasonic algorithm start flag. If the value of the ultrasonic algorithm start flag is 1, see Figure 5 At (11), the ultrasonic framework module can use the ultrasonic algorithm to determine whether there is a proximity event based on the acceleration data (the ultrasonic algorithm is driven and obtained from the acceleration sensor) and the uplink and downlink ultrasonic signals. The value of the ultrasonic algorithm start flag is 0 by default. Here, if the ultrasonic algorithm start flag is still 0, the ultrasonic framework judgment module executes the above-mentioned Figure 5 The content shown in (6) is then run in the pre-judgment mode to detect events through the pre-judgment thread.

[0131] It should be noted here that the value of the ultrasonic algorithm start flag can be changed from 0 to 1 by the pre-judgment thread when an uplink audio signal (or an uplink ultrasonic signal) is obtained. It can also be executed by the ultrasonic algorithm when an uplink audio signal (or an uplink ultrasonic signal) is obtained. In other possible cases, the ultrasonic framework module, the ultrasonic algorithm, and the pre-judgment thread can share the value of the ultrasonic start flag. Therefore, the ultrasonic pre-judgment module can determine the value of the ultrasonic algorithm start flag.

[0132] Figure 5 Middle (7) - Figure 5 Medium (5) Figure 5 The contents shown in (8a) are respectively the same as those in the above Figure 2 Middle (6) - Figure 2 Medium (9) Figure 2 The content shown in (7a) is the same as that shown in (7a), and you can refer to the aforementioned related content, which will not be repeated here.

[0133] Figure 5 and Figure 2 For details on how to perform the same steps in modules with the same name (except modules on SCP), refer to the previous Figure 2 For example, the processing of uplink and downlink communication signals by audio codecs and modems can refer to the aforementioned Figure 2 The description of the relevant contents will not be repeated here.

[0134] It should be noted here that Figure 5As shown, the ultrasonic judgment module (including the ultrasonic algorithm and the pre-judgment program) and the acceleration sensor driver are placed in the same kernel, so that the pre-judgment thread and the thread running the ultrasonic algorithm can subscribe to the acceleration data from the acceleration sensor driver. The ultrasonic judgment module and the ultrasonic framework module should also be placed in the same kernel to facilitate the transmission of data, transmission of commands and sharing of data between the ultrasonic framework module and the ultrasonic judgment module. Because after the ultrasonic judgment proximity program is started, events will be detected according to the frequency cycle, which is relatively power-consuming. The ultrasonic framework module, the ultrasonic judgment module and the acceleration sensor are independent of the Linux kernel of the main processor and placed on the kernel of the auxiliary processor (also called the SCP kernel). This can reduce the burden of the main processor during operation, improve the performance of the electronic equipment, and also facilitate management.

[0135] It should also be noted that in order to enable the pre-judgment thread to obtain the uplink audio signal (or uplink ultrasonic signal) through the ultrasonic algorithm more quickly, the pre-judgment thread and the thread running the ultrasonic algorithm can be set to be a common process. Compared with setting the pre-judgment thread and the thread running the ultrasonic algorithm in different processes, two threads belonging to the same process can be more efficient when performing data transmission.

[0136] Figure 6 An exemplary module interaction diagram is shown when implementing the ultrasonic proximity judgment function involved in the event detection method.

[0137] Figure 6 The example of quickly completing the first event detection in a communication scenario such as a call scenario or a voice playback scenario is used for explanation. The description of this process can refer to the following steps S11 to S19, and steps S21 to S25.

[0138] First, the communication application sends a request to call the proximity sensor (call request), which is responded to by the sensor HAL and audio HAL in the Linux kernel to start the software and hardware resources required for the ultrasonic judgment function. The description of this process can refer to the following steps S11 to S13, step S14a and step S14b.

[0139] S11. The communication application calls the proximity sensor.

[0140] S12. The sensor HAL determines that an ultrasonic proximity judgment event is used, and sends a message to the audio HAL to start the ultrasonic proximity judgment function.

[0141] S13. The audio HAL starts the software and hardware resources required for the ultrasonic proximity judgment function through the Linux kernel. The process of starting the hardware resources can refer to the following step S14a, and the process of starting the software resources can refer to the following step S14b.

[0142] S14a. The audio HAL calls the Linux kernel to start the microphone, earpiece, and audio codec.

[0143] S14b. The audio HAL calls the Linux kernel to notify the ultrasonic framework module to start the ultrasonic proximity judgment program.

[0144] Figure 6 Steps S11 to S13, step S14a and step S14b shown in FIG. Figure 3 Steps S11 to S13, step S14a and step S14b are the same, and reference may be made to the aforementioned description of the relevant contents, which will not be repeated here.

[0145] S14b is equivalent to the aforementioned Figure 5 In step (5), the Linux kernel sends a startup notification to the ultrasound framework module to notify the ultrasound framework module to start the ultrasound proximity judgment program. After receiving the startup notification, the ultrasound framework module first starts the pre-judgment mode, see the following step S21.

[0146] S21. The ultrasound algorithm startup flag T is 0 (indicating that it is not fully started), the pre-judgment mode is in the startup state, the ultrasound framework module creates a pre-judgment thread to run the pre-judgment program, and executes steps S22-S24.

[0147] The default value of T is 0, and the pre-judgment mode is in the startup state. The ultrasound framework module may be started when T is 0.

[0148] In the pre-judgment mode, the following steps S22 to S24 are executed to achieve the return of the first event as soon as possible.

[0149] S22. The pre-determination thread drives the acceleration sensor to subscribe to acceleration data.

[0150] S23. The pre-judgment thread pre-judgments whether there is acceleration based on acceleration data 1.

[0151] S24. When the uplink audio signal 1 is obtained, determine whether there is any obstruction based on the uplink and downlink audio signals 1, and set T=1.

[0152] The uplink audio signal 1 is the audio collected by the microphone after the speaker transmits the downlink ultrasonic signal 1 .

[0153] It should be noted that when the uplink audio signal 1 is not obtained, step S24 is not performed and T remains unchanged at 0.

[0154] Based on whether there is acceleration or whether there is acceleration and occlusion, the pre-judged approach event or distance event is returned, and the pre-judgment thread ends. In the case of executing step S24, based on whether there is acceleration and occlusion, the pre-judged approach event or distance event is returned, and the pre-judgment thread ends. In the case of executing step S24, based on whether there is acceleration, the pre-judged approach event or distance event is returned, and the pre-judgment thread ends.

[0155] The pre-judgment thread obtains the uplink audio signal 1 through the ultrasonic algorithm, indicating that the path between the ultrasonic algorithm and the hardware for transmitting audio signals such as microphones and receivers is available, and the ultrasonic algorithm can obtain the uplink ultrasonic signal. Therefore, T can be modified from 0 to 1.

[0156] The contents of the uplink audio signal acquired by the ultrasonic algorithm may refer to the following steps S15, S16, S17a and S18.

[0157] After receiving the start notification, the ultrasound framework module executes the following steps S15 and S16 in addition to the aforementioned step S21.

[0158] S15. The ultrasound framework module creates an uplink buffer area and a downlink buffer area.

[0159] S16. The ultrasound framework module creates and starts the ultrasound algorithm.

[0160] Subsequently, step S17a and step S18 are executed, and the ultrasonic algorithm acquires the uplink audio signal.

[0161] S17a. The ultrasonic algorithm sends a downlink ultrasonic signal to the ultrasonic framework module.

[0162] S18. Obtain an uplink audio signal based on the downlink ultrasonic signal, the audio codec, the earpiece and the microphone, and cache the uplink audio signal in the uplink buffer area. Subsequently, the ultrasonic framework module transmits the uplink audio signal in the uplink buffer area to the ultrasonic algorithm. If step S18 is executed before the pre-judgment thread obtains the uplink audio signal from the ultrasonic algorithm, the aforementioned step S24 can be executed.

[0163] It should be noted that the execution order of step S17a and step S22 is irrelevant. Therefore, step S24 may be executed or may not be executed.

[0164] After the pre-determination thread ends, the following step S25 is executed.

[0165] S25. The ultrasonic framework module determines the value of T. If T is 0, S21 is executed. If T=1, the pre-judgment mode is turned off.

[0166] The pre-judgment mode is closed and executed, and the ultrasonic framework module executes the following step S19a through the ultrasonic algorithm.

[0167] S19a. The ultrasonic algorithm obtains the uplink ultrasonic signal 2, the downlink ultrasonic signal 2 and the uplink ultrasonic signal 2 from the uplink audio signal 2 to determine whether there is a proximity event.

[0168] Step S17a and step S18 are executed in a loop, and multiple uplink audio signals can be obtained. Therefore, the uplink audio signal used in step S24 (referred to as uplink audio signal 1) is different from the uplink audio signal used in step S19a (referred to as uplink audio signal 2). The uplink audio signal 1 is the audio collected by the microphone after the speaker transmits the downlink ultrasonic signal 1. The uplink audio signal 2 is the audio collected by the microphone after the speaker transmits the downlink ultrasonic signal 2.

[0169] Once the pre-judgment thread and the ultrasonic algorithm subscribe to the acceleration data from the acceleration sensor, the acceleration data fed back by the acceleration sensor received by the acceleration sensor driver will be sent to the pre-judgment thread and the ultrasonic algorithm. This process is also executed in a loop, and multiple acceleration data can be obtained. Therefore, the acceleration data used in step S24 (called acceleration data 1) is different from the acceleration data used in step S19a (called acceleration data 2).

[0170] Subsequently, the ultrasonic algorithm returns an event (returns an approach event or a distance event) to the communication application. In response to the approach event, the electronic device turns off the screen. In response to the distance event, the electronic device turns on the screen.

[0171] After the ultrasonic algorithm acquires the uplink audio signal, step S19a can be executed once and executed in a loop. In response to a proximity event, the electronic device turns off the screen, including: if the two events detected are both proximity events, the electronic device remains in the screen-off state. If the previous event was a distance event and this time is a proximity event, the electronic device switches from the screen-on state to the screen-off state. In response to a distance event, the electronic device turns on the screen, including: if the two events detected are both distance events, the electronic device remains in the screen-on state. If the previous event was a distance event and this time is a distance event, the electronic device switches from the screen-off state to the screen-on state.

[0172] Figure 6 Steps S15, S16, S17a and S18 involved in Figure 3 Steps S15, S16, S17a and S18 involved are the same and will not be repeated here. Please refer to the description of the aforementioned related content.

[0173] Figure 7An exemplary flow chart involved in implementing a pre-determination mode in an event detection method is shown.

[0174] Figure 7 The steps S101 to S106 shown in FIG. 1 can be regarded as the description of the aforementioned steps S21 to S25. Step S107 is the description of event detection after the pre-judgment mode is turned off, which can be regarded as the description of the aforementioned step S19a.

[0175] S101. The ultrasound framework module receives a notification to start the ultrasound proximity determination program.

[0176] S102.T is 0, the pre-judgment mode is in the startup state, the ultrasound framework module creates a pre-judgment thread, and runs the pre-judgment module through the pre-judgment thread to perform the pre-judgment operation. T is the ultrasound algorithm startup flag, and T is initialized to 0, indicating that it is not fully started.

[0177] Here, T being 0 includes: the initial default is 0, the ultrasound framework module starts the pre-judgment module, and the pre-judgment mode is in the start state. It also includes the case where after performing a pre-judgment operation, T is still 0, and the pre-judgment mode is kept in the start state.

[0178] For the relevant contents involved in performing the pre-judgment operation based on the pre-judgment mode, reference may be made to the following steps S103 and S104 .

[0179] S103. The pre-determination thread pre-determines whether there is acceleration based on acceleration data 1.

[0180] Acceleration data (acceleration data 1 here) can be used to determine the acceleration of the electronic device, including magnitude and direction. If there is an upward acceleration or a downward acceleration, and the acceleration threshold is greater than the acceleration threshold 1, it is determined that the electronic device is accelerated. Otherwise, it is determined that the electronic device is not accelerated. Among them, the acceleration threshold 1 can be a value between 10m / s²-15m / s², for example, 10m / s². It can also be other values, which are not limited in the embodiments of the present application.

[0181] The upward acceleration may be used to indicate that the user has picked up the electronic device and put it to the ear, and the downward acceleration may be used to indicate that the user has put down the electronic device and put it to the ear.

[0182] Whether there is acceleration refers to whether the electronic device is accelerating. If there is no acceleration, the pre-judgment thread determines that it is far away and reports the far away event. At this time, the uplink audio signal is not obtained from the ultrasonic algorithm. After the pre-judgment thread reports the event this time, the value of T is not modified. However, the ultrasonic algorithm shares the value of T with the pre-judgment thread, and the ultrasonic algorithm can modify the value of T after obtaining the uplink audio signal.

[0183] If the electronic device is accelerated, the pre-judgment thread needs to obtain the uplink audio signal from the ultrasonic algorithm. The pre-judgment thread determines whether there is an obstruction in front of the electronic device based on whether the uplink audio signal is obtained, and decides whether to modify the value of T.

[0184] If acceleration is determined and no uplink audio signal is obtained, the pre-determination thread determines that the vehicle is approaching and reports a proximity event.

[0185] If an uplink audio signal is acquired, the following step S104 is executed.

[0186] S104. Change T from 0 to 1, and the pre-determination thread determines whether there is any obstruction based on the downlink ultrasonic signal 1 and the uplink audio signal 1.

[0187] The ultrasonic algorithm will send downlink ultrasonic signals to the handset through the ultrasonic framework module multiple times. The content of the downlink ultrasonic signal transmitted by the handset each time can be the same, but the transmission time is different. The downlink ultrasonic signal 1 mentioned here indicates: after the transmission, the microphone collects the downlink ultrasonic signal involved when the uplink ultrasonic signal 1 is obtained.

[0188] The pre-determination thread separates the uplink ultrasonic signal 1 from the uplink audio signal 1.

[0189] Based on the principle of ultrasonic radar ranging, the pre-judgment thread determines whether there is an obstruction in front of the electronic device by the time (i.e., flight time) of sending the downlink ultrasonic signal and retrieving the uplink ultrasonic signal 1. The uplink ultrasonic signal 1 collected by the microphone includes not only the sampling point of the audio, but also the timestamp (acquisition time) of the collected audio. Based on the emission time of the downlink audio signal 1 and the acquisition time of the uplink ultrasonic signal 1, the flight time can be determined, and the distance between the electronic device and the object is measured by the flight time. If the distance is greater than the distance threshold, it is determined that there is no obstruction in front of the electronic device. If the distance is less than or equal to the distance threshold, it is determined that there is an obstruction in front of the electronic device. Among them, the distance threshold can be taken as 2cm-10cm, for example 5cm, which is not limited in the embodiment of the present application.

[0190] If there is occlusion, the pre-judgment thread reports an approach event; if there is no occlusion, the pre-judgment thread reports a distance event.

[0191] After pre-determining the thread reporting event, the following steps S105 to S107 are executed.

[0192] S105. The ultrasound framework module ends the pre-judgment thread.

[0193] S106. The ultrasound framework module determines whether T is 1.

[0194] When T is still 0, it means that the ultrasonic algorithm has not been fully started and the uplink audio signal cannot be received, and the ultrasonic framework module executes the above step S102. In the pre-judgment mode, a pre-judgment thread detection event is created again.

[0195] When T is 1, it indicates that the ultrasonic algorithm has been fully started and the uplink audio signal can be received, and the following step S107 is executed.

[0196] S107. The ultrasonic framework module turns off the pre-judgment mode, calls the ultrasonic algorithm to obtain the uplink ultrasonic signal 2 from the uplink audio signal 2, and determines whether there is a proximity event based on the acceleration data 2, the downlink ultrasonic signal 2 and the uplink ultrasonic signal 2.

[0197] Acceleration data (acceleration data 2 here) can be used to determine the acceleration of the electronic device, including size and direction. If there is upward acceleration or downward acceleration, and the acceleration threshold is greater than the acceleration threshold 2, it is determined that the electronic device is accelerated. Otherwise, it is determined that the electronic device is not accelerated. Among them, acceleration threshold 2 can be less than acceleration threshold 1. Because the pre-judgment thread can be used to implement the first detection event, the first detection event needs to be completed in a relatively fast time. If the user puts the electronic device close to the ear within this relatively fast time, it will cause the electronic device to have a larger acceleration. Therefore, setting the acceleration threshold to be larger can avoid misjudgment even when the ultrasonic signal is not used.

[0198] The ultrasonic algorithm can determine the time (transmission time) when the earpiece transmits the downlink ultrasonic signal 2 through the downlink ultrasonic signal 2. Based on the transmission time of the downlink audio signal 2 and the acquisition time of the uplink ultrasonic signal 2, the flight time can be determined, and the distance between the electronic device and the object is measured through the flight time. If the distance is greater than the distance threshold, it is determined that there is no obstruction in front of the electronic device. If the distance is less than or equal to the distance threshold, it is determined that there is an obstruction in front of the electronic device. Among them, the acquisition time of the uplink ultrasonic signal 2 can be included in the uplink ultrasonic signal.

[0199] If it is determined that there is acceleration and there is an obstruction in front of the electronic device, the ultrasonic algorithm determines that there is an approach event. Otherwise, it is determined that there is a distance event.

[0200] In practice, it is found that when judging whether there is occlusion based only on the ultrasonic algorithm to determine whether there is an object approaching the electronic device, the probability of accurate judgment is greater than probability 1. Probability 1 is the probability of accurate judgment when judging whether there is acceleration based only on acceleration data to determine whether there is an object approaching the electronic device. Therefore, if it is judged based on the ultrasonic algorithm that there is no occlusion, the accuracy of determining the distance event is higher. In order to save computing resources, it is possible to first judge whether there is occlusion through the uplink ultrasonic signal and the downlink ultrasonic signal, and then further determine whether there is acceleration based on the acceleration data when there is occlusion. The existence of an approaching event is determined only when it is determined that there is occlusion and acceleration. When there is no occlusion, the distance event can be returned directly. It is no longer necessary to judge whether there is acceleration based on the acceleration data.

[0201] It should be noted here that, in the embodiment of the present application, the audio recorded in the uplink buffer area is an uplink audio signal, and the uplink audio signal includes at least an uplink ultrasonic signal. Then, the ultrasonic framework module transmits the uplink audio signal to the ultrasonic algorithm, which can also be understood as transmitting the uplink ultrasonic signal to the ultrasonic algorithm. In some possible cases, the audio codec can separate the uplink ultrasonic signal from the uplink audio signal, and only transmit the uplink ultrasonic signal to the ultrasonic algorithm through the ultrasonic framework module.

[0202] It should also be noted that the downlink ultrasonic signal mentioned in the embodiment of the present application is an audio signal with a frequency greater than 20 Khz, for example, an audio signal between 20 Khz and 24 Khz.

[0203] The following is an introduction to an exemplary electronic device provided in an embodiment of the present application.

[0204] Figure 8 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0205] The following is a detailed description of the embodiment using an electronic device as an example. It should be understood that the electronic device may have more than Figure 8 More or fewer components may be shown, two or more components may be combined, or there may be a different configuration of components. Figure 8 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0206] The electronic device may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194 and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.

[0207] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0208] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0209] The electronic device can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0210] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 may include an audio codec for encoding and decoding audio signals. In some embodiments, the audio module 170 may be arranged in the processor 110, or some functional modules of the audio module 170 may be arranged in the processor 110.

[0211] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device can listen to music or listen to a hands-free call through the speaker 170A.

[0212] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.

[0213] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by approaching the microphone 170C with his mouth to input the sound signal into the microphone 170C. An electronic device can be provided with at least one microphone 170C.

[0214] In some possible cases, at least one microphone 170C may be disposed near the receiver 170B (earpiece) to facilitate the at least one microphone 170C to collect the ultrasonic signal emitted by the receiver 170B. The at least one microphone 170C and the receiver 170B are on the same side of the electronic device. For example, both are disposed on the top of the electronic device.

[0215] In the embodiment of the present application, the processor 110 can call the computer instructions stored in the internal memory 121 to enable the electronic device to execute the method in the embodiment of the present application.

[0216] The present application also provides a chip system, which includes at least one processor for implementing the functions involved in the method executed by the electronic device in any of the above embodiments.

[0217] In one possible design, the chip system also includes a memory, which is used to store program instructions and data, and the memory is located inside or outside the processor.

[0218] The chip system may be composed of the chip, or may include the chip and other discrete devices.

[0219] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.

[0220] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be separated from the processor, which is not limited in the embodiment of the present application.

[0221] Exemplarily, the memory can be a non-transitory processor, such as a read-only memory ROM, which can be integrated with the processor on the same chip or can be set separately on different chips. The embodiments of the present application do not specifically limit the type of memory and the setting method of the memory and the processor.

[0222] The present application also provides a computer program product, which includes: a computer program (also referred to as code, or instruction), which enables a computer to execute the method executed by the electronic device in any of the above embodiments when the computer program is executed.

[0223] The present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program (also referred to as code or instruction). When the computer program is executed, the computer executes the method executed by the electronic device in any of the above embodiments.

[0224] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

[0225] As used in the above embodiments, the term "when..." may be interpreted to mean "if..." or "after..." or "in response to determining..." or "in response to detecting...", depending on the context. Similarly, the phrases "upon determining..." or "if (the stated condition or event) is detected" may be interpreted to mean "if determining..." or "in response to determining..." or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)", depending on the context.

[0226] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations to the present application. As used in the specification and appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear indication to the contrary in the context. It should also be understood that the term "and / or" used in the present application refers to and includes any or all possible combinations of one or more listed items.

[0227] The terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of technical features indicated. Thus, features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.

[0228] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk), etc.

[0229] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.

Claims

1. An event measurement method, characterized in that: Applied to an electronic device, the electronic device does not have a proximity sensor, or the proximity sensor is unavailable, the method includes: In response to a request from an application to call the proximity sensor, starting an earpiece and a microphone and starting a pre-judgment mode; A pre-judgment operation is performed in the pre-judgment mode, and the pre-judgment operation includes: judging whether the electronic device is accelerated based on the first acceleration data, and obtaining a first uplink ultrasonic signal through an ultrasonic algorithm; if the first uplink ultrasonic signal is successfully obtained, judging whether there is an obstruction in front of the screen of the electronic device based on the first uplink ultrasonic signal and the first downlink ultrasonic signal, and modifying the ultrasonic algorithm startup flag from the first value to the second value; if the first uplink ultrasonic signal fails to be obtained, the ultrasonic algorithm startup flag is still the first value; the first uplink ultrasonic signal is obtained by collecting the first downlink ultrasonic signal emitted by the earpiece through the microphone and transmitting it to the first memory, the first memory is the memory used by the ultrasonic algorithm, and the first downlink ultrasonic signal is provided by the ultrasonic algorithm; the first value indicates that the ultrasonic algorithm is not fully started; The pre-judgment operation further includes: feeding back a first event to the application, the first event being used to indicate whether there is an object approaching the electronic device; in the case where the first uplink ultrasonic signal acquisition fails, the first event is determined based on whether there is acceleration; in the case where the first uplink ultrasonic signal acquisition succeeds, the first event is determined based on whether there is acceleration and whether there is occlusion; After the pre-judgment operation is completed, determining the value of the ultrasonic algorithm start flag; When it is determined that the ultrasonic algorithm start flag is the second value, the pre-judgment mode is ended, and the first event is determined by the ultrasonic algorithm based on the second acceleration data, the second downlink ultrasonic signal and the second uplink ultrasonic signal, and the first event is fed back to the application again.

2. The method according to claim 1, characterized in that: The method further comprises: When it is determined that the ultrasonic algorithm start flag is still the first value, the pre-judgment operation is performed again in the pre-judgment mode.

3. The method according to claim 1, characterized in that Performing a pre-judgment operation in the pre-judgment mode specifically includes: A first thread is created, where the first thread is used to run a first program, where the first program is used to perform the pre-judgment operation; the first thread and a second thread that runs the ultrasonic algorithm are co-processed.

4. The method according to claim 3, characterized in that Create the first thread, specifically including: The first thread is created by an ultrasound framework module; the ultrasound framework module is also used to start or end the pre-judgment mode; Start the ultrasound algorithm, including: The ultrasound algorithm is started through the ultrasound framework module.

5. The method according to claim 4, characterized in that In response to the request of the application to call the proximity sensor, the earpiece and the microphone are started and the pre-judgment mode is started, which specifically includes: The proximity sensor hardware abstraction module, in response to the application's request to call the proximity sensor, notifies the audio hardware abstraction module to start the software and hardware resources required to determine the first event; The audio hardware abstraction module starts the earpiece and microphone through the first kernel, and sends a startup notification to the ultrasound framework module running on the second kernel through the first kernel, wherein the startup notification is used to notify the ultrasound framework module to start the pre-judgment mode.

6. The method according to claim 5, characterized in that The first program, the ultrasonic algorithm and the acceleration sensor driver all run on the second core; the acceleration sensor driver is used to obtain acceleration data from the acceleration sensor and transmit it to the first thread where the first program is located and the second thread where the ultrasonic algorithm is located; the acceleration data at least includes the first acceleration data and the second acceleration data.

7. The method according to claim 5 or 6, characterized in that: The startup notification is also used to notify the ultrasound framework module to create a first buffer area and a second buffer area, and to start the ultrasound algorithm after the creation. The method further includes: After starting the ultrasonic algorithm, sending the downlink ultrasonic signal to the ultrasonic framework module through the ultrasonic algorithm; The ultrasonic framework module caches the downlink ultrasonic signal in the first buffer area; The ultrasonic framework module transmits the downlink ultrasonic signal in the first buffer area to the audio codec, the audio codec is used to send the downlink audio signal to the earpiece, the downlink audio signal at least includes the downlink ultrasonic signal, the audio codec is also used to receive the uplink audio signal collected by the microphone, the uplink audio signal at least includes the uplink ultrasonic signal; the software and hardware resources include the audio codec, and the audio codec is started by the first kernel; The ultrasound framework module caches the uplink audio signal transmitted by the audio codec in the second buffer area; The ultrasonic framework module transmits the uplink audio signal in the second buffer area to the second thread where the ultrasonic algorithm is located; the uplink audio signal is used to parse the uplink ultrasonic signal through the ultrasonic algorithm; the downlink ultrasonic signal includes the first downlink ultrasonic signal and the second downlink ultrasonic signal, and the uplink audio signal includes at least the first uplink audio signal and the second uplink audio signal; the earpiece transmits the first downlink ultrasonic signal for the microphone to obtain the first uplink audio signal, and the first uplink audio signal is used to parse the first uplink ultrasonic signal, and the earpiece transmits the second downlink ultrasonic signal for the microphone to obtain the second uplink audio signal, and the second uplink audio signal is used to parse the second uplink ultrasonic signal.

8. The method according to any one of claims 1, 5-7, characterized in that: Before responding to the application's request to call the proximity sensor, the method further includes: In response to a first operation, the application issues a request to call the proximity sensor; the first operation includes at least one of the following: an operation on a dialing control, an operation on an answering control, and an operation on a voice playback control.

9. The method according to any one of claims 1, 5-7, characterized in that: After feeding back the first event to the application, the method further includes: When the first event fed back is a proximity event, the electronic device turns off the screen; When the first event fed back is a distance event, the electronic device lights up the screen.

10. An electronic device, characterized in that: include: One or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the electronic device to execute the method as described in any one of claims 1-9.

11. A computer-readable storage medium comprising computer instructions, characterized in that: When the computer instructions are executed on an electronic device, the electronic device is caused to execute the method as claimed in any one of claims 1 to 9.

12. A chip system, which is applied to electronic equipment, characterized in that: The chip system includes one or more processors, and the processor is used to call computer instructions so that the electronic device executes the method as described in any one of claims 1-9.

13. A computer program product comprising instructions, characterized in that When the computer program product is run on an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Event detecting method and event detecting device

    CN101635083A

  • Proximity detection method and mobile terminal

    CN110471068A