Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-libsensors: Commit

hardware/libsensors


Commit MetaInfo

Révision1400ddb4b38366448c1e91507fe030c20bfe6f59 (tree)
l'heure2011-04-29 17:42:25
AuteurChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Message de Log

add s103t_sensor by Oliver Dill

Change Summary

Modification

--- a/Android.mk
+++ b/Android.mk
@@ -15,3 +15,8 @@ ifeq ($(strip $(BOARD_USES_KBDSENSOR)),true)
1515 LOCAL_SRC_FILES := kbdsensor.cpp
1616 include $(BUILD_SHARED_LIBRARY)
1717 endif
18+
19+ifeq ($(strip $(BOARD_USES_S103T_SENSOR)),true)
20+LOCAL_SRC_FILES := s103t_sensor.c
21+include $(BUILD_SHARED_LIBRARY)
22+endif
--- /dev/null
+++ b/s103t_sensor.c
@@ -0,0 +1,259 @@
1+/*
2+ * s103t_sensor.c
3+ *
4+ * Created on: 19.04.2011
5+ * Author: Oliver Dill (oliver@ratio-informatik.de)
6+ * Licensed under GPLv2 or later
7+ */
8+
9+#define LOG_TAG "S103TSensors"
10+
11+#include <linux/types.h>
12+#include <linux/input.h>
13+#include <fcntl.h>
14+#include <cutils/sockets.h>
15+#include <cutils/log.h>
16+#include <cutils/native_handle.h>
17+#include <dirent.h>
18+#include <math.h>
19+#include <hardware/sensors.h>
20+
21+#define DRIVER_DESC "Lenovo front-screen buttons driver"
22+#define SKEY_ROTATE_MAPPING KEY_F12
23+#define ID_ACCELERATION (SENSORS_HANDLE_BASE + 0)
24+
25+typedef struct SensorData {
26+ struct sensors_data_device_t device;
27+ int events_fd;
28+ sensors_data_t orientation;
29+} SensorData;
30+
31+typedef struct SensorControl {
32+ struct sensors_control_device_t device;
33+ int fd;
34+ uint32_t active_sensors;
35+} SensorControl;
36+
37+/* this must return a file descriptor that will be used to read
38+ * the sensors data (it is passed to data__data_open() below
39+ */
40+static native_handle_t*
41+control__open_data_source(struct sensors_control_device_t *dev) {
42+ SensorControl* ctl = (void*) dev;
43+ native_handle_t *handle;
44+ handle = native_handle_create(1, 1);
45+ ctl->fd = -1;
46+ const char *dirname = "/dev/input";
47+ DIR *dir = opendir(dirname);
48+ if (dir != NULL) {
49+ struct dirent *de;
50+ // loop over all "eventXX" in /dev/input and look for our driver
51+ LOGD("%s: looping over all eventXX...",__FUNCTION__);
52+ do {
53+ de = readdir(dir);
54+ if (de->d_name[0] != 'e') // eventX
55+ continue;
56+ char name[PATH_MAX];
57+ snprintf(name, PATH_MAX, "%s/%s", dirname, de->d_name);
58+ LOGD("%s: open device %s",__FUNCTION__, name);
59+ ctl->fd = open(name, O_RDWR);
60+ if (ctl->fd < 0) {
61+ LOGE("could not open %s, %s", name, strerror(errno));
62+ continue;
63+ }
64+ name[sizeof(name) - 1] = '\0';
65+ if (ioctl(ctl->fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
66+ LOGE("could not get device name for %s, %s\n", name, strerror(errno));
67+ name[0] = '\0';
68+ }
69+
70+ if (!strcmp(name, DRIVER_DESC)) {
71+ // ok, it's our driver, stop the loop ...
72+ LOGI("found device %s", name);
73+ break;
74+ }
75+ close(ctl->fd);
76+ } while (de != NULL);
77+ LOGD("%s: stop loop and closing directory",__FUNCTION__);
78+ closedir(dir);
79+ }
80+ // and save the handle.
81+ handle->data[0] = ctl->fd;
82+ LOGD("%s: dev=%p handle=%p data[0]=%d", __FUNCTION__, dev, handle, handle->data[0]);
83+ return handle;
84+}
85+
86+static int control__activate(struct sensors_control_device_t *dev, int handle,
87+ int enabled) {
88+ LOGD("%s: called",__FUNCTION__);
89+ return 0;
90+}
91+
92+static int control__set_delay(struct sensors_control_device_t *dev, int32_t ms) {
93+ LOGD("%s: called",__FUNCTION__);
94+ return 0;
95+}
96+
97+static int control__wake(struct sensors_control_device_t *dev) {
98+ LOGD("%s: called",__FUNCTION__);
99+ return 0;
100+}
101+
102+static int control__close(struct hw_device_t *dev) {
103+ LOGD("%s: called",__FUNCTION__);
104+ return 0;
105+}
106+
107+static int data__data_open(struct sensors_data_device_t *dev,
108+ native_handle_t* handle) {
109+ LOGD("%s: called",__FUNCTION__);
110+ SensorData* data = (void*) dev;
111+ LOGD("%s: dev=%p fd=%d", __FUNCTION__, dev, handle->data[0]);
112+ data->events_fd = dup(handle->data[0]);
113+ native_handle_close(handle);
114+ native_handle_delete(handle);
115+ return 0;
116+}
117+
118+static int data__data_close(struct sensors_data_device_t *dev) {
119+ SensorData* data = (void*) dev;
120+ LOGD("%s: dev=%p", __FUNCTION__, dev);
121+ if (data->events_fd > 0) {
122+ LOGD("%s: closing device",__FUNCTION__);
123+ close(data->events_fd);
124+ data->events_fd = -1;
125+ }
126+ return 0;
127+}
128+
129+static int data__poll(struct sensors_data_device_t *dev, sensors_data_t* values) {
130+ SensorData* data = (void*) dev;
131+ LOGD("%s: dev=%p", __FUNCTION__, dev);
132+ while (1) {
133+ struct input_event iev;
134+ size_t res = read(data->events_fd, &iev, sizeof(iev));
135+ if (res == sizeof(iev)) {
136+ if (iev.type == EV_KEY) {
137+ LOGD("type=%d scancode=%d value=%d from fd=%d", iev.type, iev.code, iev.value, data->events_fd);
138+ if (iev.code == SKEY_ROTATE_MAPPING && iev.value == 1) {
139+ if (data->orientation.acceleration.x != 0.0) {
140+ data->orientation.acceleration.x = 0.00;
141+ data->orientation.acceleration.y = 9.77;
142+ data->orientation.acceleration.z = 0.81;
143+ } else {
144+ data->orientation.acceleration.x = 9.77;
145+ data->orientation.acceleration.y = 0.00;
146+ data->orientation.acceleration.z = 0.81;
147+ }
148+ *values = data->orientation;
149+ LOGI("orientation changed");
150+ return 0;
151+ }
152+ }
153+
154+ if (iev.type == EV_SW) {
155+ LOGD("%s: switching to/from Table Mode type=%d scancode=%d value=%d", __FUNCTION__,iev.type, iev.code, iev.value);
156+ if (iev.value == 0) {
157+ data->orientation.acceleration.x = 0.00;
158+ data->orientation.acceleration.y = 9.77;
159+ data->orientation.acceleration.z = 0.81;
160+ } else {
161+ data->orientation.acceleration.x = 9.77;
162+ data->orientation.acceleration.y = 0.00;
163+ data->orientation.acceleration.z = 0.81;
164+ }
165+ *values = data->orientation;
166+ LOGI("orientation changed");
167+ return 0;
168+ }
169+ }
170+ }
171+}
172+
173+static int data__close(struct hw_device_t *dev) {
174+ LOGD("%s: data__close",__FUNCTION__);
175+ return 0;
176+}
177+
178+static const struct sensor_t sSensorListInit[] = {
179+ { .name =
180+ "S103T Orientation sensor",
181+ .vendor = "Oliver Dill",
182+ .version = 1,
183+ .handle = ID_ACCELERATION,
184+ .type = SENSOR_TYPE_ACCELEROMETER,
185+ .maxRange = 2.8f,
186+ .resolution = 1.0f/4032.0f,
187+ .power = 3.0f,
188+ .reserved = { }
189+ },
190+};
191+
192+static uint32_t sensors__get_sensors_list(struct sensors_module_t* module,
193+ struct sensor_t const** list) {
194+ LOGD("%s: sensors__get_sensors_list called",__FUNCTION__);
195+ // there is exactly one sensor available, the accelerometer sensor
196+ *list = sSensorListInit;
197+ return 1;
198+}
199+
200+static int open_sensors(const struct hw_module_t* module, const char* name,
201+ struct hw_device_t* *device) {
202+ int status = -EINVAL;
203+
204+ LOGD("%s: name=%s", __FUNCTION__, name);
205+
206+ if (!strcmp(name, SENSORS_HARDWARE_CONTROL)) {
207+ SensorControl *dev = malloc(sizeof(*dev));
208+ LOGD("%s: init sensors control device" , __FUNCTION__);
209+ memset(dev, 0, sizeof(*dev));
210+
211+ dev->device.common.tag = HARDWARE_DEVICE_TAG;
212+ dev->device.common.version = 0;
213+ dev->device.common.module = (struct hw_module_t*) module;
214+ dev->device.common.close = control__close;
215+ dev->device.open_data_source = control__open_data_source;
216+ dev->device.activate = control__activate;
217+ dev->device.set_delay = control__set_delay;
218+ dev->device.wake = control__wake;
219+ dev->fd = -1;
220+
221+ *device = &dev->device.common;
222+ status = 0;
223+ } else if (!strcmp(name, SENSORS_HARDWARE_DATA)) {
224+
225+ SensorData *dev = malloc(sizeof(*dev));
226+ LOGD("%s: init sensors_data_device" , __FUNCTION__);
227+ memset(dev, 0, sizeof(*dev));
228+ dev->orientation.sensor = ID_ACCELERATION;
229+ dev->orientation.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
230+ dev->device.common.tag = HARDWARE_DEVICE_TAG;
231+ dev->device.common.version = 0;
232+ dev->device.common.module = (struct hw_module_t*) module;
233+ dev->device.common.close = data__close;
234+ dev->device.data_open = data__data_open;
235+ dev->device.data_close = data__data_close;
236+ dev->device.poll = data__poll;
237+ dev->events_fd = -1;
238+ *device = &dev->device.common;
239+ status = 0;
240+ }
241+ return status;
242+}
243+
244+static struct hw_module_methods_t sensors_module_methods = { .open =
245+ open_sensors };
246+
247+const struct sensors_module_t HAL_MODULE_INFO_SYM = {
248+ .common = {
249+ .tag = HARDWARE_MODULE_TAG,
250+ .version_major = 1,
251+ .version_minor = 0,
252+ .id = SENSORS_HARDWARE_MODULE_ID,
253+ .name = "s103t SENSORS Module",
254+ .author = "Oliver Dill",
255+ .methods = &sensors_module_methods,
256+ },
257+ .get_sensors_list = sensors__get_sensors_list
258+};
259+
Afficher sur ancien navigateur de dépôt.