adb push F:\push\engtest /system/bin/
#include
#include
#include
#include
#include
#include
#include "eng_tok.h"
#include "minui.h"
#include "sprd_engtest.h"
#include "sprd_engcommon.h"
#include "sprd_engui.h"
#define SOFTKEY_OK "OK"
#define SOFTKEY_FAIL "FAIL"
#define SPRD_PLS_CTL "/dev/orap_ps" // "/sys/devices/platform/sc8810-i2c.0/i2c-0/0-001c/suspend"
#define SPRD_PLS_VER "/sys/devices/platform/sc8810-i2c.0/i2c-0/0-0044/version"
#define SPRD_PLS_INPUT_DEV "orap29044" // "proximity"
#define SPRD_PLSTEST_TITLE "Proximity&Light Sensor Test"
#define SPRD_PSENSOR_NEAR "Proximity Sensor Near"
#define SPRD_PSENSOR_FAR "Proximity Sensor Far"
#define SPRD_PLS_PASS "Pass: Proximity&Light"
#define SPRD_PLSTEST_TITLE_Y 40
#define SPRD_PLS_LIGHT_THRESHOLD 30
static int proximity_value=1;
static int proximity_modifies=0;
static int light_value;
static int light_pass=0;
static int thread_run;
static char pls_version[32];
static int eng_pls_enable(int enable)
{
int fd;
char buffer[8];
fd = open(SPRD_PLS_CTL, O_RDWR);
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, "%d", enable);
SPRD_DBG("%s: enable=%s",__func__, buffer);
if(fd > 0)
{
write(fd, buffer, strlen(buffer));
close(fd);
}
return 0;
}
static int eng_pls_version(char *buffer, int size)
{
int fd;
fd = open(SPRD_PLS_VER, O_RDWR);
if(fd > 0) {
read(fd, buffer, size);
close(fd);
}
SPRD_DBG("%s: buffer=%s\n",__func__, buffer);
return 0;
}
/*
* Read key code, check value
*/
static int eng_pls_value(struct input_event *event)
{
int keycode;
if(event->type == EV_ABS) {
switch(event->code){
case ABS_DISTANCE:
proximity_modifies++;
proximity_value = event->value;
break;
case ABS_MISC:
light_value = event->value;
if(light_value >= SPRD_PLS_LIGHT_THRESHOLD)
light_pass = 1;
break;
}
}
SPRD_DBG("%s: type=%d; value=%d; code=%d; proximity_value=%d; light_value=%d",__func__, \
event->type, event->value, event->code, proximity_value, light_value);
return 0;
}
/*
* Draw plspad Test Item
*/
static void eng_plstest_show(void)
{
int start_x = gr_fb_width()/2 - 100;
int start_y = gr_fb_height()/2;
char buffer[64];
SPRD_DBG("%s, proximity_value=%d; light_value=%d", __func__, proximity_value, light_value);
sprd_ui_fill_locked();
//title
gr_color(255, 255, 255, 255);
sprd_ui_draw_title(SPRD_PLSTEST_TITLE_Y, SPRD_PLSTEST_TITLE, strlen(SPRD_PLSTEST_TITLE));
sprd_ui_draw_text(start_x, start_y-70, pls_version);
if(proximity_modifies >= 2) {
gr_color(0, 255, 0, 255);
} else {
gr_color(255, 0, 0, 255);
}
if(proximity_value==0){
sprd_ui_draw_text(start_x, start_y, SPRD_PSENSOR_NEAR);
} else {
sprd_ui_draw_text(start_x, start_y, SPRD_PSENSOR_FAR);
}
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, "Light Sensor Lux is %d",light_value);
if(light_pass == 1) {
gr_color(0, 255, 0, 255);
} else {
gr_color(255, 0, 0, 255);
}
sprd_ui_draw_text(start_x, start_y-30, buffer);
eng_draw_softkey();
//update
gr_flip();
}
void engtest_ps_thread(void )
{
int counter;
int ret,udc_input_ps, n, udc_nread;
fd_set udc_rfds;
struct input_event udc_event;
struct timeval udc_timeout;
udc_timeout.tv_sec=1;
udc_timeout.tv_usec=0;
udc_input_ps = sprd_eng_openinput(O_RDONLY, SPRD_PLS_INPUT_DEV);
SPRD_DBG("%s: udc_input_ps=%d", __func__, udc_input_ps);
FD_ZERO(&udc_rfds);
FD_SET(udc_input_ps, &udc_rfds);
n = select(udc_input_ps+1, &udc_rfds, NULL, NULL, &udc_timeout);
if(FD_ISSET(udc_input_ps, &udc_rfds)) {
//read input event
udc_nread = read(udc_input_ps, &udc_event, sizeof(udc_event));
if (udc_nread == sizeof(udc_event)) {
eng_pls_value(&udc_event);
} else {
SPRD_DBG("%s: read event too small %d", __func__, udc_nread);
}
} else {
;//SPRD_DBG("%s: fd is not set", __func__);
}
eng_plstest_show();
}
#if 1
#define AP3212C_DEVICE_NAME "/dev/orap_ps"
#define LTR_IOCTL_MAGIC 0x1C
#define LTR_IOCTL_GET_PFLAG _IOR(LTR_IOCTL_MAGIC, 1, int)
#define LTR_IOCTL_GET_LFLAG _IOR(LTR_IOCTL_MAGIC, 2, int)
#define LTR_IOCTL_SET_PFLAG _IOW(LTR_IOCTL_MAGIC, 3, int)
#define LTR_IOCTL_SET_LFLAG _IOW(LTR_IOCTL_MAGIC, 4, int)
#define LTR_IOCTL_GET_DATA _IOW(LTR_IOCTL_MAGIC, 5, unsigned char)
int dev_fd=0;
static int control_enable_disable_prox_sensor( uint32_t en )
{
int flags = en ? 1 : 0;
int err = 0;
SPRD_DBG("%s: flags:%d", __func__,flags);
if(dev_fd)
close(dev_fd);
dev_fd = open(AP3212C_DEVICE_NAME, O_RDONLY);
SPRD_DBG("%s::dev_fd=%d\n",__func__ , dev_fd);
err = ioctl(dev_fd, LTR_IOCTL_SET_PFLAG, &flags);
SPRD_DBG("%s::enable flags=%d; err=%d\n",__func__ , flags, err);
if(!flags)
close(dev_fd);
return 1;
}
static int control_enable_disable_light_sensor( uint32_t en )
{
int flags = en ? 1 : 0;
int err = 0;
SPRD_DBG("%s: flags:%d", __func__,flags);
if(dev_fd)
close(dev_fd);
dev_fd = open(AP3212C_DEVICE_NAME, O_RDONLY);
SPRD_DBG("%s::dev_fd=%d\n",__func__ , dev_fd);
err = ioctl(dev_fd, LTR_IOCTL_SET_LFLAG, &flags);
SPRD_DBG("%s::enable flags=%d; err=%d\n",__func__ , flags, err);
if(!flags)
close(dev_fd);
return 1;
}
/*
* Read pls input device
*/
static void engtest_pls_thread(void *par)
{
int ret, input_fd, n, nread;
int counter;
fd_set rfds;
struct input_event event;
struct timeval timeout;
timeout.tv_sec=1;
timeout.tv_usec=0;
control_enable_disable_prox_sensor(1);
control_enable_disable_light_sensor(1);
input_fd = sprd_eng_openinput(O_RDONLY, SPRD_PLS_INPUT_DEV);
SPRD_DBG("%s: input_fd=%d", __func__, input_fd);
while(thread_run==1) {
FD_ZERO(&rfds);
FD_SET(input_fd, &rfds);
n = select(input_fd+1, &rfds, NULL, NULL, &timeout);
if(FD_ISSET(input_fd, &rfds)) {
//read input event
nread = read(input_fd, &event, sizeof(event));
if (nread == sizeof(event)) {
eng_pls_value(&event);
} else {
SPRD_DBG("%s: read event too small %d", __func__, nread);
}
} else {
;//SPRD_DBG("%s: fd is not set", __func__);
}
eng_plstest_show();
engtest_ps_thread();
}
control_enable_disable_prox_sensor(0);
control_enable_disable_light_sensor(0);
}
#endif
/*
* Read input, Start plspad test
*/
int eng_plstest_start(void)
{
char chipid[32];
pthread_t t;
proximity_value = 1;
proximity_modifies = 0;
light_value = 0;
light_pass = 0;
SPRD_DBG("%s", __func__);
memset(pls_version, 0, sizeof(pls_version));
memset(chipid, 0, sizeof(chipid));
eng_pls_version(chipid, sizeof(chipid));
sprintf(pls_version, "CHIP ID:%s",chipid);
//draw pls
eng_plstest_show();
eng_pls_enable(1);
sleep(1);
thread_run=1;
pthread_create(&t, NULL, (void*)engtest_pls_thread, NULL);
eng_handle_softkey(ENG_ITEM_PROXIMITY);
thread_run=0;
pthread_join(t, NULL); /* wait "handle key" thread exit. */
eng_pls_enable(0);
return 0;
}
阅读(1553) | 评论(0) | 转发(0) |