static uint8_t g_hx3695_timer_installed = 0;
static int16_t crown_result = 0;
-
+static int16_t stand_still = 1; //静止标志 1 静止,0 转动
/*----------------------以下为定时函数相关定义 建立/启动/停止定时器//定时中断处理-------------------------------*/
-
+int16_t get_stand_still(void)
+{
+ return stand_still;
+}
/**
* 定时器超时处理函数
#endif
//HX3507 一个方向转动出正值, 另外一个方向就是负值, 正负值跟芯片的摆放方向有关
delatx = crown_read_reg(DeltaX) |(crown_read_reg(DeltaX_Hi)<<8);
+ if (stand_still == 1)
+ {
+ //上次是静止,上报状态改变
+ report_zero_data_for_start_stop_flag();
+ }
+ stand_still = 0;
+
if(crown_data_verify(delatx)) //先判断数据是否合理,
// 主要针对OTS冠轴质量,或者装配摆动幅度大引起的错误, 做的保护程序
{
// 图像质量应该>=80, 否则可能代表芯片表面有脏污等或者装配问题或者有漏光
// PD的饱和度应该>=100 且 <=180, 如果有漏光等问题, 结果>=240以上, 相关漏光等要处理
// TYHX_LOG("pic qulity =%d, pd saturation=%d\r\n",crown_read_reg(Img_Qa),crown_read_reg(PD_SAT));
+
+ if (stand_still == 0)
+ {
+ //上次是转动,上报状态改变
+ report_zero_data_for_start_stop_flag();
+ }
+ stand_still = 1;
+
+ uint8_t imagqa = crown_read_reg(Img_Qa);
+ uint8_t pdsat = crown_read_reg(PD_SAT);
+ if (imagqa<100 || imagqa > 180 || pdsat <240){
+ // TYHX_LOG("crown still not pass! pic qulity =%d (should img_qa>=100 && img_qa<=180) , pd saturation=%d (should pd_sat >=240)\r\n",imagqa,pdsat);
+ }
+
}
#if (defined(MOT_LOW_LEVEL_MODE))//如果低电平中断模式,要读到芯片MOT变高
void put_crown_result(int16_t x)
{
if(abs(x)<=FILTER_MIN )
+ {
return;
+ }
if(abs(x)>=4 )
{
crown_result += x/4; //大于4的值除以4, 代表角度, 单位0.5°
TYHX_LOG("no call back crown_result = %d\r\n",crown_result);
}
+
+void report_zero_data_for_start_stop_flag(void)
+{
+
+ crown_result = 0;
+ TYHX_LOG("report_zero_data_for_start_stop_flag crown_result = %d, \r\n",crown_result);
+ if (g_encoder_callback != NULL)
+ g_encoder_callback();
+ else
+ TYHX_LOG("no call back crown_result = %d\r\n",crown_result);
+}
/**
* 获取表冠的数据结果接口函数
* @param NULL
#define FILTER_MIN 1 // 偶尔冠轴被震动等各种意外产生的小的数据, 可根据产品情况把小的出值滤掉
//log 打印定义
-#define TYHX_LOG_ENABLE
+// #define TYHX_LOG_ENABLE
#ifdef TYHX_LOG_ENABLE
#define TYHX_LOG(fmt, ...) \
do { \
//把读出的数据转换为大概角度函数
void put_crown_result(int16_t x);
+int16_t get_stand_still(void);
+void report_zero_data_for_start_stop_flag(void);
//把角度结果上报的函数
int16_t get_crown_result(void);
return EXT_ERR_NOT_SUPPORT;
re_input_event_info *encoder_info = (re_input_event_info*)data;
int16_t diff = get_crown_result();
- if (diff > 0 )
+ int16_t stand_still = get_stand_still();
+ // re_print("hx3507_encoder_get_encoderinfo diff %d stand_still %d\n",diff,stand_still);
+ if (stand_still == 1 )
{
- encoder_info->re_event = MC_RE_SLIDE_UP;
- }else{
- encoder_info->re_event = MC_RE_SLIDE_DOWN;
+ encoder_info->re_event = MC_RE_COVER;
+ }else {
+ encoder_info->re_event = MC_RE_MOVE;
}
encoder_info->re_event_info.x_axis[0] = diff;
encoder_info->re_event_info.y_axis[0] = diff;
data->type = INDEV_TYPE_ENCODER;
data->rotate = (int16_t)encoder_info->re_event_info.x_axis[0];
data->timestamp = (uint32_t)encoder_info->tv_usec;
- if ((encoder_info->re_event == MC_RE_PRESS) || (encoder_info->re_event == MC_RE_MOVE)) {
+ if (encoder_info->re_event == MC_RE_MOVE) { //旋转有数据状态
data->state = INDEV_STATE_PRESS;
- } else if (encoder_info->re_event == MC_RE_RELEASE) {
+ } else if (encoder_info->re_event == MC_RE_COVER && data->rotate == 0) { //静止状态
data->state = INDEV_STATE_RELEASE;
} else {
data->state = INDEV_STATE_UNKNOWN;
// return;
// }
// re_print("report encoder diff %d ,state %d \n",data.encoderDiff,data.state);
+ // code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_hal.cpp
+ // static void EventCallback(InputDevData* data)
g_re_report_event_cb(&data);
} else {
// re_print("re_en_queue encoder diff %d \n",encoder_info->re_event_info.x_axis[0]);
int32_t ret = 0;
if (redd->encoder_api->encoder_get_encoderinfo != NULL) {
+ //实际调用函数 hx3507_encoder_get_encoderinfo
ret = redd->encoder_api->encoder_get_encoderinfo((uint8_t *)(&encoder_info), sizeof(re_input_event_info));
if (ret != EXT_ERR_SUCCESS) {
re_err("get encoder info fail! ret=0x%x", ret);
+ return EXT_ERR_FAILURE;
}
// re_print("encoder_info_process1\n");
report_or_enqueue_event(&encoder_info, redd);
void RotateInputDevice::DispatchEvent(const DeviceData& data)
{
bool cachedToRotate = false;
- if (data.rotate == 0 || rotateStart_) {
+ // INDEV_STATE_PRESS == 1 转动
+ // INDEV_STATE_RELEASE == 0 静止
+
+ static DeviceData lastdevdata={0xFF};
+ static int has_report_still = 0;
+ #define BUF_COUNT 5
+ // printf(" %s rotate = %d , state %d\n",__func__,data.rotate,data.state);
+ static int16_t zero_count = 0;
+ // if(data.rotate == 0 && data.state == 0)
+ if(data.rotate == 0 )
+ {
+ //转动0,data.state 0静止,代表停止转动
+ // if (lastdevdata.state == 0 && lastdevdata.rotate == 0)
+ if (lastdevdata.state == 0 )
+ zero_count++;
+
+ if (zero_count >= BUF_COUNT)
+ {
+ //连续BUF_COUNT个0 ,buf已满无需再次添加
+ zero_count = BUF_COUNT; //防止int16_t 溢出
+ //TODO: 只上报一次 has_report_still
+ if(has_report_still == 0)
+ {
+ has_report_still = 1;
+ }else{
+ //report过就不再report
+ return ;
+ }
+ }else
+ {
+ //少于BUF_COUNT个0 不上报,但要继续在缓存添加数据,否则计数不会变化
+ lastdevdata = data;
+ return ;
+ }
+ }else{
+ //只要有一次非still,则重新计量是否需要report
+ zero_count = 0;
+ has_report_still = 0;
+ lastdevdata = data;
+ }
+
+ if (data.rotate == 0 || rotateStart_) { //如果旋转0,或者已经开始,则清空cache 重新计数
cachedRotation_ = 0;
- } else {
+ } else { //否则缓存旋转角度
cachedRotation_ += data.rotate;
- if (MATH_ABS(cachedRotation_) >= threshold_) {
- cachedToRotate = true;
+ if (MATH_ABS(cachedRotation_) >= threshold_) {
+ cachedToRotate = true; //缓存角度大于阈值则开始转动
}
}
if (!cachedToRotate && !rotateStart_) {
+ //没达到缓存标准的,不做动作,继续缓存。
return;
}
return;
}
if (MATH_ABS(data.rotate) < threshold_ && !rotateStart_ && !cachedToRotate) {
+ //当前值没达到阈值,且没开始旋转,也没有缓存达到旋转标准,则不做动作。
+ //按理这一步走不到。前面已经做了条件限制。
return;
}
if (data.rotate == 0 && rotateStart_) {
+ //已经开始转动,但是当前值为零,认为停止转动。
view->OnRotateEndEvent(0);
rotateStart_ = false;
return;
}
if (!rotateStart_) {
+ //缓存可以转动,且之前没有开始转动,会走到这里,执行开始转动消息。
view->OnRotateStartEvent(data.rotate);
}
view->OnRotateEvent(data.rotate);