Skip to content

Commit

Permalink
Fix occasional unwanted display rotations.
Browse files Browse the repository at this point in the history
A number of people were complaining about display rotations when holding
the phone perfectly upwards and speaker activity, such as a ringtone
playing or a YouTube video playing. Fix that by

- Adding only one accelerometer to the sensor list.
Previously, both the AK8973 and the KXTF9 accelerometer were advertised
to the sensor service. Only the KXTF9 was actually used, but the AK8973
one was listed first, so the service picked up this one. This led to a
mismatch of sensor values and advertised value range.

- Dropping the KXTF9 orientation sensor code.
Due to limited precision and the fact that the KXTF9 orientation sensor
is 2-axis only, we weren't using the sensor anyway (at least we didn't
advertise it). Nevertheless, the kernel driver sent events, which we
handled and pushed to the service. While doing so, we shared the event
structure, which (at least could) lead to wrong data being sent to the
service (e.g. accelerometer precision was always sent as UNRELIABLE =
0). Stop doing that and handle only the accelerometer in the KXTF9
driver.

Change-Id: I3b3f1955c855ab1a81785767ce616d33713de341
  • Loading branch information
maniac103 authored and Quarx2k committed Apr 2, 2012
1 parent ba952bc commit 9c8326b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 79 deletions.
43 changes: 3 additions & 40 deletions libsensors/SensorKXTF9.cpp
Expand Up @@ -138,59 +138,22 @@ void SensorKXTF9::processEvent(int code, int value)
{
int state;

mPendingEvent.orientation.status = 0;
switch (code)
{
case ABS_X:
mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
mPendingEvent.acceleration.x = value * KXTF9_CONVERT_A_X;
break;
case ABS_Y:
mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
mPendingEvent.acceleration.y = value * KXTF9_CONVERT_A_Y;
break;
case ABS_Z:
mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
mPendingEvent.acceleration.z = value * KXTF9_CONVERT_A_Z;
break;

case ABS_MISC: //0x28
mPendingEvent.orientation.status = SENSOR_STATUS_ACCURACY_HIGH;
mPendingEvent.type = SENSOR_TYPE_ORIENTATION;
/*
Orientation event values:
Pitch(Y)
0x01 screen down 0°
0x02 screen up 0°
Roll (Z)
0x04 portrait, normal use 0°
0x08 portrait, reversed 180°
0x10 landscape, usb port up 270° (-90°)
0x20 landscape, usb port down 90°
*/
state = value & KXTF9_SENSOR_ROTATION_MASK; //0x3F

// roll is the orientation used to rotate screen
if (state == 0x04)
mPendingEvent.orientation.roll = 0;
else if (state == 0x8)
mPendingEvent.orientation.roll = 2;
else if (state == 0x10)
mPendingEvent.orientation.roll = 3;
else if (state == 0x20)
mPendingEvent.orientation.roll = 1;

// pitch is the other horizontal rotation
mPendingEvent.orientation.pitch = (value & 0x3);

// azimuth (vertical rotation) is not handled by this sensor event

LOGV("SensorKXTF9: orientation event (code=0x%x, value=0x%x) state=0x%x", code, value, state);

case ABS_MISC:
/* KXTF9 also sends some kind of orientation events -> drop them */
break;

default:
LOGE("SensorKXTF9: unknown event (code=0x%x, value=0x%x)", code, value);
break;
Expand Down
6 changes: 4 additions & 2 deletions libsensors/nusensors.cpp
Expand Up @@ -69,9 +69,11 @@ struct sensors_poll_context_t
switch (handle)
{
case SENSOR_TYPE_ACCELEROMETER:
//case SENSOR_TYPE_ORIENTATION:
#ifdef USE_KXTF9_ACCELEROMETER
return KXTF9;
//case SENSOR_TYPE_ACCELEROMETER:
#else
return AK8973;
#endif
case SENSOR_TYPE_ORIENTATION:
case SENSOR_TYPE_MAGNETIC_FIELD:
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
Expand Down
29 changes: 8 additions & 21 deletions libsensors/nusensors.h
Expand Up @@ -44,6 +44,14 @@ int init_nusensors(hw_module_t const* module, hw_device_t** device);

/*****************************************************************************/

/*
* The Defy has two accelerometers in hardware (KXTF9 and AK8973). We use
* the KXTF9 one for higher precision.
*/
#define USE_KXTF9_ACCELEROMETER

/*****************************************************************************/

#define KXTF9_DEVICE_NAME "/dev/kxtf9"
#define KXTF9_DEFAULT_DELAY (200 * 1000000)

Expand All @@ -53,27 +61,6 @@ int init_nusensors(hw_module_t const* module, hw_device_t** device);
#define KXTF9_CONVERT_A_Y (KXTF9_CONVERT_A)
#define KXTF9_CONVERT_A_Z (-KXTF9_CONVERT_A)

/*
Orientation events:
0x01 screen down 0°
0x02 screen up 0°
0x04 portrait, normal use 0°
0x08 portrait, reversed 180°
0x10 landscape, usb port up 270° (-90°)
0x20 landscape, usb port down 90°
so, we need to divide per 8 (3bits right)
*/
#define KXTF9_SENSOR_ROTATION_MASK (0x3F)

#define KXTF9_CONVERT_O (90.0f/8.0f)
#define KXTF9_CONVERT_O_Y (KXTF9_CONVERT_O)
#define KXTF9_CONVERT_O_P (KXTF9_CONVERT_O)
#define KXTF9_CONVERT_O_R (KXTF9_CONVERT_O)


#define AK8973_DEVICE_NAME "/dev/akm8973_aot"
#define AK8973_DEFAULT_DELAY (200 * 1000000)

Expand Down
28 changes: 12 additions & 16 deletions libsensors/sensors.c
Expand Up @@ -48,15 +48,22 @@
#define ONCHANGED 0

static const struct sensor_t sSensorList[] = {
{ "AK8973 3-axis Orientation Sensor",
"Asahi Kasei",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_ORIENTATION, SENSOR_TYPE_ORIENTATION,
360.0f, AK8973_CONVERT_O, 7.0f, 0, { } },

#ifdef USE_KXTF9_ACCELEROMETER
{ "KXTF9 3-axis Accelerometer",
"Kionix",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_ACCELEROMETER, SENSOR_TYPE_ACCELEROMETER,
8.0f*9.81f, KXTF9_CONVERT_A, 0.6f, 0, { } }, // 8G
#else
{ "AK8973 Accelerometer sensor",
"Asahi Kasei",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_ACCELEROMETER, SENSOR_TYPE_ACCELEROMETER,
5.76f*9.81f, AK8973_CONVERT_A, 0.2f, 0, { } },
#endif

{ "AK8973 3-axis Orientation Sensor",
"Asahi Kasei",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_ORIENTATION, SENSOR_TYPE_ORIENTATION,
360.0f, AK8973_CONVERT_O, 7.0f, 0, { } },

{ "AK8973 3-axis Magnetic Field Sensor",
"Asahi Kasei",
Expand All @@ -68,17 +75,6 @@ static const struct sensor_t sSensorList[] = {
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_AMBIENT_TEMPERATURE, SENSOR_TYPE_AMBIENT_TEMPERATURE,
85.0f, 1.0f, 0.2f, 0, { } },

{ "KXTF9 3-axis Accelerometer",
"Kionix",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_ACCELEROMETER, SENSOR_TYPE_ACCELEROMETER,
8.0f*9.81f, KXTF9_CONVERT_A, 0.6f, 0, { } }, // 8G

/* not required:
{ "KXTF9 2-axis Orientation Events",
"Kionix",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_ORIENTATION, SENSOR_TYPE_ORIENTATION,
270.0f, 90.0f, 0.2f, ONCHANGED, { } },
*/
{ "ISL29030 Proximity Sensor",
"Intersil Corporation",
1, SENSORS_HANDLE_BASE + SENSOR_TYPE_PROXIMITY, SENSOR_TYPE_PROXIMITY,
Expand Down

0 comments on commit 9c8326b

Please sign in to comment.