Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/**
18
 ------------
19
 CVS :        $Id: testn.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
20
 
21
 File:        $File$
22
 Revision:    $Revision: 1.1.1.1 $
23
 Last update: $Date: 2002-09-02 09:37:48 $
24
 ------------
25
 
26
 Test Number 23 (N):
27
 
28
 This is the mousfind.c Hartik's example.
29
 
30
 It find the mouse...
31
 
32
**/
33
 
34
/*
35
 * Copyright (C) 2000 Paolo Gai
36
 *
37
 * This program is free software; you can redistribute it and/or modify
38
 * it under the terms of the GNU General Public License as published by
39
 * the Free Software Foundation; either version 2 of the License, or
40
 * (at your option) any later version.
41
 *
42
 * This program is distributed in the hope that it will be useful,
43
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45
 * GNU General Public License for more details.
46
 *
47
 * You should have received a copy of the GNU General Public License
48
 * along with this program; if not, write to the Free Software
49
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
50
 *
51
 */
52
 
53
#include <kernel/kern.h>
54
#include <drivers/mouse.h>
55
#include <drivers/keyb.h>
56
 
57
/* don't include this into real applications*/
58
#include <../drivers/char/_mouse.h>
59
 
60
#define cons_columns 80
61
#define cons_rows    25
62
 
63
int done;
64
 
65
void my_ctrlC_function(KEY_EVT *k)
66
{
67
  CRSR_STD();
68
  done=1;
69
  //sys_status(0xffff);
70
  sys_end();
71
  l1_exit(0);
72
}
73
 
74
//extern int tindex;
75
//extern DWORD tdata[];
76
//int first=1;
77
 
78
 
79
void my_mouse_hook(MOUSE_EVT *m)
80
{
81
  static int buttons=-1;
82
  if (buttons!=m->buttons) {
83
    buttons=m->buttons;
84
    //mouse_off();
85
    if (isLeftButton(*m)) puts_xy(9,22,RED,"active");
86
    else                  puts_xy(9,22,RED,"      ");
87
    if (isCentralButton(*m)) puts_xy(9,23,RED,"active");
88
    else                     puts_xy(9,23,RED,"      ");
89
    if (isRightButton(*m)) puts_xy(9,24,RED,"active");
90
    else                   puts_xy(9,24,RED,"      ");
91
    //mouse_on();
92
  }
93
 
94
 
95
  /*
96
  if (tindex>20&&first) {
97
    int i;
98
    cprintf("\nSTART\n");
99
    for (i=0;i<tindex;i++) {
100
      cprintf("%i\n",(int)tdata[i]);
101
    }
102
    for (i=1;i<tindex;i++) {
103
      cprintf("%i ",(int)(tdata[i]-tdata[i-1]));
104
    }
105
    first=0;
106
  }
107
  */
108
 
109
}
110
 
111
int main(int argc,char *argv[])
112
{
113
//  KEYB_PARMS  keyb =BASE_KEYB;
114
  MOUSE_PARMS mouse=BASE_MOUSE;
115
  int ch,running,nm;
116
  int sens=5;
117
 
118
  /* keyboard initialization */
119
//  keyb_def_ctrlC(keyb,my_ctrlC_function);
120
//  keyb_init(&keyb);
121
 
122
  /* screen */
123
  clear();
124
  nm=0;
125
  while (*vmouse[nm].name!='\0') {
126
    cprintf("%c %s:\t %s\n",(char)('a'+nm),vmouse[nm].name,vmouse[nm].desc);
127
    nm++;
128
  }
129
  cprintf("\n[a-%c]\t select a mouse server\n",(char)(nm+'a'-1));
130
  cprintf("[z]\t decrement mouse threshold\n");
131
  cprintf("[x]\t incremnet mouse threshold\n");
132
  cprintf("[ctrl-c]\t exit\n");
133
  place(0,20);
134
  cputs("mouse server:\n");
135
  cputs("threshold:\n");
136
  cputs("left   :\n");
137
  cputs("central:\n");
138
  cputs("right  :");
139
  CRSR_OFF();
140
 
141
  /* main loop */
142
  running=done=0;
143
  while (!done) {
144
    ch=keyb_getch(TRUE);
145
    switch(ch) {
146
 
147
      /* decrement threshold */
148
 
149
    case 'z':
150
      sens--;
151
      if (sens<2) sens=2;
152
      mouse_threshold(sens);
153
      /* threshold */
154
      place(11,21);
155
      cprintf("%i    ",sens);
156
      break;
157
 
158
      /* increment threshold */
159
 
160
    case 'x':
161
      sens++;
162
      if (sens>100) sens=100;
163
      mouse_threshold(sens);
164
      /* threshold */
165
      place(11,21);
166
      cprintf("%i    ",sens);
167
      break;
168
 
169
      /* change mouse protocol */
170
 
171
    default:
172
      if (ch>='a'&&ch<='a'+nm-1) {
173
        /* check if a mouse server is running... */
174
        if (running) {
175
          /* disable autocursor */
176
          mouse_txtcursor(DISABLE);
177
          /* destroy actual mouse server */
178
          mouse_end();
179
        }
180
        /* mouse server name */
181
        puts_xy(14,20,GREEN,"                ");
182
        puts_xy(14,20,GREEN,vmouse[ch-'a'].name);
183
        /* threshold */
184
        place(11,21);
185
        cprintf("%i    ",sens);
186
        /* don't use this method to change a mouse protocol */
187
        /* use mouse_def_???? macros instead */
188
        mouse.type=ch-'a';
189
        /* start a new server */
190
        running=(mouse_init(&mouse)==0?1:0);
191
        /* if running ...*/
192
        if (running) {
193
          /* set mouse limit */
194
          mouse_limit(0,0,cons_columns-1,cons_rows-1);
195
          /* enable autocursor */
196
          mouse_txtcursor(ENABLE|AUTOOFF);
197
          /* hook my function */
198
          mouse_hook(my_mouse_hook);
199
          /* show mouse cursor */
200
          mouse_on();
201
        }
202
      }
203
      break;
204
 
205
    }    
206
  }
207
 
208
  CRSR_STD();
209
  sys_end();
210
  return 0;
211
}