diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d57ceda..bd0eaa42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ include(GNUInstallDirs) option(BUILD_SHARED_LIBS "ON: tslib is build as shared; OFF: tslib is build as static" ON) option(ENABLE_TOOLS "build additional tools" ON) +option(PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION "Limit coordinates to calibration resolution" OFF) set(LIBTS_VERSION_CURRENT 10) set(LIBTS_VERSION_REVISION 3) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 37a7a3ce..31e1ade3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -21,11 +21,17 @@ macro(TSLIB_CHECK_MODULE module_name default_option help_string) string(REPLACE "-" "_" module_name_uc_ul ${module_name_uc}) target_sources(tslib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${module_sources}) target_compile_definitions(tslib PRIVATE TSLIB_STATIC_${module_name_uc_ul}_MODULE) + if (PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + target_compile_definitions(tslib PUBLIC PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + endif () else() add_library(${module_name} MODULE ${module_sources}) list(APPEND plugin_targets ${module_name}) target_link_libraries(${module_name} PUBLIC tslib) SET_TARGET_PROPERTIES(${module_name} PROPERTIES PREFIX "") + if (${module_name} STREQUAL "linear" AND PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + target_compile_definitions(${module_name} PRIVATE PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION) + endif () endif() endif() diff --git a/plugins/linear.c b/plugins/linear.c index aeb22ade..769bc1a0 100644 --- a/plugins/linear.c +++ b/plugins/linear.c @@ -45,6 +45,18 @@ struct tslib_linear { unsigned int rot; }; +#ifdef PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION +int min(int a, int b) +{ + return a < b ? a : b; +} + +int max(int a, int b) +{ + return a > b ? a : b; +} +#endif + static int linear_read(struct tslib_module_info *info, struct ts_sample *samp, int nr_samples) { @@ -106,6 +118,20 @@ static int linear_read(struct tslib_module_info *info, struct ts_sample *samp, default: break; } + + #ifdef PLUGIN_LINEAR_LIMIT_TO_CALIBRATION_RESOLUTION + samp->x = max(samp->x, 0); + samp->y = max(samp->y, 0); + if(lin->cal_res_x) + { + samp->x = min(samp->x, lin->cal_res_x - 1); + } + + if(lin->cal_res_y) + { + samp->y = min(samp->y, lin->cal_res_y - 1); + } + #endif } } @@ -323,6 +349,8 @@ TSAPI struct tslib_module_info *linear_mod_init(__attribute__ ((unused)) struct lin->p_div = 1; lin->swap_xy = 0; lin->rot = 0; + lin->cal_res_x = 0; + lin->cal_res_y = 0; /* * Check calibration file