Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recycling sensors from a broken android device using adb

I just broke my s3. 3 years ago it was one of the best smartphones.

Question How can I get the values from the inertial sensors of the phone via usb?

I would like to use the accelerometer, gyroscope, magnetometer, barometer and gps sensors of the device.

Let's say that we want to get:

  • the raw acceleration's data along the three axes.

I connected the usb cable and ran adb root and adb shell. Ok.

root@android:/ # find / -type d -iname "sensors"                           
/sys/devices/virtual/sensors
/sys/class/sensors

The '/sys/class/sensors' directory contains:

root@android:/ # ls sys/class/sensors                                          
accelerometer_sensor
barometer_sensor
gyro_sensor
light_sensor
magnetic_sensor
proximity_sensor

The problem

The raw measurements do not change even if I tilt the phone. The sensor is in standby mode. It always displays the same values.

root@android:/sys/class/sensors/accelerometer_sensor # cat raw_data            
-74,121,1016

I have noticed the folder power/control which controls the power state of the sensor.

root@android:/sys/class/sensors/accelerometer_sensor # cat power/control       
auto

I tried with echo on/yes/ok/yeah/wtf > power/control but nothing changed.

I remember that when I had the screen of the phone working, it was sufficient to open an Android application with sensors' permissions, like Google Maps with the compass feature, to Enable the sensors and get the values refreshed at a constant rate. The Java application probably writes something in a file to activate the sensors and reads the raw values.

How can I activate the sensors from the shell?

like image 687
UserK Avatar asked Oct 19 '22 22:10

UserK


1 Answers

Using

root@:/ # getevent -S

You can get the list of all sensor.. look for one called "proximity_sensor" and retrieve device name. Ex.

root@:/ # getevent -S
add device 1: /dev/input/event11
  name:     "compass_sensor"
add device 2: /dev/input/event8
  name:     "barometer_sensor"
add device 3: /dev/input/event7
  name:     "light_sensor"
add device 4: /dev/input/event6
  name:     "proximity_sensor"

As you can see your device is aliased as "event6"

Now, go inside directory /sys/class/input/input6

cd /sys/class/input/input6
echo 1 > enable # TO ACTIVATE THE SENSOR
echo 0 > enable # TO TURN IT OFF AGAIN
like image 96
Micko Avatar answered Nov 03 '22 17:11

Micko