Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
// framegrabber stuffs
2
 
3
/* File name ......... : ELABOR.C
4
 * Project............ :
5
 * Object ............ :
6
 * Author ............ : Facchinetti Tullio
7
 * Language .......... : C
8
 * Compiler .......... : GNU C
9
 * Operative system .. : MS-DOS/HARTIK
10
 * Creation data ..... : 04/03/2000
11
 * Last modify ....... : 19/11/99
12
 */
13
 
14
 
15
 
16
 
17
#include <kernel/func.h>
18
#include <modules/cabs.h>
19
#include <stdio.h>
20
#include <drivers/pxc.h>
21
#include "demo.h"
22
 
23
PID image_elab_PID;
24
TIME periodo;
25
CAB PXC_CAB;
26
 
27
static CAB frameCAB; // CAB di deposito delle immagini
28
static TDataObj current, older;
29
 
30
// extern in INIT.C
31
int img_border    =  10;
32
int window_width  =  40;
33
int window_height =  40;
34
 
35
// a 256 grayscale palette
36
WORD gray_palette[256];
37
 
38
// the image to be putted on the screen
39
WORD converted_image[IMG_COL*IMG_ROW];
40
 
41
 
42
#ifdef __BLACK_ON_WHITE
43
TPixel pix_threshold = 64;
44
#else
45
TPixel pix_threshold = 243;
46
#endif
47
 
48
 
49
// Global for testing!!!
50
static char st[50];
51
TIME before;
52
 
53
TDataObj sequence[N_FRAMES];
54
int top_frame = 0;
55
 
56
double dist, speed;
57
 
58
static TPixel *grabber_frame;
59
 
60
void put_frame(TPixel *frame)
61
{
62
    register int i,j,col,row;
63
 
64
    for (i=1; i<IMG_ROW-1; i++)
65
      for (j=0; j<IMG_COL; j++) {
66
        col = (j*(N_COL-1))/(IMG_COL-1);
67
        row = (i*(N_ROW-1))/(IMG_ROW-1);
68
        converted_image[i*IMG_COL+j] = gray_palette[*(frame+row*N_COL+col)];
69
      }
70
 
71
    for (j=0; j<IMG_COL; j++) {
72
      converted_image[j] = gray_palette[0];
73
      converted_image[(IMG_ROW-1)*IMG_COL+j] = gray_palette[0];
74
    }
75
 
76
    mutex_lock(&mutex);
77
    grx_putimage(IMG_X, IMG_Y, IMG_X+IMG_COL-1, IMG_Y+IMG_ROW-1,
78
                 (BYTE *)converted_image);
79
    mutex_unlock(&mutex);
80
}
81
 
82
 
83
TASK elab_image_TASK(void)
84
{
85
//  register int i, j;
86
  static unsigned int n_frame = 0;
87
  char found;
88
  int pred_x, pred_y;
89
 
90
  // Inizializzazione del task
91
  frameCAB = PXC_GetCab();
92
 
93
  while (1) {
94
    n_frame++;
95
    sprintf(st, "frame n. %5d", n_frame);
96
 
97
    mutex_lock(&mutex);
98
    grx_text(st, 400, 290, 255, 0);
99
    mutex_unlock(&mutex);
100
 
101
    // Acquisizione immagine corrente
102
    grabber_frame = cab_getmes(frameCAB);
103
 
104
    put_frame(grabber_frame);
105
 
106
    // Release CAB
107
    cab_unget(frameCAB, grabber_frame);
108
 
109
    task_endcycle();
110
  }
111
}
112
 
113
 
114
void start_listener(void);
115
 
116
void framegrabber_close(void *arg)
117
{
118
  PXC_Close();
119
}
120
 
121
void init_framegrabber(void)
122
{
123
  register int i;
124
  KEY_EVT my_key;
125
 
126
  // Aggiusta la palette
127
    for (i = 0; i < 256; i++)
128
      gray_palette[i] = rgb16(i,i,i);
129
 
130
  periodo = PXC_Initiate(3);
131
  PXC_CAB = PXC_GetCab();
132
 
133
  if (!periodo) {
134
    grx_close();
135
    cprintf("Problemi nell'inizializzazione del driver\n");
136
    sys_end();
137
  } else {
138
    start_listener();
139
  }
140
 
141
  sys_atrunlevel(framegrabber_close, NULL, RUNLEVEL_BEFORE_EXIT);
142
}
143
 
144
 
145
void start_listener(void)
146
{
147
  SOFT_TASK_MODEL m_soft;
148
 
149
  soft_task_default_model(m_soft);
150
  soft_task_def_met(m_soft,IMAGING_WCET);
151
  soft_task_def_usemath(m_soft);
152
  soft_task_def_aperiodic(m_soft);
153
  soft_task_def_period(m_soft,(periodo));
154
  soft_task_def_group(m_soft,1);
155
  soft_task_def_ctrl_jet(m_soft);
156
 
157
  image_elab_PID = task_create("imaging", elab_image_TASK, &m_soft, NULL);
158
 
159
/*  task_activate(  image_elab_PID);
160
  PXC_Push_Listener(image_elab_PID,2);
161
  PXC_Start();*/
162
}
163
 
164
void start_framegrabber()
165
{
166
  PXC_Push_Listener(image_elab_PID,1);
167
  PXC_Start();
168
}