Subversion Repositories shark

Rev

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

// framegrabber stuffs

/* File name ......... : ELABOR.C
 * Project............ :
 * Object ............ :
 * Author ............ : Facchinetti Tullio
 * Language .......... : C
 * Compiler .......... : GNU C
 * Operative system .. : MS-DOS/HARTIK
 * Creation data ..... : 04/03/2000
 * Last modify ....... : 19/11/99
 */





#include <kernel/func.h>
#include <modules/cabs.h>
#include <stdio.h>
#include <drivers/pxc.h>
#include "demo.h"

PID image_elab_PID;
TIME periodo;
CAB PXC_CAB;

static CAB frameCAB; // CAB di deposito delle immagini
static TDataObj current, older;

// extern in INIT.C
int img_border    =  10;
int window_width  =  40;
int window_height =  40;

// a 256 grayscale palette
WORD gray_palette[256];

// the image to be putted on the screen
WORD converted_image[IMG_COL*IMG_ROW];


#ifdef __BLACK_ON_WHITE
TPixel pix_threshold = 64;
#else
TPixel pix_threshold = 243;
#endif


// Global for testing!!!
static char st[50];
TIME before;

TDataObj sequence[N_FRAMES];
int top_frame = 0;

double dist, speed;

static TPixel *grabber_frame;

void put_frame(TPixel *frame)
{
    register int i,j,col,row;

    for (i=1; i<IMG_ROW-1; i++)
      for (j=0; j<IMG_COL; j++) {
        col = (j*(N_COL-1))/(IMG_COL-1);
        row = (i*(N_ROW-1))/(IMG_ROW-1);
        converted_image[i*IMG_COL+j] = gray_palette[*(frame+row*N_COL+col)];
      }

    for (j=0; j<IMG_COL; j++) {
      converted_image[j] = gray_palette[0];
      converted_image[(IMG_ROW-1)*IMG_COL+j] = gray_palette[0];
    }

    mutex_lock(&mutex);
    grx_putimage(IMG_X, IMG_Y, IMG_X+IMG_COL-1, IMG_Y+IMG_ROW-1,
                 (BYTE *)converted_image);
    mutex_unlock(&mutex);
}


TASK elab_image_TASK(void)
{
//  register int i, j;
  static unsigned int n_frame = 0;
  char found;
  int pred_x, pred_y;

  // Inizializzazione del task
  frameCAB = PXC_GetCab();

  while (1) {
    n_frame++;
    sprintf(st, "frame n. %5d", n_frame);

    mutex_lock(&mutex);
    grx_text(st, 400, 290, 255, 0);
    mutex_unlock(&mutex);

    // Acquisizione immagine corrente
    grabber_frame = cab_getmes(frameCAB);

    put_frame(grabber_frame);

    // Release CAB
    cab_unget(frameCAB, grabber_frame);

    task_endcycle();
  }
}


void start_listener(void);

void framegrabber_close(void *arg)
{
  PXC_Close();
}

void init_framegrabber(void)
{
  register int i;
  KEY_EVT my_key;

  // Aggiusta la palette
    for (i = 0; i < 256; i++)
      gray_palette[i] = rgb16(i,i,i);

  periodo = PXC_Initiate(3);
  PXC_CAB = PXC_GetCab();

  if (!periodo) {
    grx_close();
    cprintf("Problemi nell'inizializzazione del driver\n");
    sys_end();
  } else {
    start_listener();
  }

  sys_atrunlevel(framegrabber_close, NULL, RUNLEVEL_BEFORE_EXIT);
}


void start_listener(void)
{
  SOFT_TASK_MODEL m_soft;

  soft_task_default_model(m_soft);
  soft_task_def_met(m_soft,IMAGING_WCET);
  soft_task_def_usemath(m_soft);
  soft_task_def_aperiodic(m_soft);
  soft_task_def_period(m_soft,(periodo));
  soft_task_def_group(m_soft,1);
  soft_task_def_ctrl_jet(m_soft);

  image_elab_PID = task_create("imaging", elab_image_TASK, &m_soft, NULL);

/*  task_activate(  image_elab_PID);
  PXC_Push_Listener(image_elab_PID,2);
  PXC_Start();*/

}

void start_framegrabber()
{
  PXC_Push_Listener(image_elab_PID,1);
  PXC_Start();
}