Originally Posted by marcmy
... it seems to go back to being broken when I reboot the phone. Is there any way to prevent this? Also the *#0*# doesn't work for me and the cat command returns just a 0. Thanks.
EDIT: it might help to note that I'm running cyanogenmod 10.1 nightly now
EDIT2: I figured it out! I did a search for prox_cal and found one in /sys/devices/virtual/sensors/proximity_sensor with the values 18,9. i put those values in the empty /efs/prox_cal. It now works on boot.
I described the sensor recalibration on Samsung rom or Samsung based roms. " *#0*# "is a "secret code" that starts a samsung test tool - only included in stock or stock rom based.
I have read from other users that "cat state" returns zero. I don't know exactly why. But it could be because:
1. that the sensor is powered down (on my phone the sensor never sleeps)
2. the calibration offset is too high
3. the calibration offset is optimal
To test the sensor is on and working you should read the value with finger put on. (there should be value around 127-calibration offset). I guess to do the calibration/sensor reading with display on and phone unlocked. Another user told me that it helped to start an app which reads the sensor values (so the sensor wake up).
But in your case proximity_sensor with the values 18,9 means that the sensor is already calibrated to 18 which can cause a zero at "cat state".
Note that the offset is read from file calibration file at boot time and from that on holded in ram. The RAM value can only be influenced by "/sys/class/sensors/proximity_sensor/prox_cal" or by calibration file (on boot). The auto calibration process not only try to create a /efs/prox_cal file but also changes the calibration value in ram at run time .
So if you try "echo 0 > /sys/class/sensors/proximity_sensor/prox_cal; echo 1 > /sys/class/sensors/proximity_sensor/prox_cal" -> "mmh auto calibration does not work there is no prox_cal file, i will try it manually" can be the wrong way because the calibration offset can be already changed to a calibrated value and so you wont get the correct blank value read out "state".
The other path in virtual filesystem to the sensor control you mentioned is also correct. I don't know which is the most common one.
But since both pathes are available in samsung stock i guess it should be " /sys/devices/virtual/sensors/proximity_sensor".
Be careful of putting in the calibration value manually. In Samsung stock rom the kernel which is reading the calibration value at boot time don't make a character conversion. So if you write the config file like this:
echo '18,9' > /efs/prox_cal
Ends Up with Calibration value of 49 because the kernel will read the first byte of file. This is a "1" which is the ASCII code for "0x31" which is 49 in decimal. That should work too but throw away half of the sensor sensivity.
If you would like to calibrate it manually you have to:
Read the blank value ( glass have to be clean and fingers away from sensor ).
$ cat state #finger on the sensor to test if the sensor is working properly
$ cat state #blank value
Read the actual configuration:
The first value is the "sensor offset" and the second one is "Cancelation Threshold" (threshold can not stored in calibration file)
So you calculate your calibration value: 0 (actual sensor offset) + 10 (blank value) = 10 (new offset) = 0x0a
HEX. Make shure your efs partition is mounted writeable and then:
$ echo -en $'\x0a' > /efs/prox_cal
If the prox_cal is created first you should change the permisssions. Kernel sets 666 by default :
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
After reboot you can confirm the calibration
$ cat /sys/devices/virtual/sensors/proximity_sensor/prox_cal
$ cat /sys/devices/virtual/sensors/proximity_sensor/state
If you have to calibrate to a lower sensor value and want to do it the "manual way" you have to reset the calibration or delete the calibration file and reboot. because state value = sensor value - offset . And if offset gets to big the state is alway zero.