From: SnickerSun Date: Tue, 12 Mar 2024 11:28:06 +0000 (+0800) Subject: 优化表冠已经可以正常使用 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~21^2~1 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=78b8120de680b89ffc1a1bda696d627b2b3e0559;p=mirrors%2FFD230.git 优化表冠已经可以正常使用 --- diff --git a/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.c b/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.c index 0cf2be1c9..b20c20294 100644 --- a/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.c +++ b/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.c @@ -59,10 +59,13 @@ osTimerId_t g_hx3507_timer = NULL;//定义一个定时器ID 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; +} /** * 定时器超时处理函数 @@ -294,6 +297,13 @@ void crown_data_handler(void *p_event_data, uint16_t event_size) #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冠轴质量,或者装配摆动幅度大引起的错误, 做的保护程序 { @@ -309,6 +319,20 @@ void crown_data_handler(void *p_event_data, uint16_t event_size) // 图像质量应该>=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变高 @@ -508,7 +532,9 @@ extern encoder_callback g_encoder_callback; 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° @@ -531,6 +557,17 @@ void put_crown_result(int16_t x) 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 diff --git a/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.h b/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.h index 647601e28..565d54d02 100644 --- a/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.h +++ b/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507.h @@ -51,7 +51,7 @@ #define FILTER_MIN 1 // 偶尔冠轴被震动等各种意外产生的小的数据, 可根据产品情况把小的出值滤掉 //log 打印定义 -#define TYHX_LOG_ENABLE +// #define TYHX_LOG_ENABLE #ifdef TYHX_LOG_ENABLE #define TYHX_LOG(fmt, ...) \ do { \ @@ -85,6 +85,8 @@ void crown_com_resync(void); //把读出的数据转换为大概角度函数 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); diff --git a/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507_hal.c b/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507_hal.c index 1db9ed7ef..491dac39e 100644 --- a/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507_hal.c +++ b/code/sdk/drivers/peripheral/rotary_encoder/hx3507/hx3507_hal.c @@ -55,11 +55,13 @@ static ext_errno hx3507_encoder_get_encoderinfo(uint8_t *data, uint8_t data_len) 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; diff --git a/code/sdk/drivers/peripheral/rotary_encoder/rotary_encoder_drv.c b/code/sdk/drivers/peripheral/rotary_encoder/rotary_encoder_drv.c index 277d65180..206072db8 100644 --- a/code/sdk/drivers/peripheral/rotary_encoder/rotary_encoder_drv.c +++ b/code/sdk/drivers/peripheral/rotary_encoder/rotary_encoder_drv.c @@ -72,9 +72,9 @@ static void convert_encoder_info(input_dev_data_t* data, re_input_event_info* en 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; @@ -90,6 +90,8 @@ static void report_or_enqueue_event(re_input_event_info* encoder_info, struct re // 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]); @@ -130,9 +132,11 @@ ext_errno encoder_info_process(void) 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); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/rotate_input_device.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/rotate_input_device.cpp index 21175a255..bab3b2277 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/rotate_input_device.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/rotate_input_device.cpp @@ -31,16 +31,58 @@ RotateInputDevice::RotateInputDevice() : rotateStart_(false), threshold_(ROTATE_ 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; } @@ -60,14 +102,18 @@ void RotateInputDevice::DispatchEvent(const DeviceData& data) 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);