- clamp down the touchscreen coordinates to boundaries

- fix annoying compilation warning regarding unsigned vs signed comparison
This commit is contained in:
Wolfvak 2019-04-22 18:44:48 -03:00 committed by d0k3
parent 70757e3385
commit 79aa9191f7
4 changed files with 14 additions and 7 deletions

View File

@ -30,21 +30,25 @@ u32 HID_ReadRawTouchState(void)
static fixp_t ts_mult[2]; static fixp_t ts_mult[2];
// ts_org indicates the coordinate system origin // ts_org indicates the coordinate system origin
static u32 ts_org[2]; static int ts_org[2];
void HID_ReadTouchState(u16 *x, u16 *y) void HID_ReadTouchState(u16 *x, u16 *y)
{ {
u32 ts; u32 ts;
int xc, yc;
fixp_t tx, ty; fixp_t tx, ty;
ts = HID_ReadRawTouchState(); ts = HID_ReadRawTouchState();
tx = INT_TO_FIXP(HID_RAW_TX(ts) - HID_TOUCH_MIDPOINT); tx = INT_TO_FIXP(HID_RAW_TX(ts) - HID_TOUCH_MIDPOINT);
ty = INT_TO_FIXP(HID_RAW_TY(ts) - HID_TOUCH_MIDPOINT); ty = INT_TO_FIXP(HID_RAW_TY(ts) - HID_TOUCH_MIDPOINT);
*x = FIXP_TO_INT(fixp_round(fixp_product(tx, ts_mult[0]))) + ts_org[0]; xc = FIXP_TO_INT(fixp_round(fixp_product(tx, ts_mult[0]))) + ts_org[0];
*y = FIXP_TO_INT(fixp_round(fixp_product(ty, ts_mult[1]))) + ts_org[1]; yc = FIXP_TO_INT(fixp_round(fixp_product(ty, ts_mult[1]))) + ts_org[1];
*x = clamp(xc, 0, (ts_org[0] * 2) - 1);
*y = clamp(yc, 0, (ts_org[1] * 2) - 1);
} }
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, u32 screen_w, u32 screen_h) bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, int screen_w, int screen_h)
{ {
int mid_x, mid_y; int mid_x, mid_y;
fixp_t avg_x, avg_y; fixp_t avg_x, avg_y;

View File

@ -24,7 +24,7 @@ typedef struct {
u32 HID_ReadRawTouchState(void); u32 HID_ReadRawTouchState(void);
void HID_ReadTouchState(u16 *x, u16 *y); void HID_ReadTouchState(u16 *x, u16 *y);
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, u32 screen_w, u32 screen_h); bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, int screen_w, int screen_h);
u32 InputWait(u32 timeout_sec); u32 InputWait(u32 timeout_sec);
bool CheckButton(u32 button); bool CheckButton(u32 button);

View File

@ -1072,7 +1072,7 @@ static void DrawSimpleCircle(unsigned char *screen, int x, int y, int color, int
bool ShowCalibrationDialog(void) bool ShowCalibrationDialog(void)
{ {
int current_dot; u32 current_dot;
static const u32 dot_positions[][2] = { static const u32 dot_positions[][2] = {
{16, 16}, {16, 16},
{320 - 16, 240 - 16}, {320 - 16, 240 - 16},
@ -1089,7 +1089,7 @@ bool ShowCalibrationDialog(void)
current_dot = 0; current_dot = 0;
while(current_dot < countof(dot_positions)) { while(current_dot < countof(dot_positions)) {
for (int i = 0; i < current_dot; i++) for (u32 i = 0; i < current_dot; i++)
DrawSimpleCircle(BOT_SCREEN, dot_positions[i][0], dot_positions[i][1], COLOR_BRIGHTGREEN, COLOR_BLACK); DrawSimpleCircle(BOT_SCREEN, dot_positions[i][0], dot_positions[i][1], COLOR_BRIGHTGREEN, COLOR_BLACK);
DrawSimpleCircle(BOT_SCREEN, dot_positions[current_dot][0], dot_positions[current_dot][1], COLOR_RED, COLOR_BLACK); DrawSimpleCircle(BOT_SCREEN, dot_positions[current_dot][0], dot_positions[current_dot][1], COLOR_RED, COLOR_BLACK);
for (u32 i = current_dot+1; i < countof(dot_positions); i++) for (u32 i = current_dot+1; i < countof(dot_positions); i++)

View File

@ -31,6 +31,9 @@
#define int_sign(x) \ #define int_sign(x) \
(((x) > 0) - ((x) < 0)) (((x) > 0) - ((x) < 0))
#define clamp(x, min, max) \
((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max))
#define getbe16(d) \ #define getbe16(d) \
(((d)[0]<<8) | (d)[1]) (((d)[0]<<8) | (d)[1])
#define getbe32(d) \ #define getbe32(d) \