Subversion Repositories shark

Rev

Rev 1332 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1331 giacomo 1
 
2
/*
3
 * Project: S.Ha.R.K.
4
 *
5
 * Coordinators: Giorgio Buttazzo <giorgio@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://shark.sssup.it
15
 */
16
 
17
/*
18
 * Copyright (C) 2000 Paolo Gai
19
 *
20
 * This program is free software; you can redistribute it and/or modify
21
 * it under the terms of the GNU General Public License as published by
22
 * the Free Software Foundation; either version 2 of the License, or
23
 * (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU General Public License
31
 * along with this program; if not, write to the Free Software
32
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
33
 *
34
 */
35
 
36
#include "chimera.h"
37
 
38
/* Manual step increment */
39
#define INC_LEG         2
40
 
41
unsigned char   active_leg;
42
 
43
void pad(KEY_EVT *k)
44
{
45
        switch (k->scan) {
46
                case KEY_Z:
47
                        //sem_wait(&mx_status);
48
                        status.power ^= 1;
49
                        //sem_post(&mx_status);
50
                        break;
51
 
52
                case KEY_Q:
53
                        //sem_wait(&mx_status);
54
                        status.leg[active_leg].pwm ^= 0x1;
55
                        //sem_post(&mx_status);
56
                        break;
57
                case KEY_W:
58
                        //sem_wait(&mx_status);
59
                        status.leg[active_leg].pwm ^= 0x2;
60
                        //sem_post(&mx_status);
61
                        break;
62
                case KEY_E:
63
                        //sem_wait(&mx_status);
64
                        status.leg[active_leg].pwm ^= 0x4;
65
                        //sem_post(&mx_status);
66
                        break;
67
 
68
                case KEY_U:
69
                        //sem_wait(&mx_status);
70
                        status.leg[active_leg].x += INC_LEG;
71
                        if (status.leg[active_leg].x > POS_X_MAX) status.leg[active_leg].x = POS_X_MAX;
72
                        //sem_post(&mx_status);
73
                        break;
74
                case KEY_J:
75
                        //sem_wait(&mx_status);
76
                        status.leg[active_leg].x -= INC_LEG;
77
                        if (status.leg[active_leg].x < POS_X_MIN) status.leg[active_leg].x = POS_X_MIN;
78
                        //sem_post(&mx_status);
79
                        break;
80
                case KEY_I:
81
                        //sem_wait(&mx_status);
82
                        status.leg[active_leg].y += INC_LEG;
83
                        if (status.leg[active_leg].y > POS_Y_MAX) status.leg[active_leg].y = POS_Y_MAX;
84
                        //sem_post(&mx_status);
85
                        break;
86
                case KEY_K:
87
                        //sem_wait(&mx_status);
88
                        status.leg[active_leg].y -= INC_LEG;
89
                        if (status.leg[active_leg].y < POS_Y_MIN) status.leg[active_leg].y = POS_Y_MIN;
90
                        //sem_post(&mx_status);
91
                        break;
92
                case KEY_O:
93
                        //sem_wait(&mx_status);
94
                        status.leg[active_leg].z += INC_LEG;
95
                        if (status.leg[active_leg].z > POS_Z_MAX) status.leg[active_leg].z = POS_Z_MAX;
96
                        //sem_post(&mx_status);
97
                        break;
98
                case KEY_L:
99
                        //sem_wait(&mx_status);
100
                        status.leg[active_leg].z -= INC_LEG;
101
                        if (status.leg[active_leg].z < POS_Z_MIN) status.leg[active_leg].z = POS_Z_MIN;
102
                        //sem_post(&mx_status);
103
                        break;
104
 
105
                case KEY_1:
106
                        active_leg = 0;
107
                        break;
108
                case KEY_2:
109
                        active_leg = 1;
110
                        break;
111
                case KEY_3:
112
                        active_leg = 2;
113
                        break;
114
                case KEY_4:
115
                        active_leg = 3;
116
                        break;
117
                case KEY_5:
118
                        active_leg = 4;
119
                        break;
120
                case KEY_6:
121
                        active_leg = 5;
122
                        break;
123
        }
124
}
125
 
126
void init_key()
127
{
128
        KEY_EVT k;
129
 
130
        /* Leg Selector */
131
        k.flag = 0;
132
        k.scan = KEY_1;
133
        k.ascii = '1';
134
        keyb_hook(k,pad);
135
 
136
        k.flag = 0;
137
        k.scan = KEY_2;
138
        k.ascii = '2';
139
        keyb_hook(k,pad);
140
 
141
        k.flag = 0;
142
        k.scan = KEY_3;
143
        k.ascii = '3';
144
        keyb_hook(k,pad);
145
 
146
        k.flag = 0;
147
        k.scan = KEY_4;
148
        k.ascii = '4';
149
        keyb_hook(k,pad);
150
 
151
        k.flag = 0;
152
        k.scan = KEY_5;
153
        k.ascii = '5';
154
        keyb_hook(k,pad);
155
 
156
        k.flag = 0;
157
        k.scan = KEY_6;
158
        k.ascii = '6';
159
        keyb_hook(k,pad);
160
 
161
        /* Leg Position */
162
        k.flag = 0;
163
        k.scan = KEY_J;
164
        k.ascii = 'j';
165
        keyb_hook(k,pad);
166
 
167
        k.flag = 0;
168
        k.scan = KEY_K;
169
        k.ascii = 'k';
170
        keyb_hook(k,pad);
171
 
172
        k.flag = 0;
173
        k.scan = KEY_L;
174
        k.ascii = 'l';
175
        keyb_hook(k,pad);
176
 
177
        k.flag = 0;
178
        k.scan = KEY_U;
179
        k.ascii = 'u';
180
        keyb_hook(k,pad);
181
 
182
        k.flag = 0;
183
        k.scan = KEY_I;
184
        k.ascii = 'i';
185
        keyb_hook(k,pad);
186
 
187
        k.flag = 0;
188
        k.scan = KEY_O;
189
        k.ascii = 'o';
190
        keyb_hook(k,pad);
191
 
192
        k.flag = 0;
193
        k.scan = KEY_Q;
194
        k.ascii = 'o';
195
        keyb_hook(k,pad);
196
 
197
        k.flag = 0;
198
        k.scan = KEY_W;
199
        k.ascii = 'o';
200
        keyb_hook(k,pad);
201
 
202
        k.flag = 0;
203
        k.scan = KEY_E;
204
        k.ascii = 'o';
205
        keyb_hook(k,pad);
206
 
207
        k.flag = 0;
208
        k.scan = KEY_Z;
209
        k.ascii = 'o';
210
        keyb_hook(k,pad);
211
}