[Q] proximity sensor accurate values - Galaxy S 4 Q&A, Help & Troubleshooting

Hi,
using the service diagnostic application on my s4 I can read a range of values (ADC) from proximity sensor spanning from 0 to 255 (they are more or less proportional to the object distance). Is there a method to get this values within a native (or ndk) app. With the standard android api I get only near/far value.
Thanks,
Marco

marco.co said:
Hi,
using the service diagnostic application on my s4 I can read a range of values (ADC) from proximity sensor spanning from 0 to 255 (they are more or less proportional to the object distance). Is there a method to get this values within a native (or ndk) app. With the standard android api I get only near/far value.
Thanks,
Marco
Click to expand...
Click to collapse
*#0*#
Sensors.
"If someone helps, never forget to hit thanks ? "

DeepankarS said:
*#0*#
Sensors.
"If someone helps, never forget to hit thanks ? "
Click to expand...
Click to collapse
I know that, I would like to replicate the same behaviour by code into one of my apps.

Related

[APP]Water-level/spirit-level

Current version is SpiritLevel_0.9.1.zip http://forum.xda-developers.com/attachment.php?attachmentid=98776
Now I re-engineered the spirit level app a little bit.
It can now also show the raw X, Y and Z tilt data. Thus, you can easily see how much the g-sensor might need to be calibrated. Just check the option "Show Raw Sensor Data" from the menu.
Calibrating for this app ONLY available in SpiritLevel_SVC0.9.zip
works very well, thx!
Great little App, nice one! The trick is using it on a surface that is flat and level to get an accurate reading.
Putting it on my desk at work:
x: 1 degree
y: 7 degree
x Tilt: -19
y Tilt: 117
z Tilt: -879
This keeps changing tho, which would indicate that the surface isnt very level.
Also looking at where the indicators are, it looks slightly off, but not enough to worry me thinks.
Congrats on the useful little app. Cheers!
Great app, but what if the g-sensor is not completely accurate?
as in this thread
http://forum.xda-developers.com/showthread.php?t=405691&highlight=sensor
Well, I could add an option that (somehow) calibrates the g-sensor, but only for this app. E.g. a menu entry "Calibrate" which, then asks you to put it on a perfect spot with 0° on X and Y axis and then maybe to 90 ° on X and Y axis. Maybe it will come - depends on my time. Maybe there is also a registry entry for this for the g-sensor.
fxxxxxx said:
Well, I could add an option that (somehow) calibrates the g-sensor, but only for this app. E.g. a menu entry "Calibrate" which, then asks you to put it on a perfect spot with 0° on X and Y axis and then maybe to 90 ° on X and Y axis. Maybe it will come - depends on my time. Maybe there is also a registry entry for this for the g-sensor.
Click to expand...
Click to collapse
thanks ;-)
Menkul
GREAT app ;-)
And even better if a calibration option is added.
This would help alot of people
fxxxxxx said:
Well, I could add an option that (somehow) calibrates the g-sensor, but only for this app. E.g. a menu entry "Calibrate" which, then asks you to put it on a perfect spot with 0° on X and Y axis and then maybe to 90 ° on X and Y axis. Maybe it will come - depends on my time. Maybe there is also a registry entry for this for the g-sensor.
Click to expand...
Click to collapse
this would be a great option. Currently the app displays x tilt: 270 when my phone is laying down on my desk. and it would be great if i could calibrate it from this position so that X an Y are back to 0
Ok, there is a new version in post #1. With that version you can calibrate the g-sensor, but ONLY for the spirit-level/water-level application. Currently it has no other effect. I am not sure if there is a way to "calibrate" the g-sensor globally.
On the table in my office I get:
X: 3-4°
Y: 355-357°
X Tilt: -59
Y Tilt: -59
Z Tilt: 820
But the values are not steady, even if I do not move the device the numbers
are changing about twice a second.
Do others have the same behavior?
Yes, it is the same behavior here.
X: 2-3°
Y: 357-359°
X Tilt: ~ -39
Y Tilt: ~ -19
Z Tilt: ~ -938
Keep in mind, that 358 ° is only 2° from 0 ° away.
cool app
TML1504 said:
On the table in my office I get:
X: 3-4°
Y: 355-357°
X Tilt: -59
Y Tilt: -59
Z Tilt: 820
But the values are not steady, even if I do not move the device the numbers
are changing about twice a second.
Do others have the same behavior?
Click to expand...
Click to collapse
I have the same experience regarding the switching values.
fxxxxxx said:
Keep in mind, that 358 ° is only 2° from 0 ° away.
Click to expand...
Click to collapse
yop, thats clear!
at least i hope so...
if not i would have to return my degree in mechanical engineering
TML1504 said:
if not i would have to return my degree in mechanical engineering
Click to expand...
Click to collapse
me too
sorry for OT
nice software
ykat said:
cool app
I have the same experience regarding the switching values.
Click to expand...
Click to collapse
Me 2.............
X: 353
Y: 8
X Tilt:96
Y Tilt: 136
Z Tilt: -899
X: 0
Y: 2
X Tilt: 0 (+/- 5)
Y Tilt: 37 (+/-2)
Z Tilt: -770 (+/-15)
Not so bad ^_^
And, as Diamond back cover isn't really flat, I tried watch results when the face of the Diamond was on my desk... hum... not transparent huhu. So I launched Resco Screen Capture (comes with Resco Photo Viewer) and take the screen after 10sec (I made 5 test)
Results :
X: 180 (only 1 time with 179)
Y: 179 (1° better )... and one time : 180°
X Tilt:0 (each time)
Y Tilt : ~8 (different values : 18, 18, 8, 8, 3)
Z Value : ~1200 (different values : 1206, 1206, 1201, 1190, 1172)
Calibration bug fixed, new version in post #1
yess! very good, now it's a real tool for my job. But i've question : the calibrating function is very important for the diamonds missaligned. But can you add an option for saving data after calibrating? it isn't possible to calibrate in any situation and it can be fun to have a single calibration a the first start of spirit-level... thanks by advance and sorry for my bad english

Can you sample a vertical movement of the device?

I'm trying to sample a gesture of physically moving the device up and down (not necessarily tilting it) - is this possible?
The only values that i get either from the accelerometer/orientation/magnetometer is from tilting the device..
yes.
download "Sensor Test" from the market to see what sensor data is available to your program
sensing a jerk is easy simply root sum squates (RSS) the accelerometer values and test against some threshold.
If you want to know up from down you need to rotate the acceleration values by the normalized orientation vector.
Then integrate acceleration with respect to time.
p = (1/2)at^2 + vt +p;
if you want relative sample to sample movements you can simplify by assigning initial conditions to 0... thus
p = 1/2at^2.
p = change in position
t = change in time from sample to sample.
now the accelerometer is probably only accurate to 0.1 G which is very poor
so don't expect super accurate distances.
machine learning gesture algorithm
Thanks, but unfortunately "elevator" like movements can't be detected by simply using any of the sensors.
i guess for that you'll need to manipulate some data using the device's camera.
or for a simpler solution, check if any natural vertical movement is joined with some tilt to the device which can be easily sensed by any of the built in sensors.
But for anther topic, do you know by any chance where could i find a working machine learning gesture algorithm?

[INFO] Auto-Backlight Settings for Cyanogenmod ROMs

Some of you would already know that the lightsensor filter in the Evo kernels is now working ( I would say atleast 80% working ) and responds best to Desire builds.
I have it working just fine for the last few hours on the AndroidMedaUltimate 1.3 version. Here are my settings in case you wanna try out.
CAUTION : If you change the values too many times, lightsensor stops responding and you will not see any changes in values. I believe thats CM related.
My Setup
Build : AndroidMedaUltimate 1.3
Kernel : StockEvo Autobuild dated Oct 29
(No SetCpU/taskkillers/etc)
1. Make sure Auto Brightness is disabled under Settings->Display
2. Goto Settings->Cyanogenmod Settings->User Interface->Automatic Backlight
3. Under Light Sensor filter, make sure Enabled is unchecked (No filters!)
4. Under Light levels, check "Allow Light Decrease" and set "Decrease hysteresis" to 0% (Yes thats no typo, for some reason sensor responds faster this way )
5. Check "Use Custom"
6. Tap on Edit Other Levels...
7. Now set values as in below screenshot and table
Lower ....... Upper ............Screen...........Buttons
0 ____________ 169 _______________ 85 _____________ 255
170 __________ 279 _______________ 120 ____________ 255
280 __________ 749 _______________ 170 ____________ 255
800 __________ () _______________ 254 ____________ 255
Note - The last value is 254, for some reason when I had it as 255 and went outside, brightness got stuck at max and sensor stopped responding
Click to expand...
Click to collapse
8. Tap Save & Apply
9. Wait for few seconds and try covering and changing light, you should see the sensor values change on top
10. Once that starts happening, enable Auto Brightness under Display settings
11. Reboot (Best Practice )
---------------
You can add more levels and adjust the lower/upper range alongwith the Screen values (30-255) to suit you better. However, the more you change it the more its likely to end up not working. Dont know why.
Interesting, will be testing this today with Shubcraft 2.0 and post my findings.
thanks, done the changes and testing with Htcclays V1.4.
edit: it is working very well for me.no lightsensor issue for me.
many thanks for your tip.
Thank you works grat
v-b-n said:
1. Make sure Auto Brightness is disabled under Settings->Display
2. Goto Settings->Cyanogenmod Settings->User Interface->Automatic Backlight
3. Under Light Sensor filter, make sure Enabled is unchecked (No filters!)
4. Under Light levels, check "Allow Light Decrease" and set "Decrease hysteresis" to 0% (Yes thats no typo, for some reason sensor responds faster this way )
5. Check "Use Custom"
6. Tap on Edit Other Levels...
7. Now set values as in below screenshot and table
8. Tap Save & Apply
9. Wait for few seconds and try covering and changing light, you should see the sensor values change on top
10. Once that starts happening, enable Auto Brightness under Display settings
11. Reboot (Best Practice )
---------------
You can add more levels and adjust the lower/upper range alongwith the Screen values (30-255) to suit you better. However, the more you change it the more its likely to end up not working. Dont know why.
Click to expand...
Click to collapse
Thanks very much for this, a few questions if you please.....
I'm using Typhoon 3.8.0.
I'm finding these settings under
Settings->Cyanogenmod Settings->Display->Automatic Backlight
not
Settings->Cyanogenmod Settings->User Interface->Automatic Backlight
And I don't know if that has any underlying significance - like it not being implemented in the same way in Typhoon?
Secondly you don't mention the "screen dim level" setting I see in the same "Display" menu. I've wound it down to 6 (default is 20), but not seeing much difference?
Thirdly, I've used the settings in the "other levels" as your table shows, but I wonder why you used those settings, what drove you to pick those numbers?
Finally, you talk about changing it too much stopping it working....when that happens what do you do to revert? Reboot? Or return to defaults and reboot? or something else?
Thanks, I'm hoping this will help balance out the fact that up to now I've not used auto-brightness so as to keep the battery life up but it's a bit of a pain in bright light to see the screen....
Thanks

[Q] LED Flashlight code

Ive tried so many ways to have the led flash light to turn on in one of my apps, but every code i try fails. Can any one please give me some type of example code?
I'm no programmer but I looked around in the Android API documentation and found this:
http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FLASH_MODE_TORCH
And after 2minutes of googling I found this on the forum:
Code:
echo 125 > /sys/devices/platform/flashlight.0/leds/flashlight/brightness
From: http://forum.xda-developers.com/showpost.php?p=6305305&postcount=8
It's phone specific
Motorola you need to use some reflection like this:
http://code.google.com/p/droidled/s...com/droidled/demo/DroidLED.java?spec=svn2&r=2
HTC you can echo to the /sys/devices as patric.f mentioned
Nexus One/Galaxy S you can use FLASH_MODE_TORCH (also as patric.f mentioned)
Alternatively, if your app is focusing on something else and you don't want to deal with supported every device's flash light method, my TeslaLED app accepts service intents:
if you do a startService with an action of:
com.teslacoilsw.intent.FLASHLIGHT
You can attach a boolean extra with a key of "on", "off" or "toggle"
and a value of true to turn the flashlight on or off.
Strobe can be done by using an int extra of "strobe" followed by the
rate in Hz.

[Hack]Improved Hardware Auto Brightness

This is a hacky fix but it is a fix.
It gives you a backlight that will go from dim to full bright without the need for any other apps running. It's not uber configurable like dedicated apps as it's limited by hardware but it requires 0 ram, 0 runtime and 0 battery
Append the following to hw_config.sh. The sleep is a hack but a viable one - hw_config is fired up by one of the rc files as a oneshot service so it should be OK to extend it's operation
If you prefer you could just make a standalone script with everything after the sleep command (make sure you have the dev= assignment from hw_setup too!) and fire it off with a script executer of your choice
Code:
#this sleep ensures that the system is up and done [email protected] with light levels before setup
sleep 30
#select als group for backlight
echo 1 > $dev/leds/lcd-backlight1/als_group
echo 1 > $dev/leds/lcd-backlight2/als_group
#set both to max. brightness - als will lower
echo 255 > $dev/leds/lcd-backlight1/brightness
echo 255 > $dev/leds/lcd-backlight2/brightness
#set custom als curve
echo 7,1,48,72,24,255,0 > $dev/als_group1
#set custom filter frequency
echo 1000 > $dev/als_filter_down_speed_mHz
echo 1000 > $dev/als_filter_up_speed_mHz
#turn on hardware als
echo 1 > $dev/als_on
Notes
Make sure you have completely uninstalled any other light controllers - Velis in particular wreaks havoc even when disabled - it still receives the screen on intent and resets the brightness which results in a black display - guess how I know ....
Make sure you have disabled auto brightness control in the standard Sony settings and set the slider to full bright for good measure
I use nobootanimation so my phone boots a bit quicker than some. It might be that sleep 30 isn't long enough for an animated startup
Best thing is probably to create a setup script and run that to satisfy yourself the hack works. Then add it to hw_config and increase the delay if it doesn't work!
If you want to know more about the als setup check HERE or read the AS3677 datasheet.
Sadly I wasn't able to find out how the ALS curves are loaded into the current system, hence the direct hardware poking
There's some useful debug capability built into the sysfs
cat $dev/debug to see light sensor outputs and calculated backlight settings
cat als_group1 to read back the curve settings complete with a graph showing the response curve
A software guy could probably easily make an apk that hooked to the SCREEN_ON intent to program all this (and have a nice gui to show/edit the curve) but I'm a hardware engineer so that ain't me!
It's easier to just use Lux. Thanks anyway.
pakatsui said:
It's easier to just use Lux. Thanks anyway.
Click to expand...
Click to collapse
LUX, YAB or other brightness app will don`t work correct on all my Xperias. Only with "system brightness settings" active in the background this apps will change the brightness in realtime. When i close the systemsettings brightness will change no longer or with some luck once when unlocking.
so i will test this Hack, hope it helps to become a wide range in realtime.
heross said:
LUX, YAB or other brightness app will don`t work correct on all my Xperias. Only with "system brightness settings" active in the background this apps will change the brightness in realtime. When i close the systemsettings brightness will change no longer or with some luck once when unlocking.
so i will test this Hack, hope it helps to become a wide range in realtime.
Click to expand...
Click to collapse
Lux works fine. I'm using it now.
Sent from my Xperia SP using xda premium
Hello t_o_f,
today i have made test this fix in Car navigation from sunlight to the moon. awesome. this is the best fix i have always seen for xperia autobrightness. :good::laugh::good: ten points from germany.
the best, lowest brightness it is configurable with the Stock slider!
Call me daft. I disabled auto brightness, jacked the brightness to high, and have no other brightness apps installed. I appended the above to /etc/hw_config.sh and rebooted.
auto brightness didn't work. It was still jacked up to high so I enabled it and tested, still not working. Did I do something wrong? I'm on 254 rooted.

Categories

Resources