分析以下代码 if (0 < p_instance_ctrl->pinfo.num_drift) { if (0 == *(p_instance_ctrl->pinfo.p_num_touch)) { /* If not touching, drift correction counter's being incremented */ (*(p_instance_ctrl->pinfo.p_drift_count))++; for (i = 0; i < num_y; i++) { for (j = 0; j < num_x; j++) { /* It is an addition for the drift correction average calculation */ tmp_count = (int16_t) g_touch_pad_buf[element_num + j + (i * num_x)]; *(p_instance_ctrl->pinfo.p_drift_buf + (j + (i * num_x))) += (int32_t) tmp_count; if (*(p_instance_ctrl->pinfo.p_drift_count) >= p_instance_ctrl->pinfo.num_drift) { drift_diff = (int32_t) (*(p_instance_ctrl->pinfo.p_drift_buf + j + (i * num_x)) / *(p_instance_ctrl->pinfo.p_drift_count)); *(p_instance_ctrl->pinfo.p_base_buf + j + (i * num_x)) = (uint16_t) ((int32_t) (*(p_instance_ctrl->pinfo.p_base_buf + j + (i * num_x))) - drift_diff); /* Clear total value for the average */ *(p_instance_ctrl->pinfo.p_drift_buf + (j + (i * num_x))) = 0; } } } if (*(p_instance_ctrl->pinfo.p_drift_count) >= p_instance_ctrl->pinfo.num_drift) { /* Count clear */ *(p_instance_ctrl->pinfo.p_drift_count) = 0; } }
时间: 2024-02-14 22:35:57 浏览: 155
这段代码主要是进行触摸屏的漂移校准。首先判断漂移校准次数是否大于0,如果是,则继续执行。然后再判断是否正在触摸屏上触摸,如果不是,则漂移校准计数器会被递增。接着,使用双重循环遍历触摸屏的每个数据点,并将每个数据点的值加入到漂移校准缓冲区中,以便计算漂移校准平均值。如果漂移校准计数器达到设定的次数,则计算漂移校准平均值,并将其从触摸基准值中减去,以完成漂移校准。最后,如果漂移校准计数器达到设定的次数,则将其清零。
相关问题
分析代码 else { /* format difference value */ for (j = 0; j < num_x; j++) { for (i = 0; i < num_y; i++) { /* get count data ,and changing the order */ tmp_value = g_touch_pad_buf[*(p_instance_ctrl->p_touch_cfg->p_pad->p_elem_index_rx + j) + (*(p_instance_ctrl->p_touch_cfg->p_pad->p_elem_index_tx + i) * num_x)]; /* make difference from base value */ tmp_diff = *(p_instance_ctrl->pinfo.p_base_buf + j + (i * num_x)) - tmp_value; /* save difference value to buffer in the second half */ g_touch_pad_buf[element_num + j + (i * num_x)] = (uint16_t) tmp_diff; } } }
这段代码是在处理电容式触摸屏的原始数据,具体分析如下:
1. 内部的else分支表示前面的条件语句不成立时执行这里的代码。
2. 外层循环用变量j遍历电容式触摸屏的X轴传感器,内层循环用变量i遍历Y轴传感器。
3. 在内层循环中,首先通过指针p_elem_index_rx和p_elem_index_tx获取传感器的计数数据,并将其保存到临时变量tmp_value中。
4. 接着,通过指针p_base_buf获取基准值,并将其与tmp_value相减,计算得到该传感器的差异值tmp_diff。
5. 最后,将差异值tmp_diff保存到缓冲区的第二半部分中。
总体来说,这段代码的作用是将电容式触摸屏的原始数据转换成差异数据,以便后续的处理和分析。在实际应用中,这些差异数据可以用于检测用户的触摸操作,并实现相应的功能。
为什么下面的sql语句会输出重复的结果:SELECT tp.parent_production_orders AS parent_production_orders, tp.production_orders AS production_orders, tp.work_order AS work_order, tp.contract AS contract, tp.sbbh AS sbbh, tp.batch_num AS batch_num, tp.product_code AS product_code, tp.product_number AS product_number, tp.product_name AS product_name, to_char( middle.create_date, 'yyyy-mm-dd' ) AS issued_date, to_char( to_timestamp( tp.delivery_time / 1000 ), 'yyyy-mm-dd' ) AS delivery_time, middle.line_code AS work_area_code, middle.line_name AS work_area_name, tp.workorder_number AS workorder_number, tp.complete_number AS complete_number, tp.part_unit AS part_unit, middle.work_time_type AS work_time_type, middle.process_time AS process_time, CASE WHEN sc.totalSubmitHours IS NULL THEN 0 ELSE sc.totalSubmitHours END AS submit_work_hours, CASE WHEN middle.process_time > 0 AND sc.totalSubmitHours IS NOT NULL THEN round( ( sc.totalSubmitHours / middle.process_time ), 2 ) * 100 ELSE 0 END plan_achievement_rate, CASE WHEN sc.totalSubmitHours IS NULL THEN 0 ELSE round( CAST ( sc.totalSubmitHours AS NUMERIC ) / CAST ( 60 AS NUMERIC ), 1 ) END AS submit_work_hours_h, round( CAST ( middle.process_time AS NUMERIC ) / CAST ( 60 AS NUMERIC ), 1 ) AS process_time_h, pinfo.material_channel AS material_channel FROM hm_model_work_order_report_middle middle LEFT JOIN hm_model_trc_plan tp ON middle.work_order = tp.work_order LEFT JOIN ( SELECT oro.work_order AS orderNo, oro.work_area_code AS lineCode, SUM ( submit_work_hours ) AS totalSubmitHours, '自制' AS workHourType FROM hm_model_trc_order_report_operation_u orou LEFT JOIN hm_model_trc_order_report_operation oro ON orou.work_order_process_id = oro.ID WHERE orou.work_order_process_id IS NOT NULL AND oro.work_area_code IS NOT NULL GROUP BY oro.work_order, oro.work_area_code UNION all SELECT ohs.work_order_no AS orderNo, ohs.line_code AS lineCode, SUM ( receiving_hour ) AS totalSubmitHours, '外委' AS workHourType FROM hm_model_outsourcing_hour_statistics ohs GROUP BY ohs.work_order_no, ohs.line_code ) sc ON middle.work_order = sc.orderNo AND middle.line_code = sc.lineCode AND middle.work_time_type = sc.workHourType LEFT JOIN hm_model_part_info AS pinfo ON tp.product_number = pinfo.part_code WHERE middle.process_time > 0 AND tp.delivery_time IS NOT NULL AND tp.production_orders LIKE'FJ2023051100286' ORDER BY to_char( to_timestamp( tp.delivery_time / 1000 ), 'yyyy-mm-dd' ) DESC, tp.parent_production_orders DESC, tp.node_level ASC
可能是因为查询结果中有多个相同的记录,即存在多个记录的各个字段的值都相同,因此会出现重复的结果。可以使用 DISTINCT 关键字去除重复的记录。例如:SELECT DISTINCT tp.parent_production_orders AS parent_production_orders, tp.production_orders AS production_orders, ... (省略后面的 SQL 语句)。另外,还可以检查查询条件是否合理,是否需要增加更多的条件来过滤数据。
阅读全文