Move touchbox functions to hid.c / hid.h

This commit is contained in:
d0k3 2019-05-03 01:37:41 +02:00
parent 2f64a8046a
commit c3152838db
5 changed files with 28 additions and 36 deletions

View File

@ -106,6 +106,23 @@ bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, in
return true;
}
bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn) {
*id = 0;
// read coordinates, check if inside touchbox
if (!HID_ReadTouchState(x, y)) return false;
for (u32 i = 0; i < tbn; i++) {
const TouchBox* tb = tbs + i;
if ((*x >= tb->x) && (*y >= tb->y) &&
(*x < tb->x + tb->w) && (*y < tb->y + tb->h)) {
*id = tb->id;
break;
}
}
return true;
}
u32 InputWait(u32 timeout_sec) {
static u64 delay = 0;
u64 timer = timer_start();

View File

@ -26,6 +26,17 @@ u32 HID_ReadRawTouchState(void);
bool HID_ReadTouchState(u16 *x, u16 *y);
bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, int screen_w, int screen_h);
typedef struct {
u16 x;
u16 y;
u16 w;
u16 h;
u32 id; // shouldn't be zero
} __attribute__((packed)) TouchBox;
// abstraction for HID_ReadTouchState, also returns touchbox id (if any)
bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn);
u32 InputWait(u32 timeout_sec);
bool CheckButton(u32 button);

View File

@ -1,20 +0,0 @@
#include "touchui.h"
#include "hid.h"
bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn) {
*id = 0;
// read coordinates, check if inside touchbox
if (!HID_ReadTouchState(x, y)) return false;
for (u32 i = 0; i < tbn; i++) {
const TouchBox* tb = tbs + i;
if ((*x >= tb->x) && (*y >= tb->y) &&
(*x < tb->x + tb->w) && (*y < tb->y + tb->h)) {
*id = tb->id;
break;
}
}
return true;
}

View File

@ -1,15 +0,0 @@
#pragma once
#include "common.h"
typedef struct {
u16 x;
u16 y;
u16 w;
u16 h;
u32 id; // shouldn't be zero
} __attribute__((packed)) TouchBox;
// this assumes the touchscreen is actually in use
bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn);

View File

@ -1,5 +1,4 @@
#include "paint9.h"
#include "touchui.h"
#include "hid.h"
#include "ui.h"