I managed to fix it. For reference:

- Acceleration sensor is enough to rotate the screen (no need of
orientation which makes sense).

- Launcher or Launcher2 doesn't rotate by default because of the
nosensor reported by Craig in AOSP.

- The crazy behavior reported in the previous post (acceleration value
changed after rotation) is due to code in frameworks/base/core/java/
android/hardware/SensorManager.java. Value of acceleration are changed
depending if rotation = 90 or 270. I think that it's a wrong behavior
and it should be reported as a  bug.

- Rotation code in frameworks doesn't include support for 180 and 270,
only 0 and 90.

- I had a problem in the device policy that was prevented rotation.
Check your policy file if you experience similar problem,

Grégoire


On Sep 21, 11:56 pm, G2 <grego...@gentil.com> wrote:
> This story starts to get me totally crazy.
>
> Sorry Dianne ;-), but Craig is right. In AOSP, part of the problem is
> that screenOrientation is not set up in the manifest files.
>
> Nevertheless, it still not working. Moreover, I have now a crazy
> behavior. Perhaps I'm wrong, but it shows a bug in AOSP.
>
> If I do screenOrientation=sensor for Launcher and
> screenOrientation=portrait for Browser in the manifest files, the
> following happens:
>
> - I launch the Launcher. It's in landscape mode which is my default
> mode as I have a kind of netbook. I move the device, the screen
> doesn't rotate.
>
> - I launch the IBM eye application mentioned in the thread.
> Acceleration reports x=0, y=8, z=0. The screen is at 90d of the
> keyboard. I move the device, the values are changing and they "make
> sense".
>
> - I launch the browser. It switches to portrait. So far, everything
> makes sense due to the manifest.
>
> - I press the back button, the launcher is now in portrait mode!!!
>
> - I launch the IBM eye application. The screen is still at 90d of the
> keyboard. Acceleration reports now x=-8, y=0, z=0!!!!!!!
>
> This is Star Trek! My sensors.c code is below for reference.
>
> Question 1: if I just implement acceleration (but not orientation) in
> the sensor, can AOSP rotate the screen when the device rotates? Or do
> I need to fake an orientation sensor? I beg you, please answer by yes
> or no!
>
> Question 2: at this point, and with the crazy behavior reported above,
> I don't think that I have a problem in sensors.c. My guess is that I
> have a problem somewhere else in the configuration of my Eclair AOSP,
>
> Grégoire
>
> /* Android driver for the Freescale MMA7455L 3-axis accelerometer
>  *
>  * Copyright (C) 2010 by Always Innovating, Inc.
>  * Author: Gregoire Gentil <grego...@gentil.com>
>  * Author: GPTechinno - Georges
>  * All rights reserved.
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License as
>  * published by the Free Software Foundation; either version 2 of
>  * the License, or (at your option) any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
>  * MA 02111-1307 USA
>  *
>  */
>
> #define LOG_TAG "Sensors"
>
> #include <hardware/sensors.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <dirent.h>
> #include <math.h>
> #include <poll.h>
> #include <pthread.h>
>
> #include <linux/input.h>
> #include <linux/mma7455l.h>
>
> #include <cutils/atomic.h>
> #include <cutils/log.h>
> #include <cutils/native_handle.h>
>
> /
> *****************************************************************************/
>
> #define MAX_NUM_SENSORS 1
>
> #define SUPPORTED_SENSORS  ((1<<MAX_NUM_SENSORS)-1)
>
> #define ID_A  (0)
>
> #define SENSORS_ACCELERATION   (1<<ID_A)
>
> /
> *****************************************************************************/
>
> struct sensors_control_context_t {
>     struct sensors_control_device_t device;
>     int acceld_fd;
>     uint32_t active_sensors;
>
> };
>
> struct sensors_data_context_t {
>     struct sensors_data_device_t device;
>     int events_fd;
>     sensors_data_t sensors[MAX_NUM_SENSORS];
>     uint32_t pendingSensors;
>
> };
>
> /*
>  * The SENSORS Module
>  */
>
> static const struct sensor_t sSensorList[] = {
>         { "MMA7455L 3-axis Low-g Accelerometer",
>                 "Freescale",
>                 1, SENSORS_HANDLE_BASE+ID_A,
>                 SENSOR_TYPE_ACCELEROMETER, 8.0f*9.81f, 9.81f/64.0f,
> 5.0f, { } },
>
> };
>
> static int open_sensors(const struct hw_module_t* module, const char*
> name,
>         struct hw_device_t** device);
>
> static uint32_t sensors__get_sensors_list(struct sensors_module_t*
> module,
>         struct sensor_t const** list)
> {
>     *list = sSensorList;
>     return sizeof(sSensorList)/sizeof(sSensorList[0]);
>
> }
>
> static struct hw_module_methods_t sensors_module_methods = {
>     .open = open_sensors
>
> };
>
> struct sensors_module_t HAL_MODULE_INFO_SYM = {
>     .common = {
>         .tag = HARDWARE_MODULE_TAG,
>         .version_major = 1,
>         .version_minor = 0,
>         .id = SENSORS_HARDWARE_MODULE_ID,
>         .name = "MMA7455L SENSORS Module",
>         .author = "The Android Open Source Project",
>         .methods = &sensors_module_methods,
>     },
>     .get_sensors_list = sensors__get_sensors_list
>
> };
>
> float x, y, z;
>
> static int open_input(int mode)
> {
>     /* scan all input drivers and look for "mma7455l" */
>     int fd = -1;
>     const char *dirname = "/dev/input";
>     char devname[PATH_MAX];
>     char *filename;
>     DIR *dir;
>     struct dirent *de;
>     dir = opendir(dirname);
>     if(dir == NULL)
>         return -1;
>     strcpy(devname, dirname);
>     filename = devname + strlen(devname);
>     *filename++ = '/';
>     while((de = readdir(dir))) {
>         if(de->d_name[0] == '.' &&
>            (de->d_name[1] == '\0' ||
>             (de->d_name[1] == '.' && de->d_name[2] == '\0')))
>             continue;
>         strcpy(filename, de->d_name);
>         fd = open(devname, mode);
>         if (fd>=0) {
>             char name[80];
>             if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
>                 name[0] = '\0';
>             }
>             if (!strcmp(name, "MMA7455L")) {
>                 //LOGD("using %s (name=%s)", devname, name);
>                 break;
>             }
>             close(fd);
>             fd = -1;
>         }
>     }
>     closedir(dir);
>
>     if (fd < 0) {
>         LOGE("Couldn't find or open 'mma7455l' driver (%s)",
> strerror(errno));
>     }
>     return fd;
>
> }
>
> static int open_accel(struct sensors_control_context_t* dev)
> {
>     if (dev->acceld_fd <= 0) {
>         dev->acceld_fd = open_input(O_RDONLY);
>         //LOGD("%s, fd=%d", __PRETTY_FUNCTION__, dev->acceld_fd);
>         if (dev->acceld_fd >= 0) {
>             dev->active_sensors = 0;
>         }
>     }
>     return dev->acceld_fd;
>
> }
>
> static void close_accel(struct sensors_control_context_t* dev)
> {
>     if (dev->acceld_fd > 0) {
>         //LOGD("%s, fd=%d", __PRETTY_FUNCTION__, dev->acceld_fd);
>         close(dev->acceld_fd);
>         dev->acceld_fd = -1;
>     }
>
> }
>
> static void enable_disable(int fd, uint32_t sensors, uint32_t mask)
> {
>     return;
>
> }
>
> static uint32_t read_sensors_state(int fd)
> {
>     return SENSORS_ACCELERATION;
>
> }
>
> /
> *****************************************************************************/
>
> static native_handle_t* control__open_data_source(struct
> sensors_control_context_t *dev)
> {
>     native_handle_t* handle;
>     int fd = open_input(O_RDONLY);
>     if (fd < 0) {
>         return NULL;
>     }
>
>     handle = native_handle_create(1, 0);
>     handle->data[0] = fd;
>     return handle;
>
> }
>
> static int control__activate(struct sensors_control_context_t *dev,
>         int handle, int enabled)
> {
>     if ((handle<SENSORS_HANDLE_BASE) ||
>             (handle>=SENSORS_HANDLE_BASE+MAX_NUM_SENSORS)) {
>         return -1;
>     }
>
>     uint32_t mask = (1<<handle);
>     uint32_t sensors = enabled ? mask : 0;
>
>     uint32_t active = dev->active_sensors;
>     uint32_t new_sensors = (active & ~mask) | (sensors & mask);
>     uint32_t changed = active ^ new_sensors;
>     if (changed) {
>         int fd = open_accel(dev);
>         if (fd >= 0) {
>             if (!active && new_sensors) {
>                 // force all sensors to be updated
>                 changed = SUPPORTED_SENSORS;
>             }
>
>             enable_disable(fd, new_sensors, changed);
>
>             LOGD("sensors=%08x, real=%08x",
>                     new_sensors, read_sensors_state(fd));
>
>             if (active && !new_sensors) {
>                 // close the driver
>                 close_accel(dev);
>             }
>             dev->active_sensors = active = new_sensors;
>         } else {
>             active = -1;
>         }
>     }
>     return 0;
>
> }
>
> static int control__set_delay(struct sensors_control_context_t *dev,
> int32_t ms)
> {
>     return -1;
>
> }
>
> static int control__wake(struct sensors_control_context_t *dev)
> {
>     int err = 0;
>     int fd = open_input(O_WRONLY);
>     if (fd > 0) {
>         struct input_event event[1];
>         event[0].type = EV_SYN;
>         event[0].code = SYN_CONFIG;
>         event[0].value = 0;
>         err = write(fd, event, sizeof(event));
>         LOGD_IF(err<0, "control__wake, err=%d (%s)", errno,
> strerror(errno));
>         close(fd);
>     }
>     return err;
>
> }
>
> /
> *****************************************************************************/
>
> static int data__data_open(struct sensors_data_context_t *dev,
> native_handle_t* handle)
> {
>     int i;
>     memset(&dev->sensors, 0, sizeof(dev->sensors));
>
>     dev->sensors[ID_A].sensor = SENSOR_TYPE_ACCELEROMETER;
>
>     for (i=0 ; i<MAX_NUM_SENSORS ; i++) {
>         // by default all sensors have high accuracy
>         // (we do this because we don't get an update if the value
> doesn't
>         // change).
>         dev->sensors[i].vector.status = SENSOR_STATUS_ACCURACY_HIGH;
>     }
>     dev->pendingSensors = 0;
>     dev->events_fd = dup(handle->data[0]);
>     //LOGD("data__data_open: fd = %d", handle->data[0]);
>     native_handle_close(handle);
>     native_handle_delete(handle);
>     return 0;
>
> }
>
> static int data__data_close(struct sensors_data_context_t *dev)
> {
>     if (dev->events_fd > 0) {
>         //LOGD("(data close) about to close fd=%d", dev->events_fd);
>         close(dev->events_fd);
>         dev->events_fd = -1;
>     }
>     return 0;
>
> }
>
> static int pick_sensor(struct sensors_data_context_t *dev,
>         sensors_data_t* values)
> {
>     uint32_t mask = SUPPORTED_SENSORS;
>     while (mask) {
>         uint32_t i =...
>
> read more »

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: http://groups.google.com/group/android-porting

Reply via email to