aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZiyan <jaraidaniel@gmail.com>2016-01-29 17:30:38 +0100
committerAndreas Blaesius <skate4life@gmx.de>2016-02-22 22:09:03 +0100
commit0e766ffb17c5d867a87ed04d8cb6c5c603577d53 (patch)
tree05886d002097f01805cd24b590e4479f6371c72c
parent2ea956fe4ba6fe76702b021cfb1d39c80bcfc69a (diff)
downloaddevice_samsung_espressowifi-0e766ffb17c5d867a87ed04d8cb6c5c603577d53.zip
device_samsung_espressowifi-0e766ffb17c5d867a87ed04d8cb6c5c603577d53.tar.gz
device_samsung_espressowifi-0e766ffb17c5d867a87ed04d8cb6c5c603577d53.tar.bz2
libsensors: set up sensors at runtime based on the current device variant
Change-Id: I6bf89a3b00205e53594764b291a0445f250e1001
-rw-r--r--libsensors/Android.mk13
-rw-r--r--libsensors/piranha_sensors.c69
-rw-r--r--libsensors/piranha_sensors.h2
3 files changed, 59 insertions, 25 deletions
diff --git a/libsensors/Android.mk b/libsensors/Android.mk
index f916e27..b3e39ee 100644
--- a/libsensors/Android.mk
+++ b/libsensors/Android.mk
@@ -38,19 +38,6 @@ LOCAL_MODULE := sensors.piranha
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_TAGS := optional
-ifeq ($(TARGET_DEVICE),p5100)
- LOCAL_CFLAGS += -DTARGET_DEVICE_P5100
-endif
-ifeq ($(TARGET_DEVICE),p5110)
- LOCAL_CFLAGS += -DTARGET_DEVICE_P5100
-endif
-ifeq ($(TARGET_DEVICE),p3100)
- LOCAL_CFLAGS += -DTARGET_DEVICE_P3100 -DTARGET_HAS_PROXIMITY_SENSOR
-endif
-ifeq ($(TARGET_DEVICE),p3110)
- LOCAL_CFLAGS += -DTARGET_DEVICE_P3100
-endif
-
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH := $(PIRANHA_SENSORS_PATH)/geomagneticd
diff --git a/libsensors/piranha_sensors.c b/libsensors/piranha_sensors.c
index 4ab6943..eec9d68 100644
--- a/libsensors/piranha_sensors.c
+++ b/libsensors/piranha_sensors.c
@@ -16,6 +16,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
@@ -30,6 +31,10 @@
#include "piranha_sensors.h"
+/* Boolean indicating if the sensors are
+ set up for the current device variant */
+int8_t setup_done = 0;
+
/*
* Sensors list
*/
@@ -44,21 +49,21 @@ struct sensor_t piranha_sensors[] = {
{ "YAS Orientation Sensor", "Yamaha Corporation", 1, SENSOR_TYPE_ORIENTATION,
SENSOR_TYPE_ORIENTATION, 360.0f, 0.1f, 0.0f, 10000,
0, 0, 0, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {0}, },
-#ifdef TARGET_DEVICE_P5100
+/* P51xx only */
{ "BH1721 Light Sensor", "ROHM", 1, SENSOR_TYPE_LIGHT,
SENSOR_TYPE_LIGHT, 0.0f, 0.0f, 0.0f, 0,
0, 0, 0, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {0}, },
-#endif
-#ifdef TARGET_DEVICE_P3100
+/* ---------- */
+/* P31xx only */
{ "GP2A Light Sensor", "Sharp", 1, SENSOR_TYPE_LIGHT,
SENSOR_TYPE_LIGHT, 0.0f, 0.0f, 0.0f, 0,
0, 0, 0, 0, 0, SENSOR_FLAG_CONTINUOUS_MODE, {0}, },
-#endif
-#ifdef TARGET_HAS_PROXIMITY_SENSOR
+/* ---------- */
+/* P3100 only */
{ "GP2A Proximity Sensor", "Sharp", 1, SENSOR_TYPE_PROXIMITY,
SENSOR_TYPE_PROXIMITY, 5.0f, 0.0f, 0.0f, 0,
0, 0, 0, 0, 0, SENSOR_FLAG_WAKE_UP | SENSOR_FLAG_ON_CHANGE_MODE, {0}, },
-#endif
+/* ---------- */
};
int piranha_sensors_count = sizeof(piranha_sensors) / sizeof(struct sensor_t);
@@ -67,15 +72,15 @@ struct piranha_sensors_handlers *piranha_sensors_handlers[] = {
&bma250,
&yas530,
&yas_orientation,
-#ifdef TARGET_DEVICE_P5100
+/* P51xx only */
&bh1721,
-#endif
-#ifdef TARGET_DEVICE_P3100
+/* ---------- */
+/* P31xx only */
&gp2a_light,
-#endif
-#ifdef TARGET_HAS_PROXIMITY_SENSOR
+/* ---------- */
+/* P3100 only */
&gp2a_proximity,
-#endif
+/* ---------- */
};
int piranha_sensors_handlers_count = sizeof(piranha_sensors_handlers) /
@@ -232,6 +237,42 @@ int piranha_sensors_close(hw_device_t *device)
return 0;
}
+void piranha_sensors_setup() {
+ if (setup_done)
+ return;
+
+ char device[16];
+ FILE *f = fopen(DEVICE_VARIANT_SYSFS, "r");
+ if (!f || fgets(device, 16, f) == NULL) {
+ ALOGE("Failed to read " DEVICE_VARIANT_SYSFS ", assuming P51xx\n");
+ strcpy(device, "espresso10");
+ }
+ fclose(f);
+
+ ALOGD("Device: %s", device);
+
+ if (strcmp(device, "espresso10") == 0) {
+ /* Device is P51xx */
+ piranha_sensors_count = 4;
+ } else if (strcmp(device, "espressowifi") == 0) {
+ /* Device is P3110 */
+ piranha_sensors[3] = piranha_sensors[4];
+ piranha_sensors_handlers[3] = piranha_sensors_handlers[4];
+ piranha_sensors_count = 4;
+ } else {
+ /* Device is P3100 */
+ piranha_sensors[3] = piranha_sensors[4];
+ piranha_sensors_handlers[3] = piranha_sensors_handlers[4];
+ piranha_sensors[4] = piranha_sensors[5];
+ piranha_sensors_handlers[4] = piranha_sensors_handlers[5];
+ piranha_sensors_count = 5;
+ }
+
+ piranha_sensors_handlers_count = piranha_sensors_count;
+
+ setup_done = 1;
+}
+
int piranha_sensors_open(const struct hw_module_t* module, const char *id,
struct hw_device_t** device)
{
@@ -243,6 +284,8 @@ int piranha_sensors_open(const struct hw_module_t* module, const char *id,
if (module == NULL || device == NULL)
return -EINVAL;
+ piranha_sensors_setup();
+
piranha_sensors_device = (struct piranha_sensors_device *)
calloc(1, sizeof(struct piranha_sensors_device));
piranha_sensors_device->device.common.tag = HARDWARE_DEVICE_TAG;
@@ -285,6 +328,8 @@ int piranha_sensors_get_sensors_list(struct sensors_module_t* module,
if (sensors_p == NULL)
return -EINVAL;
+ piranha_sensors_setup();
+
*sensors_p = piranha_sensors;
return piranha_sensors_count;
}
diff --git a/libsensors/piranha_sensors.h b/libsensors/piranha_sensors.h
index 876aaec..2b5a935 100644
--- a/libsensors/piranha_sensors.h
+++ b/libsensors/piranha_sensors.h
@@ -30,6 +30,8 @@
#define PIRANHA_SENSORS_NEEDED_API (1 << 0)
#define PIRANHA_SENSORS_NEEDED_ORIENTATION (1 << 1)
+#define DEVICE_VARIANT_SYSFS "/sys/board_properties/type"
+
struct piranha_sensors_device;
struct piranha_sensors_handlers {