Пример #1
0
static int trv_scale_input_pitch(FAR const struct ajoy_sample_s *sample)
{
  int tmp;
  b16_t pitch16;
  int pitch;

  trv_vdebug("  RAW: Y=%d\n", sample->as_y);

  tmp = sample->as_y - g_trv_joystick.centery;
  if ((g_trv_joystick.fplus && tmp >= 0) || (!g_trv_joystick.fplus && tmp < 0))
    {
       pitch16 = tmp * g_trv_joystick.uturnslope;
    }
  else
    {
       pitch16 = tmp * g_trv_joystick.dturnslope;
    }

  pitch = b16toi(pitch16 + b16HALF);
  trv_vdebug("  Calibrated: pitch=%d\n", pitch);
  return pitch;
}
Пример #2
0
static int trv_scale_input_yaw(FAR const struct ajoy_sample_s *sample)
{
  int tmp;
  b16_t yaw16;
  int yaw;

  trv_vdebug("  RAW: X=%d\n", sample->as_x);

  tmp = sample->as_x - g_trv_joystick.centerx;
  if ((g_trv_joystick.lplus && tmp >= 0) || (!g_trv_joystick.lplus && tmp < 0))
    {
       yaw16 = tmp * g_trv_joystick.lturnslope;
    }
  else
    {
       yaw16 = tmp * g_trv_joystick.rturnslope;
    }

  yaw = -b16toi(yaw16 + b16HALF);
  trv_vdebug("  Calibrated: pitch=%d\n", yaw);
  return yaw;
}
Пример #3
0
static int trv_scale_input_y(FAR const struct ajoy_sample_s *sample)
{
  int tmp;
  b16_t y16;
  int y;

  trv_vdebug("  RAW: Y=%d\n", sample->as_y);

  tmp = sample->as_y - g_trv_joystick.centery;
  if ((g_trv_joystick.fplus && tmp >= 0) || (!g_trv_joystick.fplus && tmp < 0))
    {
       y16 = tmp * g_trv_joystick.fwdslope;
    }
  else
    {
       y16 = tmp * g_trv_joystick.backslope;
    }

  y = b16toi(y16 + b16HALF);
  trv_vdebug("  Calibrated: Y=%d\n", y);
  return y;
}
Пример #4
0
static int trv_scale_input_x(FAR const struct ajoy_sample_s *sample)
{
  int tmp;
  b16_t x16;
  int x;

  trv_vdebug("  RAW: X=%d\n", sample->as_x);

  tmp = sample->as_x - g_trv_joystick.centerx;
  if ((g_trv_joystick.lplus && tmp >= 0) || (!g_trv_joystick.lplus && tmp < 0))
    {
       x16 = tmp * g_trv_joystick.leftslope;
    }
  else
    {
       x16 = tmp * g_trv_joystick.rightslope;
    }

  x = b16toi(x16 + b16HALF);

  trv_vdebug("  Calibrated: X=%d\n", x);
  return x;
}
int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo)
{
  int width;
  int height;
  int scale;

  /* Initialize the graphics device and get information about the display */

#if !defined(CONFIG_NX)
  trv_fb_initialize(ginfo);
#elif defined(CONFIG_NX_MULTIUSER)
  trv_nxmu_initialize(ginfo);
#else
  trv_nxsu_initialize(ginfo);
#endif

  /* Check the size of the display */

  width  = ginfo->xres;
  height = ginfo->yres;

  if (width < TRV_SCREEN_WIDTH || height < TRV_SCREEN_HEIGHT)
    {
      trv_abort("ERROR: Display is too small\n");
    }

  /* Check if we need to scale the image */

  scale = 0;

  while (width >= TRV_SCREEN_WIDTH)
    {
      width -= TRV_SCREEN_WIDTH;
      scale++;
    }

  ginfo->xscale   = scale;
  ginfo->xoffset  = (width >> 1);
  ginfo->imgwidth = scale * TRV_SCREEN_WIDTH * sizeof(dev_pixel_t);

  scale = 0;
  while (height >= TRV_SCREEN_HEIGHT)
    {
      height -= TRV_SCREEN_HEIGHT;
      scale++;
    }

  ginfo->yscale  = scale;
  ginfo->yoffset = (height >> 1);

  /* Allocate buffers
   *
   * ginfo->swbuffer - Software renders into this buffer using an 8-bit
   *   encoding and perhaps at a different resolution that the final
   *   image.
   */

   ginfo->swbuffer = (trv_pixel_t*)
     trv_malloc(TRV_SCREEN_WIDTH * TRV_SCREEN_HEIGHT * sizeof(trv_pixel_t));
   if (!ginfo->swbuffer)
     {
       trv_abort("ERROR: Failed to allocate render buffer\n");
     }

  /* Using the framebuffer driver:
   *   ginfo->hwbuffer - This address of the final, expanded frame image.
   *   This address is determined by hardware and is neither allocated
   *   nor freed.
   *
   * Using NX
   *   ginfo->hwbuffer - This address of one line of the final expanded
   *   image that must transferred to the window.
   */

#ifdef CONFIG_NX
   ginfo->hwbuffer = (trv_pixel_t*)trv_malloc(ginfo->imgwidth);
   if (!ginfo->hwbuffer)
     {
       trv_abort("ERROR: Failed to allocate hardware line buffer\n");
     }
#endif

  /* Allocate color mapping information */

  trv_color_allocate(&ginfo->palette);
  trv_vdebug("%d colors allocated\n", ginfo->palette.ncolors);
  return OK;
}