accelerometer.c revision e239cd8de06a62c9adc71ff1329a1ce76e8735a5
/*
* accelerometer - exports device orientation through property
*
* When an "change" event is received on an accelerometer,
* open its device node, and from the value, as well as the previous
* value of the property, calculate the device's new orientation,
* and export it as ID_INPUT_ACCELEROMETER_ORIENTATION.
*
* Possible values are:
* undefined
* * normal
* * bottom-up
* * left-up
* * right-up
*
* The property will be persistent across sessions, and the new
* orientations can be deducted from the previous one (it allows
* for a threshold for switching between opposite ends of the
* orientation).
*
* Copyright (C) 2011 Red Hat, Inc.
* Author:
* Bastien Nocera <hadess@hadess.net>
*
* orientation_calc() from the sensorfw package
* Copyright (C) 2009-2010 Nokia Corporation
* Authors:
* Üstün Ergenoglu <ext-ustun.ergenoglu@nokia.com>
* Timo Rongas <ext-timo.2.rongas@nokia.com>
* Lihan Guo <lihan.guo@digia.com>
*
* 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 keymap; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <limits.h>
#include "libudev.h"
#include "libudev-private.h"
/* we must use this kernel-compatible implementation */
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
#define OFF(x) ((x)%BITS_PER_LONG)
#define LONG(x) ((x)/BITS_PER_LONG)
static int debug = 0;
{
if (debug) {
} else {
}
}
typedef enum {
static const char *orientations[] = {
"undefined",
"normal",
"bottom-up",
"left-up",
"right-up",
};
#define ORIENTATION_UP_UP ORIENTATION_NORMAL
#define DEFAULT_THRESHOLD 250
#define SAME_AXIS_LIMIT 5
#define THRESHOLD_LANDSCAPE 25
#define THRESHOLD_PORTRAIT 20
static const char *
{
return orientations[o];
}
static OrientationUp
string_to_orientation (const char *orientation)
{
int i;
if (orientation == NULL)
return ORIENTATION_UNDEFINED;
for (i = 0; orientations[i] != NULL; i++) {
return i;
}
return ORIENTATION_UNDEFINED;
}
static OrientationUp
int x, int y, int z)
{
int rotation;
/* Portrait check */
/* Some threshold to switching between portrait modes */
}
}
} else {
/* Landscape check */
/* Some threshold to switching between landscape modes */
}
}
}
}
return ret;
}
static OrientationUp
{
const char *value;
return ORIENTATION_UNDEFINED;
return string_to_orientation(value);
}
#define SET_AXIS(axis, code_) if (ev[i].code == code_) { if (got_##axis == 0) { axis = ev[i].value; got_##axis = 1; } }
/* accelerometers */
struct udev_device *dev,
const char *devpath)
{
int fd, r;
int got_syn = 0;
int x = 0, y = 0, z = 0;
char text[64];
return;
while (1) {
int i;
if (r < (int) sizeof(struct input_event))
return;
for (i = 0; i < r / (int) sizeof(struct input_event); i++) {
if (got_syn == 1) {
}
}
got_syn = 1;
}
goto read_dev;
}
}
return;
}
static void help(void)
{
printf("Usage: accelerometer [options] <device path>\n"
" --debug debug to stderr\n"
" --help print this help text\n\n");
}
{
struct udev_device *dev;
{}
};
char *devnode;
const char *id_path;
struct udev_enumerate *enumerate;
struct udev_list_entry *list_entry;
return 1;
log_open();
/* CLI argument parsing */
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'd':
debug = 1;
break;
case 'h':
help();
exit(0);
default:
exit(1);
}
}
help();
exit(1);
}
/* get the device */
return 1;
}
return 0;
}
/* Get the children devices and find the devnode */
/* FIXME: use udev_enumerate_add_match_parent() instead */
struct udev_device *device;
const char *node;
continue;
/* Already found it */
continue;
}
continue;
}
/* Use the event sub-device */
continue;
}
}
return 0;
}
log_close();
return 0;
}