Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to limit to calibration resolution #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
28 changes: 28 additions & 0 deletions plugins/linear.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down