More newmouse updates
This commit is contained in:
parent
b5c3f3f4f8
commit
676c416a9b
3 changed files with 91 additions and 55 deletions
|
@ -57,7 +57,7 @@ typedef struct GMouse {
|
||||||
#if !GINPUT_TOUCH_NOCALIBRATE
|
#if !GINPUT_TOUCH_NOCALIBRATE
|
||||||
GMouseCalibrationSaveRoutine fnsavecal; // The calibration load routine
|
GMouseCalibrationSaveRoutine fnsavecal; // The calibration load routine
|
||||||
GMouseCalibrationLoadRoutine fnloadcal; // The calibration save routine
|
GMouseCalibrationLoadRoutine fnloadcal; // The calibration save routine
|
||||||
MouseCalibration caldata; // The calibration data
|
GMouseCalibration caldata; // The calibration data
|
||||||
#endif
|
#endif
|
||||||
// Other driver specific fields may follow.
|
// Other driver specific fields may follow.
|
||||||
} GMouse;
|
} GMouse;
|
||||||
|
|
|
@ -16,10 +16,16 @@
|
||||||
|
|
||||||
#if GFX_USE_GINPUT
|
#if GFX_USE_GINPUT
|
||||||
|
|
||||||
|
#if GINPUT_NEED_MOUSE
|
||||||
|
extern void _gmouseInit(void);
|
||||||
|
extern void _gmouseDeinit(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
void _ginputInit(void)
|
void _ginputInit(void)
|
||||||
{
|
{
|
||||||
/* ToDo */
|
#if GINPUT_NEED_MOUSE
|
||||||
|
_gmouseInit();
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* This should really call an init routine for each ginput sub-system.
|
* This should really call an init routine for each ginput sub-system.
|
||||||
* Maybe we'll do this later.
|
* Maybe we'll do this later.
|
||||||
|
@ -28,7 +34,9 @@ void _ginputInit(void)
|
||||||
|
|
||||||
void _ginputDeinit(void)
|
void _ginputDeinit(void)
|
||||||
{
|
{
|
||||||
|
#if GINPUT_NEED_MOUSE
|
||||||
|
_gmouseDeinit();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GFX_USE_GINPUT */
|
#endif /* GFX_USE_GINPUT */
|
||||||
|
|
|
@ -75,7 +75,7 @@ static GTIMER_DECL(MouseTimer);
|
||||||
pt->y = (coord_t) (c->ay * pt->x + c->by * pt->y + c->cy);
|
pt->y = (coord_t) (c->ay * pt->x + c->by * pt->y + c->cy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void CalibrationCalculate(GMouse *m, const MousePoint *cross, const MousePoint *points) {
|
static inline void CalibrationCalculate(GMouse *m, const point *cross, const point *points) {
|
||||||
float dx;
|
float dx;
|
||||||
coord_t c0, c1, c2;
|
coord_t c0, c1, c2;
|
||||||
(void) m;
|
(void) m;
|
||||||
|
@ -108,6 +108,8 @@ static GTIMER_DECL(MouseTimer);
|
||||||
c1 -= cross[1].y;
|
c1 -= cross[1].y;
|
||||||
c2 -= cross[2].y;
|
c2 -= cross[2].y;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,6 +151,8 @@ static GTIMER_DECL(MouseTimer);
|
||||||
c1 = cross[1].x;
|
c1 = cross[1].x;
|
||||||
c2 = cross[2].x;
|
c2 = cross[2].x;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -186,33 +190,33 @@ static void GetMouseReading(GMouse *m) {
|
||||||
// Double check up & down events if needed
|
// Double check up & down events if needed
|
||||||
if ((gmvmt(m)->d.flags & GMOUSE_VFLG_POORUPDOWN)) {
|
if ((gmvmt(m)->d.flags & GMOUSE_VFLG_POORUPDOWN)) {
|
||||||
// Are we in a transition test
|
// Are we in a transition test
|
||||||
if ((pm->flags & GMOUSE_FLG_INDELTA)) {
|
if ((m->flags & GMOUSE_FLG_INDELTA)) {
|
||||||
if (!((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) {
|
if (!((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) {
|
||||||
// Transition failed
|
// Transition failed
|
||||||
pm->flags &= ~GMOUSE_FLG_INDELTA;
|
m->flags &= ~GMOUSE_FLG_INDELTA;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Transition succeeded
|
// Transition succeeded
|
||||||
pm->flags &= ~GMOUSE_FLG_INDELTA;
|
m->flags &= ~GMOUSE_FLG_INDELTA;
|
||||||
|
|
||||||
// Should we start a transition test
|
// Should we start a transition test
|
||||||
} else if (((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) {
|
} else if (((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) {
|
||||||
pm->flags |= GMOUSE_FLG_INDELTA;
|
m->flags |= GMOUSE_FLG_INDELTA;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mouse is up we may need to keep our previous position
|
// If the mouse is up we may need to keep our previous position
|
||||||
if ((gmvmt(m)->d.flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) {
|
if ((gmvmt(m)->d.flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) {
|
||||||
r.x = pm->r.x;
|
r.x = m->r.x;
|
||||||
r.y = pm->r.y;
|
r.y = m->r.y;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
coord_t w, h;
|
coord_t w, h;
|
||||||
|
|
||||||
#if !GINPUT_TOUCH_NOCALIBRATE
|
#if !GINPUT_TOUCH_NOCALIBRATE
|
||||||
// Do we need to calibrate the reading?
|
// Do we need to calibrate the reading?
|
||||||
if ((pm->flags & GMOUSE_FLG_CALIBRATE))
|
if ((m->flags & GMOUSE_FLG_CALIBRATE))
|
||||||
CalibrationTransform(&r, &m->caldata);
|
CalibrationTransform(&r, &m->caldata);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -252,7 +256,7 @@ static void GetMouseReading(GMouse *m) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Do we need to clip the reading to the display
|
// Do we need to clip the reading to the display
|
||||||
if ((pm->flags & GMOUSE_FLG_CLIP)) {
|
if ((m->flags & GMOUSE_FLG_CLIP)) {
|
||||||
if (r.x < 0) r.x = 0;
|
if (r.x < 0) r.x = 0;
|
||||||
else if (r.x >= w) r.x = w-1;
|
else if (r.x >= w) r.x = w-1;
|
||||||
if (r.y < 0) r.y = 0;
|
if (r.y < 0) r.y = 0;
|
||||||
|
@ -325,7 +329,7 @@ static void GetMouseReading(GMouse *m) {
|
||||||
|
|
||||||
// Send the event to the listeners that are interested.
|
// Send the event to the listeners that are interested.
|
||||||
psl = 0;
|
psl = 0;
|
||||||
while ((psl = geventGetSourceListener((GSourceHandle)(&MouseConfig), psl))) {
|
while ((psl = geventGetSourceListener((GSourceHandle)m, psl))) {
|
||||||
if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) {
|
if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) {
|
||||||
// This listener is missing - save the meta events that have happened
|
// This listener is missing - save the meta events that have happened
|
||||||
psl->srcflags |= meta;
|
psl->srcflags |= meta;
|
||||||
|
@ -341,7 +345,7 @@ static void GetMouseReading(GMouse *m) {
|
||||||
if (((r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES))
|
if (((r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES))
|
||||||
|| (!(r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES))
|
|| (!(r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES))
|
||||||
|| (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) {
|
|| (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) {
|
||||||
pe->type = GINPUT_MOUSE_EVENT_TYPE;
|
pe->type = (gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) ? GEVENT_TOUCH : GEVENT_MOUSE;
|
||||||
pe->x = r.x;
|
pe->x = r.x;
|
||||||
pe->y = r.y;
|
pe->y = r.y;
|
||||||
pe->z = r.z;
|
pe->z = r.z;
|
||||||
|
@ -370,77 +374,102 @@ static void MousePoll(void *param) {
|
||||||
GMouse * m;
|
GMouse * m;
|
||||||
(void) param;
|
(void) param;
|
||||||
|
|
||||||
for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, m)) {
|
for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, (GDriver *)m)) {
|
||||||
if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_NOPOLL) || (m->flags & GMOUSE_FLG_NEEDREAD))
|
if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_NOPOLL) || (m->flags & GMOUSE_FLG_NEEDREAD))
|
||||||
GetMouseReading(m);
|
GetMouseReading(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _gmouseInit(void) {
|
||||||
|
// GINPUT_MOUSE_DRIVER_LIST is defined - create each driver instance
|
||||||
|
#if defined(GINPUT_MOUSE_DRIVER_LIST)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
extern GDriverVMTList GINPUT_MOUSE_DRIVER_LIST;
|
||||||
|
static const struct GDriverVMT const * dclist[] = {GINPUT_MOUSE_DRIVER_LIST};
|
||||||
|
static const unsigned dnlist[] = {GDISP_CONTROLLER_DISPLAYS};
|
||||||
|
|
||||||
|
for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++)
|
||||||
|
gdriverRegister(dclist[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// One and only one display
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
extern GDriverVMTList GINPUTMOUSEVMT_OnlyOne;
|
||||||
|
|
||||||
|
gdriverRegister(GINPUTMOUSEVMT_OnlyOne);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void _gmouseDeinit(void) {
|
||||||
|
}
|
||||||
|
|
||||||
GSourceHandle ginputGetMouse(uint16_t instance) {
|
GSourceHandle ginputGetMouse(uint16_t instance) {
|
||||||
|
GMouse *m;
|
||||||
#if GINPUT_MOUSE_NEED_CALIBRATION
|
#if GINPUT_MOUSE_NEED_CALIBRATION
|
||||||
Calibration *pc;
|
GCalibration *pc;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// We only support a single mouse instance currently
|
if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance)))
|
||||||
// Instance 9999 is the same as instance 0 except that it installs
|
|
||||||
// a special "raw" calibration if there isn't one we can load.
|
|
||||||
if (instance && instance != 9999)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Make sure we have a valid mouse display
|
// Make sure we have a valid mouse display
|
||||||
if (!MouseConfig.display)
|
if (!m->display)
|
||||||
MouseConfig.display = GDISP;
|
m->display = GDISP;
|
||||||
|
|
||||||
// Do we need to initialise the mouse subsystem?
|
// Do we need to initialise the mouse subsystem?
|
||||||
if (!(MouseConfig.flags & FLG_INIT_DONE)) {
|
if (!(m->flags & FLG_INIT_DONE)) {
|
||||||
ginput_lld_mouse_init();
|
ginput_lld_mouse_init();
|
||||||
|
|
||||||
#if GINPUT_MOUSE_NEED_CALIBRATION
|
#if GINPUT_MOUSE_NEED_CALIBRATION
|
||||||
#if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE
|
#if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE
|
||||||
if (!MouseConfig.fnloadcal) {
|
if (!m->fnloadcal) {
|
||||||
MouseConfig.fnloadcal = ginput_lld_mouse_calibration_load;
|
m->fnloadcal = ginput_lld_mouse_calibration_load;
|
||||||
MouseConfig.flags &= ~FLG_CAL_FREE;
|
m->flags &= ~FLG_CAL_FREE;
|
||||||
}
|
}
|
||||||
if (!MouseConfig.fnsavecal)
|
if (!m->fnsavecal)
|
||||||
MouseConfig.fnsavecal = ginput_lld_mouse_calibration_save;
|
m->fnsavecal = ginput_lld_mouse_calibration_save;
|
||||||
#endif
|
#endif
|
||||||
if (MouseConfig.fnloadcal && (pc = (Calibration *)MouseConfig.fnloadcal(instance))) {
|
if (m->fnloadcal && (pc = (Calibration *)m->fnloadcal(instance))) {
|
||||||
memcpy(&MouseConfig.caldata, pc, sizeof(MouseConfig.caldata));
|
memcpy(&m->caldata, pc, sizeof(m->caldata));
|
||||||
MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED);
|
m->flags |= (FLG_CAL_OK|FLG_CAL_SAVED);
|
||||||
if ((MouseConfig.flags & FLG_CAL_FREE))
|
if ((m->flags & FLG_CAL_FREE))
|
||||||
gfxFree((void *)pc);
|
gfxFree((void *)pc);
|
||||||
} else if (instance == 9999) {
|
} else if (instance == 9999) {
|
||||||
CalibrationSetIdentity(&MouseConfig.caldata);
|
CalibrationSetIdentity(&m->caldata);
|
||||||
MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW);
|
m->flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW);
|
||||||
} else
|
} else
|
||||||
ginputCalibrateMouse(instance);
|
ginputCalibrateMouse(instance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Get the first reading
|
// Get the first reading
|
||||||
MouseConfig.last_buttons = 0;
|
m->last_buttons = 0;
|
||||||
get_calibrated_reading(&MouseConfig.t);
|
get_calibrated_reading(&m->t);
|
||||||
|
|
||||||
// Mark init as done and start the Poll timer
|
// Mark init as done and start the Poll timer
|
||||||
MouseConfig.flags |= FLG_INIT_DONE;
|
m->flags |= FLG_INIT_DONE;
|
||||||
gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD);
|
gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our structure as the handle
|
// Return our structure as the handle
|
||||||
return (GSourceHandle)&MouseConfig;
|
return (GSourceHandle)m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ginputSetMouseDisplay(uint16_t instance, GDisplay *g) {
|
void ginputSetMouseDisplay(uint16_t instance, GDisplay *g) {
|
||||||
if (instance)
|
if (instance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MouseConfig.display = g ? g : GDISP;
|
m->display = g ? g : GDISP;
|
||||||
}
|
}
|
||||||
|
|
||||||
GDisplay *ginputGetMouseDisplay(uint16_t instance) {
|
GDisplay *ginputGetMouseDisplay(uint16_t instance) {
|
||||||
if (instance)
|
if (instance)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return MouseConfig.display;
|
return m->display;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) {
|
bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) {
|
||||||
|
@ -448,16 +477,15 @@ bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) {
|
||||||
// so we add a sleep here to prevent 100% polled applications from locking up.
|
// so we add a sleep here to prevent 100% polled applications from locking up.
|
||||||
gfxSleepMilliseconds(1);
|
gfxSleepMilliseconds(1);
|
||||||
|
|
||||||
if (instance || (MouseConfig.flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE)
|
if (instance || (m->flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
pe->type = GINPUT_MOUSE_EVENT_TYPE;
|
pe->type = GINPUT_MOUSE_EVENT_TYPE;
|
||||||
pe->instance = instance;
|
pe->x = m->t.x;
|
||||||
pe->x = MouseConfig.t.x;
|
pe->y = m->t.y;
|
||||||
pe->y = MouseConfig.t.y;
|
pe->z = m->t.z;
|
||||||
pe->z = MouseConfig.t.z;
|
pe->current_buttons = m->t.buttons;
|
||||||
pe->current_buttons = MouseConfig.t.buttons;
|
pe->last_buttons = m->last_buttons;
|
||||||
pe->last_buttons = MouseConfig.last_buttons;
|
|
||||||
if (pe->current_buttons & ~pe->last_buttons & GINPUT_MOUSE_BTN_LEFT)
|
if (pe->current_buttons & ~pe->last_buttons & GINPUT_MOUSE_BTN_LEFT)
|
||||||
pe->meta = GMETA_MOUSE_DOWN;
|
pe->meta = GMETA_MOUSE_DOWN;
|
||||||
else if (~pe->current_buttons & pe->last_buttons & GINPUT_MOUSE_BTN_LEFT)
|
else if (~pe->current_buttons & pe->last_buttons & GINPUT_MOUSE_BTN_LEFT)
|
||||||
|
|
Loading…
Add table
Reference in a new issue