Sensor calibration method and electronic device

By controlling the ambient light detection module and the distance detection module in an electronic device to work serially, the first infrared light intensity is obtained for noise floor calibration, which solves the problem of incorrect noise floor calibration in a two-in-one device of ambient light sensor and a distance sensor. , avoids the situation where the object is not approaching but the screen is turned off, and improves the user experience of the device.

CN118444291BActive Publication Date: 2024-11-22HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410884062.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-11-22
Estimated Expiration
2044-07-03

AI Technical Summary

Technical Problem

In electronic devices that use a two-in-one ambient light sensor and a distance sensor, the first infrared light intensity cannot be correctly obtained, resulting in incorrect noise floor calibration and abnormal situations in which the object is not close to the screen but the screen is turned off.

Method used

By controlling the ambient light detection module and the distance detection module to work serially in the display screen, and obtaining the first infrared light intensity after the first preset time, it is used to calibrate the distance detection module in the sensor to ensure the bottom Accuracy of noise calibration.

Benefits of technology

It effectively avoids abnormal situations in which the object is not approaching but the screen is shut down due to incorrect noise floor calibration, ensures the correct operation of the distance detection module, and improves the user experience of electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118444291B_ABST
    Figure CN118444291B_ABST
Patent Text Reader

Abstract

The embodiments of the present application relate to the field of electronic technology, and in particular to a sensor calibration method and electronic device, which can obtain the first infrared light intensity detected by the sensor, so as to perform background noise calibration on the distance detection module in the sensor based on the first infrared light intensity, and avoid the abnormal situation that the screen of the sensor is off even though the object is not close to the sensor due to the lack of background noise calibration. The method includes: when the screen is in the bright screen state, controlling the ambient light detection module to work; when the first preset condition is met, switching the working mode of the sensor and synchronously starting the timing; obtaining the first infrared light intensity from the moment the timing is started to the first preset time; the first preset time is less than or equal to the signal detection time of the ambient light detection module; calibrating the distance detection module in the sensor according to the first infrared light intensity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of electronic technology, and in particular to a sensor calibration method and electronic equipment. Background Art

[0002] At present, electronic devices are generally equipped with proximity sensors (P-sensors) to implement the function of preventing accidental touches. For example, when an object approaches the P-sensor of an electronic device, the electronic device controls the display screen to turn off, thereby saving power and preventing accidental touches; and when the object moves away, the display screen is controlled to turn on, allowing the user to perform other operations.

[0003] After an electronic device is turned on, the distance sensor is generally calibrated for background noise first. Background noise is the light intensity obtained when there is no obstruction on the surface of the distance sensor. Conventional technology provides a sensor calibration method, which uses the first infrared light intensity detected by the distance sensor after each startup as the background noise value to calibrate the distance sensor for background noise.

[0004] In order to save space and reduce design complexity, more and more electronic devices use two-in-one sensors that combine distance sensors and ambient light sensors. This sensor includes a distance detection module and an ambient light sensing module, and has both the functions of a distance sensor and an ambient light sensor. However, when performing background noise calibration on the distance detection module in the sensor, there is a problem of being unable to obtain the true first infrared light intensity, resulting in incorrect background noise calibration. Electronic devices equipped with this sensor may experience an abnormal situation where the screen goes off even though the object is not close due to incorrect background noise calibration. Summary of the invention

[0005] The embodiments of the present application provide a sensor calibration method and an electronic device. After the electronic device is turned on, the first infrared light intensity detected by the sensor can be obtained, so that the noise floor calibration of the distance detection module in the sensor can be performed based on the first infrared light intensity, thereby avoiding the abnormal situation in which the sensor display screen goes off even though the object is not close to it due to the lack of noise floor calibration.

[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:

[0007] In the first aspect, a sensor calibration method is provided, which is applied to an electronic device, and the electronic device includes a display screen and a sensor. The sensor includes an ambient light detection module and a distance detection module. The ambient light detection module is used to obtain the ambient light intensity of the environment in which the electronic device is located; the distance detection module is used to emit infrared light and obtain the infrared light intensity of the reflected infrared light. The method includes: when the display screen is in a bright screen state, controlling the ambient light detection module to work; when a first preset condition is met, controlling the distance detection module and the ambient light detection module to work in series and start timing synchronously; wherein, when working in series, the distance detection module works first, and the ambient light detection module and the distance detection module work alternately; from the moment of starting the timing to the first preset time, obtaining the first infrared light intensity; the first preset time is less than or equal to the signal detection time of the ambient light detection module; and calibrating the distance detection module in the sensor according to the first infrared light intensity.

[0008] In the present application, the electronic device starts timing when switching the working mode of the sensor. Since when timing starts, the ambient light detection module stops working and the distance detection module starts working, the first infrared light intensity can be read after the first preset time.

[0009] In a possible implementation of the first aspect, the first preset time length is greater than the infrared light signal integration time length of the distance detection module. In this way, the distance detection module reads the first infrared light intensity after completing the first infrared light intensity detection, and can read the accurate first infrared light intensity.

[0010] In a possible implementation of the first aspect, when the electronic device enters a voice call state, or when the display screen of the electronic device changes from a bright screen to a locked screen state, the electronic device executes the sensor calibration method provided by the present application. In this way, when the electronic device uses the distance detection module, it can calibrate the threshold in real time based on the current usage scenario.

[0011] In a possible implementation of the first aspect, after the electronic device is turned on, when it enters a voice call state for the first time, or when the display screen enters a lock screen state from a bright screen state, the electronic device executes the sensor calibration method provided by the present application, so that when the distance detection module is used for the first time after the electronic device is turned on, the threshold can be calibrated in real time based on the current usage scenario.

[0012] In a possible implementation of the first aspect, the signal detection duration is the signal integration duration, and the signal integration includes collecting light signals, performing photoelectric conversion based on the light signals, and obtaining light intensity through signal integration. The signal integration duration is the duration required for collecting light signals, performing photoelectric conversion based on light information, and obtaining light intensity. The light signals include infrared light signals and ambient light signals.

[0013] In a possible implementation of the first aspect, when the first preset condition is met, after the ambient light detection module of the electronic device writes the ambient light intensity obtained after completing signal integration to the preset location, the distance detection module and the ambient light detection module are controlled to work in series and the timing is started synchronously. Switching the mode only after the ambient light intensity is written to the preset location will not interrupt the generation logic of the ambient light intensity, and can avoid the problem of wasting resources and untimely updating of ambient light.

[0014] In a possible implementation of the first aspect, it is recognized that the display screen is on, the ambient light detection module is started, and the first flag is set to the first flag; the first flag indicates that the working mode of the sensor is that the ambient light detection module works alone. When the first preset condition is met, the electronic device sets the first flag to the second flag. The second flag indicates that the working mode of the sensor is that the distance detection module and the ambient light detection module work in series. After the ambient light detection module writes the acquired ambient light intensity to the preset position, the first flag is read; when the first flag is the second flag, the distance detection module and the ambient light detection module are controlled to work in series and start timing. This implementation provides a feasible way to achieve synchronous switching modes and start timing.

[0015] In a possible implementation of the first aspect, the electronic device can respond in a timely manner, interrupt the ambient light detection process currently being performed by the sensor, enter the ambient light and infrared light detection process, and start timing at the same time. Specifically, when the first preset condition is met, the ambient light detection module is controlled to stop working. After the ambient light detection module stops working, the distance detection module and the ambient light detection module are controlled to work in series and start timing.

[0016] In a possible implementation of the first aspect, the electronic device may perform background noise normalization based on the first infrared light intensity, and after the background noise normalization, adjust the approach threshold and the distance threshold of the distance detection module. Specifically, the electronic device periodically obtains the first infrared light intensity detected by the distance detection module with a first time length as a period. According to the first infrared light intensity, a first offset is obtained. The first offset is the difference between the first infrared light intensity and the first target reference value. The electronic device is preset with multiple reference values, the first infrared light intensity is greater than the first target reference value, and the difference between the first infrared light intensity and the first target reference value is the smallest. Afterwards, each first infrared light intensity obtained is subtracted from the first offset to obtain the corresponding second infrared light intensity. Finally, when the second preset condition is met, the approach threshold and the distance threshold of the distance detection module are adjusted according to the first target light intensity. The first target light intensity is a second infrared light intensity that meets the second preset condition. The second preset condition includes: the difference between the second infrared light intensity and one or more second infrared light intensities before and / or after the second infrared light intensity is less than or equal to the first preset value and / or the second infrared light intensity is less than the first threshold and greater than the second threshold.

[0017] Since the first infrared light intensity acquired by the distance detection module is unstable after the distance detection module is started, for example, the change trend may be a process of gradually increasing until it stabilizes. The difference between the second infrared light intensity and one or more second infrared light intensities before and / or after the second infrared light intensity is less than or equal to the first preset value, indicating that the second infrared light intensity corresponds to the first infrared light intensity that tends to be stable. The stabilized first infrared light intensity can reflect the true background noise of the distance detection module, so it is correct and true to use the second infrared light intensity adjustment threshold corresponding to the stabilized first infrared light intensity. In addition, in order to avoid using an unreasonable second infrared light intensity adjustment threshold, the second infrared light intensity needs to be less than the first threshold and greater than the second threshold.

[0018] In a possible implementation of the first aspect, the threshold can also be adjusted dynamically during the use of the distance detection module. Specifically, when the third preset condition is met, the second offset is obtained according to the third infrared light intensity. The third preset condition includes that n consecutive second infrared light intensities are all less than the second preset value. If n consecutive second infrared light intensities are all less than the second preset value, then the first infrared light intensities corresponding to the n consecutive second infrared light intensities are all less than the first infrared light intensity. Meeting the third condition indicates that the first infrared light intensity is not the background noise value when the distance detection module is not blocked. Therefore, after finding a smaller first infrared light intensity, the smaller first infrared light intensity can be used to re-normalize the background noise and adjust the threshold. The third infrared light intensity is one of the n consecutive second infrared light intensities; wherein n is an integer greater than 1. The third infrared light intensity may be the maximum value, minimum value, mode, etc. of the n consecutive second infrared light intensities. In a preferred embodiment, the third infrared light intensity may be the nth second infrared light intensity of the n consecutive second infrared light intensities. This implementation provides a feasible way to dynamically adjust the distance detection mode.

[0019] In a possible implementation of the first aspect, after re-normalizing the background noise, that is, calculating a new offset, namely, the second offset, the electronic device will obtain each first infrared light intensity by subtracting the second offset to obtain a corresponding fourth infrared light intensity. And when the fourth preset condition is met, the second target light intensity is used to adjust the approach threshold and the distance threshold of the distance detection module. The fourth preset condition includes: the largest fourth infrared light intensity among the m consecutive fourth infrared light intensities is less than the infrared light intensity of the last threshold update, and the largest fourth infrared light intensity is greater than the second threshold, and the difference between the largest fourth infrared light intensity and the smallest fourth infrared light intensity among the m consecutive fourth infrared light intensities is greater than or equal to the third preset value; wherein m is an integer greater than 1. The second target light intensity is one of the m consecutive fourth infrared light intensities.

[0020] In a possible implementation of the first aspect, when the third preset condition is not met and the fifth preset condition is met, the third target light intensity is used to adjust the approach threshold and the distance threshold of the distance detection module. The fifth preset condition includes: the largest second infrared light intensity among m consecutive second infrared light intensities is less than the infrared light intensity of the last threshold update, and the largest second infrared light intensity is greater than the second threshold, and the difference between the largest second infrared light intensity and the smallest second infrared light intensity among m consecutive second infrared light intensities is greater than or equal to the third preset value; wherein m is an integer greater than 1. The third target light intensity is one of the m consecutive second infrared light intensities. This implementation provides another feasible way to dynamically adjust the distance detection mode.

[0021] In a possible implementation of the first aspect, when the display screen is in a bright screen state, the ambient light detection module is controlled to work; when the first preset condition is met, the distance detection module and the ambient light detection module are controlled to work in series and start timing synchronously; wherein, when working in series, the distance detection module works first, and the ambient light detection module and the distance detection module work alternately; from the moment the timing is started to a first preset time, the infrared light intensity is obtained; and the distance detection module in the sensor is calibrated according to the infrared light intensity. That is, the present application can calibrate the distance detection module in the sensor based on any one or more infrared light intensities obtained after the first preset time.

[0022] In a second aspect, the present application provides an electronic device, comprising: a memory, a display screen, one or more processors, and a sensor; the sensor comprises an ambient light detection module and a distance detection module; the ambient light detection module is used to obtain the ambient light intensity of the environment in which the electronic device is located; the distance detection module is used to emit infrared light and obtain the infrared light intensity of the reflected infrared light; the memory, the sensor, and the display screen are coupled to the processor; wherein the memory is used to store computer program code, and the computer program code comprises computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method as in the first aspect and any possible design thereof.

[0023] In a third aspect, the present application provides a chip system, which can be applied to an electronic device including a memory. The chip system includes one or more interface circuits and one or more processors. The interface circuit and the processor are interconnected by a line. The interface circuit is used to receive a signal from the above-mentioned memory and send the signal to the processor, and the signal includes a computer instruction stored in the memory. When the processor executes the computer instruction, the electronic device executes the method as in the first aspect and any possible design thereof.

[0024] In a fourth aspect, the present application provides a computer-readable storage medium, the computer-readable storage medium comprising computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method of the first aspect and any possible design thereof.

[0025] In a fifth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method of the first aspect and any possible design thereof.

[0026] It can be understood that the beneficial effects that can be achieved by the electronic device of any possible design of the second aspect, the chip system of the third aspect, the computer-readable storage medium of the fourth aspect, and the computer program product of the fifth aspect can be referred to as the beneficial effects in the first aspect and any possible design of the electronic device, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 A schematic diagram of a method for controlling a display screen on or off based on infrared light intensity in a conventional technology provided in an embodiment of the present application by a mobile phone;

[0028] Figure 2 A schematic diagram of the working process of a two-in-one sensor provided in an embodiment of the present application;

[0029] Figure 3 A schematic diagram of a two-in-one sensor operating mode switching timing provided in an embodiment of the present application;

[0030] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;

[0031] Figure 5 A schematic diagram of the software / hardware architecture of an electronic device provided in an embodiment of the present application;

[0032] Figure 6 A schematic diagram of an interface of an electronic device provided in an embodiment of the present application;

[0033] Figure 7 A schematic diagram of a flow chart of an electronic device controlling a two-in-one sensor to switch working modes provided in an embodiment of the present application;

[0034] Figure 8 A schematic diagram of a flow chart of a two-in-one sensor switching working mode provided in an embodiment of the present application;

[0035] Fig. 9 A schematic diagram of a flow chart of another electronic device controlling a two-in-one sensor to switch working modes provided in an embodiment of the present application;

[0036] Fig.10 A schematic diagram of another flow chart of switching working modes of a two-in-one sensor provided in an embodiment of the present application;

[0037] Fig.11 A schematic diagram of a flow chart of a calibration method for a two-in-one sensor provided in an embodiment of the present application. DETAILED DESCRIPTION

[0038] The distance sensor includes an infrared light emitting diode and an infrared light detector. When the distance sensor is working, the infrared light emitting diode emits infrared light, and the infrared light reflected by the surrounding objects is received by the infrared light detector. The infrared light detector can obtain the light intensity of the infrared light (hereinafter referred to as infrared light intensity) based on the received infrared light. Light intensity refers to the luminous flux of light received per unit area, which can be used to indicate the intensity of light. The unit of light intensity is lux (Lux or lx).

[0039] An electronic device such as a mobile phone includes a distance sensor, which is usually arranged below a display screen, for example, below the top of the display screen. The mobile phone can determine whether an object is close to or far away from the mobile phone based on the intensity of infrared light acquired by the distance sensor.

[0040] For example, in a call scenario, the distance sensor can turn off the screen when the face approaches the screen, and turn on the screen when the face moves away from the screen. This can save the power of the mobile phone and prevent erroneous operations caused by the face touching the screen. Among them, call scenarios include answering voice calls and making voice calls. Call scenarios include voice communications based on mobile communication networks and voice calls based on the Internet. This application does not make specific restrictions on this.

[0041] The distance sensor can also implement the function of preventing accidental touches when the phone is locked and the screen is on. For example, if you put the phone in a pocket or backpack after locking the screen, the screen may be turned on due to squeezing or sliding of other objects in the pocket or backpack. After the screen is turned on, the distance sensor in the phone emits and receives infrared light. When the phone recognizes that the object is close to the phone based on the intensity of the infrared light, the phone can turn off the screen and not respond to touch screen operations or key operations. Optionally, in some embodiments, when the phone recognizes that the object is close to the phone based on the intensity of the infrared light, the phone can also display a prompt message. The prompt message may be "Do not block the top of the display screen."

[0042] In order to achieve the above functions, the mobile phone can compare the infrared light intensity detected by the distance sensor with the threshold to determine whether the object is far away or close. The threshold includes a close threshold and a far threshold, and the close threshold is greater than the far threshold.

[0043] When the infrared light intensity is greater than the proximity threshold, the phone recognizes that the object is approaching the phone and the phone can turn off the screen. For example, when the face blocks the distance sensor, the phone is placed in a pocket, the phone is placed on a table with the display screen facing down, etc., the infrared light intensity obtained by the distance sensor is greater than the proximity threshold and the phone can turn off the screen. When the infrared light intensity is less than the distance threshold, the phone recognizes that the object is away from the phone and the phone can turn on the screen. For example, when a user answers a call but the phone is not yet placed on the ear, the infrared light intensity obtained by the distance sensor is less than the distance threshold and the phone can turn on the screen to facilitate the user's operation of the display. The following is a method for a mobile phone to identify the distance between an object and the phone. This method is as follows: Figure 1 As shown, it may include:

[0044] S1, the mobile phone turns on the distance sensor.

[0045] As an example, the mobile phone recognizes that it has entered a voice call state, and the mobile phone turns on the distance sensor. For example, in a voice call scenario, after the mobile phone recognizes an incoming call, it displays the caller ID interface. In response to the user answering the call, the mobile phone recognizes that it has entered a voice call state. For another example, in a voice call scenario, the called person answers the call, and the mobile phone recognizes that it has entered a voice call state. As another example, when the mobile phone is in the lock screen state, it recognizes that the power button is triggered and the mobile phone turns on the screen, that is, it enters the light-on lock screen state. When it recognizes that it has entered the light-on lock screen state, the mobile phone turns on the distance sensor.

[0046] S2, the mobile phone obtains the infrared light intensity.

[0047] After the distance sensor is turned on, the distance sensor can periodically collect infrared light signals and perform photoelectric conversion to obtain infrared light intensity, and write the infrared light intensity to a preset storage location. The mobile phone can periodically obtain infrared light intensity from the preset storage location. For each infrared light intensity obtained, the mobile phone can execute the method shown in S3-S7 to control the display screen to turn off or on based on the infrared light intensity.

[0048] S3, the mobile phone identifies whether the infrared light intensity is greater than or equal to the proximity threshold.

[0049] When the infrared light intensity is greater than or equal to the proximity threshold, the mobile phone recognizes that an object is approaching the mobile phone, and the mobile phone can control the display screen to turn off.

[0050] S4, when the infrared light intensity is greater than or equal to the threshold, the mobile phone controls the display screen to turn off.

[0051] S5, when the infrared light intensity is not greater than or equal to the approach threshold, the mobile phone identifies whether the infrared light intensity is less than or equal to the distance threshold.

[0052] When the infrared light intensity is less than or equal to the distance threshold, the mobile phone recognizes that the object is away from the mobile phone. Then, the mobile phone can control the display screen to light up.

[0053] S6: When the infrared light intensity is less than or equal to the distance threshold, the mobile phone controls the display screen to light up.

[0054] S7: When the infrared light intensity is not less than or equal to the distance threshold, the mobile phone does not change the current on / off state of the display.

[0055] After starting the distance sensor, the mobile phone generally performs a noise floor calibration on the distance sensor. The noise floor is the noise interference in the distance sensor measurement data. For example, the light intensity measured by the distance sensor is the sum of the noise floor value and the true value. For example, even if there is no obstruction on the surface of the distance sensor, it will receive ambient light, light emitted by the display or peripheral devices, which is an interference signal, namely the noise floor. In addition, the same distance sensor has different noise floors under different ambient light intensities. For example, when the ambient light intensity is high, the noise floor is large. When the ambient light intensity is low, the noise floor is small. In addition, as the mobile phone is used, stains on the surface of the mobile phone display will also affect the noise floor. For example, the noise floor corresponding to a stained display is higher than the noise floor corresponding to a display without stains. In some cases, changes in the internal structure of the mobile phone will also affect the noise floor. For example, the placement of the internal components of different versions of mobile phones has changed. Even if the same distance sensor is used, the corresponding noise floor is different due to changes in the reflected light of the device.

[0056] Therefore, in conventional technology, when a mobile phone uses the distance sensor for the first time after each startup, the noise floor calibration is performed on the infrared light intensity obtained by the distance sensor according to the noise floor value when the distance sensor is not blocked, and the approach threshold and the distance threshold are adjusted based on the infrared light intensity after the noise floor calibration. In one implementation, the first infrared light intensity obtained after the mobile phone is turned on is used as the noise floor value when the distance sensor is not blocked, and the noise floor calibration is performed based on the first infrared light intensity.

[0057] However, more and more mobile phones now use a two-in-one sensor that combines an ambient light sensor with a distance sensor. The sensor integrates an ambient light sensing module and a distance detection module, which helps save the internal space of the mobile phone and reduce the complexity of the mobile phone design. The sensor includes multiple working modes, such as ambient light detection mode, ambient light and infrared light detection mode, infrared light detection mode, etc. Among them, the ambient light sensing module can obtain the light intensity of the ambient light in the environment where the mobile phone is located. After the automatic brightness adjustment function of the mobile phone is turned on, the mobile phone can adaptively adjust the brightness of the mobile phone display based on the ambient light intensity detected by the ambient light sensing module. For example, when the current ambient brightness is dark, the mobile phone increases the brightness of the display; when the current ambient brightness is bright, the mobile phone reduces the brightness of the display.

[0058] Combine the following Figure 2 , introducing the different working modes of this two-in-one sensor.

[0059] like Figure 2 As shown in a, in the ambient light detection mode, the ambient light sensing module can periodically collect the ambient light intensity and store the ambient light intensity in the register of the sensor. Specifically, the ambient light sensing module periodically collects the light signal with a first signal integration time length such as 100ms and performs photoelectric conversion to obtain the ambient light intensity. Afterwards, the ambient light sensing module writes the light intensity to position 1. At the same time, the mobile phone can periodically read the ambient light intensity from position 1 with a preset time length such as 140ms. After each reading of the ambient light intensity, the mobile phone can use the ambient light intensity to adaptively adjust the brightness of the display.

[0060] like Figure 2 As shown in a, in the ambient light and infrared light detection mode, the distance detection module and the ambient light sensing module work alternately, and the distance detection module works first. For example, the distance sensor first collects the infrared light signal with a second signal integration time length such as 5ms and performs photoelectric conversion to obtain the infrared light intensity, and writes the infrared light intensity into a register such as position 2 in the register. Afterwards, the ambient light sensing module collects the light signal with a first integration time length and performs photoelectric conversion to obtain the ambient light intensity, and writes the light intensity into position 1. At the same time, the mobile phone can periodically read the infrared light intensity from position 2 with a preset time length such as 100ms, and periodically read the ambient light intensity from position 1 with a preset time length such as 140ms.

[0061] The mobile phone can switch the working mode of the sensor. For example, in response to the power button being triggered, the mobile phone can control the sensor to work in the ambient light detection mode. When it is recognized that the voice call state or the screen is on and locked, the mobile phone will control the sensor to switch from the ambient light detection mode to the ambient light and infrared light detection mode. However, when the working mode is switched, the first infrared light intensity obtained by the mobile phone will be a null value due to the switch. The mobile phone uses the null value as the noise floor value of the distance detection module that is not blocked, and performs noise floor calibration on the distance sensor. Because it is a null value, it is equivalent to not performing noise floor calibration on the distance sensor. Failure to perform noise floor calibration will cause the distance sensor to obtain a larger infrared light intensity, and there may be a situation where the infrared light intensity obtained is greater than the proximity threshold. Especially when the device itself is due to reasons such as the display film or dirt on the display screen blocking the distance detection module, and the deformation of the mobile phone structure causing the distance detection module to have a large noise floor, if the noise floor calibration is not performed, the infrared light intensity obtained is usually greater than the proximity threshold. This causes the distance detection module to be unblocked but the screen is turned off, affecting the normal use of the user. For example, when the phone is on a call and the face is not close to the person's face, the phone screen goes off, or when the phone is in lock screen mode and the screen is on and the person is not covered, the phone enters the anti-accidental touch mode.

[0062] The reason for this problem is that in the ambient light and infrared light detection modes, the distance detection module and the ambient light sensor module are integrated in series. In addition, the first signal integration time of the ambient light sensor module is greater than or equal to the preset reading time of the infrared light intensity. When the sensor switches modes, it needs to complete the current ambient light integration before switching to the ambient light and infrared light alternating integration reporting process. This may cause the phone to read before the sensor obtains the infrared light intensity, and then read a null value.

[0063] by Figure 3 For example, the mobile phone sends a switching instruction at time t1 and starts the timer. The mobile phone reads the first infrared light intensity at time t2. The interval between t1 and t2 is 100ms, which is the first preset time length. Figure 3 As shown in a in the figure, at time t1, the ambient light detection module has just started the ambient light integration process. Then, after 100ms, the sensor will switch to the working mode at time t2. At time t2, the proximity light detection module has not yet started the infrared light integration process. So, at time t2, the first infrared light intensity read by the mobile phone is a null value. Figure 3 As shown in b, at time t1, the ambient light detection module has already carried out a 10ms ambient light integration process, so the working mode will not be switched until 90ms later. After 5ms, the proximity light detection module can obtain the first infrared light intensity, so the mobile phone can read a non-null value at time t2. In other words, the sensor will take at least 105ms or more to write the first infrared light intensity to the register. After sending the switching command, the mobile phone will read the first infrared light intensity from the register after 100ms, resulting in the situation where the first infrared light intensity has not been written and a null value is read.

[0064] To this end, an embodiment of the present application provides a sensor calibration method and an electronic device. The electronic device starts timing while switching the working mode of the sensor. Since the ambient light detection module stops working and the distance detection module starts working when the timing starts, the first infrared light intensity can be read after the first preset time. The first preset time is less than or equal to the integration time of the ambient light detection module. Optionally, the first preset time is much greater than the signal integration time of the distance detection module.

[0065] Optional, such as Figure 2As shown in b, after the mobile phone reads the first infrared light intensity, the mobile phone can identify whether the infrared light intensity is a null value or zero. In the case that the infrared light intensity is a null value or zero, the mobile phone can directly discard the data, for example, not use the data. After discarding, the mobile phone can obtain a second infrared light intensity, and use the second infrared light intensity for background noise calibration when the second infrared light intensity is not a null value or zero. In the case that the first infrared light intensity is not a null value or zero, the mobile phone can use the first infrared light intensity for background noise calibration. This method is simple to implement, but due to the discarding of a sum of infrared light intensity data and the failure to adjust the threshold of the distance detection module in time, it may cause the distance detection module to react slowly to screen extinguishing after being started due to occlusion.

[0066] The method provided in the embodiment of the present application can be applied to an electronic device with data processing capabilities. The electronic device includes the two-in-one sensor of the ambient light sensing module and the distance detection module as described above. The above-mentioned electronic device may include a mobile phone, a tablet computer, a netbook, a wearable device (such as a smart watch, a smart bracelet, etc.), a virtual reality device, etc., and the embodiment of the present application does not impose any restrictions on this. In the embodiment of the present application, the above-mentioned electronic device is an electronic device that can run an operating system and install application programs. Optionally, the operating system running on the electronic device may be an Android® system, a Windows® system, an iOS® system, etc.

[0067] For example, please refer to Figure 4 , which shows a schematic diagram of the structure of an electronic device 400. The electronic device 400 may include a processor 410, an external memory interface 420, an internal memory 421, an audio module 430, a speaker 430A, a microphone 430B, a display screen 440, a communication module 450, a power module 460, an input device 470, a sensor 480, a camera 490, etc. Among them, the sensor 480 may include a pressure sensor, a touch sensor, an ambient light sensing module and a distance detection module two-in-one sensor, etc. The two-in-one sensor is used to obtain the ambient light intensity of the environment in which the electronic device is located, and is also used to emit infrared light and obtain the infrared light intensity of the reflected infrared light.

[0068] It is understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 400. In other embodiments of the present application, the electronic device 400 may include more or fewer components than shown in the figure, or combine some components, or split some 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.

[0069] The processor 410 may include one or more processing units. For example, the processor 410 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), and / or a neural-network processing unit (NPU). Different processing units may be independent components or integrated into one or more processors. In some embodiments, the electronic device 400 may also include one or more processors 410.

[0070] The processor 410 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 410 is a cache memory. The memory may store instructions or data that the processor 410 has just used or cyclically used. If the processor 410 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 410, and thus improves the efficiency of the system.

[0071] The external memory interface 420 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 400. The external memory card communicates with the processor 410 through the external memory interface 420 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0072] The internal memory 421 may be used to store one or more computer programs, which include instructions. The processor 410 may enable the electronic device 400 to execute the application running method provided in some embodiments of the present application, as well as various applications and data management, by running the above instructions stored in the internal memory 421. In some embodiments, the processor 410 may enable the electronic device 400 to execute the sensor calibration method provided in the embodiments of the present application by running the instructions stored in the internal memory 421 and / or the instructions stored in the memory provided in the processor 410.

[0073] The electronic device 400 can implement audio functions such as music playing and recording through the audio module 430, the speaker 430A, the microphone 430B, and the application processor. The speaker 430A, also called the "speaker", is used to convert audio electrical signals into sound signals.

[0074] Microphone 430B, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. A user can make a sound by approaching microphone 430B with his mouth, and input the sound signal into microphone 430B.

[0075] The communication function of the electronic device 400 can be realized through the antenna 1, the antenna 2 and the communication module 450.

[0076] The communication module 450 can provide solutions for wireless communications including cellular, Wi-Fi, Bluetooth (BT), wireless data transmission modules (e.g., 433MHz, 868MHz, 915MHz) applied to the electronic device 400. The communication module 450 can be one or more devices integrating at least one communication processing module. The communication module 450 receives electromagnetic waves via antenna 1 or antenna 2, filters and frequency modulates the electromagnetic wave signals, and sends the processed signals to the processor 410. The communication module 450 can also receive the signal to be sent from the processor 410, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through antenna 1 or antenna 2.

[0077] The electronic device 400 implements the display function through a GPU, a display screen 440, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 440 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 410 may include one or more GPUs, which execute program instructions to generate or change display information.

[0078] The display screen 440 is used to display images, videos, etc. The display screen 440 includes a display panel. In some embodiments, the electronic device 400 may include 1 or N display screens 440, where N is a positive integer greater than 1. In the embodiment of the present application, the display screen 440 may be used to display a UI and receive user operations on the UI.

[0079] The power module 460 can be used to supply power to various components included in the electronic device 400. In some embodiments, the power module 460 can be a battery, such as a rechargeable battery.

[0080] The input device 470 may include a keyboard, a mouse, etc. The keyboard is used to input English letters, numbers, punctuation marks, etc. into the electronic device 400, thereby issuing commands to the electronic device 400, inputting data, etc.

[0081] The electronic device 400 can realize the shooting function through an ISP, a camera 490, a video codec, a GPU, a display screen 440, and an application processor. The ISP is used to process the data fed back by the camera 490. The camera 490 is used to capture static images or videos. In some embodiments, the electronic device 400 includes 1 or N cameras 490, where N is a positive integer greater than 1. The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 400 is at a frequency point selection, the digital signal processor is used to perform Fourier transform on the frequency point energy, etc. The video codec is used to compress or decompress digital video.

[0082] Take the above electronic device 400 as a mobile phone. The software system of the electronic device 400 can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to illustrate the software structure of the electronic device 400. The software structure is as follows: Figure 5 shown.

[0083] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into six layers, from top to bottom: application layer, application framework layer, hardware abstraction layer, kernel layer, sensor hub, and hardware.

[0084] The application layer may include a series of application packages. Figure 5 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, social and other applications.

[0085] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 5 As shown, the application framework layer may include a content provider, a view system, a resource manager, a notification manager, an input system, a proximity light service, an ambient light service, and the like.

[0086] The input system is used to monitor the input module of the mobile phone (such as the touch screen driver), and convert the parameters input by the input module into usable events and pass them to the upper-level related modules. For example, the input system is used to monitor the touch screen of the mobile phone through the touch screen driver, and convert the touch parameters generated by the touch operation input by the touch screen into usable events and pass them to the upper-level APP.

[0087] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0088] The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build the display interface of an application.

[0089] The notification manager enables applications to display notification information in the status bar, which can be used to convey notification-type messages and disappear automatically after a short stay without user interaction.

[0090] The proximity light service can interact with the sensor driver in the sensorHub through the sensor HAL, for example, to send control instructions, obtain infrared light intensity, etc. The proximity light service can also interact with the display driver, for example, to control the on / off status of the display.

[0091] The ambient light service can interact with the sensor driver in the sensorHub through the sensor HAL, for example, to send control instructions, obtain the ambient light intensity, etc. The ambient light service can also interact with the display driver, for example, to control the brightness of the display.

[0092] The hardware abstraction layer is located between the driver and the operating system kernel. The hardware abstraction layer can provide a hardware call interface and shield the implementation details of the low-level hardware. In the embodiment of the present application, the hardware abstraction layer includes a sensor HAL.

[0093] The sensor HAL is used to receive instructions from upper-layer services such as proximity light service and ambient light service, and pass the instructions to the sensor driver. The sensor HAL is also used to receive data uploaded by the sensor driver, such as infrared light intensity and ambient light driver, and report the data to the upper-layer service.

[0094] The core layer may include touch screen driver, display driver, etc.

[0095] The sensor hub is a general concept of a subsystem, including hardware and software. It can be understood as a low-power detection module running a real-time operating system on a separate microcontroller unit (MCU) or a small core. It can connect and process data from various sensor devices to realize functions such as gesture recognition, device status recognition, user status recognition, and user traffic behavior judgment. In an embodiment of the present application, the sensor hub includes a sensor driver. The sensor driver is used to drive the sensor to work based on instructions from upper-layer services such as proximity light service and ambient light service. The sensor driver is also used to periodically read infrared light intensity and ambient light intensity from the sensor register.

[0096] Hardware can include displays, sensors, etc.

[0097] The following takes a mobile phone as an example to introduce a sensor calibration method and an electronic device provided by an embodiment of the present application in conjunction with the accompanying drawings. Figure 6 An application scenario of a sensor calibration method provided in an embodiment of the present application is introduced.

[0098] When the mobile phone enters the bright screen lock state from the display screen bright screen state, a sensor calibration method provided by the embodiment of the present application will be executed. Figure 6 In the example, scenario a is an example of a mobile phone entering a bright screen lock screen state from a display screen bright screen state. In scenario a, the mobile phone is in a bright screen state, and in response to a user clicking the power button, the mobile phone enters a bright screen lock screen state, the anti-mistouch function of the mobile phone is turned on, and the mobile phone displays a bright screen lock screen interface 601. At the same time, a sensor calibration method provided in an embodiment of the present application is executed.

[0099] When the mobile phone enters the voice call state with the display screen on, a sensor calibration method provided by the embodiment of the present application will be executed. Figure 6 In scenario b, the mobile phone lights up and displays the main interface. After receiving an incoming call, the mobile phone displays the incoming call interface 602. In response to the user answering the call, the mobile phone enters the voice call state and executes a sensor calibration method provided in an embodiment of the present application. In scenario c, the mobile phone lights up and displays the main interface. In response to the user opening the call APP, the mobile phone displays the dialing interface ( Figure 6 In response to the user inputting a number to be called and performing a dialing operation in the dialing interface 603, the mobile phone displays that a call is being made and displays a call interface 604. After the called end answers the call, the mobile phone executes a sensor calibration method provided in an embodiment of the present application.

[0100] exist Figure 6 In the embodiment, the mobile phone is in a bright screen state and displays the main interface. In some embodiments, the mobile phone can be in a bright screen state and display any interface. The embodiment of the present application does not make any limitation to this.

[0101] In the implementation of this application, the mobile phone can control the ambient light detection module to work when the display screen is on. When the first preset condition is met, the timing is started synchronously when the working mode is switched, and the first infrared light intensity is obtained after the first preset time from the start of the timing. Since the ambient light detection module stops working and the distance detection module starts working when the timing starts, the first infrared light intensity can be read after the first preset time. Among them, the first preset condition is that the mobile phone enters a voice call state or the display screen of the mobile phone enters a bright screen lock state.

[0102] A sensor calibration method provided in an embodiment of the present application can be executed by a mobile phone, specifically, by a sensor driver in the mobile phone. Optionally, it can also be executed by other software / hardware modules in the mobile phone, and this application does not make specific limitations. The following is an introduction using the execution by the sensor driver in the mobile phone as an example.

[0103] Figure 7 is a flow chart of a sensor calibration method provided in an embodiment of the present application, such as Figure 7 As shown, the method includes:

[0104] S701, in response to the user pressing the power button, the display screen turns on.

[0105] When the display screen is in the bright screen state, the sensor driver can control the ambient light detection module in the sensor to work. Specifically, the mobile phone can execute S702-S703.

[0106] S702, the ambient light service in the mobile phone detects that the display screen is on, and sends a control signal 1 to the sensor driver.

[0107] After the automatic backlight adjustment function of the mobile phone is turned on, the ambient light service can adjust the brightness of the display screen based on the intensity of the ambient light. The ambient light service can be, for example, an automatic brightness controller.

[0108] The ambient light service can monitor the status of the display screen, which includes off and on. When the display screen is monitored to be on, the ambient light service sends a control signal 1 to the sensor driver. The control signal 1 is used to start the ambient light detection module in the sensor. The control signal 1 can be an enable signal.

[0109] S703, in response to the control signal 1, the sensor drives and starts the timer 1, sets the first flag of the mobile phone to the first flag, and controls the sensor to work in the ambient light detection mode.

[0110] The first flag of the mobile phone may be a preset position in a flag register in the mobile phone. The first flag indicates that the ambient light detection module in the sensor works alone, that is, indicates that the working mode is the ambient light detection mode. The first flag may be F.

[0111] Customizer 1 can be a cyclic timer. Based on timer 1, the ambient light service can cyclically execute the action of reading the light intensity from the preset position 1 at intervals of timing period 1, such as 140ms. Before starting the timer, the sensor driver can first create a timer according to the control signal. For example, the sensor driver receives control signal 1, and the sensor driver creates timer 1. The sensor driver receives control signal 2, and the sensor driver creates timer 2. Control signal 2 is used to start the distance detection module in the sensor.

[0112] The sensor driver can write the working mode flag (such as 00x1) corresponding to the ambient light detection mode into the target flag bit of the sensor's register and instruct the sensor to read the flag. After reading the flag, the sensor starts the ambient light detection module and controls the ambient light detection module to work alone.

[0113] After the ambient light detection module is started, the ambient light detection module can detect the ambient light intensity based on the signal detection duration. The signal detection duration of the ambient light detection module can be the first signal integration duration. Specifically, the ambient light detection module in the sensor can execute S704-S705 in a loop.

[0114] S704, collecting light signals within a first signal integration time and performing photoelectric conversion to obtain ambient light intensity.

[0115] The first signal integration time length may be 100 ms. The first signal integration time length is related to the device and may be a preset value. For example, it may be pre-written into the register of the sensor by the sensor developer.

[0116] S705, writing the ambient light intensity into preset location 1.

[0117] The preset position 1 is a preset position of a register in the sensor. After the ambient light detection module writes the ambient light intensity into the preset position 1, the sensor driver may execute S706.

[0118] S706, the sensor driver reads the flag in the first flag position of the mobile phone.

[0119] After the ambient light detection module completes signal integration and obtains the ambient light intensity and writes it to the preset position 1, the sensor driver can read the flag in the first flag position of the mobile phone. For example, the first signal integration time of the ambient light detection module is 100ms, and the sensor driver can read the flag in the first flag position after at least 100ms. Then, after the ambient light detection module completes signal integration and obtains the ambient light intensity and writes it to the preset position 1, the sensor will read the flag in the first flag position.

[0120] S707: Whether the sensor drive identification flag is the second flag.

[0121] If the flag is not the second flag, the sensor driver does not perform any operation. If the flag is the second flag, the sensor driver executes S711.

[0122] The second mark indicates that the distance detection module and the ambient light detection module in the sensor work alternately, that is, the working mode is the ambient light and infrared light detection mode. The second mark can be T.

[0123] S708: The sensor is driven to periodically read the ambient light intensity from the preset position 1 with a second preset time period as a period, and report the ambient light intensity to the ambient light service.

[0124] For example, after starting timer 1, timer 1 may cyclically execute the action of reading the ambient light intensity from preset position 1 when the second preset time duration is reached. The sensor driver may obtain the ambient light intensity periodically read by the timer from timer 1.

[0125] S709, the proximity light service monitors that a voice call state has been entered, and sends a control signal 2 to the sensor driver.

[0126] Optionally, S709 may also be: the proximity light service monitors that the screen is in a bright screen or locked screen state, and sends a control signal 2 to the sensor driver.

[0127] S710: In response to the control signal 2, the sensor driver sets the first flag bit to the second flag bit.

[0128] S711 , when the sensor driver reads that the identifier is the second mark, it starts timer 2 and controls the sensor to work in the ambient light and distance detection mode.

[0129] The sensor driver may start the timer 2. The timer 2 may be, for example, cyclically executed to read the infrared light intensity from the preset position 2 at a timing period 2 such as 100 ms.

[0130] The sensor driver can write the working mode flag (such as 00x2) corresponding to the ambient light and infrared light detection modes into the target flag bit of the sensor register and instruct the sensor to read the flag. After reading the flag, the sensor starts the distance detection module and controls the ambient light detection module and the distance detection module to work alternately.

[0131] In the ambient light and infrared light detection mode, the ambient light detection module and the distance detection module work in series. Specifically, the distance detection module works first, and the ambient light detection module and the distance detection module work alternately. The distance detection module can detect the infrared light intensity by the signal detection duration. Among them, the signal detection duration of the distance detection module can be the second signal integration duration.

[0132] Exemplarily, the sensor may execute S712 - S715 in a loop.

[0133] S712, collecting light signals within a second signal integration time and performing photoelectric conversion to obtain infrared light intensity.

[0134] The second signal integration time length may be 5 ms. The second signal integration time length is device-dependent and may be a preset value. For example, it may be pre-written into a register of the sensor by a sensor developer.

[0135] S713, writing the infrared light intensity into the preset position 2.

[0136] The preset position 2 is a preset position of the register of the sensor. The preset position 2 and the preset position 1 are different preset positions of the register of the sensor.

[0137] Specifically, the distance detection module in the sensor collects the light signal within the second signal integration time and performs photoelectric conversion to obtain infrared light intensity, and writes the infrared light intensity into the preset position 2.

[0138] S714, collecting light signals within the first signal integration time and performing photoelectric conversion to obtain ambient light intensity.

[0139] S715, writing the ambient light intensity into preset location 1.

[0140] S716: The sensor is driven to periodically read the infrared light intensity from the preset position 2 with a first preset time period as a cycle, and report the infrared light intensity to the proximity light service.

[0141] Exemplarily, after starting timer 2, timer 2 can cyclically execute the action of reading the infrared light intensity from preset position 2 when the first preset time duration is reached. The sensor driver can obtain the infrared light intensity periodically read by the timer from timer 2. Exemplarily, from the start time of timing to the first preset time duration, the sensor driver can obtain the first infrared light intensity. From the first acquisition time to the first preset time duration, the sensor driver can obtain the second infrared light intensity, ..., from the nth acquisition time to the first preset time duration, the sensor driver can obtain the n+1th infrared light intensity.

[0142] The first preset duration is equal to the first signal integration duration of the ambient light detection module, such as 100ms. Alternatively, the first preset duration is less than the first signal integration duration of the ambient light detection module, such as 100ms. In some embodiments, the first preset duration is greater than the second signal integration duration of the distance detection module, such as 5ms, and less than or equal to the first signal integration duration of the ambient light detection module, such as 100ms.

[0143] The ambient light service can exchange data with the sensor driver through the sensor hardware abstraction module (sensor HAL). The data can be, for example, the control signal 1, control signal 2, ambient light intensity, infrared light intensity, etc. For example, the ambient light service sends control signal 1 to the sensor HAL, and the sensor HAL calls the corresponding interface to send control signal 1 to the sensor driver.

[0144] exist Figure 7 In the illustrated embodiment, after the sensor driver recognizes that the ambient light detection module writes the ambient light to position 1, it instructs the sensor to switch the working mode and starts timer 2 at the same time. Since the time of starting timer 2 is synchronized with the time of the sensor switching the working mode, after switching the working mode, the sensor can generate infrared light intensity after 5ms, and the sensor driver can read the first infrared light intensity after 100ms (the first preset duration). In this way, the situation where the background noise in the infrared light of the sensor cannot be calibrated due to the failure to obtain the first infrared light intensity will not occur. And in this embodiment, the mode is switched only after the ambient light intensity is written to the preset position 1, and the generation logic of the ambient light intensity will not be interrupted. It can avoid the problem of waste of resources and untimely update of ambient light, and will not change the integration time of the distance detection module and the ambient light detection module.

[0145] For example, Figure 8 As shown, the sensor includes an ambient light detection module, a distance detection module, a control unit, and a register. The control unit can read the working mode flag from position 3 of the register in response to the instruction of the sensor driver. And the sensor is controlled to work in different working modes based on the working mode flag. Specifically, the sensor driver writes 00x1 at position 3 in response to the control signal 1 of the ambient light detection module, and instructs the control unit to read. The control unit reads 00x1 and controls the ambient light detection module to perform a cyclic integration process. The sensor driver will also read and identify the identifier of the preset position each time the ambient light detection module writes the ambient light to position 1. When the identifier is the second identifier, the working mode identifier in position 3 is changed from 00x1 to 00x2 and the control unit is instructed to read. The control unit reads 00x2 and controls the ambient light detection module and the distance detection module to perform an alternating integration process.

[0146] In other embodiments, the ambient light detection mode in the sensor may be directly terminated and the operating mode may be directly switched. Fig. 9 As shown, the method includes:

[0147] S901, in response to the user clicking the power button, the display screen turns on.

[0148] S902, the ambient light service in the mobile phone detects that the display screen is on, and sends a control signal 1 to the sensor driver.

[0149] S903 , in response to the control signal 1 , the sensor drives and starts the timer 1 , and controls the sensor to operate in the ambient light detection mode.

[0150] After starting the ambient light detection module, the sensor may execute S904 - S905 in a loop.

[0151] S904, collecting light signals within the first signal integration time and performing photoelectric conversion to obtain ambient light intensity.

[0152] S905, writing the ambient light intensity into preset location 1.

[0153] S906: The sensor driver periodically reads the ambient light intensity from the preset position 1 and reports the ambient light intensity to the ambient light service.

[0154] S907: Upon detecting that a voice call is in progress, the proximity light service sends a control signal 2 to the sensor driver.

[0155] Optionally, S907 may also be: monitoring that the screen is in a bright screen or locked screen state, and the proximity light service sends a control signal 2 to the sensor driver.

[0156] S908 , in response to control signal 2 , the sensor driver starts timer 2 and controls the sensor to operate in the ambient light and distance detection mode.

[0157] In response to control signal 2, the sensor driver can first interrupt the current ambient light detection process. For example, the sensor driver can initialize the register of the sensor. After initializing the register, the sensor ends the currently executing process such as the current ambient light detection process. After that, the sensor driver can write the working mode flag (such as 00x2) corresponding to the ambient light and infrared light detection mode into the preset position of the sensor register, and instruct the sensor to read the flag. After reading the flag, the sensor starts the distance detection module and the ambient light detection module, and controls the ambient light detection module and the distance detection module to work alternately.

[0158] The sensor may execute S909 - S912 in a loop.

[0159] S909, collecting light signals within the second signal integration time and performing photoelectric conversion to obtain infrared light intensity.

[0160] S910, writing the infrared light intensity into the preset position 2.

[0161] S911, collecting light signals within a first signal integration time and performing photoelectric conversion to obtain ambient light intensity.

[0162] S912, writing the ambient light intensity into preset location 1.

[0163] S913, the sensor driver periodically reads the infrared light intensity from the preset position 2, and reports the infrared light intensity to the proximity light service.

[0164] In this embodiment, after the sensor driver receives the control signal 2 of the upper layer approaching light, it can respond to the control signal of the upper layer in time, end the current ambient light integration process of the sensor, and instruct the sensor to switch the working mode and start the timer 2. Since the time of starting the timer 2 is synchronized with the time of switching the working mode of the sensor, it can also avoid the situation where the intensity value of the first infrared light cannot be read.

[0165] For example, Fig.10 As shown, the sensor driver responds to the control signal 1 of the ambient light detection module, writes 00x1 at position 3, and instructs the control unit to read. The control unit reads 00x1 and controls the ambient light detection module to perform a cyclic integration process. The sensor driver responds to the control signal 2 of the ambient light detection module, initializes the sensor register, and writes 00x2 at the position after initialization and instructs the control unit to read. The control unit reads 00x2 and controls the ambient light detection module and the distance detection module to perform an alternating integration process.

[0166] The previous article introduced how the mobile phone obtains the infrared light intensity. Fig.11 This paper introduces a method for calibrating the distance detection module of a mobile phone based on the acquired infrared light intensity.

[0167] After booting up, the phone can perform the following operations: Figure 7 or Figure 8 The method shown in S1101-S1103 switches the working mode of the sensor, and after obtaining the first infrared light intensity, the noise floor calibration can be performed on the measured value of the distance detection module of the sensor based on the first infrared light intensity. Exemplarily, after powering on, when the mobile phone switches the working mode of the sensor for the first time and starts the distance detection module of the sensor, the mobile phone can execute the method shown in S1101-S1103 to adjust the approach threshold and the distance threshold.

[0168] S1101, calculating a first offset according to a first infrared light intensity.

[0169] The first infrared light intensity may be the first infrared light intensity obtained after the phone is turned on. The phone uses the first infrared light intensity as the noise floor value when the surface of the distance detection module is not blocked, and uses the noise floor value to calculate the first offset.

[0170] The mobile phone includes multiple reference values, for example, 1lux, 300lux, 1500lux, 5000lux, 8000lux, 11000lux, 15000lux. The mobile phone first determines the first target reference value corresponding to the first infrared light intensity. Among them, the first target reference value is one of the multiple reference values. The first target reference value is less than the first infrared light intensity, and the difference between the first infrared light intensity and the first target reference value is the smallest. Exemplarily, such as the first infrared light intensity of 450lux, the reference values ​​less than the first infrared light intensity include 1lux and 300lux. Among them, the difference between the first infrared light intensity of 450lux and the reference value of 300lux is the smallest, so the reference value of 300lux is the first target reference value. The first offset is the difference between the first infrared light intensity and the first target reference value. For example, the first offset 450lux-300lux=150lux. Furthermore, the first infrared light intensity is 1800 lux, and the corresponding first target reference value is 1500 lux. The first offset is 1800 lux-1500 lux=300 lux.

[0171] Optionally, before S1101, the method further includes: starting the distance detection module and identifying whether it is the first start.

[0172] Exemplarily, after the mobile phone is turned on, the third flag is written into the second flag position, and the third flag indicates that the distance detection module is started for the first time. After starting the distance detection module, the mobile phone reads the flag from the second flag position, and when the third flag is read, the mobile phone recognizes that it is the first time to start the distance detection module. In the case of starting the distance detection module for the first time, the method shown in S1101-S1103 is executed. After reading, the mobile phone deletes the third flag. Optionally, after deletion, the mobile phone can write a fourth flag in the preset flag, and the fourth flag indicates that the distance detection module is not started for the first time.

[0173] When the mobile phone cannot read the third mark and recognizes that it is not the first time to start the distance detection module, the mobile phone can execute S1104.

[0174] After obtaining the first offset, the mobile phone can calibrate each first infrared light intensity detected by the distance detection module, and use the calibrated second infrared light intensity to calibrate the approach threshold and the distance threshold of the distance detection module. Exemplarily, the mobile phone can execute S1102.

[0175] S1102, after acquiring a first infrared light intensity, subtract the first infrared light intensity from the first offset to obtain a corresponding second infrared light intensity.

[0176] After obtaining a first infrared light intensity, the mobile phone subtracts the first infrared light intensity from the first offset to obtain the second infrared light intensity corresponding to the infrared light. The mobile phone can cache multiple second infrared light intensities obtained. For example, if the first offset is 150 lux and the obtained infrared light intensity is 550 lux, the corresponding second infrared light intensity is (550-150) lux = 400 lux.

[0177] S1103, using the first target light intensity to adjust the threshold.

[0178] After obtaining the second infrared light intensity, the proximity threshold and the distance threshold can be adjusted based on the first target light intensity. The first target light intensity is the second infrared light intensity that satisfies the second preset condition. The second preset condition includes: the difference between the second infrared light intensity and one or more second infrared light intensities before and / or after the second infrared light intensity is less than or equal to the first preset value, and the second infrared light intensity is less than the first threshold and greater than the second threshold. The first threshold is the difference between the absolute proximity threshold (min_proximity) and the fixed value 1. The second threshold is the absolute distance threshold (far_threshold).

[0179] After the distance detection module is started, the infrared light intensity obtained by the distance detection module may not be very stable at the beginning of operation. For example, as the startup time increases, the infrared light intensity gradually increases to a stable state. Therefore, in order to obtain a more accurate proximity threshold and a distance threshold, the proximity light service can use the second infrared light intensity corresponding to the stabilized infrared light intensity to adjust the threshold. If the difference between the second infrared light intensity and the second infrared light intensity before and / or after the second infrared light intensity is less than or equal to the first preset value, it means that the second infrared light intensity is the second infrared light intensity corresponding to the infrared light intensity obtained when the operation is stable. Among them, the threshold range of the first preset value can be 0lux-10lux.

[0180] Furthermore, in order to avoid using abnormal data (such as negative values) to update the threshold, the light intensity used to update the threshold should be greater than the absolute distance threshold, that is, the second threshold. The absolute distance threshold is usually set to 0 lux.

[0181] In addition, when the distance detection module in the sensor is blocked, for example, when the mobile phone is in a pocket or placed face down on a table, the infrared light intensity obtained is relatively large. Using the light intensity when blocked to update the approach and distance thresholds may cause the updated approach threshold and distance threshold to have large values, causing the distance detection module to fail to work. For example, the initial approach threshold is 2000 lux, and the initial distance threshold is 1999 lux. Assuming that the mobile phone is placed face down on the table, the first target light intensity is 2500 lux, the fixed value 1 is 100 lux, and the fixed value 2 is 100 lux, the mobile phone will update the distance threshold to the sum of the first target light intensity and the fixed value 1, 2600 lux, and the approach threshold to the sum of the distance threshold and the fixed value 2, 2700 lux. When the user does not move the mobile phone and the mobile phone is still placed face down on the table, the light intensity obtained by the subsequent distance detection module is still 2500 lux, which is less than the distance threshold. The mobile phone will recognize that the object is far away from the mobile phone and turn on the screen, resulting in resource waste and increased power consumption. Therefore, the sum of the infrared light intensity used to update the threshold and the fixed value 1 should be less than the absolute proximity threshold, that is, the second infrared light intensity used to update the threshold is less than the first threshold, to avoid excessive infrared light intensity used to update the threshold. The absolute proximity threshold can be a preset value stored in the sensor, and the mobile phone can read the preset value when it is used for the first time after powering on.

[0182] The sum of the first target light intensity and the fixed value 1 is used as the distance threshold, and the sum of the distance threshold and the fixed value 2 is used as the approach threshold. That is, the distance threshold = the first target light intensity + the fixed value 1. The approach threshold = the distance threshold + the fixed value 2. Exemplarily, the first target light intensity can be, for example, the difference between the sixth infrared light intensity after the first infrared light and the first offset.

[0183] Among them, the fixed value 1=P far -P nocover , fixed value 2 = P near -P far Among them, P far It is the infrared light intensity obtained by the sensor when the obstruction is 5cm away from the sensor. near It is the infrared light intensity obtained by the sensor when the obstruction is 3cm away from the sensor. nocover is the infrared light intensity obtained by the sensor when there is no obstruction. far , P near , P nocover It is the data of the mobile phone tested in the factory before leaving the factory. For example, after starting the distance detection module, the obstruction is placed at a distance of 3 cm and 5 cm from the mobile phone display screen, and P is obtained respectively. near and P far .P nocoverIt is the infrared light intensity when the phone screen is facing the air after the distance detection module is activated. The air can be understood as no obstructions within the preset distance, which can be 1 meter, 3 meters or 5 meters.

[0184] The mobile phone can save the updated distance threshold and approach threshold, and save the infrared light intensity used to update the threshold.

[0185] In this way, after the mobile phone is turned on, when the working mode is switched for the first time and the distance detection module is started, the first offset can be generated and the first threshold calibration can be performed. After the first threshold calibration, the mobile phone can use the threshold after the first calibration to determine the distance between the object and the mobile phone. In the process of using the distance detection module, the mobile phone can also dynamically adjust the threshold.

[0186] For example, when the distance detection module is started for the first time after each startup, the mobile phone can execute S1101-S1103 and cyclically execute the method shown in S1104-S1111. After this startup and before shutdown, when the distance detection module is started again, the mobile phone can cyclically execute the method shown in S1104-S1111. The number of cycles can be at least 1.

[0187] S1104, identifying whether a third preset condition is met.

[0188] The third preset condition is that n consecutive second infrared light intensities are all less than the second preset value. Wherein, n is an integer greater than 1, and illustratively, n can be any value in [1,10]. The value range of the second preset value can be 40lux-80lux. The second preset value is less than the first target reference value.

[0189] If the second infrared light intensity is less than the second preset value, then the first infrared light intensity corresponding to the second infrared light intensity is less than the infrared light intensity used to calculate the offset last time. If n consecutive first infrared light intensities are less than the infrared light intensity used to calculate the offset last time, and the difference between n consecutive first infrared light intensities and the first offset is less than the second preset value, the offset is recalculated.

[0190] If the third preset condition is met, it means that the last infrared light intensity used to calculate the offset (such as the first infrared light intensity) is not the background noise value when there is no obstruction on the surface of the distance detection module. Therefore, it is necessary to update the offset based on the latest smaller light intensity value obtained as the background noise value when the surface of the distance detection module is not obstructed. It should be understood that the light intensity obtained when there is no obstruction on the surface of the distance detection module is less than the light intensity obtained when the surface of the distance detection module is obstructed. If the third preset condition is met, the mobile phone can execute S1105-S1109. If the second preset condition is not met, the mobile phone can execute S1110-S1111.

[0191] S1105, when a third preset condition is met, calculating a second offset according to the third infrared light intensity.

[0192] The third infrared light intensity may be one of the consecutive n second infrared light intensities. For example, the third infrared light intensity may be the maximum value among the consecutive n second infrared light intensities. For another example, the third infrared light intensity may be the minimum value among the consecutive n second infrared light intensities. Preferably, the third infrared light intensity may be the nth second infrared light intensity among the consecutive n second infrared light intensities.

[0193] For example, the first offset is 450lux-300lux=150lux, and the mobile phone obtains 6 consecutive first infrared light intensities of 210lux, 210lux, 200lux, 190lux, 200lux, and 280lux. The mobile phone subtracts these 6 first infrared light intensities from the first offset, and obtains the corresponding second infrared light intensities of 60lux, 60lux, 50lux, 40lux, 50lux, and 30lux. At this time, the mobile phone recognizes that the third preset condition is met and the offset needs to be recalculated. Specifically, the mobile phone recalculates the second offset based on the third infrared light intensity of 30lux. The first infrared light intensity corresponding to the third infrared light intensity of 30lux is 280lux. The mobile phone determines that the second target reference value corresponding to the first infrared light intensity of 280lux is 1lux, then the second offset is the difference between 280lux and 1lux, 179lux.

[0194] For another example, the first offset is 800lux-300lux=500lux, and the mobile phone obtains 6 consecutive first infrared light intensities of 560lux, 500lux, 550lux, 540lux, 560lux, and 530lux. The mobile phone subtracts the first offset from the 6 first infrared light intensities, and obtains the corresponding second infrared light intensities of 60lux, 0lux, 50lux, 40lux, 60lux, and 30lux. At this time, the mobile phone recognizes that the third preset condition is met, and the mobile phone determines that the first infrared light intensity corresponding to the third infrared light intensity is 530lux. The mobile phone determines that the second target reference value corresponding to the first infrared light intensity of 530lux is 300lux, then the second offset is the difference between 530lux and 300lux, which is 130lux. The second target reference value is one of multiple reference values. The second target reference value is less than the first infrared light intensity corresponding to the third infrared light intensity, and the difference between the first infrared light intensity corresponding to the third infrared light intensity and the second target reference value is the smallest.

[0195] S1106, using the third infrared light intensity to adjust the threshold.

[0196] If the third preset condition is met, it means that the infrared light intensity used to adjust the threshold last time is not the noise floor value when there is no obstruction on the surface of the distance detection module. After obtaining a smaller infrared light intensity, the mobile phone can use the infrared light intensity as the noise floor value when there is no obstruction on the surface of the distance detection module to adjust the threshold. For example, the distance threshold = the third infrared light intensity + the fixed value 1. The approach threshold = the distance threshold + the fixed value 2.

[0197] S1107, after obtaining an infrared light intensity, subtract the infrared light intensity from the second offset to obtain a corresponding fourth infrared light intensity.

[0198] S1108, identifying whether a fourth preset condition is met.

[0199] The fourth preset condition may be: the maximum fourth infrared light intensity among the continuous m fourth infrared light intensities is less than the infrared light intensity (third infrared light intensity) of the last updated threshold, and the maximum fourth infrared light intensity is greater than the absolute distance threshold (second threshold). Wherein, m is an integer greater than 1, and exemplary, m may be 10. The third condition may also include: the difference between the maximum fourth infrared light intensity and the minimum fourth infrared light intensity among the continuous m fourth infrared light intensities is less than or equal to the third preset value, wherein the threshold range of the third preset value is 40lux-80lux. Satisfying the third condition indicates that the infrared light intensity (such as the third infrared light intensity) used to update the threshold last time is not the background noise value when there is no obstruction on the surface of the distance detection module. It should be understood that the noise value obtained when there is no obstruction on the surface of the distance detection module is smaller than the noise value obtained when there is obstruction. Only by using the real noise value obtained when there is no obstruction can the threshold of the distance detection module be adjusted more accurately. Therefore, when the mobile phone uses the distance detection module, it continuously obtains a smaller infrared light intensity, and uses the smaller infrared light intensity as the noise value obtained when there is any obstruction to update the threshold of the distance detection module.

[0200] S1109: When the fourth preset condition is met, the threshold is updated using the second target light intensity.

[0201] The second target light intensity is one of the m consecutive fourth infrared light intensities. For example, the second target light intensity is the maximum fourth infrared light intensity among the m consecutive fourth infrared light intensities. For another example, the second target light intensity is the minimum fourth infrared light intensity among the m consecutive fourth infrared light intensities.

[0202] For example, the distance threshold = the second target light intensity + the fixed value 1. The proximity threshold = the distance threshold + the fixed value 2.

[0203] If the second preset condition is not met, it means that the infrared light intensity used to adjust the threshold last time is the background noise value when there is no shielding on the surface of the distance detection module. The mobile phone can further execute S1110.

[0204] S1110, identifying whether a fifth preset condition is met.

[0205] The fifth preset condition may be: the maximum second infrared light intensity among the m consecutive second infrared light intensities is less than the infrared light intensity of the last updated threshold (such as the first target light intensity), and the maximum second infrared light intensity is greater than the absolute distance threshold (the second threshold). Wherein, m is an integer greater than 1, and illustratively, m may be 10. The fifth preset condition may also include: the difference between the maximum second infrared light intensity and the minimum second infrared light intensity among the m consecutive second infrared light intensities is less than or equal to the third preset value, wherein the threshold range of the third preset value is 40lux-80lux.

[0206] If the fifth preset condition is met, it means that the infrared light intensity (such as the first target light intensity) used to update the threshold last time is not the background noise value when there is no obstruction on the surface of the distance detection module. It should be understood that the noise value obtained when there is no obstruction on the surface of the distance detection module is smaller than the noise value obtained when there is obstruction. Only by using the real noise value obtained when there is no obstruction can the threshold of the distance detection module be adjusted more accurately. Therefore, when the mobile phone uses the distance detection module, it continuously obtains a smaller infrared light intensity, and uses the smaller infrared light intensity as the noise value obtained when there is any obstruction to update the threshold of the distance detection module.

[0207] S1111 , when the fifth preset condition is met, use the third target light intensity to update the threshold.

[0208] The third target light intensity is one of the m consecutive second infrared light intensities. For example, the third target light intensity is the maximum fourth infrared light intensity among the m consecutive second infrared light intensities. For another example, the third target light intensity is the minimum second infrared light intensity among the m consecutive second infrared light intensities.

[0209] For example, the distance threshold = the third target light intensity + the fixed value 1. The proximity threshold = the distance threshold + the fixed value 2.

[0210] Optionally, if the fourth preset condition is not met, the mobile phone may re-execute S1104. Optionally, if the fifth preset condition is not met, the mobile phone may re-execute S1104.

[0211] Optionally, m is greater than n, for example, n is 6 and m is 10. That is, it is prioritized to identify whether the previously determined offset is appropriate, and if the previously determined offset is not appropriate, the offset needs to be re-determined.

[0212] An embodiment of the present application provides an electronic device, which includes: a memory, a display screen, one or more processors, and a sensor; the sensor includes an ambient light detection module and a distance detection module; the ambient light detection module is used to obtain the ambient light intensity of the environment in which the electronic device is located; the distance detection module is used to emit infrared light and obtain the infrared light intensity of reflected infrared light; the memory, the sensor, and the display screen are coupled to the processor; wherein the memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device can execute each function or step executed by the mobile phone in the above method embodiment.

[0213] An embodiment of the present application also provides a computer storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned server, the electronic device executes each function or step in the above-mentioned method embodiment.

[0214] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute each function or step in the above method embodiment.

[0215] The embodiment of the present application also provides a chip system, which includes at least one processor and at least one interface circuit. The processor and the interface circuit can be interconnected through lines. For example, the interface circuit can be used to receive signals from other devices (such as the memory of the electronic device). For another example, the interface circuit can be used to send signals to other devices (such as processors). Exemplarily, the interface circuit can read instructions stored in the memory and send the instructions to the processor. When the instruction is executed by the processor, the electronic device can execute the various steps in the above embodiments. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiment of the present application.

[0216] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0217] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0218] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0219] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0220] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0221] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A sensor calibration method, characterized in that: Applied to an electronic device, the electronic device comprises a display screen and a sensor; the sensor has an ambient light detection function and a distance detection function; the sensor comprises an ambient light detection module and a distance detection module; the ambient light detection module is used to obtain the ambient light intensity of the environment in which the electronic device is located; The distance detection module is used to emit infrared light and obtain the infrared light intensity of the reflected infrared light; the method includes: When the display screen is in a bright screen state, controlling the ambient light detection module to operate; When the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, the distance detection module and the ambient light detection module are controlled to work in series and start timing synchronously; wherein, when working in series, the distance detection module works first, and the ambient light detection module and the distance detection module work alternately; From the moment when the timing is started to a first preset time, a first infrared light intensity is obtained; the first preset time is less than or equal to the signal detection time of the ambient light detection module; The distance detection module in the sensor is calibrated according to the first infrared light intensity.

2. The method according to claim 1, characterized in that: The signal detection duration is the signal integration duration, and when the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, controlling the distance detection module and the ambient light detection module to work in series and start timing synchronously includes: When the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, the ambient light detection module writes the ambient light intensity obtained after completing signal integration to a preset position, and then controls the distance detection module and the ambient light detection module to work in series and start timing synchronously.

3. The method according to claim 2, characterized in that When the display screen is in a bright screen state, controlling the ambient light detection module to work includes: Recognize that the display screen is on, start the ambient light detection module, and set the first flag bit to the first flag; When the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, after the ambient light detection module writes the acquired ambient light intensity to a preset position, controlling the distance detection module and the ambient light detection module to work in series to start timing, includes: When the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, setting the first flag bit to a second flag; After the ambient light detection module writes the acquired ambient light intensity into a preset position, reading the first flag bit; When the first flag is the second flag, the distance detection module and the ambient light detection module are controlled to work in series and start timing.

4. The method according to claim 1, characterized in that: When the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, controlling the distance detection module and the ambient light detection module to work in series and start timing, includes: When the electronic device enters a voice call state or the display screen of the electronic device enters a screen-on / lock state, controlling the ambient light detection module to stop working; After the ambient light detection module stops working, the distance detection module and the ambient light detection module are controlled to work in series and start timing.

5. The method according to claim 1, characterized in that The method further comprises: Taking the first preset time as a period, periodically acquiring the first infrared light intensity detected by the distance detection module; The step of calibrating the distance detection module in the sensor according to the first infrared light intensity includes: A first offset is obtained according to the first infrared light intensity; the first offset is the difference between the first infrared light intensity and a first target reference value; the electronic device is preset with a plurality of reference values, the first infrared light intensity is greater than the first target reference value, and the difference between the first infrared light intensity and the first target reference value is the smallest; the plurality of reference values ​​include the first target reference value; Subtract each of the first infrared light intensities obtained from the first offset to obtain a corresponding second infrared light intensity; The approach threshold and the distance threshold of the distance detection module are adjusted according to the first target light intensity; the first target light intensity is a second infrared light intensity that satisfies a second preset condition; the second preset condition includes: the difference between the second infrared light intensity and one or more second infrared light intensities before and / or after the second infrared light intensity is less than or equal to a first preset value; the second infrared light intensity is less than a first threshold value and greater than a second threshold value.

6. The method according to claim 5, characterized in that The method further comprises: In the case where a third preset condition is met, a second offset is obtained according to the third infrared light intensity; the second offset is the difference between the first infrared light intensity corresponding to the third infrared light intensity and the second target reference value; the first infrared light intensity corresponding to the third infrared light intensity is greater than the second target reference value, and the difference between the first infrared light intensity corresponding to the third infrared light intensity and the second target reference value is the smallest; the multiple reference values ​​include the second target reference value; The third preset condition includes that n consecutive second infrared light intensities are all less than a second preset value; the third infrared light intensity is one of the n consecutive second infrared light intensities; wherein n is an integer greater than 1; The approach threshold and the distance threshold of the distance detection module are adjusted according to the third infrared light intensity.

7. The method according to claim 6, characterized in that The method further comprises: Subtract each of the first infrared light intensities obtained from the second offset to obtain a corresponding fourth infrared light intensity; When a fourth preset condition is met, the second target light intensity is used to adjust the approach threshold and the distance threshold of the distance detection module; the fourth preset condition includes: the largest fourth infrared light intensity among the m consecutive fourth infrared light intensities is less than the infrared light intensity of the last threshold update, and the largest fourth infrared light intensity is greater than the second threshold, and the difference between the largest fourth infrared light intensity and the smallest fourth infrared light intensity among the m consecutive fourth infrared light intensities is greater than or equal to a third preset value; wherein m is an integer greater than 1; The second target light intensity is one of the consecutive m fourth infrared light intensities.

8. The method according to claim 6, characterized in that The method further comprises: When the third preset condition is not satisfied and the fifth preset condition is satisfied, the approach threshold and the distance threshold of the distance detection module are adjusted using the third target light intensity; the fifth preset condition includes: the maximum second infrared light intensity among the m consecutive second infrared light intensities is less than the infrared light intensity of the last threshold update, and the maximum second infrared light intensity is greater than the second threshold value, and the difference between the maximum second infrared light intensity and the minimum second infrared light intensity among the m consecutive second infrared light intensities is greater than or equal to the third preset value; wherein m is an integer greater than 1; The third target light intensity is one of the m consecutive second infrared light intensities.

9. An electronic device, characterized in that: The electronic device includes: a memory, a display screen, one or more processors, and a sensor; the sensor includes an ambient light detection module and a distance detection module; the ambient light detection module is used to obtain the ambient light intensity of the environment in which the electronic device is located; the distance detection module is used to emit infrared light and obtain the infrared light intensity of the reflected infrared light; the memory, the sensor, and the display screen are coupled to the processor; wherein the memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 8.

11. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.