概述
sensor
将底层值转换的地方
khadas/hardware/amlogic/sensor/st/LightSensor.cpp
LightSensor::readEvents
上传adc原始数据
diff --git a/common/drivers/input/sensors/lsensor/cm3218.c b/common/drivers/input/sensors/lsensor/cm3218.c
index 03ab8f4291..c5f848063e 100755
--- a/common/drivers/input/sensors/lsensor/cm3218.c
+++ b/common/drivers/input/sensors/lsensor/cm3218.c
@@ -299,13 +364,13 @@ static int light_report_value(struct input_dev *input, int data)
index = 7;
}
- input_report_abs(input, ABS_MISC, index);
+ input_report_abs(input, ABS_MISC, data);
input_sync(input);
return index;
}
diff --git a/hardware/amlogic/sensor/st/LightSensor.cpp b/hardware/amlogic/sensor/st/LightSensor.cpp
index 4f4fde4f09..9c11e06643 100644
--- a/hardware/amlogic/sensor/st/LightSensor.cpp
+++ b/hardware/amlogic/sensor/st/LightSensor.cpp
@@ -147,7 +147,7 @@ int LightSensor::readEvents(sensors_event_t* data, int count)
if (event->code == EVENT_TYPE_LIGHT) {
if (event->value != -1) {
// FIXME: not sure why we're getting -1 sometimes
- mPendingEvent.light = indexToValue(event->value);
+ mPendingEvent.light = event->value;
}
}
} else if (type == EV_SYN) {
(END)
总的patch
diff --git a/common/drivers/input/sensors/lsensor/cm3218.c b/common/drivers/input/sensors/lsensor/cm3218.c
index 03ab8f4291..c5f848063e 100755
--- a/common/drivers/input/sensors/lsensor/cm3218.c
+++ b/common/drivers/input/sensors/lsensor/cm3218.c
@@ -71,7 +71,9 @@
static int als_code = 20;
static int change_sensitivity = 50;
static int if_sensor_init;
-
+//add by zhongyukang
+extern struct class *sensor_class;
+static struct i2c_client *gclient;
static int cm3218_read_ara(struct i2c_client *client)
{
int status;
@@ -239,6 +241,62 @@ static int sensor_active(struct i2c_client *client, int enable, int rate)
return result;
}
+static bool flags_debug = false;
+static ssize_t light_reg_show(struct class *class,
+ struct class_attribute *attr, char *buf)
+{
+ int reg_addr ;//= sprintf(buf , "%xn", cm3218_read(client, sensor->client->addr));
+ if (1 != sscanf(buf, "%d", ®_addr)) {
+ printk("<zyk> sscanf fail %sn",__func__);
+ return -1;
+ }
+ return sprintf(buf, "%xn",cm3218_read(gclient, reg_addr));
+}
+static ssize_t light_reg_store(struct class *class,
+ struct class_attribute *attr, const char *buf, size_t count)
+{
+ int reg_addr = 0,reg_value;
+ char *kbuf, *p, *argv[2];
+ int argn;
+ // int i;
+ unsigned int val = 0, val2 = 0;
+ ssize_t status;
+ long value;
+ int temp_reg_addr_value ;
+ kbuf = kstrdup(buf, GFP_KERNEL);
+ p = kbuf;
+ for (argn = 0; argn < 2; argn++) {
+ argv[argn] = strsep(&p, " ");
+ printk(KERN_EMERG"func %s %c n",__FUNCTION__,*argv[argn]);
+ if (argv[argn] == NULL)
+ break;
+ }
+ status = kstrtol(argv[0], 0, &value);
+ if (status == 0)
+ val = (unsigned int)value;
+ reg_addr = argn ? val : 0;
+ status = kstrtol(argv[1], 0, &value);
+ if (status == 0)
+ val2 = (unsigned int)value;
+ reg_value = (argn > 1) ? val2 : 0;
+ if (reg_addr < 0)
+ return -EINVAL;
+
+ printk(KERN_EMERG"zyk---- %s %x %x n",__FUNCTION__,reg_addr,reg_value);
+ if(reg_addr == 0xf){
+ temp_reg_addr_value = cm3218_read(gclient, reg_value);
+ printk("reg:0x%x value:0x%xn",reg_value,temp_reg_addr_value);
+ // status = sprintf(buf, "%xn",reg_value);
+ }else if(reg_addr == 0xd){
+ flags_debug = !flags_debug;
+ }
+ else {
+ cm3218_write(gclient, reg_addr, reg_value);
+ }
+ return count;
+
+}
+static CLASS_ATTR(light_reg, 0664, light_reg_show, light_reg_store);
static int sensor_init(struct i2c_client *client)
{
@@ -273,14 +331,21 @@ static int sensor_init(struct i2c_client *client)
if_sensor_init = 1;
msleep(250);
-
+ gclient = client;
+ status = class_create_file(sensor_class, &class_attr_light_reg);
+ if (status) {
+ printk(KERN_ERR "%s:Fail to creat accel class filen", __func__);
+ return status;
+ }
return status;
}
static int light_report_value(struct input_dev *input, int data)
{
unsigned char index = 0;
-
+ if(!!flags_debug){
+ printk("%s data:%dn",__func__,data);
+ }
if (data <= 700) {
index = 0;
} else if (data <= 1400) {
@@ -299,13 +364,13 @@ static int light_report_value(struct input_dev *input, int data)
index = 7;
}
- input_report_abs(input, ABS_MISC, index);
+ input_report_abs(input, ABS_MISC, data);
input_sync(input);
return index;
}
-static int cm3218_read_lux(struct i2c_client *client, int *lux)
+int cm3218_read_lux(struct i2c_client *client, int *lux)
{
int lux_data;
diff --git a/common/drivers/input/sensors/sensor-dev.c b/common/drivers/input/sensors/sensor-dev.c
index ef942f3901..2fccdfa698 100755
--- a/common/drivers/input/sensors/sensor-dev.c
+++ b/common/drivers/input/sensors/sensor-dev.c
@@ -50,7 +50,7 @@ struct sensor_calibration_data {
static struct sensor_private_data *g_sensor[SENSOR_NUM_TYPES];
static struct sensor_operate *sensor_ops[SENSOR_NUM_ID];
static int sensor_probe_times[SENSOR_NUM_ID];
-static struct class *sensor_class;
+struct class *sensor_class;
static struct sensor_calibration_data sensor_cali_data;
static int sensor_calibration_data_read(struct sensor_calibration_data *calibration_data)
@@ -279,6 +279,44 @@ static ssize_t gyro_calibration_store(struct class *class,
static CLASS_ATTR(gyro_calibration, 0664, gyro_calibration_show, gyro_calibration_store);
+#define __FITURE_LIGHT_LUX_DEBUG__
+#ifdef __FITURE_LIGHT_LUX_DEBUG__
+extern int cm3218_read_lux(struct i2c_client *client, int *lux);
+static ssize_t light_lux_show(struct class *class,
+ struct class_attribute *attr, char *buf){
+ int result = 0;
+ int value = 0;
+ struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_LIGHT];
+ if (sensor == NULL)
+ return -1;
+ cm3218_read_lux(sensor->client, &result);
+ if (result <= 700) {
+ value = 10;
+ } else if (result <= 1400) {
+ value = 160;
+ } else if (result <= 2800) {
+ value = 225;
+ } else if (result <= 5600) {
+ value = 320;
+ } else if (result <= 11200) {
+ value = 640;
+ } else if (result <= 22400) {
+ value = 1280;
+ } else if (result <= 44800) {
+ value = 2600;
+ } else {
+ value = 10240;
+ }
+ return sprintf(buf, "light lux value: %dn", value);
+}
+
+static ssize_t light_lux_store(struct class *class,
+ struct class_attribute *attr, const char *buf, size_t count){
+ return count;
+}
+
+static CLASS_ATTR(light_lux, 0664, light_lux_show, light_lux_store);
+#endif
static int sensor_class_init(void)
{
int ret ;
@@ -295,6 +333,13 @@ static int sensor_class_init(void)
printk(KERN_ERR "%s:Fail to creat gyro class filen", __func__);
return ret;
}
+ #ifdef __FITURE_LIGHT_LUX_DEBUG__
+ ret = class_create_file(sensor_class, &class_attr_light_lux);
+ if (ret) {
+ printk(KERN_ERR "%s:Fail to creat light sensor class filen", __func__);
+ return ret;
+ }
+ #endif
return 0;
}
diff --git a/hardware/amlogic/sensor/st/LightSensor.cpp b/hardware/amlogic/sensor/st/LightSensor.cpp
index 4f4fde4f09..9c11e06643 100644
--- a/hardware/amlogic/sensor/st/LightSensor.cpp
+++ b/hardware/amlogic/sensor/st/LightSensor.cpp
@@ -147,7 +147,7 @@ int LightSensor::readEvents(sensors_event_t* data, int count)
if (event->code == EVENT_TYPE_LIGHT) {
if (event->value != -1) {
// FIXME: not sure why we're getting -1 sometimes
- mPendingEvent.light = indexToValue(event->value);
+ mPendingEvent.light = event->value;
}
}
} else if (type == EV_SYN) {
关掉sensor服务:
确认:
console:/ # dumpsys sensorservice
No Sensors on the device
devInitCheck : -19
console:/ #
patch
---
common/arch/arm/boot/dts/amlogic/manzala.dts | 2 +-
common/arch/arm/configs/manzala_a32_defconfig | 2 +-
device/amlogic/common/core_amlogic.mk | 7 +++---
.../products/mbox/manifest/manifest_aosp.xml | 9 --------
device/amlogic/manzala/BoardConfig.mk | 22 +++++++++----------
5 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/common/arch/arm/boot/dts/amlogic/manzala.dts b/common/arch/arm/boot/dts/amlogic/manzala.dts
index d41e3bb871..0542cfa09a 100755
--- a/common/arch/arm/boot/dts/amlogic/manzala.dts
+++ b/common/arch/arm/boot/dts/amlogic/manzala.dts
@@ -1001,7 +1001,7 @@
irq_enable = <0>;
poll_delay_ms = <30>;
layout = <1>;
- status = "okay";
+ status = "disabled";
};
};
diff --git a/common/arch/arm/configs/manzala_a32_defconfig b/common/arch/arm/configs/manzala_a32_defconfig
index b2ed708b27..13af79a45d 100755
--- a/common/arch/arm/configs/manzala_a32_defconfig
+++ b/common/arch/arm/configs/manzala_a32_defconfig
@@ -253,7 +253,7 @@ CONFIG_AMLOGIC_CRYPTO=y
CONFIG_AMLOGIC_CRYPTO_DMA=y
CONFIG_AMLOGIC_INPUT=y
CONFIG_SENSOR_DEVICE=y
-CONFIG_LIGHT_DEVICE=y
+# CONFIG_LIGHT_DEVICE is not set
CONFIG_AMLOGIC_AVIN_DETECT=y
CONFIG_AMLOGIC_INPUT_KEYBOARD=y
CONFIG_AMLOGIC_ADC_KEYPADS=y
diff --git a/device/amlogic/common/core_amlogic.mk b/device/amlogic/common/core_amlogic.mk
index 7a5cafd1f3..901950bdd0 100755
--- a/device/amlogic/common/core_amlogic.mk
+++ b/device/amlogic/common/core_amlogic.mk
@@ -209,7 +209,6 @@ PRODUCT_PACKAGES +=
hwcomposer.amlogic
memtrack.amlogic
screen_source.amlogic
- sensors.amlogic
thermal.amlogic
#glscaler and 3d format api
@@ -429,9 +428,9 @@ PRODUCT_PACKAGES +=
android.hardware.light@2.0-impl
android.hardware.light@2.0-service
# Sensor HAL
-PRODUCT_PACKAGES +=
- android.hardware.sensors@1.0-service
- android.hardware.sensors@1.0-impl
+#PRODUCT_PACKAGES +=
+# android.hardware.sensors@1.0-service
+# android.hardware.sensors@1.0-impl
#thermal hal
PRODUCT_PACKAGES +=
android.hardware.thermal@1.0-impl
diff --git a/device/amlogic/common/products/mbox/manifest/manifest_aosp.xml b/device/amlogic/common/products/mbox/manifest/manifest_aosp.xml
index 7eabbb0ad9..ed47eb0eb0 100755
--- a/device/amlogic/common/products/mbox/manifest/manifest_aosp.xml
+++ b/device/amlogic/common/products/mbox/manifest/manifest_aosp.xml
@@ -300,15 +300,6 @@
<instance>default</instance>
</interface>
</hal>
- <hal format="hidl">
- <name>android.hardware.sensors</name>
- <transport>hwbinder</transport>
- <version>1.0</version>
- <interface>
- <name>ISensors</name>
- <instance>default</instance>
- </interface>
- </hal>
<sepolicy>
<version>27.0</version>
</sepolicy>
diff --git a/device/amlogic/manzala/BoardConfig.mk b/device/amlogic/manzala/BoardConfig.mk
index 08ccf247c8..16409a7173 100755
--- a/device/amlogic/manzala/BoardConfig.mk
+++ b/device/amlogic/manzala/BoardConfig.mk
@@ -104,17 +104,17 @@ BOARD_ROOT_EXTRA_FOLDERS += odm
endif
# Sensors
-BOARD_GRAVITY_SENSOR_SUPPORT := false
-BOARD_COMPASS_SENSOR_SUPPORT := false
-BOARD_GYROSCOPE_SENSOR_SUPPORT := false
-BOARD_PROXIMITY_SENSOR_SUPPORT := false
-BOARD_LIGHT_SENSOR_SUPPORT := true
-BOARD_PRESSURE_SENSOR_SUPPORT := false
-BOARD_TEMPERATURE_SENSOR_SUPPORT := false
-
-BOARD_SENSOR_ST := true
-BOARD_SENSOR_MPU_VR := false
-BOARD_SENSOR_MPU_PAD := false
+#BOARD_GRAVITY_SENSOR_SUPPORT := false
+#BOARD_COMPASS_SENSOR_SUPPORT := false
+#BOARD_GYROSCOPE_SENSOR_SUPPORT := false
+#BOARD_PROXIMITY_SENSOR_SUPPORT := false
+#BOARD_LIGHT_SENSOR_SUPPORT := true
+#BOARD_PRESSURE_SENSOR_SUPPORT := false
+#BOARD_TEMPERATURE_SENSOR_SUPPORT := false
+
+#BOARD_SENSOR_ST := true
+#BOARD_SENSOR_MPU_VR := false
+#BOARD_SENSOR_MPU_PAD := false
BOARD_ODMIMAGE_FILE_SYSTEM_TYPE := ext4
BOARD_USES_ODMIMAGE := true
--
2.17.1
最后
以上就是寂寞舞蹈为你收集整理的LightSensor传感器的全部内容,希望文章能够帮你解决LightSensor传感器所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复