mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 05:32:47 +00:00
- clamp down the touchscreen coordinates to boundaries
- fix annoying compilation warning regarding unsigned vs signed comparison
This commit is contained in:
parent
70757e3385
commit
79aa9191f7
@ -30,21 +30,25 @@ u32 HID_ReadRawTouchState(void)
|
||||
static fixp_t ts_mult[2];
|
||||
|
||||
// ts_org indicates the coordinate system origin
|
||||
static u32 ts_org[2];
|
||||
static int ts_org[2];
|
||||
void HID_ReadTouchState(u16 *x, u16 *y)
|
||||
{
|
||||
u32 ts;
|
||||
int xc, yc;
|
||||
fixp_t tx, ty;
|
||||
|
||||
ts = HID_ReadRawTouchState();
|
||||
tx = INT_TO_FIXP(HID_RAW_TX(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];
|
||||
*y = FIXP_TO_INT(fixp_round(fixp_product(ty, ts_mult[1]))) + ts_org[1];
|
||||
xc = FIXP_TO_INT(fixp_round(fixp_product(tx, ts_mult[0]))) + ts_org[0];
|
||||
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;
|
||||
fixp_t avg_x, avg_y;
|
||||
|
@ -24,7 +24,7 @@ typedef struct {
|
||||
|
||||
u32 HID_ReadRawTouchState(void);
|
||||
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);
|
||||
bool CheckButton(u32 button);
|
||||
|
@ -1072,7 +1072,7 @@ static void DrawSimpleCircle(unsigned char *screen, int x, int y, int color, int
|
||||
|
||||
bool ShowCalibrationDialog(void)
|
||||
{
|
||||
int current_dot;
|
||||
u32 current_dot;
|
||||
static const u32 dot_positions[][2] = {
|
||||
{16, 16},
|
||||
{320 - 16, 240 - 16},
|
||||
@ -1089,7 +1089,7 @@ bool ShowCalibrationDialog(void)
|
||||
|
||||
current_dot = 0;
|
||||
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[current_dot][0], dot_positions[current_dot][1], COLOR_RED, COLOR_BLACK);
|
||||
for (u32 i = current_dot+1; i < countof(dot_positions); i++)
|
||||
|
@ -31,6 +31,9 @@
|
||||
#define int_sign(x) \
|
||||
(((x) > 0) - ((x) < 0))
|
||||
|
||||
#define clamp(x, min, max) \
|
||||
((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max))
|
||||
|
||||
#define getbe16(d) \
|
||||
(((d)[0]<<8) | (d)[1])
|
||||
#define getbe32(d) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user