Subversion Repositories shark

Rev

Rev 1120 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * Project: S.Ha.R.K.
 *
 * Coordinators:
 *   Giorgio Buttazzo    <giorgio@sssup.it>
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *
 * Authors     :
 *   Paolo Gai           <pj@gandalf.sssup.it>
 *   (see the web pages for full authors list)
 *
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
 *
 * http://www.sssup.it
 * http://retis.sssup.it
 * http://shark.sssup.it
 */


/*
 * Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 * CVS :        $Id: mousfind.c,v 1.2 2003-03-24 11:18:19 pj Exp $
 */


/*
 * Copyright (C) 2000 Paolo Gai, Massimiliano Giorgi
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include <kernel/kern.h>
#include <drivers/mouse.h>
#include <drivers/keyb.h>

/* don't include this into real applications!!! */
#include <../drivers/oldchar/_mouse.h>

int done;

void my_mouse_hook(MOUSE_EVT *m)
{
  static int buttons=-1;
  if (buttons!=m->buttons) {
    buttons=m->buttons;
    //mouse_off();
    if (isLeftButton(*m)) puts_xy(9,22,RED,"active");
    else                  puts_xy(9,22,RED,"      ");
    if (isCentralButton(*m)) puts_xy(9,23,RED,"active");
    else                     puts_xy(9,23,RED,"      ");
    if (isRightButton(*m)) puts_xy(9,24,RED,"active");
    else                   puts_xy(9,24,RED,"      ");
    //mouse_on();
  }


  /*
  if (tindex>20&&first) {
    int i;
    cprintf("\nSTART\n");
    for (i=0;i<tindex;i++) {
      cprintf("%i\n",(int)tdata[i]);
    }
    for (i=1;i<tindex;i++) {
      cprintf("%i ",(int)(tdata[i]-tdata[i-1]));
    }
    first=0;
  }
  */

 
}

int main(int argc,char *argv[])
{
  MOUSE_PARMS mouse=BASE_MOUSE;
  int ch,running,nm;
  int sens=5;

  /* screen */
  clear();

  nm=0;
  while (*vmouse[nm].name!='\0') {
    cprintf("%c %s:\t %s\n",(char)('a'+nm),vmouse[nm].name,vmouse[nm].desc);
    nm++;
  }

  cprintf("\n[a-%c]\t select a mouse server\n",(char)(nm+'a'-1));
  cprintf("[z]\t decrement mouse threshold\n");
  cprintf("[x]\t incremnet mouse threshold\n");
  cprintf("[1-4]\t COM port\n");
  cprintf("[ENTER]\t exit\n");
  place(0,20);
  cputs("mouse server:\n");
  cputs("threshold:\n");
  cputs("left   :\n");
  cputs("central:\n");
  cputs("right  :");
  CRSR_OFF();

  /* main loop */
  running=done=0;

  mouse_def_ms(mouse,0);

  while (!done) {
    ch=keyb_getch(TRUE);
    switch(ch) {

      /* exit demo */

    case ENTER:
      done = 1;
      break;
     
      /* decrement threshold */

    case 'z':
      sens--;
      if (sens<2) sens=2;
      mouse_threshold(sens);
      /* threshold */
      place(11,21);
      cprintf("%i    ",sens);
      break;

      /* increment threshold */
     
    case 'x':
      sens++;
      if (sens>100) sens=100;
      mouse_threshold(sens);
      /* threshold */
      place(11,21);
      cprintf("%i    ",sens);
      break;

      /* change mouse protocol */
     
    default:
      if (ch>='a'&&ch<='a'+nm-1) {
        /* don't use this method to change a mouse protocol */
        /* use mouse_def_???? macros instead */
        mouse.type=ch-'a';
      } else
      if (ch>='1'&&ch<='4') {
        /* don't use this method to change a mouse com port */
        /* use mouse_def_???? macros instead */
        mouse.port = ch-'1';
      }
      else
        break;

      /* check if a mouse server is running... */
      if (running) {
        /* disable autocursor */
        mouse_txtcursor(DISABLE);
        /* destroy actual mouse server */
        mouse_end();
      }
      /* mouse server name */
      puts_xy(14,20,GREEN,"                ");
      puts_xy(14,20,GREEN,vmouse[mouse.type].name);
      /* threshold */
      place(11,21);
      cprintf("%i    ",sens);
      /* start a new server */
      running=(mouse_init(&mouse)==0?1:0);
      /* if running ...*/
      if (running) {
        /* set mouse limit */
        mouse_limit(0,0,cons_columns-1,cons_rows-1);
        /* enable autocursor */
        mouse_txtcursor(ENABLE|AUTOOFF);
        /* hook my function */
        mouse_hook(my_mouse_hook);
        /* show mouse cursor */
        mouse_on();
      }
      break;
     
    }    
  }

  CRSR_STD();
  clear();
  sys_end();
  return 0;
}