35,7 → 35,8 |
* |
*/ |
|
#define __MOUSE_DEBUG__ |
//#define __MOUSE_DEBUG__ |
//#define MOUSE_TASK |
|
#include <kernel/kern.h> |
|
50,54 → 51,244 |
extern int mouse_init(void); |
extern void mouse_exit(void); |
|
/* Functions */ |
extern int mouse_get(int *dx, int *dy, int *dz, unsigned long *buttons); |
|
extern int input_installed; |
|
/* Mouse driver currently installed */ |
/* Mouse driver currently installed/actived */ |
static int mouse_installed = FALSE; |
static int mouse_enabled = FALSE; |
|
/*static short int mouse_lim_x1 = 0; |
static short int mouse_lim_y1 = 0; |
static short int mouse_lim_x2 = 79; |
static short int mouse_lim_y2 = 24; |
static short int mouse_x = 40; |
static short int mouse_x_mick = 0; |
static short int mouse_y = 12; |
static short int mouse_y_mick = 0; |
static short int mouse_buttons = 0; |
static short int mouse_thresholdlim = 5; |
static int mouse_xmin_tick; |
static int mouse_ymin_tick; |
static int mouse_xmax_tick; |
static int mouse_ymax_tick; |
|
#define MOUSE_DEF_THRESHOLD 10 |
static int mouse_threshold; |
|
static int mouse_x = 0; |
static int mouse_y = 0; |
static int mouse_x_tick = 0; |
static int mouse_y_tick = 0; |
static int mouse_z = 0; |
static unsigned long mouse_buttons = 0; |
|
static MOUSE_HANDLER mouse_handler = NULL; |
static MOUSE_HANDLER user_mouse_handler = NULL; |
|
static int autocursormode=DISABLE; |
#ifdef MOUSE_TASK |
/* mouse task PID */ |
static PID mousepid = NIL; |
#else |
void mouseProc(void); |
#endif |
|
static PID mouse_pid = NIL;*/ |
|
|
/* |
* Start mouseProc Task |
*/ |
void shark_mouse_task(void) |
void shark_mouse_exec(void) |
{ |
//task_activate(mousebpid); |
#ifdef MOUSE_TASK |
task_activate(mousepid); |
#else |
mouseProc(); |
#endif |
} |
|
#ifdef MOUSE_TASK |
TASK mouseProc(void) |
#else |
void mouseProc(void) |
#endif |
{ |
static MOUSE_EVT ev; |
unsigned long dbuttons; |
int dx, dy, dz; |
int res; |
|
#ifdef MOUSE_TASK |
while (1) { |
#endif |
if (mouse_enabled) { |
res = mouse_get(&dx, &dy, &dz, &dbuttons); |
if (res >= 0) { |
mouse_x_tick += dx; |
if (mouse_x_tick < mouse_xmin_tick) |
mouse_x_tick = mouse_xmin_tick; |
if (mouse_x_tick > mouse_xmax_tick) |
mouse_x_tick = mouse_xmax_tick; |
mouse_x = (mouse_x_tick + (mouse_threshold/2)) / mouse_threshold; |
ev.x = mouse_x; |
ev.dx = dx; |
|
mouse_y_tick -= dy; |
if (mouse_y_tick < mouse_ymin_tick) |
mouse_y_tick = mouse_ymin_tick; |
if (mouse_y_tick > mouse_ymax_tick) |
mouse_y_tick = mouse_ymax_tick; |
mouse_y = (mouse_y_tick + (mouse_threshold/2)) / mouse_threshold; |
ev.y = mouse_y; |
ev.dy = dy; |
|
mouse_z += dz; |
ev.z = mouse_z; |
ev.dz = dz; |
|
mouse_buttons = dbuttons; |
ev.buttons = mouse_buttons; |
#ifdef __MOUSE_DEBUG__ |
printk(KERN_DEBUG "shark_mouse.c: delta ( %3d %3d %3d - %6x) -> ( %3d %3d %3d - %6x)\n", |
dx, dy, dz, (int)dbuttons, mouse_x, mouse_y, mouse_z, (int)mouse_buttons); |
#endif |
/* mouse handler */ |
if (mouse_handler!=NULL) mouse_handler(&ev); |
} |
} |
#ifdef MOUSE_TASK |
task_endcycle(); |
} |
#endif |
} |
|
/**** Start User Functions ****/ |
|
void mouse_enable(void) |
{ |
mouse_enabled = TRUE; /* TODO */ |
} |
|
void mouse_disable(void) |
{ |
mouse_enabled = FALSE; /* TODO */ |
} |
|
void mouse_getpos(int *x,int *y,int *z, unsigned long *buttons) |
{ |
*x = mouse_x; |
*y = mouse_y; |
*z = mouse_z; |
*buttons = mouse_buttons; |
} |
|
void mouse_setpos(int x,int y, int z) |
{ |
mouse_enabled = FALSE; |
|
mouse_x = x; |
if (x < (mouse_xmin_tick / mouse_threshold)) |
mouse_x = mouse_xmin_tick / mouse_threshold; |
if (x > (mouse_xmax_tick / mouse_threshold)) |
mouse_x = mouse_xmax_tick / mouse_threshold; |
|
mouse_y = y; |
if (y < (mouse_ymin_tick / mouse_threshold)) |
mouse_y = mouse_ymin_tick / mouse_threshold; |
if (y > (mouse_ymax_tick / mouse_threshold)) |
mouse_y = mouse_ymax_tick / mouse_threshold; |
|
mouse_z = z; |
|
mouse_enabled = TRUE; |
} |
|
void mouse_getlimit(int *xmin, int *ymin, int *xmax, int *ymax) |
{ |
*xmin = mouse_xmin_tick / mouse_threshold; |
*ymin = mouse_ymin_tick / mouse_threshold; |
*xmax = mouse_xmax_tick / mouse_threshold; |
*ymax = mouse_ymax_tick / mouse_threshold; |
} |
|
int mouse_setlimit(int xmin, int ymin, int xmax, int ymax) |
{ |
if ((xmin < 0) && (ymin < 0) && (xmax < xmin) && (ymax < ymin)) |
return -1; |
|
mouse_xmin_tick = xmin * mouse_threshold; |
mouse_ymin_tick = ymin * mouse_threshold; |
mouse_xmax_tick = xmax * mouse_threshold; |
mouse_ymax_tick = ymax * mouse_threshold; |
|
return 0; |
} |
|
void mouse_hook(MOUSE_HANDLER h) |
{ |
mouse_handler = h; |
} |
|
int mouse_getthreshold(void) |
{ |
return mouse_threshold; |
} |
|
int mouse_setthreshold(int t) |
{ |
mouse_enabled = FALSE; |
|
if ((t>0) && (t<=200)) { |
mouse_xmin_tick = (mouse_xmin_tick * t) / mouse_threshold; |
mouse_ymin_tick = (mouse_ymin_tick * t) / mouse_threshold; |
mouse_xmax_tick = (mouse_xmax_tick * t) / mouse_threshold; |
mouse_ymax_tick = (mouse_ymax_tick * t) / mouse_threshold; |
mouse_threshold = t; |
return 0; |
} else { |
return -1; |
} |
|
mouse_enabled = TRUE; |
} |
|
/**** End User Functions ****/ |
|
/* Init the Linux Speaker Driver */ |
/*int MOUSE26_init(MOUSE_PARMS *s)*/ |
int MOUSE26_init(void) |
int MOUSE26_init(MOUSE_PARMS *s) |
{ |
/*MOUSE_PARMS mparms=BASE_MOUSE; |
TASK_MODEL *m; |
SOFT_TASK_MODEL base_m;*/ |
MOUSE_PARMS mparms = BASE_MOUSE; |
int status = 0; |
|
#ifdef MOUSE_TASK |
TASK_MODEL *m; |
SOFT_TASK_MODEL base_m; |
#endif |
|
if (mouse_installed == TRUE) return 0; |
|
/* if a NULL is passed */ |
/*if (s == NULL) |
if (s == NULL) |
s = &mparms; |
|
/* set mouse threshold */ |
if (s->threshold == (int) MOUSE_DEFAULT) |
mouse_threshold = MOUSE_DEF_THRESHOLD; |
else |
mouse_threshold = s->threshold; |
|
/* set mouse limits */ |
if ((s->xmin == (int) MOUSE_DEFAULT) || (s->xmin < 0)) |
mouse_xmin_tick = 0; |
else |
mouse_xmin_tick = s->xmin * mouse_threshold; |
|
if ((s->ymin == (int) MOUSE_DEFAULT) || (s->ymin < 0)) |
mouse_ymin_tick = 0; |
else |
mouse_ymin_tick = s->ymin * mouse_threshold; |
|
if ((s->xmax == (int) MOUSE_DEFAULT) || ((s->xmax * mouse_threshold) < mouse_xmin_tick)) |
mouse_xmax_tick = 79 * mouse_threshold; |
else |
mouse_xmax_tick = s->xmax * mouse_threshold; |
|
if ((s->ymax == (int) MOUSE_DEFAULT) || ((s->ymax * mouse_threshold) < mouse_ymin_tick)) |
mouse_ymax_tick = 24 * mouse_threshold; |
else |
mouse_ymax_tick = s->ymax * mouse_threshold; |
|
#ifdef MOUSE_TASK |
if (s->tm == (TASK_MODEL *)MOUSE_DEFAULT) { |
soft_task_default_model(base_m); |
soft_task_def_wcet(base_m,2000); |
108,11 → 299,18 |
soft_task_def_aperiodic(base_m); |
m = (TASK_MODEL *)&base_m; |
} else |
m = parms->tm;*/ |
m = s->tm; |
|
mousepid = task_create ("MouseTask", mouseProc, m, NULL); |
if (mousepid == -1) { |
return -1; |
} |
#endif |
|
if (input_installed == FALSE) { |
status = INPUT26_init(); |
if (status) { |
|
printk(KERN_ERR "shark_mouse.c: Unable to open Input SubSystem.\n"); |
return -1; |
} |
131,6 → 329,7 |
} |
|
mouse_installed = TRUE; |
mouse_enabled = TRUE; |
|
return status; |
} |
137,12 → 336,29 |
|
int MOUSE26_close() |
{ |
#ifdef MOUSE_TASK |
int free; |
SYS_FLAGS f; |
#endif |
|
if (!mouse_installed) |
return -1; |
|
mouse_enabled = FALSE; |
mouse_exit(); |
psmouse_exit(); |
|
|
#ifdef MOUSE_TASK |
f = kern_fsave(); |
free = (proc_table[mousepid].status == FREE); |
kern_frestore(f); |
#ifdef __MOUSE_DEBUG__ |
printk(KERN_DEBUG "shark_mouse.c: MouseTask is %s.\n", free ? "killed" : "alive"); |
#endif |
if (free) |
task_kill (mousepid); |
#endif |
|
mouse_installed = FALSE; |
|
return 0; |