解释以下代码 /* Data get */ err = p_instance_ctrl->p_ctsu_instance->p_api->dataGet(p_instance_ctrl->p_ctsu_instance->p_ctrl, g_touch_pad_buf); FSP_ERROR_RETURN(FSP_ERR_CTSU_SCANNING != err, FSP_ERR_CTSU_SCANNING); /* check for max touch */ if (*(p_instance_ctrl->pinfo.p_max_touch) > TOUCH_PAD_MONITOR_TOUCH_NUM_MAX) { max_touch = TOUCH_PAD_MONITOR_TOUCH_NUM_MAX; } else { max_touch = *(p_instance_ctrl->pinfo.p_max_touch); } /* make difference value = secondary - primary */ for (i = 0; i < element_num; i++) { /* save to buffer in the first half */ g_touch_pad_buf[i] = (uint16_t) (g_touch_pad_buf[(i * 2) + 1] - g_touch_pad_buf[i * 2]); } /* Data get section */ if (!g_touch_base_set_falg) { /* format base value , changing the order */ for (j = 0; j < num_x; j++) { for (i = 0; i < num_y; i++) { *(p_instance_ctrl->pinfo.p_base_buf + j + (i * num_x)) = (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)]); } } g_touch_base_set_falg = 1; }
时间: 2024-04-26 09:23:24 浏览: 146
这段代码是一个触摸板监测程序的一部分,主要用于获取触摸板的数据并进行处理。首先,使用 p_api->dataGet() 函数从触摸板获取数据,并检查是否正在进行扫描。然后,检查触摸板上触摸的最大数量,并将其与 TOUCH_PAD_MONITOR_TOUCH_NUM_MAX 进行比较,以确保不超过最大值。接着,使用从触摸板获取的数据计算出每个元素的差值,并将其存储在缓冲区的前半部分。如果触摸板的基准值未设置,则使用获取的数据设置基准值。最后,将基准值设置标志设置为 1。
相关问题
仔细分析这一段 /* initialize touch number and corrdinate */ *(p_instance_ctrl->pinfo.p_num_touch) = 0; *(p_instance_ctrl->pinfo.p_rx_coordinate) = TOUCH_OFF_VALUE; *(p_instance_ctrl->pinfo.p_tx_coordinate) = TOUCH_OFF_VALUE; /* Get local variable (TS number & data pinch) */ num_x = p_instance_ctrl->p_touch_cfg->p_ctsu_instance->p_cfg->num_rx; TOUCH_ERROR_RETURN(0 != num_x, FSP_ERR_ASSERTION); num_y = p_instance_ctrl->p_touch_cfg->p_ctsu_instance->p_cfg->num_tx; TOUCH_ERROR_RETURN(0 != num_y, FSP_ERR_ASSERTION); element_num = (uint16_t) (num_x * num_y); /* Data get */ err = p_instance_ctrl->p_ctsu_instance->p_api->dataGet(p_instance_ctrl->p_ctsu_instance->p_ctrl, g_touch_pad_buf); FSP_ERROR_RETURN(FSP_ERR_CTSU_SCANNING != err, FSP_ERR_CTSU_SCANNING); /* check for max touch */ if (*(p_instance_ctrl->pinfo.p_max_touch) > TOUCH_PAD_MONITOR_TOUCH_NUM_MAX) { max_touch = TOUCH_PAD_MONITOR_TOUCH_NUM_MAX; } else { max_touch = *(p_instance_ctrl->pinfo.p_max_touch); } /* make difference value = secondary - primary */ for (i = 0; i < element_num; i++) { /* save to buffer in the first half */ g_touch_pad_buf[i] = (uint16_t) (g_touch_pad_buf[(i * 2) + 1] - g_touch_pad_buf[i * 2]); }
这段代码是在初始化触摸板相关的变量和获取触摸数据。首先,它将触摸数和坐标值初始化为0和TOUCH_OFF_VALUE。然后,它从触摸板配置结构体中获取接收和发送通道的数量,并计算出元素数量。接下来,它调用dataGet函数来获取触摸数据,并将数据存储在g_touch_pad_buf数组中。如果获取数据时发现触摸板正在扫描,则返回FSP_ERR_CTSU_SCANNING错误。然后,它检查最大触摸数是否超过了最大值,如果超过了,则将最大触摸数设置为最大值,否则将最大触摸数设置为p_max_touch指针所指向的值。最后,它对每个元素进行处理,将其次级值减去主级值,并将结果保存在g_touch_pad_buf数组的前一半中。这个程序的目的是为了监控触摸板上的触摸情况,并将数据处理成差分形式方便后续使用。
分析一下下面这段代码:ds = datastores_get_ds(dsid); if (ds == NULL) { return (nc_reply_error(nc_err_new(NC_ERR_OP_FAILED))); } //DBG("%s/%d ds->datastore->name %s", //__func__,__LINE__,ds->data_model->name); //xmlContentPrintALL(((struct ncds_ds_file*)ds)->xml); op = nc_rpc_get_op(rpc); /* if transapi used AND operation will affect running repository => store current running content */ i = pthread_mutex_lock(&ds->lock); if (i != 0) { ERROR("Failed to lock datastore (%s).", strerror(errno)); return (NULL); } DBG("%s/%d op %d target %d",__func__,__LINE__,op,nc_rpc_get_target(rpc)); if (ds->transapis != NULL && (op == NC_OP_COMMIT || op == NC_OP_COPYCONFIG || (op == NC_OP_EDITCONFIG && (nc_rpc_get_testopt(rpc) != NC_EDIT_TESTOPT_TEST))) && (nc_rpc_get_target(rpc) == NC_DATASTORE_RUNNING)) { old_data = ds->func.getconfig(ds, session, NC_DATASTORE_RUNNING, &e); old = read_datastore_data(ds->id, old_data); if (old == NULL) {/* cannot get or parse data */ pthread_mutex_unlock(&ds->lock); if (e == NULL) { /* error not set */ e = nc_err_new(NC_ERR_OP_FAILED); nc_err_set(e, NC_ERR_PARAM_MSG, "TransAPI: Failed to get data from RUNNING datastore."); } return nc_reply_error(e); } free(old_data); } filter = NULL;
这段代码主要是从数据存储中获取数据,并根据操作类型和目标数据存储是否为“running”来决定是否使用事务API。具体来说,它会获取一个数据存储的指针,如果指针为空,则返回一个操作失败的错误消息。然后,它会尝试获取一个锁,如果获取锁失败,则返回 NULL。接下来,它会检查操作类型和目标数据存储是否为“running”,如果是,则使用事务API来获取旧的数据。最后,它将过滤器设置为 NULL。
阅读全文