Subversion Repositories shark

Rev

Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1655 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 <kernel/kern.h>
37
#include <kernel/func.h>
38
#include <stdlib.h>
39
#include <drivers/keyb.h>
40
#include <drivers/glib.h>
41
#include <semaphore.h>
42
#include "modules/sem.h"
43
#include "modules/hartport.h"
44
 
45
#include <math.h>
46
 
47
#include "joy.h"
48
 
49
#define RGB_BLACK     rgb16(  0,  0,  0)
50
#define RGB_GRAY      rgb16(127,127,127)
51
#define RGB_WHITE     rgb16(255,255,255)
52
#define RGB_RED       rgb16(255,  0,  0)
53
#define RGB_GREEN     rgb16(  0,255,  0)
54
#define RGB_BLUE      rgb16(  0,  0,255)
55
#define RGB_YELLOW    rgb16(255,255,  0)
56
#define RGB_MAGENTA   rgb16(255,  0,255)
57
#define RGB_CYAN      rgb16(  0,255,255)
58
#define RGB_D_RED     rgb16(127,  0,  0)
59
#define RGB_D_GREEN   rgb16(  0,127,  0)
60
#define RGB_D_BLUE    rgb16(  0,  0,127)
61
#define RGB_D_YELLOW  rgb16(127,127,  0)
62
#define RGB_D_MAGENTA rgb16(127,  0,127)
63
#define RGB_D_CYAN    rgb16(  0,127,127)
64
 
65
sem_t           mx_mat, mx_grf;         /* mutex semaphores */
66
PID             pid;
67
JOY_BOUND       jb;
68
 
69
 
70
TASK write()
71
{
72
        int             x = 319, y = 239;
73
        float           dx, dy;
74
        JOY_STATE       jsa;
75
 
76
        clear();
77
 
78
        dx = 640 / (jb.x_max - jb.x_min);
79
        dy = 480 / (jb.y_max - jb.y_min);
80
 
81
        while (1) {
82
                sem_wait(&mx_grf);
83
                grx_circle(10 + x, 10 + y, 9, RGB_BLACK);
84
                sem_post(&mx_grf);
85
 
86
                get_joystick_A(&jsa);
87
 
88
                x = (jsa.x - jb.x_min) * dx;
89
                y = (jsa.y - jb.y_min) * dy;
90
 
91
                sem_wait(&mx_grf);
92
                if (jsa.b1==1)
93
                        grx_circle(10 + dx * x, 10 + dy * y, 9, RGB_RED);
94
                else
95
                        grx_circle(10 + dx * x, 10 + dy * y, 9, RGB_YELLOW);
96
                sem_post(&mx_grf);
97
 
98
                task_endcycle();
99
        }
100
        return 0;
101
}
102
 
103
void endfun(KEY_EVT *k)
104
{
105
        cprintf("Ctrl-Brk pressed! Ending...\n");
106
        sys_end();
107
}
108
 
109
void my_close(void *arg)
110
{
111
        int i;
112
        TIME tmp;
113
 
114
        grx_close();
115
        kern_printf("Taskset Execution Time\n\n");
116
        for (i=3; i<MAX_PROC; i++){
117
                if (!jet_getstat(i, NULL, &tmp, NULL, NULL))
118
                        kern_printf("Task Name : %s - Max Time  : %d\n", proc_table[i].name, (int)tmp);
119
        }
120
}
121
 
122
void init_graph() {
123
        grx_box( 0, 0,639,479,RGB_BLACK);
124
}
125
 
126
int main(int argc, char **argv)
127
{
128
        SOFT_TASK_MODEL ms;
129
        KEY_EVT         k;
130
        TIME            seme;
131
        int             modenum;
132
 
133
        k.flag = CNTR_BIT;
134
        k.scan = KEY_C;
135
        k.ascii = 'c';
136
        keyb_hook(k,endfun);
137
 
138
        k.flag = CNTL_BIT;
139
        k.scan = KEY_C;
140
        k.ascii = 'c';
141
        keyb_hook(k,endfun);
142
 
143
        sem_init(&mx_mat,0,1);
144
        sem_init(&mx_grf,0,1);
145
 
146
        seme = sys_gettime(NULL);
147
        srand(seme);
148
 
149
        sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT);
150
 
151
        if (get_joystick_bound_A(&jb)) {
152
                perror("Could not find Joystick.");
153
                sys_end();
154
        }
155
 
156
        grx_init();
157
        modenum = grx_getmode(640, 480, 16);
158
        grx_setmode(modenum);
159
        init_graph();
160
 
161
        soft_task_default_model(ms);
162
        soft_task_def_level(ms,1);
163
        soft_task_def_ctrl_jet(ms);
164
        soft_task_def_met(ms,100);
165
        soft_task_def_period(ms,10000);
166
        soft_task_def_usemath(ms);
167
        pid = task_create("Write", write, &ms, NULL);
168
        if (pid == NIL) {
169
                grx_close();
170
                perror("Could not create task <Write>");
171
                sys_end();
172
        } else {
173
                task_activate(pid);
174
        }
175
 
176
        return 0;
177
}